int main(string[] args) {
    var value = PhpefRuntimeCore.Zval.from_string("abcdef");
    var offset = PhpefRuntimeCore.Zval.from_int(1);
    var length = PhpefRuntimeCore.Zval.from_int(3);
    var result = PhpefRuntimeEmbed.phpfunc_substr(value, offset, length);
    if (result.kind != PhpefRuntimeCore.ValueKind.STRING || result.as_string() != "bcd") {
        stderr.printf("unexpected substr(abcdef, 1, 3) result: %s\n", result.to_php_string());
        return 1;
    }

    var tail = PhpefRuntimeEmbed.phpfunc_substr(value, offset);
    if (tail.kind != PhpefRuntimeCore.ValueKind.STRING || tail.as_string() != "bcdef") {
        stderr.printf("unexpected substr(abcdef, 1) result: %s\n", tail.to_php_string());
        return 1;
    }

    var trimmed = PhpefRuntimeEmbed.phpfunc_trim(PhpefRuntimeCore.Zval.from_string("  abc  "));
    if (trimmed.kind != PhpefRuntimeCore.ValueKind.STRING || trimmed.as_string() != "abc") {
        stderr.printf("unexpected trim result: %s\n", trimmed.to_php_string());
        return 1;
    }

    var char_trimmed = PhpefRuntimeEmbed.phpfunc_trim(PhpefRuntimeCore.Zval.from_string("xxabcxx"), PhpefRuntimeCore.Zval.from_string("x"));
    if (char_trimmed.kind != PhpefRuntimeCore.ValueKind.STRING || char_trimmed.as_string() != "abc") {
        stderr.printf("unexpected trim chars result: %s\n", char_trimmed.to_php_string());
        return 1;
    }

    var exists = PhpefRuntimeEmbed.phpfunc_zendcall_function_exists(PhpefRuntimeCore.Zval.from_string("strlen"));
    if (exists.kind != PhpefRuntimeCore.ValueKind.BOOL || !exists.as_bool()) {
        stderr.printf("unexpected function_exists(strlen) result: %s\n", exists.to_php_string());
        return 1;
    }

    var class_exists = PhpefRuntimeEmbed.phpfunc_zendcall_class_exists(PhpefRuntimeCore.Zval.from_string("stdClass"));
    if (class_exists.kind != PhpefRuntimeCore.ValueKind.BOOL || !class_exists.as_bool()) {
        stderr.printf("unexpected class_exists(stdClass) result: %s\n", class_exists.to_php_string());
        return 1;
    }

    var strlen_typed = PhpefRuntimeEmbed.phpfunc_strlen_typed_int_arg1_string("abcdef");
    if (strlen_typed != 6) {
        stderr.printf("unexpected typed strlen result\n");
        return 1;
    }

    var host_typed = PhpefRuntimeEmbed.phpfunc_gethostbyname_typed_string_arg1_string("localhost");
    if (host_typed == "") {
        stderr.printf("unexpected empty typed gethostbyname result\n");
        return 1;
    }


    var php_version_defined = PhpefRuntimeEmbed.phpfunc_zendcall_defined(PhpefRuntimeCore.Zval.from_string("PHP_VERSION"));
    if (php_version_defined.kind != PhpefRuntimeCore.ValueKind.BOOL || !php_version_defined.as_bool()) {
        stderr.printf("unexpected defined(PHP_VERSION) result: %s\n", php_version_defined.to_php_string());
        return 1;
    }

    return 0;
}
