/* Generated by Bux Compiler (LIR backend) */
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include <string.h>

typedef struct TaskHandle TaskHandle;
typedef struct Mutex Mutex;
typedef struct RwLock RwLock;
typedef struct JsonValue JsonValue;
typedef struct JsonParser JsonParser;
typedef struct StringBuilder StringBuilder;
typedef struct Channel_int Channel_int;
typedef struct Channel_float64 Channel_float64;

/* Extern function declarations */
extern void* bux_alloc(unsigned int size);
extern void* bux_realloc(void* ptr, unsigned int size);
extern void bux_free(void* ptr);
extern void bux_bounds_check(unsigned int index, unsigned int len);
extern void* bux_channel_new(int64_t capacity, int64_t elem_size);
extern void bux_channel_send(void* handle, void* elem);
extern int bux_channel_recv(void* handle, void* out);
extern void bux_channel_close(void* handle);
extern void bux_channel_free(void* handle);
extern int bux_dir_exists(const char* path);
extern int bux_mkdir_if_needed(const char* path);
extern const char** bux_list_dir(const char* dir, const char* ext, int* out_count);
extern void PrintLine(const char* s);
extern void Print(const char* s);
extern void PrintInt(int n);
extern void PrintInt64(int64_t n);
extern void PrintFloat(double f);
extern void PrintBool(bool b);
extern const char* ReadLine(void);
extern const char* bux_read_file(const char* path);
extern int bux_write_file(const char* path, const char* content);
extern int bux_file_exists(const char* path);
extern unsigned int bux_hash_bytes(void* ptr, unsigned int size);
extern unsigned int bux_hash_string(const char* s);
extern double bux_sqrt(double x);
extern double bux_pow(double x, double y);
extern int64_t bux_abs_i64(int64_t x);
extern double bux_abs_f64(double x);
extern int64_t bux_min_i64(int64_t a, int64_t b);
extern int64_t bux_max_i64(int64_t a, int64_t b);
extern double bux_min_f64(double a, double b);
extern double bux_max_f64(double a, double b);
extern void* bux_alloc(unsigned int size);
extern void* bux_realloc(void* ptr, unsigned int size);
extern void bux_free(void* ptr);
extern int bux_mem_eq(void* a, void* b, unsigned int size);
extern const char* bux_path_join(const char* a, const char* b);
extern const char* bux_path_parent(const char* path);
extern const char* bux_path_ext(const char* path);
extern unsigned int bux_hash_bytes(void* ptr, unsigned int size);
extern int bux_mem_eq(void* a, void* b, unsigned int size);
extern void* bux_alloc(unsigned int size);
extern void bux_free(void* ptr);
extern void* bux_task_spawn(void* fn, void* arg);
extern void bux_task_join(void* handle);
extern void bux_task_sleep(int64_t ms);
extern int bux_argc(void);
extern const char* bux_argv(int index);
extern const char* bux_getenv(const char* name);
extern int bux_setenv(const char* name, const char* value);
extern const char* bux_getcwd(void);
extern int bux_chdir(const char* path);
extern int64_t bux_time_ms(void);
extern int64_t bux_time_us(void);
extern void bux_sleep_ms(int64_t ms);
extern int bux_process_run(const char* cmd);
extern const char* bux_process_output(const char* cmd);
extern int bux_socket_create(void);
extern int bux_socket_reuse(int fd);
extern int bux_socket_bind(int fd, const char* addr, int port);
extern int bux_socket_listen(int fd, int backlog);
extern int bux_socket_accept(int fd);
extern int bux_socket_connect(int fd, const char* addr, int port);
extern int bux_socket_send(int fd, const char* data, int len);
extern const char* bux_socket_recv(int fd, int maxLen);
extern int bux_socket_close(int fd);
extern const char* bux_socket_error(void);
extern unsigned int bux_strlen(const char* s);
extern int64_t bux_str_to_int(const char* s);
extern void* bux_alloc(unsigned int size);
extern void bux_sha256(const char* data, int len, void* out);
extern void bux_hmac_sha256(const char* key, int keylen, const char* msg, int msglen, void* out);
extern int bux_random_bytes(void* buf, int len);
extern const char* bux_base64_encode(const char* data, int len);
extern const char* bux_base64_decode(const char* data, int len, int* outlen);
extern const char* bux_bytes_to_hex(void* data, int len);
extern void* bux_mutex_new(void);
extern void bux_mutex_lock(void* handle);
extern void bux_mutex_unlock(void* handle);
extern void bux_mutex_free(void* handle);
extern void* bux_rwlock_new(void);
extern void bux_rwlock_rdlock(void* handle);
extern void bux_rwlock_wrlock(void* handle);
extern void bux_rwlock_unlock(void* handle);
extern void bux_rwlock_free(void* handle);
extern void bux_exit(int code);
extern void bux_assert(int cond, const char* file, int line, const char* expr);
extern JsonValue JsonParser_ParseValue(JsonParser* p);
extern unsigned int bux_strlen(const char* s);
extern int bux_strcmp(const char* a, const char* b);
extern int bux_strncmp(const char* a, const char* b, unsigned int n);
extern char* bux_strcpy(char* dest, const char* src);
extern char* bux_strcat(char* dest, const char* src);
extern char* bux_strncpy(char* dest, const char* src, unsigned int n);
extern const char* bux_strstr(const char* haystack, const char* needle);
extern int bux_str_contains(const char* haystack, const char* needle);
extern unsigned int bux_str_offset(const char* pos, const char* base);
extern int bux_str_is_null(const char* s);
extern const char* bux_str_slice(const char* s, unsigned int start, unsigned int len);
extern const char* bux_str_trim_left(const char* s);
extern const char* bux_str_trim_right(const char* s);
extern const char* bux_str_trim(const char* s);
extern const char* bux_int_to_str(int64_t n);
extern int64_t bux_str_to_int(const char* s);
extern void* bux_sb_new(unsigned int initial_cap);
extern void bux_sb_append(void* sb, const char* s);
extern void bux_sb_append_int(void* sb, int64_t n);
extern void bux_sb_append_float(void* sb, double f);
extern void bux_sb_append_char(void* sb, char c);
extern const char* bux_sb_build(void* sb);
extern void bux_sb_free(void* sb);
extern unsigned int bux_str_split_count(const char* s, const char* delim);
extern const char* bux_str_split_part(const char* s, const char* delim, unsigned int index);
extern const char* bux_str_join2(const char* a, const char* b, const char* sep);
extern const char* bux_float_to_string(double f);
extern const char* bux_str_format(const char* pattern, const char* a0, const char* a1, const char* a2, const char* a3, const char* a4, const char* a5, const char* a6, const char* a7);
extern double bux_str_to_float(const char* s);
extern void bux_sha1(const char* data, int len, void* out);
extern void bux_sha256(const char* data, int len, void* out);
extern void bux_sha384(const char* data, int len, void* out);
extern void bux_sha512(const char* data, int len, void* out);
extern const char* bux_bytes_to_hex(void* data, int len);
extern const char* bux_base64_encode(const char* data, int len);
extern const char* bux_base64_decode(const char* data, int len, int* outlen);
extern const char* bux_base64url_encode(const char* data, int len);
extern const char* bux_base64url_decode(const char* data, int len, int* outlen);
extern void bux_hmac_sha256(const char* key, int keylen, const char* msg, int msglen, void* out);
extern void bux_hmac_sha384(const char* key, int keylen, const char* msg, int msglen, void* out);
extern void bux_hmac_sha512(const char* key, int keylen, const char* msg, int msglen, void* out);
extern const char* bux_bytes_to_hex(void* data, int len);
extern const char* bux_base64_encode(const char* data, int len);
extern int bux_random_bytes(void* buf, int len);
extern const char* bux_base64_encode(const char* data, int len);
extern const char* bux_bytes_to_hex(void* data, int len);
extern int bux_random_bytes(void* buf, int len);
extern const char* bux_aes_256_cbc_encrypt(const char* plain, int plainlen, const char* key, const char* iv, int* outlen);
extern const char* bux_aes_256_cbc_decrypt(const char* cipher, int cipherlen, const char* key, const char* iv, int* outlen);
extern const char* bux_aes_256_gcm_encrypt(const char* plain, int plainlen, const char* key, const char* iv, void* tag, int* outlen);
extern const char* bux_aes_256_gcm_decrypt(const char* cipher, int cipherlen, const char* key, const char* iv, const char* tag, int* outlen);
extern const char* bux_base64_encode(const char* data, int len);
extern unsigned int bux_str_split_count(const char* s, const char* delim);
extern const char* bux_str_split_part(const char* s, const char* delim, unsigned int index);
extern const char* bux_ecdsa_sign_p256(const char* key, int keylen, const char* data, int datalen, int* outlen);
extern int bux_ecdsa_verify_p256(const char* key, int keylen, const char* data, int datalen, const char* sig, int siglen);
extern const char* bux_ecdsa_sign_p384(const char* key, int keylen, const char* data, int datalen, int* outlen);
extern int bux_ecdsa_verify_p384(const char* key, int keylen, const char* data, int datalen, const char* sig, int siglen);
extern const char* bux_base64_encode(const char* data, int len);
extern const char* bux_base64_decode(const char* data, int len, int* outlen);
extern int bux_ed25519_keypair(void* pubKey, void* privKey);
extern int bux_ed25519_sign(const char* privKey, const char* data, int datalen, void* sig);
extern int bux_ed25519_verify(const char* pubKey, const char* sig, const char* data, int datalen);
extern const char* bux_base64_encode(const char* data, int len);
extern const char* bux_base64_decode(const char* data, int len, int* outlen);
extern const char* bux_rsa_sign_sha256(const char* key, int keylen, const char* data, int datalen, int* outlen);
extern const char* bux_rsa_sign_sha384(const char* key, int keylen, const char* data, int datalen, int* outlen);
extern const char* bux_rsa_sign_sha512(const char* key, int keylen, const char* data, int datalen, int* outlen);
extern int bux_rsa_verify_sha256(const char* key, int keylen, const char* data, int datalen, const char* sig, int siglen);
extern int bux_rsa_verify_sha384(const char* key, int keylen, const char* data, int datalen, const char* sig, int siglen);
extern int bux_rsa_verify_sha512(const char* key, int keylen, const char* data, int datalen, const char* sig, int siglen);
extern const char* bux_base64_encode(const char* data, int len);
extern const char* bux_base64_decode(const char* data, int len, int* outlen);

/* Constants */
#define JsonTagNull 0
#define JsonTagBool 1
#define JsonTagNumber 2
#define JsonTagString 3
#define JsonTagArray 4
#define JsonTagObject 5
#define AES_KEY_SIZE 32
#define AES_IV_SIZE 16
#define AES_GCM_TAG_SIZE 16
#define ED25519_PUBKEY_SIZE 32
#define ED25519_PRIVKEY_SIZE 32
#define ED25519_SIG_SIZE 64

typedef enum {
    Result_Ok,
    Result_Err
} Result_Tag;

typedef union {
    int Ok_0;
    const char* Err_0;
} Result_Data;

typedef struct {
    Result_Tag tag;
    Result_Data data;
} Result;

typedef enum {
    Option_Some,
    Option_None
} Option_Tag;

typedef union {
    int Some_0;
} Option_Data;

typedef struct {
    Option_Tag tag;
    Option_Data data;
} Option;

typedef enum {
    JwtAlg_HS256,
    JwtAlg_HS384,
    JwtAlg_HS512,
    JwtAlg_RS256,
    JwtAlg_RS384,
    JwtAlg_RS512,
    JwtAlg_ES256,
    JwtAlg_ES384,
    JwtAlg_EdDSA
} JwtAlg;


typedef struct TaskHandle {
    void* handle;
} TaskHandle;

typedef struct Mutex {
    void* handle;
} Mutex;

typedef struct RwLock {
    void* handle;
} RwLock;

typedef struct JsonValue {
    int tag;
    bool boolVal;
    double numVal;
    const char* strVal;
    JsonValue* arrData;
    unsigned int arrLen;
    unsigned int arrCap;
    const char** objKeys;
    JsonValue* objValues;
    unsigned int objLen;
    unsigned int objCap;
} JsonValue;

typedef struct JsonParser {
    const char* src;
    unsigned int pos;
    unsigned int len;
    const char* error;
} JsonParser;

typedef struct StringBuilder {
    void* handle;
} StringBuilder;

typedef struct Channel_int {
    void* handle;
} Channel_int;

typedef struct Channel_float64 {
    void* handle;
} Channel_float64;

void Channel_SendInt(Channel_int* ch, int value);
int Channel_RecvInt(Channel_int* ch);
void Channel_SendFloat64(Channel_float64* ch, double value);
double Channel_RecvFloat64(Channel_float64* ch);
bool DirExists(const char* path);
bool Mkdir(const char* path);
const char** ListDir(const char* dir, const char* ext, int* count);
const char* ReadFile(const char* path);
bool WriteFile(const char* path, const char* content);
bool FileExists(const char* path);
double Sqrt(double x);
double Pow(double x, double y);
int64_t Abs(int64_t n);
double AbsF(double f);
int64_t Min(int64_t a, int64_t b);
double MinF(double a, double b);
double MaxF(double a, double b);
void* Alloc(unsigned int size);
void* Realloc(void* ptr, unsigned int size);
void Free(void* ptr);
bool MemEq(void* a, void* b, unsigned int size);
const char* Path_Join(const char* a, const char* b);
const char* Path_Parent(const char* path);
const char* Path_Ext(const char* path);
TaskHandle Task_Spawn(void* fn, void* arg);
void Task_Join(TaskHandle t);
void Task_Sleep(int64_t ms);
int Os_ArgsCount(void);
const char* Os_Args(int index);
const char* Os_GetEnv(const char* name);
bool Os_SetEnv(const char* name, const char* value);
const char* Os_GetCwd(void);
bool Os_Chdir(const char* path);
int64_t Time_NowMs(void);
int64_t Time_NowUs(void);
void Time_SleepMs(int64_t ms);
int Process_Run(const char* cmd);
const char* Process_Output(const char* cmd);
int Net_Create(void);
bool Net_SetReuse(int fd);
bool Net_Bind(int fd, const char* addr, int port);
bool Net_Listen(int fd, int backlog);
int Net_Accept(int fd);
bool Net_Connect(int fd, const char* addr, int port);
int Net_Send(int fd, const char* data);
const char* Net_Recv(int fd, int maxLen);
bool Net_Close(int fd);
const char* Net_LastError(void);
const char* Fmt_Format(const char* tmpl, const char** argStrs, int argCount);
const char* Fmt_Fmt1(const char* tmpl, const char* a1);
const char* Fmt_FmtInt(const char* tmpl, int64_t val);
const char* Fmt_FmtBool(const char* tmpl, bool val);
const char* Fmt_FmtFloat(const char* tmpl, double val);
const char* Fmt_Fmt2(const char* tmpl, const char* a1, const char* a2);
const char* Fmt_Fmt3(const char* tmpl, const char* a1, const char* a2, const char* a3);
const char* Crypto_Sha256(const char* data);
const char* Crypto_HmacSha256(const char* key, const char* message);
const char* Crypto_RandomBytes(int n);
const char* Crypto_Base64Encode(const char* s);
const char* Crypto_HmacSha256Raw(const char* key, const char* message);
const char* Crypto_Base64Decode(const char* s);
Mutex Mutex_New(void);
void Mutex_Lock(Mutex* m);
void Mutex_Unlock(Mutex* m);
void Mutex_Free(Mutex* m);
RwLock RwLock_New(void);
void RwLock_ReadLock(RwLock* rw);
void RwLock_WriteLock(RwLock* rw);
void RwLock_Unlock(RwLock* rw);
void RwLock_Free(RwLock* rw);
void Test_Exit(int code);
void Test_Assert(bool cond);
void Test_AssertEqInt(int a, int b);
void Test_AssertTrue(bool cond);
void Test_AssertFalse(bool cond);
void Test_Fail(const char* msg);
Result Result_NewOk(int value);
Result Result_NewErr(const char* msg);
bool Result_IsOk(Result r);
bool Result_IsErr(Result r);
int Result_Unwrap(Result r);
int Result_UnwrapOr(Result r, int fallback);
Option Option_NewSome(int value);
Option Option_NewNone(void);
bool Option_IsSome(Option o);
bool Option_IsNone(Option o);
int Option_Unwrap(Option o);
int Option_UnwrapOr(Option o, int fallback);
JsonValue Json_Null(void);
JsonValue Json_Bool(bool b);
JsonValue Json_Number(double n);
JsonValue Json_String(const char* s);
JsonValue Json_Array(void);
JsonValue Json_Object(void);
unsigned int Json_ArrayLen(JsonValue v);
JsonValue Json_ArrayGet(JsonValue v, unsigned int index);
void Json_ArrayPush(JsonValue* self, JsonValue val);
unsigned int Json_ObjectLen(JsonValue v);
JsonValue Json_ObjectGet(JsonValue v, const char* key);
bool Json_ObjectHas(JsonValue v, const char* key);
void Json_ObjectSet(JsonValue* self, const char* key, JsonValue val);
bool Json_IsNull(JsonValue v);
bool Json_AsBool(JsonValue v);
double Json_AsNumber(JsonValue v);
const char* Json_AsString(JsonValue v);
int JsonParser_Peek(JsonParser* p);
void JsonParser_Advance(JsonParser* p);
void JsonParser_SkipWhitespace(JsonParser* p);
bool JsonParser_Match(JsonParser* p, const char* expected);
const char* JsonParser_ParseString(JsonParser* p);
JsonValue JsonParser_ParseNumber(JsonParser* p);
JsonValue JsonParser_ParseArray(JsonParser* p);
JsonValue JsonParser_ParseObject(JsonParser* p);
JsonValue JsonParser_ParseValue(JsonParser* p);
JsonValue Json_Parse(const char* s);
void Json_StringifyImpl(StringBuilder* sb, JsonValue v);
const char* Json_Stringify(JsonValue v);
unsigned int String_Len(const char* s);
bool String_IsNull(const char* s);
bool String_Eq(const char* a, const char* b);
const char* String_Concat(const char* a, const char* b);
const char* String_Copy(const char* s);
bool String_StartsWith(const char* s, const char* prefix);
bool String_EndsWith(const char* s, const char* suffix);
bool String_Contains(const char* s, const char* substr);
const char* String_Slice(const char* s, unsigned int start, unsigned int len);
const char* String_Trim(const char* s);
const char* String_TrimLeft(const char* s);
const char* String_TrimRight(const char* s);
const char* String_FromInt(int64_t n);
int64_t String_ToInt(const char* s);
StringBuilder StringBuilder_New(void);
StringBuilder StringBuilder_NewCap(unsigned int cap);
void StringBuilder_Append(StringBuilder* sb, const char* s);
void StringBuilder_AppendInt(StringBuilder* sb, int64_t n);
void StringBuilder_AppendFloat(StringBuilder* sb, double f);
void StringBuilder_AppendChar(StringBuilder* sb, char c);
const char* StringBuilder_Build(StringBuilder* sb);
void StringBuilder_Free(StringBuilder* sb);
unsigned int String_SplitCount(const char* s, const char* delim);
const char* String_SplitPart(const char* s, const char* delim, unsigned int index);
const char* String_Join2(const char* a, const char* b, const char* sep);
const char* String_Chars(const char* s, unsigned int index);
const char* String_Find(const char* haystack, const char* needle);
unsigned int String_Offset(const char* pos, const char* base);
const char* String_Replace(const char* s, const char* old, const char* new);
double String_ToFloat(const char* s);
const char* String_FromBool(bool b);
const char* String_FromFloat(double f);
const char* String_Format1(const char* pattern, const char* a0);
const char* String_Format2(const char* pattern, const char* a0, const char* a1);
const char* String_Format3(const char* pattern, const char* a0, const char* a1, const char* a2);
const char* Hash_Sha1(const char* data);
const char* Hash_Sha256(const char* data);
const char* Hash_Sha384(const char* data);
const char* Hash_Sha512(const char* data);
void Hash_Sha256Raw(const char* data, void* out);
void Hash_Sha384Raw(const char* data, void* out);
void Hash_Sha512Raw(const char* data, void* out);
int Hash_Sha1Size(void);
int Hash_Sha256Size(void);
int Hash_Sha384Size(void);
int Hash_Sha512Size(void);
const char* Base64_Encode(const char* s);
const char* Base64_Decode(const char* s);
const char* Base64URL_Encode(const char* s);
const char* Base64URL_Decode(const char* s);
const char* Hmac_Sha256(const char* key, const char* message);
void Hmac_Sha256Raw(const char* key, const char* message, void* out);
const char* Hmac_Sha256Base64(const char* key, const char* message);
const char* Hmac_Sha384(const char* key, const char* message);
void Hmac_Sha384Raw(const char* key, const char* message, void* out);
const char* Hmac_Sha384Base64(const char* key, const char* message);
const char* Hmac_Sha512(const char* key, const char* message);
void Hmac_Sha512Raw(const char* key, const char* message, void* out);
const char* Hmac_Sha512Base64(const char* key, const char* message);
const char* Random_Bytes(int n);
const char* Random_Hex(int n);
const char* Random_Base64(int n);
unsigned int Random_Uint32(void);
const char* Aes_GenerateKey(void);
const char* Aes_GenerateIV(void);
const char* Aes_CbcEncrypt(const char* plain, const char* key, const char* iv);
const char* Aes_CbcDecrypt(const char* cipher, const char* key, const char* iv);
const char* Aes_GcmEncrypt(const char* plain, const char* key, const char* iv, void* tag);
const char* Aes_GcmDecrypt(const char* cipher, const char* key, const char* iv, const char* tag);
const char* Jwt_MakeHeader(JwtAlg alg);
const char* Jwt_Sign(JwtAlg alg, const char* signingInput, const char* key);
bool Jwt_Verify(JwtAlg alg, const char* signingInput, const char* signatureB64, const char* key);
const char* Jwt_Encode(const char* headerJson, const char* payloadJson, JwtAlg alg, const char* key);
bool Jwt_Decode(const char* token, JwtAlg alg, const char* key, const char** headerOut, const char** payloadOut);
const char* Jwt_EncodeHS256(const char* payloadJson, const char* secret);
const char* Jwt_EncodeHS384(const char* payloadJson, const char* secret);
const char* Jwt_EncodeHS512(const char* payloadJson, const char* secret);
const char* Jwt_EncodeRS256(const char* payloadJson, const char* pemPrivateKey);
const char* Jwt_EncodeES256(const char* payloadJson, const char* pemPrivateKey);
const char* Jwt_EncodeEdDSA(const char* payloadJson, const char* rawPrivKey);
const char* Ecdsa_SignP256(const char* pemPrivateKey, const char* data);
const char* Ecdsa_SignP256Base64(const char* pemPrivateKey, const char* data);
bool Ecdsa_VerifyP256(const char* pemPublicKey, const char* data, const char* signature);
bool Ecdsa_VerifyP256Base64(const char* pemPublicKey, const char* data, const char* signatureB64);
const char* Ecdsa_SignP384(const char* pemPrivateKey, const char* data);
const char* Ecdsa_SignP384Base64(const char* pemPrivateKey, const char* data);
bool Ecdsa_VerifyP384(const char* pemPublicKey, const char* data, const char* signature);
bool Ecdsa_VerifyP384Base64(const char* pemPublicKey, const char* data, const char* signatureB64);
bool Ed25519_Keypair(void* pubKey, void* privKey);
const char* Ed25519_KeypairBase64(void);
const char* Ed25519_Sign(const char* privKey, const char* data);
const char* Ed25519_SignBase64(const char* privKey, const char* data);
bool Ed25519_Verify(const char* pubKey, const char* signature, const char* data);
bool Ed25519_VerifyBase64(const char* pubKey, const char* signatureB64, const char* data);
const char* Rsa_SignSha256(const char* pemPrivateKey, const char* data);
const char* Rsa_SignSha384(const char* pemPrivateKey, const char* data);
const char* Rsa_SignSha512(const char* pemPrivateKey, const char* data);
const char* Rsa_SignSha256Base64(const char* pemPrivateKey, const char* data);
const char* Rsa_SignSha384Base64(const char* pemPrivateKey, const char* data);
const char* Rsa_SignSha512Base64(const char* pemPrivateKey, const char* data);
bool Rsa_VerifySha256(const char* pemPublicKey, const char* data, const char* signature);
bool Rsa_VerifySha384(const char* pemPublicKey, const char* data, const char* signature);
bool Rsa_VerifySha512(const char* pemPublicKey, const char* data, const char* signature);
bool Rsa_VerifySha256Base64(const char* pemPublicKey, const char* data, const char* signatureB64);
bool Rsa_VerifySha384Base64(const char* pemPublicKey, const char* data, const char* signatureB64);
bool Rsa_VerifySha512Base64(const char* pemPublicKey, const char* data, const char* signatureB64);
int Main(void);
int Max_int(int a, int b);

void Channel_SendInt(Channel_int* ch, int value) {
    void* _t2;
    void* _t3;
    void* _t1;
    _t1 = ch->handle;
    _t2 = &value;
    _t3 = (void*)_t2;
    bux_channel_send(_t1, _t3);
}

int Channel_RecvInt(Channel_int* ch) {
    void* _t5;
    void* _t6;
    int result;
    result = 0;
    void* _t4;
    _t4 = ch->handle;
    _t5 = &result;
    _t6 = (void*)_t5;
    bux_channel_recv(_t4, _t6);
    return result;
}

void Channel_SendFloat64(Channel_float64* ch, double value) {
    void* _t8;
    void* _t9;
    void* _t7;
    _t7 = ch->handle;
    _t8 = &value;
    _t9 = (void*)_t8;
    bux_channel_send(_t7, _t9);
}

double Channel_RecvFloat64(Channel_float64* ch) {
    void* _t11;
    void* _t12;
    double result;
    result = 0.0;
    void* _t10;
    _t10 = ch->handle;
    _t11 = &result;
    _t12 = (void*)_t11;
    bux_channel_recv(_t10, _t12);
    return result;
}

bool DirExists(const char* path) {
    int _t14;
    int _t13;
    _t13 = bux_dir_exists(path);
    _t14 = (_t13 != 0);
    return _t14;
}

bool Mkdir(const char* path) {
    int _t16;
    int _t15;
    _t15 = bux_mkdir_if_needed(path);
    _t16 = (_t15 != 0);
    return _t16;
}

const char** ListDir(const char* dir, const char* ext, int* count) {
    const char** _t17;
    _t17 = bux_list_dir(dir, ext, count);
    return _t17;
}

const char* ReadFile(const char* path) {
    const char* _t18;
    _t18 = bux_read_file(path);
    return _t18;
}

bool WriteFile(const char* path, const char* content) {
    int _t20;
    int r;
    int _t19;
    _t19 = bux_write_file(path, content);
    r = _t19;
    _t20 = (r != 0);
    return _t20;
}

bool FileExists(const char* path) {
    int _t22;
    int r;
    int _t21;
    _t21 = bux_file_exists(path);
    r = _t21;
    _t22 = (r != 0);
    return _t22;
}

double Sqrt(double x) {
    double _t23;
    _t23 = bux_sqrt(x);
    return _t23;
}

double Pow(double x, double y) {
    double _t24;
    _t24 = bux_pow(x, y);
    return _t24;
}

int64_t Abs(int64_t n) {
    int64_t _t25;
    _t25 = bux_abs_i64(n);
    return _t25;
}

double AbsF(double f) {
    double _t26;
    _t26 = bux_abs_f64(f);
    return _t26;
}

int64_t Min(int64_t a, int64_t b) {
    int64_t _t27;
    _t27 = bux_min_i64(a, b);
    return _t27;
}

double MinF(double a, double b) {
    double _t28;
    _t28 = bux_min_f64(a, b);
    return _t28;
}

double MaxF(double a, double b) {
    double _t29;
    _t29 = bux_max_f64(a, b);
    return _t29;
}

void* Alloc(unsigned int size) {
    void* _t30;
    _t30 = bux_alloc(size);
    return _t30;
}

void* Realloc(void* ptr, unsigned int size) {
    void* _t31;
    _t31 = bux_realloc(ptr, size);
    return _t31;
}

void Free(void* ptr) {
    bux_free(ptr);
}

bool MemEq(void* a, void* b, unsigned int size) {
    int _t33;
    int _t32;
    _t32 = bux_mem_eq(a, b, size);
    _t33 = (_t32 != 0);
    return _t33;
}

const char* Path_Join(const char* a, const char* b) {
    const char* _t34;
    _t34 = bux_path_join(a, b);
    return _t34;
}

const char* Path_Parent(const char* path) {
    const char* _t35;
    _t35 = bux_path_parent(path);
    return _t35;
}

const char* Path_Ext(const char* path) {
    const char* _t36;
    _t36 = bux_path_ext(path);
    return _t36;
}

TaskHandle Task_Spawn(void* fn, void* arg) {
    TaskHandle _t38;
    void* _t37;
    _t37 = bux_task_spawn(fn, arg);
    _t38 = (TaskHandle){.handle = _t37};
    return _t38;
}

void Task_Join(TaskHandle t) {
    void* _t39;
    _t39 = t.handle;
    bux_task_join(_t39);
}

void Task_Sleep(int64_t ms) {
    bux_task_sleep(ms);
}

int Os_ArgsCount(void) {
    int _t40;
    _t40 = bux_argc();
    return _t40;
}

const char* Os_Args(int index) {
    const char* _t41;
    _t41 = bux_argv(index);
    return _t41;
}

const char* Os_GetEnv(const char* name) {
    const char* _t42;
    _t42 = bux_getenv(name);
    return _t42;
}

bool Os_SetEnv(const char* name, const char* value) {
    int _t44;
    int _t43;
    _t43 = bux_setenv(name, value);
    _t44 = (_t43 == 0);
    return _t44;
}

const char* Os_GetCwd(void) {
    const char* _t45;
    _t45 = bux_getcwd();
    return _t45;
}

bool Os_Chdir(const char* path) {
    int _t47;
    int _t46;
    _t46 = bux_chdir(path);
    _t47 = (_t46 == 0);
    return _t47;
}

int64_t Time_NowMs(void) {
    int64_t _t48;
    _t48 = bux_time_ms();
    return _t48;
}

int64_t Time_NowUs(void) {
    int64_t _t49;
    _t49 = bux_time_us();
    return _t49;
}

void Time_SleepMs(int64_t ms) {
    bux_sleep_ms(ms);
}

int Process_Run(const char* cmd) {
    int _t50;
    _t50 = bux_process_run(cmd);
    return _t50;
}

const char* Process_Output(const char* cmd) {
    const char* _t51;
    _t51 = bux_process_output(cmd);
    return _t51;
}

int Net_Create(void) {
    int _t52;
    _t52 = bux_socket_create();
    return _t52;
}

bool Net_SetReuse(int fd) {
    int _t54;
    int _t53;
    _t53 = bux_socket_reuse(fd);
    _t54 = (_t53 == 0);
    return _t54;
}

bool Net_Bind(int fd, const char* addr, int port) {
    int _t56;
    int _t55;
    _t55 = bux_socket_bind(fd, addr, port);
    _t56 = (_t55 == 0);
    return _t56;
}

bool Net_Listen(int fd, int backlog) {
    int _t58;
    int _t57;
    _t57 = bux_socket_listen(fd, backlog);
    _t58 = (_t57 == 0);
    return _t58;
}

int Net_Accept(int fd) {
    int _t59;
    _t59 = bux_socket_accept(fd);
    return _t59;
}

bool Net_Connect(int fd, const char* addr, int port) {
    int _t61;
    int _t60;
    _t60 = bux_socket_connect(fd, addr, port);
    _t61 = (_t60 == 0);
    return _t61;
}

int Net_Send(int fd, const char* data) {
    int _t63;
    unsigned int _t62;
    _t62 = bux_strlen(data);
    _t63 = (int)_t62;
    int _t64;
    _t64 = bux_socket_send(fd, data, _t63);
    return _t64;
}

const char* Net_Recv(int fd, int maxLen) {
    const char* _t65;
    _t65 = bux_socket_recv(fd, maxLen);
    return _t65;
}

bool Net_Close(int fd) {
    int _t67;
    int _t66;
    _t66 = bux_socket_close(fd);
    _t67 = (_t66 == 0);
    return _t67;
}

const char* Net_LastError(void) {
    const char* _t68;
    _t68 = bux_socket_error();
    return _t68;
}

const char* Fmt_Format(const char* tmpl, const char** argStrs, int argCount) {
    int _t71;
    int _t74;
    int _t75;
    int _t78;
    int64_t _t79;
    int _t80;
    int _t82;
    int _t83;
    int _t86;
    unsigned int _t87;
    void* _t89;
    void* _t90;
    int _t91;
    void* _t92;
    StringBuilder sb;
    StringBuilder _t69;
    _t69 = StringBuilder_New();
    sb = _t69;
    unsigned int i;
    i = 0;
    unsigned int tmplLen;
    unsigned int _t70;
    _t70 = bux_strlen(tmpl);
    tmplLen = _t70;
    while1:;
    _t71 = (i < tmplLen);
    if (!_t71) goto wend3;
    {
    const char* ch;
    const char* _t72;
    _t72 = String_Chars(tmpl, i);
    ch = _t72;
    bool _t73;
    _t73 = String_Eq(ch, "{");
    if (!_t73) goto endif5;
    {
    unsigned int digitIdx;
    _t74 = i + 1;
    digitIdx = _t74;
    _t75 = (digitIdx < tmplLen);
    if (!_t75) goto endif7;
    {
    const char* digitCh;
    const char* _t76;
    _t76 = String_Chars(tmpl, digitIdx);
    digitCh = _t76;
    int64_t d;
    int64_t _t77;
    _t77 = bux_str_to_int(digitCh);
    d = _t77;
    bool __and_tmp_0;
    _t78 = (d >= 0);
    if (!_t78) goto else8;
    _t79 = (int64_t)argCount;
    _t80 = (d < _t79);
    *(bool*)&__and_tmp_0 = _t80;
    goto endif9;
    else8:;
    *(bool*)&__and_tmp_0 = 0;
    endif9:;
    bool _t81;
    _t81 = *(bool*)&__and_tmp_0;
    if (!_t81) goto endif11;
    {
    _t82 = i + 2;
    i = _t82;
    _t83 = (i < tmplLen);
    if (!_t83) goto endif13;
    {
    const char* closeCh;
    const char* _t84;
    _t84 = String_Chars(tmpl, i);
    closeCh = _t84;
    bool _t85;
    _t85 = String_Eq(closeCh, "}");
    if (!_t85) goto endif15;
    {
    _t86 = i + 1;
    i = _t86;
    const char* argStr;
    _t87 = (unsigned int)d;
    const char* _t88;
    _t88 = argStrs[_t87];
    argStr = _t88;
    _t89 = &sb;
    StringBuilder_Append(_t89, argStr);
    goto while1;
    }
    endif15:;
    }
    endif13:;
    }
    endif11:;
    }
    endif7:;
    }
    endif5:;
    _t90 = &sb;
    StringBuilder_Append(_t90, ch);
    _t91 = i + 1;
    i = _t91;
    }
    goto while1;
    wend3:;
    _t92 = &sb;
    const char* _t93;
    _t93 = StringBuilder_Build(_t92);
    return _t93;
}

const char* Fmt_Fmt1(const char* tmpl, const char* a1) {
    const char** _t96;
    const char** args;
    /* sizeof(const char*) */
    void* _t95;
    _t95 = bux_alloc(sizeof(const char*));
    _t96 = (const char**)_t95;
    args = _t96;
    args[0] = a1;
    const char* _t97;
    _t97 = Fmt_Format(tmpl, args, 1);
    return _t97;
}

const char* Fmt_FmtInt(const char* tmpl, int64_t val) {
    const char* s;
    const char* _t98;
    _t98 = String_FromInt(val);
    s = _t98;
    const char* _t99;
    _t99 = Fmt_Fmt1(tmpl, s);
    return _t99;
}

const char* Fmt_FmtBool(const char* tmpl, bool val) {
    const char* s;
    const char* _t100;
    _t100 = String_FromBool(val);
    s = _t100;
    const char* _t101;
    _t101 = Fmt_Fmt1(tmpl, s);
    return _t101;
}

const char* Fmt_FmtFloat(const char* tmpl, double val) {
    const char* s;
    const char* _t102;
    _t102 = String_FromFloat(val);
    s = _t102;
    const char* _t103;
    _t103 = Fmt_Fmt1(tmpl, s);
    return _t103;
}

const char* Fmt_Fmt2(const char* tmpl, const char* a1, const char* a2) {
    int _t105;
    const char** _t107;
    const char** args;
    /* sizeof(const char*) */
    _t105 = 2 * sizeof(const char*);
    void* _t106;
    _t106 = bux_alloc(_t105);
    _t107 = (const char**)_t106;
    args = _t107;
    args[0] = a1;
    args[1] = a2;
    const char* _t108;
    _t108 = Fmt_Format(tmpl, args, 2);
    return _t108;
}

const char* Fmt_Fmt3(const char* tmpl, const char* a1, const char* a2, const char* a3) {
    int _t110;
    const char** _t112;
    const char** args;
    /* sizeof(const char*) */
    _t110 = 3 * sizeof(const char*);
    void* _t111;
    _t111 = bux_alloc(_t110);
    _t112 = (const char**)_t111;
    args = _t112;
    args[0] = a1;
    args[1] = a2;
    args[2] = a3;
    const char* _t113;
    _t113 = Fmt_Format(tmpl, args, 3);
    return _t113;
}

const char* Crypto_Sha256(const char* data) {
    int _t115;
    void* _t117;
    int len;
    unsigned int _t114;
    _t114 = String_Len(data);
    _t115 = (int)_t114;
    len = _t115;
    void* hashBuf;
    void* _t116;
    _t116 = Alloc(32);
    hashBuf = _t116;
    bux_sha256(data, len, hashBuf);
    const char* result;
    _t117 = (void*)hashBuf;
    const char* _t118;
    _t118 = bux_bytes_to_hex(_t117, 32);
    result = _t118;
    Free(hashBuf);
    return result;
}

const char* Crypto_HmacSha256(const char* key, const char* message) {
    int _t120;
    int _t122;
    void* _t124;
    int keylen;
    unsigned int _t119;
    _t119 = String_Len(key);
    _t120 = (int)_t119;
    keylen = _t120;
    int msglen;
    unsigned int _t121;
    _t121 = String_Len(message);
    _t122 = (int)_t121;
    msglen = _t122;
    void* hmacBuf;
    void* _t123;
    _t123 = Alloc(32);
    hmacBuf = _t123;
    bux_hmac_sha256(key, keylen, message, msglen, hmacBuf);
    const char* result;
    _t124 = (void*)hmacBuf;
    const char* _t125;
    _t125 = bux_bytes_to_hex(_t124, 32);
    result = _t125;
    Free(hmacBuf);
    return result;
}

const char* Crypto_RandomBytes(int n) {
    int _t126;
    unsigned int _t127;
    int _t130;
    const char* _t131;
    _t126 = (n <= 0);
    if (!_t126) goto endif17;
    {
    return "";
    }
    endif17:;
    void* buf;
    _t127 = (unsigned int)n;
    void* _t128;
    _t128 = Alloc(_t127);
    buf = _t128;
    int _t129;
    _t129 = bux_random_bytes(buf, n);
    _t130 = (_t129 != 1);
    if (!_t130) goto endif19;
    {
    Free(buf);
    return "";
    }
    endif19:;
    const char* result;
    _t131 = (const char*)buf;
    const char* _t132;
    _t132 = bux_base64_encode(_t131, n);
    result = _t132;
    Free(buf);
    return result;
}

const char* Crypto_Base64Encode(const char* s) {
    int _t134;
    unsigned int _t133;
    _t133 = String_Len(s);
    _t134 = (int)_t133;
    const char* _t135;
    _t135 = bux_base64_encode(s, _t134);
    return _t135;
}

const char* Crypto_HmacSha256Raw(const char* key, const char* message) {
    int _t137;
    int _t139;
    const char* _t141;
    int keylen;
    unsigned int _t136;
    _t136 = String_Len(key);
    _t137 = (int)_t136;
    keylen = _t137;
    int msglen;
    unsigned int _t138;
    _t138 = String_Len(message);
    _t139 = (int)_t138;
    msglen = _t139;
    void* hmacBuf;
    void* _t140;
    _t140 = Alloc(32);
    hmacBuf = _t140;
    bux_hmac_sha256(key, keylen, message, msglen, hmacBuf);
    const char* result;
    _t141 = (const char*)hmacBuf;
    const char* _t142;
    _t142 = bux_base64_encode(_t141, 32);
    result = _t142;
    Free(hmacBuf);
    return result;
}

const char* Crypto_Base64Decode(const char* s) {
    int _t144;
    void* _t145;
    int outlen;
    outlen = 0;
    unsigned int _t143;
    _t143 = String_Len(s);
    _t144 = (int)_t143;
    _t145 = &outlen;
    const char* _t146;
    _t146 = bux_base64_decode(s, _t144, _t145);
    return _t146;
}

Mutex Mutex_New(void) {
    Mutex _t148;
    void* _t147;
    _t147 = bux_mutex_new();
    _t148 = (Mutex){.handle = _t147};
    return _t148;
}

void Mutex_Lock(Mutex* m) {
    void* _t149;
    _t149 = m->handle;
    bux_mutex_lock(_t149);
}

void Mutex_Unlock(Mutex* m) {
    void* _t150;
    _t150 = m->handle;
    bux_mutex_unlock(_t150);
}

void Mutex_Free(Mutex* m) {
    void* _t151;
    _t151 = m->handle;
    bux_mutex_free(_t151);
}

RwLock RwLock_New(void) {
    RwLock _t153;
    void* _t152;
    _t152 = bux_rwlock_new();
    _t153 = (RwLock){.handle = _t152};
    return _t153;
}

void RwLock_ReadLock(RwLock* rw) {
    void* _t154;
    _t154 = rw->handle;
    bux_rwlock_rdlock(_t154);
}

void RwLock_WriteLock(RwLock* rw) {
    void* _t155;
    _t155 = rw->handle;
    bux_rwlock_wrlock(_t155);
}

void RwLock_Unlock(RwLock* rw) {
    void* _t156;
    _t156 = rw->handle;
    bux_rwlock_unlock(_t156);
}

void RwLock_Free(RwLock* rw) {
    void* _t157;
    _t157 = rw->handle;
    bux_rwlock_free(_t157);
}

void Test_Exit(int code) {
    bux_exit(code);
}

void Test_Assert(bool cond) {
    int _t158;
    _t158 = (int)cond;
    bux_assert(_t158, "", 0, "");
}

void Test_AssertEqInt(int a, int b) {
    int _t159;
    _t159 = (a != b);
    if (!_t159) goto endif21;
    {
    PrintLine("ASSERT_EQ FAILED:");
    PrintInt(a);
    PrintLine(" != ");
    PrintInt(b);
    bux_exit(1);
    }
    endif21:;
}

void Test_AssertTrue(bool cond) {
    int _t160;
    _t160 = !cond;
    if (!_t160) goto endif23;
    {
    PrintLine("ASSERT_TRUE FAILED");
    bux_exit(1);
    }
    endif23:;
}

void Test_AssertFalse(bool cond) {
    if (!cond) goto endif25;
    {
    PrintLine("ASSERT_FALSE FAILED");
    bux_exit(1);
    }
    endif25:;
}

void Test_Fail(const char* msg) {
    PrintLine("FAIL:");
    PrintLine(msg);
    bux_exit(1);
}

Result Result_NewOk(int value) {
    Result _t161;
    Result r;
    _t161 = (Result){.tag = Result_Ok};
    r = _t161;
    r.data.Ok_0 = value;
    return r;
}

Result Result_NewErr(const char* msg) {
    Result _t162;
    Result r;
    _t162 = (Result){.tag = Result_Err};
    r = _t162;
    r.data.Err_0 = msg;
    return r;
}

bool Result_IsOk(Result r) {
    int _t164;
    Result_Tag _t163;
    _t163 = r.tag;
    _t164 = (_t163 == Result_Ok);
    return _t164;
}

bool Result_IsErr(Result r) {
    int _t166;
    Result_Tag _t165;
    _t165 = r.tag;
    _t166 = (_t165 == Result_Err);
    return _t166;
}

int Result_Unwrap(Result r) {
    int _t168;
    Result_Tag _t167;
    _t167 = r.tag;
    _t168 = (_t167 != Result_Ok);
    if (!_t168) goto endif27;
    {
    PrintLine("panic: unwrap on Err");
    return 0;
    }
    endif27:;
    Result_Data _t169;
    _t169 = r.data;
    int _t170;
    _t170 = _t169.Ok_0;
    return _t170;
}

int Result_UnwrapOr(Result r, int fallback) {
    int _t172;
    Result_Tag _t171;
    _t171 = r.tag;
    _t172 = (_t171 == Result_Ok);
    if (!_t172) goto endif29;
    {
    Result_Data _t173;
    _t173 = r.data;
    int _t174;
    _t174 = _t173.Ok_0;
    return _t174;
    }
    endif29:;
    return fallback;
}

Option Option_NewSome(int value) {
    Option _t175;
    Option o;
    _t175 = (Option){.tag = Option_Some};
    o = _t175;
    o.data.Some_0 = value;
    return o;
}

Option Option_NewNone(void) {
    Option _t176;
    _t176 = (Option){.tag = Option_None};
    return _t176;
}

bool Option_IsSome(Option o) {
    int _t178;
    Option_Tag _t177;
    _t177 = o.tag;
    _t178 = (_t177 == Option_Some);
    return _t178;
}

bool Option_IsNone(Option o) {
    int _t180;
    Option_Tag _t179;
    _t179 = o.tag;
    _t180 = (_t179 == Option_None);
    return _t180;
}

int Option_Unwrap(Option o) {
    int _t182;
    Option_Tag _t181;
    _t181 = o.tag;
    _t182 = (_t181 != Option_Some);
    if (!_t182) goto endif31;
    {
    PrintLine("panic: unwrap on None");
    return 0;
    }
    endif31:;
    Option_Data _t183;
    _t183 = o.data;
    int _t184;
    _t184 = _t183.Some_0;
    return _t184;
}

int Option_UnwrapOr(Option o, int fallback) {
    int _t186;
    Option_Tag _t185;
    _t185 = o.tag;
    _t186 = (_t185 == Option_Some);
    if (!_t186) goto endif33;
    {
    Option_Data _t187;
    _t187 = o.data;
    int _t188;
    _t188 = _t187.Some_0;
    return _t188;
    }
    endif33:;
    return fallback;
}

JsonValue Json_Null(void) {
    JsonValue _t189;
    _t189 = (JsonValue){.tag = JsonTagNull, .boolVal = 0, .numVal = 0.0, .strVal = "", .arrData = 0, .arrLen = 0, .arrCap = 0, .objKeys = 0, .objValues = 0, .objLen = 0, .objCap = 0};
    return _t189;
}

JsonValue Json_Bool(bool b) {
    JsonValue _t190;
    _t190 = (JsonValue){.tag = JsonTagBool, .boolVal = b, .numVal = 0.0, .strVal = "", .arrData = 0, .arrLen = 0, .arrCap = 0, .objKeys = 0, .objValues = 0, .objLen = 0, .objCap = 0};
    return _t190;
}

JsonValue Json_Number(double n) {
    JsonValue _t191;
    _t191 = (JsonValue){.tag = JsonTagNumber, .boolVal = 0, .numVal = n, .strVal = "", .arrData = 0, .arrLen = 0, .arrCap = 0, .objKeys = 0, .objValues = 0, .objLen = 0, .objCap = 0};
    return _t191;
}

JsonValue Json_String(const char* s) {
    JsonValue _t192;
    _t192 = (JsonValue){.tag = JsonTagString, .boolVal = 0, .numVal = 0.0, .strVal = s, .arrData = 0, .arrLen = 0, .arrCap = 0, .objKeys = 0, .objValues = 0, .objLen = 0, .objCap = 0};
    return _t192;
}

JsonValue Json_Array(void) {
    JsonValue _t193;
    _t193 = (JsonValue){.tag = JsonTagArray, .boolVal = 0, .numVal = 0.0, .strVal = "", .arrData = 0, .arrLen = 0, .arrCap = 0, .objKeys = 0, .objValues = 0, .objLen = 0, .objCap = 0};
    return _t193;
}

JsonValue Json_Object(void) {
    JsonValue _t194;
    _t194 = (JsonValue){.tag = JsonTagObject, .boolVal = 0, .numVal = 0.0, .strVal = "", .arrData = 0, .arrLen = 0, .arrCap = 0, .objKeys = 0, .objValues = 0, .objLen = 0, .objCap = 0};
    return _t194;
}

unsigned int Json_ArrayLen(JsonValue v) {
    int _t196;
    int _t195;
    _t195 = v.tag;
    _t196 = (_t195 != JsonTagArray);
    if (!_t196) goto endif35;
    {
    return 0;
    }
    endif35:;
    unsigned int _t197;
    _t197 = v.arrLen;
    return _t197;
}

JsonValue Json_ArrayGet(JsonValue v, unsigned int index) {
    int _t199;
    int _t202;
    int _t198;
    _t198 = v.tag;
    _t199 = (_t198 != JsonTagArray);
    if (!_t199) goto endif37;
    {
    JsonValue _t200;
    _t200 = Json_Null();
    return _t200;
    }
    endif37:;
    unsigned int _t201;
    _t201 = v.arrLen;
    _t202 = (index >= _t201);
    if (!_t202) goto endif39;
    {
    JsonValue _t203;
    _t203 = Json_Null();
    return _t203;
    }
    endif39:;
    JsonValue* _t204;
    _t204 = v.arrData;
    JsonValue _t205;
    _t205 = _t204[index];
    return _t205;
}

void Json_ArrayPush(JsonValue* self, JsonValue val) {
    int _t207;
    int _t210;
    int _t212;
    int _t214;
    JsonValue* _t216;
    int _t217;
    void* _t219;
    int _t221;
    JsonValue* _t223;
    int _t227;
    int _t206;
    _t206 = self->tag;
    _t207 = (_t206 != JsonTagArray);
    if (!_t207) goto endif41;
    {
    return;
    }
    endif41:;
    unsigned int _t208;
    _t208 = self->arrLen;
    unsigned int _t209;
    _t209 = self->arrCap;
    _t210 = (_t208 >= _t209);
    if (!_t210) goto endif43;
    {
    unsigned int arrNewCap;
    unsigned int _t211;
    _t211 = self->arrCap;
    arrNewCap = _t211;
    _t212 = (arrNewCap == 0);
    if (!_t212) goto else44;
    {
    self->arrCap = 4;
    /* sizeof(JsonValue) */
    _t214 = 4 * sizeof(JsonValue);
    void* _t215;
    _t215 = Alloc(_t214);
    _t216 = (JsonValue*)_t215;
    self->arrData = _t216;
    }
    goto endif45;
    else44:;
    {
    unsigned int doubleCap;
    _t217 = arrNewCap * 2;
    doubleCap = _t217;
    self->arrCap = doubleCap;
    JsonValue* _t218;
    _t218 = self->arrData;
    _t219 = (void*)_t218;
    /* sizeof(JsonValue) */
    _t221 = doubleCap * sizeof(JsonValue);
    void* _t222;
    _t222 = Realloc(_t219, _t221);
    _t223 = (JsonValue*)_t222;
    self->arrData = _t223;
    }
    endif45:;
    }
    endif43:;
    JsonValue* _t224;
    _t224 = self->arrData;
    unsigned int _t225;
    _t225 = self->arrLen;
    _t224[_t225] = val;
    unsigned int _t226;
    _t226 = self->arrLen;
    _t227 = _t226 + 1;
    self->arrLen = _t227;
}

unsigned int Json_ObjectLen(JsonValue v) {
    int _t229;
    int _t228;
    _t228 = v.tag;
    _t229 = (_t228 != JsonTagObject);
    if (!_t229) goto endif47;
    {
    return 0;
    }
    endif47:;
    unsigned int _t230;
    _t230 = v.objLen;
    return _t230;
}

JsonValue Json_ObjectGet(JsonValue v, const char* key) {
    int _t232;
    int _t235;
    int _t241;
    int _t231;
    _t231 = v.tag;
    _t232 = (_t231 != JsonTagObject);
    if (!_t232) goto endif49;
    {
    JsonValue _t233;
    _t233 = Json_Null();
    return _t233;
    }
    endif49:;
    unsigned int i;
    i = 0;
    while50:;
    unsigned int _t234;
    _t234 = v.objLen;
    _t235 = (i < _t234);
    if (!_t235) goto wend52;
    {
    const char** _t236;
    _t236 = v.objKeys;
    const char* _t237;
    _t237 = _t236[i];
    bool _t238;
    _t238 = String_Eq(_t237, key);
    if (!_t238) goto endif54;
    {
    JsonValue* _t239;
    _t239 = v.objValues;
    JsonValue _t240;
    _t240 = _t239[i];
    return _t240;
    }
    endif54:;
    _t241 = i + 1;
    i = _t241;
    }
    goto while50;
    wend52:;
    JsonValue _t242;
    _t242 = Json_Null();
    return _t242;
}

bool Json_ObjectHas(JsonValue v, const char* key) {
    int _t244;
    int _t246;
    int _t250;
    int _t243;
    _t243 = v.tag;
    _t244 = (_t243 != JsonTagObject);
    if (!_t244) goto endif56;
    {
    return 0;
    }
    endif56:;
    unsigned int i;
    i = 0;
    while57:;
    unsigned int _t245;
    _t245 = v.objLen;
    _t246 = (i < _t245);
    if (!_t246) goto wend59;
    {
    const char** _t247;
    _t247 = v.objKeys;
    const char* _t248;
    _t248 = _t247[i];
    bool _t249;
    _t249 = String_Eq(_t248, key);
    if (!_t249) goto endif61;
    {
    return 1;
    }
    endif61:;
    _t250 = i + 1;
    i = _t250;
    }
    goto while57;
    wend59:;
    return 0;
}

void Json_ObjectSet(JsonValue* self, const char* key, JsonValue val) {
    int _t252;
    int _t254;
    int _t259;
    int _t262;
    int _t264;
    int _t266;
    const char** _t268;
    int _t270;
    JsonValue* _t272;
    int _t273;
    void* _t275;
    int _t277;
    const char** _t279;
    void* _t281;
    int _t283;
    JsonValue* _t285;
    int _t291;
    int _t251;
    _t251 = self->tag;
    _t252 = (_t251 != JsonTagObject);
    if (!_t252) goto endif63;
    {
    return;
    }
    endif63:;
    unsigned int i;
    i = 0;
    while64:;
    unsigned int _t253;
    _t253 = self->objLen;
    _t254 = (i < _t253);
    if (!_t254) goto wend66;
    {
    const char** _t255;
    _t255 = self->objKeys;
    const char* _t256;
    _t256 = _t255[i];
    bool _t257;
    _t257 = String_Eq(_t256, key);
    if (!_t257) goto endif68;
    {
    JsonValue* _t258;
    _t258 = self->objValues;
    _t258[i] = val;
    return;
    }
    endif68:;
    _t259 = i + 1;
    i = _t259;
    }
    goto while64;
    wend66:;
    unsigned int _t260;
    _t260 = self->objLen;
    unsigned int _t261;
    _t261 = self->objCap;
    _t262 = (_t260 >= _t261);
    if (!_t262) goto endif70;
    {
    unsigned int objNewCap;
    unsigned int _t263;
    _t263 = self->objCap;
    objNewCap = _t263;
    _t264 = (objNewCap == 0);
    if (!_t264) goto else71;
    {
    self->objCap = 4;
    /* sizeof(const char*) */
    _t266 = 4 * sizeof(const char*);
    void* _t267;
    _t267 = Alloc(_t266);
    _t268 = (const char**)_t267;
    self->objKeys = _t268;
    /* sizeof(JsonValue) */
    _t270 = 4 * sizeof(JsonValue);
    void* _t271;
    _t271 = Alloc(_t270);
    _t272 = (JsonValue*)_t271;
    self->objValues = _t272;
    }
    goto endif72;
    else71:;
    {
    unsigned int doubleCap;
    _t273 = objNewCap * 2;
    doubleCap = _t273;
    self->objCap = doubleCap;
    const char** _t274;
    _t274 = self->objKeys;
    _t275 = (void*)_t274;
    /* sizeof(const char*) */
    _t277 = doubleCap * sizeof(const char*);
    void* _t278;
    _t278 = Realloc(_t275, _t277);
    _t279 = (const char**)_t278;
    self->objKeys = _t279;
    JsonValue* _t280;
    _t280 = self->objValues;
    _t281 = (void*)_t280;
    /* sizeof(JsonValue) */
    _t283 = doubleCap * sizeof(JsonValue);
    void* _t284;
    _t284 = Realloc(_t281, _t283);
    _t285 = (JsonValue*)_t284;
    self->objValues = _t285;
    }
    endif72:;
    }
    endif70:;
    const char** _t286;
    _t286 = self->objKeys;
    unsigned int _t287;
    _t287 = self->objLen;
    _t286[_t287] = key;
    JsonValue* _t288;
    _t288 = self->objValues;
    unsigned int _t289;
    _t289 = self->objLen;
    _t288[_t289] = val;
    unsigned int _t290;
    _t290 = self->objLen;
    _t291 = _t290 + 1;
    self->objLen = _t291;
}

bool Json_IsNull(JsonValue v) {
    int _t293;
    int _t292;
    _t292 = v.tag;
    _t293 = (_t292 == JsonTagNull);
    return _t293;
}

bool Json_AsBool(JsonValue v) {
    int _t295;
    int _t294;
    _t294 = v.tag;
    _t295 = (_t294 == JsonTagBool);
    if (!_t295) goto endif74;
    {
    bool _t296;
    _t296 = v.boolVal;
    return _t296;
    }
    endif74:;
    return 0;
}

double Json_AsNumber(JsonValue v) {
    int _t298;
    int _t297;
    _t297 = v.tag;
    _t298 = (_t297 == JsonTagNumber);
    if (!_t298) goto endif76;
    {
    double _t299;
    _t299 = v.numVal;
    return _t299;
    }
    endif76:;
    return 0.0;
}

const char* Json_AsString(JsonValue v) {
    int _t301;
    int _t300;
    _t300 = v.tag;
    _t301 = (_t300 == JsonTagString);
    if (!_t301) goto endif78;
    {
    const char* _t302;
    _t302 = v.strVal;
    return _t302;
    }
    endif78:;
    return "";
}

int JsonParser_Peek(JsonParser* p) {
    int _t305;
    int _t309;
    unsigned int _t303;
    _t303 = p->pos;
    unsigned int _t304;
    _t304 = p->len;
    _t305 = (_t303 >= _t304);
    if (!_t305) goto endif80;
    {
    return 0;
    }
    endif80:;
    const char* _t306;
    _t306 = p->src;
    unsigned int _t307;
    _t307 = p->pos;
    int _t308;
    _t308 = _t306[_t307];
    _t309 = (int)_t308;
    return _t309;
}

void JsonParser_Advance(JsonParser* p) {
    int _t312;
    int _t314;
    unsigned int _t310;
    _t310 = p->pos;
    unsigned int _t311;
    _t311 = p->len;
    _t312 = (_t310 < _t311);
    if (!_t312) goto endif82;
    {
    unsigned int _t313;
    _t313 = p->pos;
    _t314 = _t313 + 1;
    p->pos = _t314;
    }
    endif82:;
}

void JsonParser_SkipWhitespace(JsonParser* p) {
    int _t316;
    int _t317;
    int _t319;
    int _t321;
    while83:;
    if (!1) goto wend85;
    {
    int c;
    int _t315;
    _t315 = JsonParser_Peek(p);
    c = _t315;
    bool __or_tmp_1;
    bool __or_tmp_2;
    bool __or_tmp_3;
    _t316 = (c == 32);
    if (!_t316) goto else86;
    *(bool*)&__or_tmp_3 = 1;
    goto endif87;
    else86:;
    _t317 = (c == 9);
    *(bool*)&__or_tmp_3 = _t317;
    endif87:;
    bool _t318;
    _t318 = *(bool*)&__or_tmp_3;
    if (!_t318) goto else88;
    *(bool*)&__or_tmp_2 = 1;
    goto endif89;
    else88:;
    _t319 = (c == 10);
    *(bool*)&__or_tmp_2 = _t319;
    endif89:;
    bool _t320;
    _t320 = *(bool*)&__or_tmp_2;
    if (!_t320) goto else90;
    *(bool*)&__or_tmp_1 = 1;
    goto endif91;
    else90:;
    _t321 = (c == 13);
    *(bool*)&__or_tmp_1 = _t321;
    endif91:;
    bool _t322;
    _t322 = *(bool*)&__or_tmp_1;
    if (!_t322) goto else92;
    {
    JsonParser_Advance(p);
    }
    goto endif93;
    else92:;
    {
    return;
    }
    endif93:;
    }
    goto while83;
    wend85:;
}

bool JsonParser_Match(JsonParser* p, const char* expected) {
    int _t325;
    int _t327;
    int _t328;
    int _t331;
    int _t334;
    int _t335;
    int _t337;
    unsigned int elen;
    unsigned int _t323;
    _t323 = String_Len(expected);
    elen = _t323;
    unsigned int _t324;
    _t324 = p->pos;
    _t325 = _t324 + elen;
    unsigned int _t326;
    _t326 = p->len;
    _t327 = (_t325 > _t326);
    if (!_t327) goto endif95;
    {
    return 0;
    }
    endif95:;
    unsigned int i;
    i = 0;
    while96:;
    _t328 = (i < elen);
    if (!_t328) goto wend98;
    {
    const char* _t329;
    _t329 = p->src;
    unsigned int _t330;
    _t330 = p->pos;
    _t331 = _t330 + i;
    int _t332;
    _t332 = _t329[_t331];
    int _t333;
    _t333 = expected[i];
    _t334 = (_t332 != _t333);
    if (!_t334) goto endif100;
    {
    return 0;
    }
    endif100:;
    _t335 = i + 1;
    i = _t335;
    }
    goto while96;
    wend98:;
    unsigned int _t336;
    _t336 = p->pos;
    _t337 = _t336 + elen;
    p->pos = _t337;
    return 1;
}

const char* JsonParser_ParseString(JsonParser* p) {
    int _t339;
    int _t342;
    int _t343;
    int _t345;
    int _t347;
    void* _t348;
    int _t349;
    void* _t350;
    char _t351;
    int _t352;
    void* _t353;
    char _t354;
    int _t355;
    void* _t356;
    char _t357;
    int _t358;
    void* _t359;
    char _t360;
    int _t361;
    void* _t362;
    char _t363;
    int _t364;
    void* _t365;
    char _t366;
    int _t367;
    void* _t368;
    char _t369;
    void* _t370;
    char _t371;
    void* _t372;
    char _t373;
    void* _t374;
    char _t375;
    int _t377;
    void* _t378;
    void* _t379;
    void* _t381;
    int _t338;
    _t338 = JsonParser_Peek(p);
    _t339 = (_t338 != 34);
    if (!_t339) goto endif102;
    {
    p->error = "Expected string";
    return "";
    }
    endif102:;
    JsonParser_Advance(p);
    StringBuilder sb;
    StringBuilder _t340;
    _t340 = StringBuilder_New();
    sb = _t340;
    while103:;
    if (!1) goto wend105;
    {
    int c;
    int _t341;
    _t341 = JsonParser_Peek(p);
    c = _t341;
    bool __or_tmp_4;
    _t342 = (c == 0);
    if (!_t342) goto else106;
    *(bool*)&__or_tmp_4 = 1;
    goto endif107;
    else106:;
    _t343 = (c == 34);
    *(bool*)&__or_tmp_4 = _t343;
    endif107:;
    bool _t344;
    _t344 = *(bool*)&__or_tmp_4;
    if (!_t344) goto endif109;
    {
    goto wend105;
    }
    endif109:;
    _t345 = (c == 92);
    if (!_t345) goto else110;
    {
    JsonParser_Advance(p);
    int esc;
    int _t346;
    _t346 = JsonParser_Peek(p);
    esc = _t346;
    _t347 = (esc == 0);
    if (!_t347) goto endif113;
    {
    p->error = "Unterminated string escape";
    _t348 = &sb;
    StringBuilder_Free(_t348);
    return "";
    }
    endif113:;
    _t349 = (esc == 110);
    if (!_t349) goto else114;
    {
    _t350 = &sb;
    _t351 = (char)10;
    StringBuilder_AppendChar(_t350, _t351);
    }
    goto endif115;
    else114:;
    _t352 = (esc == 116);
    if (!_t352) goto else116;
    {
    _t353 = &sb;
    _t354 = (char)9;
    StringBuilder_AppendChar(_t353, _t354);
    }
    goto endif117;
    else116:;
    _t355 = (esc == 114);
    if (!_t355) goto else118;
    {
    _t356 = &sb;
    _t357 = (char)13;
    StringBuilder_AppendChar(_t356, _t357);
    }
    goto endif119;
    else118:;
    _t358 = (esc == 98);
    if (!_t358) goto else120;
    {
    _t359 = &sb;
    _t360 = (char)8;
    StringBuilder_AppendChar(_t359, _t360);
    }
    goto endif121;
    else120:;
    _t361 = (esc == 102);
    if (!_t361) goto else122;
    {
    _t362 = &sb;
    _t363 = (char)12;
    StringBuilder_AppendChar(_t362, _t363);
    }
    goto endif123;
    else122:;
    _t364 = (esc == 34);
    if (!_t364) goto else124;
    {
    _t365 = &sb;
    _t366 = (char)34;
    StringBuilder_AppendChar(_t365, _t366);
    }
    goto endif125;
    else124:;
    _t367 = (esc == 92);
    if (!_t367) goto else126;
    {
    _t368 = &sb;
    _t369 = (char)92;
    StringBuilder_AppendChar(_t368, _t369);
    }
    goto endif127;
    else126:;
    {
    _t370 = &sb;
    _t371 = (char)92;
    StringBuilder_AppendChar(_t370, _t371);
    _t372 = &sb;
    _t373 = (char)esc;
    StringBuilder_AppendChar(_t372, _t373);
    }
    endif127:;
    endif125:;
    endif123:;
    endif121:;
    endif119:;
    endif117:;
    endif115:;
    JsonParser_Advance(p);
    }
    goto endif111;
    else110:;
    {
    _t374 = &sb;
    _t375 = (char)c;
    StringBuilder_AppendChar(_t374, _t375);
    JsonParser_Advance(p);
    }
    endif111:;
    }
    goto while103;
    wend105:;
    int _t376;
    _t376 = JsonParser_Peek(p);
    _t377 = (_t376 != 34);
    if (!_t377) goto endif129;
    {
    p->error = "Unterminated string";
    _t378 = &sb;
    StringBuilder_Free(_t378);
    return "";
    }
    endif129:;
    JsonParser_Advance(p);
    const char* result;
    _t379 = &sb;
    const char* _t380;
    _t380 = StringBuilder_Build(_t379);
    result = _t380;
    _t381 = &sb;
    StringBuilder_Free(_t381);
    return result;
}

JsonValue JsonParser_ParseNumber(JsonParser* p) {
    int _t384;
    int _t386;
    int _t387;
    int _t390;
    int _t392;
    int _t393;
    int _t397;
    unsigned int start;
    unsigned int _t382;
    _t382 = p->pos;
    start = _t382;
    int c0;
    int _t383;
    _t383 = JsonParser_Peek(p);
    c0 = _t383;
    _t384 = (c0 == 45);
    if (!_t384) goto endif131;
    {
    JsonParser_Advance(p);
    }
    endif131:;
    while132:;
    if (!1) goto wend134;
    {
    int c;
    int _t385;
    _t385 = JsonParser_Peek(p);
    c = _t385;
    bool __and_tmp_5;
    _t386 = (c >= 48);
    if (!_t386) goto else135;
    _t387 = (c <= 57);
    *(bool*)&__and_tmp_5 = _t387;
    goto endif136;
    else135:;
    *(bool*)&__and_tmp_5 = 0;
    endif136:;
    bool _t388;
    _t388 = *(bool*)&__and_tmp_5;
    if (!_t388) goto else137;
    {
    JsonParser_Advance(p);
    }
    goto endif138;
    else137:;
    {
    goto wend134;
    }
    endif138:;
    }
    goto while132;
    wend134:;
    int _t389;
    _t389 = JsonParser_Peek(p);
    _t390 = (_t389 == 46);
    if (!_t390) goto endif140;
    {
    JsonParser_Advance(p);
    while141:;
    if (!1) goto wend143;
    {
    int c;
    int _t391;
    _t391 = JsonParser_Peek(p);
    c = _t391;
    bool __and_tmp_6;
    _t392 = (c >= 48);
    if (!_t392) goto else144;
    _t393 = (c <= 57);
    *(bool*)&__and_tmp_6 = _t393;
    goto endif145;
    else144:;
    *(bool*)&__and_tmp_6 = 0;
    endif145:;
    bool _t394;
    _t394 = *(bool*)&__and_tmp_6;
    if (!_t394) goto else146;
    {
    JsonParser_Advance(p);
    }
    goto endif147;
    else146:;
    {
    goto wend143;
    }
    endif147:;
    }
    goto while141;
    wend143:;
    }
    endif140:;
    const char* numStr;
    const char* _t395;
    _t395 = p->src;
    unsigned int _t396;
    _t396 = p->pos;
    _t397 = _t396 - start;
    const char* _t398;
    _t398 = String_Slice(_t395, start, _t397);
    numStr = _t398;
    double n;
    double _t399;
    _t399 = String_ToFloat(numStr);
    n = _t399;
    JsonValue _t400;
    _t400 = Json_Number(n);
    return _t400;
}

JsonValue JsonParser_ParseArray(JsonParser* p) {
    int _t403;
    int _t406;
    void* _t408;
    int _t410;
    int _t411;
    JsonParser_Advance(p);
    JsonValue arr;
    JsonValue _t401;
    _t401 = Json_Array();
    arr = _t401;
    JsonParser_SkipWhitespace(p);
    int _t402;
    _t402 = JsonParser_Peek(p);
    _t403 = (_t402 == 93);
    if (!_t403) goto endif149;
    {
    JsonParser_Advance(p);
    return arr;
    }
    endif149:;
    while150:;
    if (!1) goto wend152;
    {
    JsonParser_SkipWhitespace(p);
    JsonValue val;
    JsonValue _t404;
    _t404 = JsonParser_ParseValue(p);
    val = _t404;
    const char* _t405;
    _t405 = p->error;
    _t406 = (_t405 != "");
    if (!_t406) goto endif154;
    {
    JsonValue _t407;
    _t407 = Json_Null();
    return _t407;
    }
    endif154:;
    _t408 = &arr;
    Json_ArrayPush(_t408, val);
    JsonParser_SkipWhitespace(p);
    int c;
    int _t409;
    _t409 = JsonParser_Peek(p);
    c = _t409;
    _t410 = (c == 93);
    if (!_t410) goto endif156;
    {
    JsonParser_Advance(p);
    return arr;
    }
    endif156:;
    _t411 = (c == 44);
    if (!_t411) goto else157;
    {
    JsonParser_Advance(p);
    }
    goto endif158;
    else157:;
    {
    p->error = "Expected ',' or ']' in array";
    JsonValue _t412;
    _t412 = Json_Null();
    return _t412;
    }
    endif158:;
    }
    goto while150;
    wend152:;
}

JsonValue JsonParser_ParseObject(JsonParser* p) {
    int _t415;
    int _t418;
    int _t421;
    int _t425;
    void* _t427;
    int _t429;
    int _t430;
    JsonParser_Advance(p);
    JsonValue obj;
    JsonValue _t413;
    _t413 = Json_Object();
    obj = _t413;
    JsonParser_SkipWhitespace(p);
    int _t414;
    _t414 = JsonParser_Peek(p);
    _t415 = (_t414 == 125);
    if (!_t415) goto endif160;
    {
    JsonParser_Advance(p);
    return obj;
    }
    endif160:;
    while161:;
    if (!1) goto wend163;
    {
    JsonParser_SkipWhitespace(p);
    const char* key;
    const char* _t416;
    _t416 = JsonParser_ParseString(p);
    key = _t416;
    const char* _t417;
    _t417 = p->error;
    _t418 = (_t417 != "");
    if (!_t418) goto endif165;
    {
    JsonValue _t419;
    _t419 = Json_Null();
    return _t419;
    }
    endif165:;
    JsonParser_SkipWhitespace(p);
    int _t420;
    _t420 = JsonParser_Peek(p);
    _t421 = (_t420 != 58);
    if (!_t421) goto endif167;
    {
    p->error = "Expected ':' after object key";
    JsonValue _t422;
    _t422 = Json_Null();
    return _t422;
    }
    endif167:;
    JsonParser_Advance(p);
    JsonParser_SkipWhitespace(p);
    JsonValue val;
    JsonValue _t423;
    _t423 = JsonParser_ParseValue(p);
    val = _t423;
    const char* _t424;
    _t424 = p->error;
    _t425 = (_t424 != "");
    if (!_t425) goto endif169;
    {
    JsonValue _t426;
    _t426 = Json_Null();
    return _t426;
    }
    endif169:;
    _t427 = &obj;
    Json_ObjectSet(_t427, key, val);
    JsonParser_SkipWhitespace(p);
    int c;
    int _t428;
    _t428 = JsonParser_Peek(p);
    c = _t428;
    _t429 = (c == 125);
    if (!_t429) goto endif171;
    {
    JsonParser_Advance(p);
    return obj;
    }
    endif171:;
    _t430 = (c == 44);
    if (!_t430) goto else172;
    {
    JsonParser_Advance(p);
    }
    goto endif173;
    else172:;
    {
    p->error = "Expected ',' or '}' in object";
    JsonValue _t431;
    _t431 = Json_Null();
    return _t431;
    }
    endif173:;
    }
    goto while161;
    wend163:;
}

JsonValue JsonParser_ParseValue(JsonParser* p) {
    int _t433;
    int _t435;
    int _t438;
    int _t440;
    int _t442;
    int _t446;
    int _t450;
    int _t454;
    int _t455;
    int _t457;
    JsonParser_SkipWhitespace(p);
    int c;
    int _t432;
    _t432 = JsonParser_Peek(p);
    c = _t432;
    _t433 = (c == 0);
    if (!_t433) goto endif175;
    {
    p->error = "Unexpected end of input";
    JsonValue _t434;
    _t434 = Json_Null();
    return _t434;
    }
    endif175:;
    _t435 = (c == 34);
    if (!_t435) goto endif177;
    {
    const char* _t436;
    _t436 = JsonParser_ParseString(p);
    JsonValue _t437;
    _t437 = Json_String(_t436);
    return _t437;
    }
    endif177:;
    _t438 = (c == 123);
    if (!_t438) goto endif179;
    {
    JsonValue _t439;
    _t439 = JsonParser_ParseObject(p);
    return _t439;
    }
    endif179:;
    _t440 = (c == 91);
    if (!_t440) goto endif181;
    {
    JsonValue _t441;
    _t441 = JsonParser_ParseArray(p);
    return _t441;
    }
    endif181:;
    _t442 = (c == 116);
    if (!_t442) goto endif183;
    {
    bool _t443;
    _t443 = JsonParser_Match(p, "true");
    if (!_t443) goto endif185;
    {
    JsonValue _t444;
    _t444 = Json_Bool(1);
    return _t444;
    }
    endif185:;
    p->error = "Expected 'true'";
    JsonValue _t445;
    _t445 = Json_Null();
    return _t445;
    }
    endif183:;
    _t446 = (c == 102);
    if (!_t446) goto endif187;
    {
    bool _t447;
    _t447 = JsonParser_Match(p, "false");
    if (!_t447) goto endif189;
    {
    JsonValue _t448;
    _t448 = Json_Bool(0);
    return _t448;
    }
    endif189:;
    p->error = "Expected 'false'";
    JsonValue _t449;
    _t449 = Json_Null();
    return _t449;
    }
    endif187:;
    _t450 = (c == 110);
    if (!_t450) goto endif191;
    {
    bool _t451;
    _t451 = JsonParser_Match(p, "null");
    if (!_t451) goto endif193;
    {
    JsonValue _t452;
    _t452 = Json_Null();
    return _t452;
    }
    endif193:;
    p->error = "Expected 'null'";
    JsonValue _t453;
    _t453 = Json_Null();
    return _t453;
    }
    endif191:;
    bool __or_tmp_7;
    bool __and_tmp_8;
    _t454 = (c >= 48);
    if (!_t454) goto else194;
    _t455 = (c <= 57);
    *(bool*)&__and_tmp_8 = _t455;
    goto endif195;
    else194:;
    *(bool*)&__and_tmp_8 = 0;
    endif195:;
    bool _t456;
    _t456 = *(bool*)&__and_tmp_8;
    if (!_t456) goto else196;
    *(bool*)&__or_tmp_7 = 1;
    goto endif197;
    else196:;
    _t457 = (c == 45);
    *(bool*)&__or_tmp_7 = _t457;
    endif197:;
    bool _t458;
    _t458 = *(bool*)&__or_tmp_7;
    if (!_t458) goto endif199;
    {
    JsonValue _t459;
    _t459 = JsonParser_ParseNumber(p);
    return _t459;
    }
    endif199:;
    p->error = "Unexpected character";
    JsonValue _t460;
    _t460 = Json_Null();
    return _t460;
}

JsonValue Json_Parse(const char* s) {
    JsonParser _t462;
    void* _t463;
    void* _t465;
    int _t467;
    int _t470;
    JsonParser p;
    unsigned int _t461;
    _t461 = String_Len(s);
    _t462 = (JsonParser){.src = s, .pos = 0, .len = _t461, .error = ""};
    p = _t462;
    JsonValue result;
    _t463 = &p;
    JsonValue _t464;
    _t464 = JsonParser_ParseValue(_t463);
    result = _t464;
    _t465 = &p;
    JsonParser_SkipWhitespace(_t465);
    bool __and_tmp_9;
    const char* _t466;
    _t466 = p.error;
    _t467 = (_t466 == "");
    if (!_t467) goto else200;
    unsigned int _t468;
    _t468 = p.pos;
    unsigned int _t469;
    _t469 = p.len;
    _t470 = (_t468 != _t469);
    *(bool*)&__and_tmp_9 = _t470;
    goto endif201;
    else200:;
    *(bool*)&__and_tmp_9 = 0;
    endif201:;
    bool _t471;
    _t471 = *(bool*)&__and_tmp_9;
    if (!_t471) goto endif203;
    {
    p.error = "Trailing data after JSON value";
    JsonValue _t472;
    _t472 = Json_Null();
    return _t472;
    }
    endif203:;
    return result;
}

void Json_StringifyImpl(StringBuilder* sb, JsonValue v) {
    int _t474;
    int _t476;
    int _t479;
    int _t482;
    char _t483;
    char _t485;
    int _t487;
    char _t488;
    int _t490;
    int _t491;
    char _t492;
    int _t495;
    char _t496;
    int _t498;
    char _t499;
    int _t501;
    int _t502;
    char _t503;
    char _t504;
    char _t507;
    char _t508;
    int _t511;
    char _t512;
    int _t473;
    _t473 = v.tag;
    _t474 = (_t473 == JsonTagNull);
    if (!_t474) goto endif205;
    {
    StringBuilder_Append(sb, "null");
    return;
    }
    endif205:;
    int _t475;
    _t475 = v.tag;
    _t476 = (_t475 == JsonTagBool);
    if (!_t476) goto endif207;
    {
    bool _t477;
    _t477 = v.boolVal;
    if (!_t477) goto else208;
    {
    StringBuilder_Append(sb, "true");
    }
    goto endif209;
    else208:;
    {
    StringBuilder_Append(sb, "false");
    }
    endif209:;
    return;
    }
    endif207:;
    int _t478;
    _t478 = v.tag;
    _t479 = (_t478 == JsonTagNumber);
    if (!_t479) goto endif211;
    {
    double _t480;
    _t480 = v.numVal;
    StringBuilder_AppendFloat(sb, _t480);
    return;
    }
    endif211:;
    int _t481;
    _t481 = v.tag;
    _t482 = (_t481 == JsonTagString);
    if (!_t482) goto endif213;
    {
    _t483 = (char)34;
    StringBuilder_AppendChar(sb, _t483);
    const char* _t484;
    _t484 = v.strVal;
    StringBuilder_Append(sb, _t484);
    _t485 = (char)34;
    StringBuilder_AppendChar(sb, _t485);
    return;
    }
    endif213:;
    int _t486;
    _t486 = v.tag;
    _t487 = (_t486 == JsonTagArray);
    if (!_t487) goto endif215;
    {
    _t488 = (char)91;
    StringBuilder_AppendChar(sb, _t488);
    unsigned int i;
    i = 0;
    while216:;
    unsigned int _t489;
    _t489 = v.arrLen;
    _t490 = (i < _t489);
    if (!_t490) goto wend218;
    {
    _t491 = (i > 0);
    if (!_t491) goto endif220;
    {
    _t492 = (char)44;
    StringBuilder_AppendChar(sb, _t492);
    }
    endif220:;
    JsonValue* _t493;
    _t493 = v.arrData;
    JsonValue _t494;
    _t494 = _t493[i];
    Json_StringifyImpl(sb, _t494);
    _t495 = i + 1;
    i = _t495;
    }
    goto while216;
    wend218:;
    _t496 = (char)93;
    StringBuilder_AppendChar(sb, _t496);
    return;
    }
    endif215:;
    int _t497;
    _t497 = v.tag;
    _t498 = (_t497 == JsonTagObject);
    if (!_t498) goto endif222;
    {
    _t499 = (char)123;
    StringBuilder_AppendChar(sb, _t499);
    unsigned int i;
    i = 0;
    while223:;
    unsigned int _t500;
    _t500 = v.objLen;
    _t501 = (i < _t500);
    if (!_t501) goto wend225;
    {
    _t502 = (i > 0);
    if (!_t502) goto endif227;
    {
    _t503 = (char)44;
    StringBuilder_AppendChar(sb, _t503);
    }
    endif227:;
    _t504 = (char)34;
    StringBuilder_AppendChar(sb, _t504);
    const char** _t505;
    _t505 = v.objKeys;
    const char* _t506;
    _t506 = _t505[i];
    StringBuilder_Append(sb, _t506);
    _t507 = (char)34;
    StringBuilder_AppendChar(sb, _t507);
    _t508 = (char)58;
    StringBuilder_AppendChar(sb, _t508);
    JsonValue* _t509;
    _t509 = v.objValues;
    JsonValue _t510;
    _t510 = _t509[i];
    Json_StringifyImpl(sb, _t510);
    _t511 = i + 1;
    i = _t511;
    }
    goto while223;
    wend225:;
    _t512 = (char)125;
    StringBuilder_AppendChar(sb, _t512);
    return;
    }
    endif222:;
}

const char* Json_Stringify(JsonValue v) {
    void* _t514;
    void* _t515;
    StringBuilder sb;
    StringBuilder _t513;
    _t513 = StringBuilder_New();
    sb = _t513;
    _t514 = &sb;
    Json_StringifyImpl(_t514, v);
    _t515 = &sb;
    const char* _t516;
    _t516 = StringBuilder_Build(_t515);
    return _t516;
}

unsigned int String_Len(const char* s) {
    unsigned int _t517;
    _t517 = bux_strlen(s);
    return _t517;
}

bool String_IsNull(const char* s) {
    int _t519;
    int _t518;
    _t518 = bux_str_is_null(s);
    _t519 = (_t518 != 0);
    return _t519;
}

bool String_Eq(const char* a, const char* b) {
    int _t521;
    int _t520;
    _t520 = bux_strcmp(a, b);
    _t521 = (_t520 == 0);
    return _t521;
}

const char* String_Concat(const char* a, const char* b) {
    int _t524;
    int _t525;
    char* _t527;
    unsigned int len_a;
    unsigned int _t522;
    _t522 = bux_strlen(a);
    len_a = _t522;
    unsigned int len_b;
    unsigned int _t523;
    _t523 = bux_strlen(b);
    len_b = _t523;
    unsigned int total;
    _t524 = len_a + len_b;
    _t525 = _t524 + 1;
    total = _t525;
    char* buf;
    void* _t526;
    _t526 = bux_alloc(total);
    _t527 = (char*)_t526;
    buf = _t527;
    bux_strcpy(buf, a);
    bux_strcat(buf, b);
    return buf;
}

const char* String_Copy(const char* s) {
    int _t529;
    char* _t531;
    unsigned int len;
    unsigned int _t528;
    _t528 = bux_strlen(s);
    len = _t528;
    char* buf;
    _t529 = len + 1;
    void* _t530;
    _t530 = bux_alloc(_t529);
    _t531 = (char*)_t530;
    buf = _t531;
    bux_strcpy(buf, s);
    return buf;
}

bool String_StartsWith(const char* s, const char* prefix) {
    int _t534;
    int _t536;
    unsigned int s_len;
    unsigned int _t532;
    _t532 = bux_strlen(s);
    s_len = _t532;
    unsigned int p_len;
    unsigned int _t533;
    _t533 = bux_strlen(prefix);
    p_len = _t533;
    _t534 = (p_len > s_len);
    if (!_t534) goto endif229;
    {
    return 0;
    }
    endif229:;
    int r;
    int _t535;
    _t535 = bux_strncmp(s, prefix, p_len);
    r = _t535;
    _t536 = (r == 0);
    return _t536;
}

bool String_EndsWith(const char* s, const char* suffix) {
    int _t539;
    int _t540;
    int _t543;
    unsigned int s_len;
    unsigned int _t537;
    _t537 = bux_strlen(s);
    s_len = _t537;
    unsigned int suf_len;
    unsigned int _t538;
    _t538 = bux_strlen(suffix);
    suf_len = _t538;
    _t539 = (suf_len > s_len);
    if (!_t539) goto endif231;
    {
    return 0;
    }
    endif231:;
    unsigned int start;
    _t540 = s_len - suf_len;
    start = _t540;
    const char* tail;
    const char* _t541;
    _t541 = bux_str_slice(s, start, suf_len);
    tail = _t541;
    bool eq;
    int _t542;
    _t542 = bux_strcmp(tail, suffix);
    _t543 = (_t542 == 0);
    eq = _t543;
    return eq;
}

bool String_Contains(const char* s, const char* substr) {
    int _t545;
    int r;
    int _t544;
    _t544 = bux_str_contains(s, substr);
    r = _t544;
    _t545 = (r != 0);
    return _t545;
}

const char* String_Slice(const char* s, unsigned int start, unsigned int len) {
    const char* _t546;
    _t546 = bux_str_slice(s, start, len);
    return _t546;
}

const char* String_Trim(const char* s) {
    const char* _t547;
    _t547 = bux_str_trim(s);
    return _t547;
}

const char* String_TrimLeft(const char* s) {
    const char* _t548;
    _t548 = bux_str_trim_left(s);
    return _t548;
}

const char* String_TrimRight(const char* s) {
    const char* _t549;
    _t549 = bux_str_trim_right(s);
    return _t549;
}

const char* String_FromInt(int64_t n) {
    const char* _t550;
    _t550 = bux_int_to_str(n);
    return _t550;
}

int64_t String_ToInt(const char* s) {
    int64_t _t551;
    _t551 = bux_str_to_int(s);
    return _t551;
}

StringBuilder StringBuilder_New(void) {
    StringBuilder _t553;
    void* _t552;
    _t552 = bux_sb_new(64);
    _t553 = (StringBuilder){.handle = _t552};
    return _t553;
}

StringBuilder StringBuilder_NewCap(unsigned int cap) {
    StringBuilder _t555;
    void* _t554;
    _t554 = bux_sb_new(cap);
    _t555 = (StringBuilder){.handle = _t554};
    return _t555;
}

void StringBuilder_Append(StringBuilder* sb, const char* s) {
    void* _t556;
    _t556 = sb->handle;
    bux_sb_append(_t556, s);
}

void StringBuilder_AppendInt(StringBuilder* sb, int64_t n) {
    void* _t557;
    _t557 = sb->handle;
    bux_sb_append_int(_t557, n);
}

void StringBuilder_AppendFloat(StringBuilder* sb, double f) {
    void* _t558;
    _t558 = sb->handle;
    bux_sb_append_float(_t558, f);
}

void StringBuilder_AppendChar(StringBuilder* sb, char c) {
    void* _t559;
    _t559 = sb->handle;
    bux_sb_append_char(_t559, c);
}

const char* StringBuilder_Build(StringBuilder* sb) {
    void* _t560;
    _t560 = sb->handle;
    const char* _t561;
    _t561 = bux_sb_build(_t560);
    return _t561;
}

void StringBuilder_Free(StringBuilder* sb) {
    void* _t562;
    _t562 = sb->handle;
    bux_sb_free(_t562);
}

unsigned int String_SplitCount(const char* s, const char* delim) {
    unsigned int _t563;
    _t563 = bux_str_split_count(s, delim);
    return _t563;
}

const char* String_SplitPart(const char* s, const char* delim, unsigned int index) {
    const char* _t564;
    _t564 = bux_str_split_part(s, delim, index);
    return _t564;
}

const char* String_Join2(const char* a, const char* b, const char* sep) {
    const char* _t565;
    _t565 = bux_str_join2(a, b, sep);
    return _t565;
}

const char* String_Chars(const char* s, unsigned int index) {
    const char* _t566;
    _t566 = bux_str_slice(s, index, 1);
    return _t566;
}

const char* String_Find(const char* haystack, const char* needle) {
    const char* _t567;
    _t567 = bux_strstr(haystack, needle);
    return _t567;
}

unsigned int String_Offset(const char* pos, const char* base) {
    unsigned int _t568;
    _t568 = bux_str_offset(pos, base);
    return _t568;
}

const char* String_Replace(const char* s, const char* old, const char* new) {
    int _t574;
    int _t576;
    int _t577;
    const char* pos;
    const char* _t569;
    _t569 = bux_strstr(s, old);
    pos = _t569;
    bool _t570;
    _t570 = String_IsNull(pos);
    if (!_t570) goto endif233;
    {
    return s;
    }
    endif233:;
    unsigned int oldLen;
    unsigned int _t571;
    _t571 = bux_strlen(old);
    oldLen = _t571;
    unsigned int prefixLen;
    unsigned int _t572;
    _t572 = String_Offset(pos, s);
    prefixLen = _t572;
    const char* prefix;
    const char* _t573;
    _t573 = bux_str_slice(s, 0, prefixLen);
    prefix = _t573;
    const char* suffix;
    _t574 = prefixLen + oldLen;
    unsigned int _t575;
    _t575 = bux_strlen(s);
    _t576 = _t575 - prefixLen;
    _t577 = _t576 - oldLen;
    const char* _t578;
    _t578 = bux_str_slice(s, _t574, _t577);
    suffix = _t578;
    const char* temp;
    const char* _t579;
    _t579 = String_Concat(prefix, new);
    temp = _t579;
    const char* result;
    const char* _t580;
    _t580 = String_Concat(temp, suffix);
    result = _t580;
    return result;
}

double String_ToFloat(const char* s) {
    double _t581;
    _t581 = bux_str_to_float(s);
    return _t581;
}

const char* String_FromBool(bool b) {
    if (!b) goto endif235;
    {
    return "true";
    }
    endif235:;
    return "false";
}

const char* String_FromFloat(double f) {
    const char* _t582;
    _t582 = bux_float_to_string(f);
    return _t582;
}

const char* String_Format1(const char* pattern, const char* a0) {
    const char* _t583;
    _t583 = bux_str_format(pattern, a0, "", "", "", "", "", "", "");
    return _t583;
}

const char* String_Format2(const char* pattern, const char* a0, const char* a1) {
    const char* _t584;
    _t584 = bux_str_format(pattern, a0, a1, "", "", "", "", "", "");
    return _t584;
}

const char* String_Format3(const char* pattern, const char* a0, const char* a1, const char* a2) {
    const char* _t585;
    _t585 = bux_str_format(pattern, a0, a1, a2, "", "", "", "", "");
    return _t585;
}

const char* Hash_Sha1(const char* data) {
    int _t587;
    int len;
    unsigned int _t586;
    _t586 = String_Len(data);
    _t587 = (int)_t586;
    len = _t587;
    void* buf;
    void* _t588;
    _t588 = Alloc(20);
    buf = _t588;
    bux_sha1(data, len, buf);
    const char* result;
    const char* _t589;
    _t589 = bux_bytes_to_hex(buf, 20);
    result = _t589;
    Free(buf);
    return result;
}

const char* Hash_Sha256(const char* data) {
    int _t591;
    int len;
    unsigned int _t590;
    _t590 = String_Len(data);
    _t591 = (int)_t590;
    len = _t591;
    void* buf;
    void* _t592;
    _t592 = Alloc(32);
    buf = _t592;
    bux_sha256(data, len, buf);
    const char* result;
    const char* _t593;
    _t593 = bux_bytes_to_hex(buf, 32);
    result = _t593;
    Free(buf);
    return result;
}

const char* Hash_Sha384(const char* data) {
    int _t595;
    int len;
    unsigned int _t594;
    _t594 = String_Len(data);
    _t595 = (int)_t594;
    len = _t595;
    void* buf;
    void* _t596;
    _t596 = Alloc(48);
    buf = _t596;
    bux_sha384(data, len, buf);
    const char* result;
    const char* _t597;
    _t597 = bux_bytes_to_hex(buf, 48);
    result = _t597;
    Free(buf);
    return result;
}

const char* Hash_Sha512(const char* data) {
    int _t599;
    int len;
    unsigned int _t598;
    _t598 = String_Len(data);
    _t599 = (int)_t598;
    len = _t599;
    void* buf;
    void* _t600;
    _t600 = Alloc(64);
    buf = _t600;
    bux_sha512(data, len, buf);
    const char* result;
    const char* _t601;
    _t601 = bux_bytes_to_hex(buf, 64);
    result = _t601;
    Free(buf);
    return result;
}

void Hash_Sha256Raw(const char* data, void* out) {
    int _t603;
    unsigned int _t602;
    _t602 = String_Len(data);
    _t603 = (int)_t602;
    bux_sha256(data, _t603, out);
}

void Hash_Sha384Raw(const char* data, void* out) {
    int _t605;
    unsigned int _t604;
    _t604 = String_Len(data);
    _t605 = (int)_t604;
    bux_sha384(data, _t605, out);
}

void Hash_Sha512Raw(const char* data, void* out) {
    int _t607;
    unsigned int _t606;
    _t606 = String_Len(data);
    _t607 = (int)_t606;
    bux_sha512(data, _t607, out);
}

int Hash_Sha1Size(void) {
    return 20;
}

int Hash_Sha256Size(void) {
    return 32;
}

int Hash_Sha384Size(void) {
    return 48;
}

int Hash_Sha512Size(void) {
    return 64;
}

const char* Base64_Encode(const char* s) {
    int _t609;
    unsigned int _t608;
    _t608 = String_Len(s);
    _t609 = (int)_t608;
    const char* _t610;
    _t610 = bux_base64_encode(s, _t609);
    return _t610;
}

const char* Base64_Decode(const char* s) {
    int _t612;
    void* _t613;
    int outlen;
    outlen = 0;
    unsigned int _t611;
    _t611 = String_Len(s);
    _t612 = (int)_t611;
    _t613 = &outlen;
    const char* _t614;
    _t614 = bux_base64_decode(s, _t612, _t613);
    return _t614;
}

const char* Base64URL_Encode(const char* s) {
    int _t616;
    unsigned int _t615;
    _t615 = String_Len(s);
    _t616 = (int)_t615;
    const char* _t617;
    _t617 = bux_base64url_encode(s, _t616);
    return _t617;
}

const char* Base64URL_Decode(const char* s) {
    int _t619;
    void* _t620;
    int outlen;
    outlen = 0;
    unsigned int _t618;
    _t618 = String_Len(s);
    _t619 = (int)_t618;
    _t620 = &outlen;
    const char* _t621;
    _t621 = bux_base64url_decode(s, _t619, _t620);
    return _t621;
}

const char* Hmac_Sha256(const char* key, const char* message) {
    int _t623;
    int _t625;
    int kl;
    unsigned int _t622;
    _t622 = String_Len(key);
    _t623 = (int)_t622;
    kl = _t623;
    int ml;
    unsigned int _t624;
    _t624 = String_Len(message);
    _t625 = (int)_t624;
    ml = _t625;
    void* buf;
    void* _t626;
    _t626 = Alloc(32);
    buf = _t626;
    bux_hmac_sha256(key, kl, message, ml, buf);
    const char* result;
    const char* _t627;
    _t627 = bux_bytes_to_hex(buf, 32);
    result = _t627;
    Free(buf);
    return result;
}

void Hmac_Sha256Raw(const char* key, const char* message, void* out) {
    int _t629;
    int _t631;
    unsigned int _t628;
    _t628 = String_Len(key);
    _t629 = (int)_t628;
    unsigned int _t630;
    _t630 = String_Len(message);
    _t631 = (int)_t630;
    bux_hmac_sha256(key, _t629, message, _t631, out);
}

const char* Hmac_Sha256Base64(const char* key, const char* message) {
    int _t633;
    int _t635;
    const char* _t637;
    int kl;
    unsigned int _t632;
    _t632 = String_Len(key);
    _t633 = (int)_t632;
    kl = _t633;
    int ml;
    unsigned int _t634;
    _t634 = String_Len(message);
    _t635 = (int)_t634;
    ml = _t635;
    void* buf;
    void* _t636;
    _t636 = Alloc(32);
    buf = _t636;
    bux_hmac_sha256(key, kl, message, ml, buf);
    const char* result;
    _t637 = (const char*)buf;
    const char* _t638;
    _t638 = bux_base64_encode(_t637, 32);
    result = _t638;
    Free(buf);
    return result;
}

const char* Hmac_Sha384(const char* key, const char* message) {
    int _t640;
    int _t642;
    int kl;
    unsigned int _t639;
    _t639 = String_Len(key);
    _t640 = (int)_t639;
    kl = _t640;
    int ml;
    unsigned int _t641;
    _t641 = String_Len(message);
    _t642 = (int)_t641;
    ml = _t642;
    void* buf;
    void* _t643;
    _t643 = Alloc(48);
    buf = _t643;
    bux_hmac_sha384(key, kl, message, ml, buf);
    const char* result;
    const char* _t644;
    _t644 = bux_bytes_to_hex(buf, 48);
    result = _t644;
    Free(buf);
    return result;
}

void Hmac_Sha384Raw(const char* key, const char* message, void* out) {
    int _t646;
    int _t648;
    unsigned int _t645;
    _t645 = String_Len(key);
    _t646 = (int)_t645;
    unsigned int _t647;
    _t647 = String_Len(message);
    _t648 = (int)_t647;
    bux_hmac_sha384(key, _t646, message, _t648, out);
}

const char* Hmac_Sha384Base64(const char* key, const char* message) {
    int _t650;
    int _t652;
    const char* _t654;
    int kl;
    unsigned int _t649;
    _t649 = String_Len(key);
    _t650 = (int)_t649;
    kl = _t650;
    int ml;
    unsigned int _t651;
    _t651 = String_Len(message);
    _t652 = (int)_t651;
    ml = _t652;
    void* buf;
    void* _t653;
    _t653 = Alloc(48);
    buf = _t653;
    bux_hmac_sha384(key, kl, message, ml, buf);
    const char* result;
    _t654 = (const char*)buf;
    const char* _t655;
    _t655 = bux_base64_encode(_t654, 48);
    result = _t655;
    Free(buf);
    return result;
}

const char* Hmac_Sha512(const char* key, const char* message) {
    int _t657;
    int _t659;
    int kl;
    unsigned int _t656;
    _t656 = String_Len(key);
    _t657 = (int)_t656;
    kl = _t657;
    int ml;
    unsigned int _t658;
    _t658 = String_Len(message);
    _t659 = (int)_t658;
    ml = _t659;
    void* buf;
    void* _t660;
    _t660 = Alloc(64);
    buf = _t660;
    bux_hmac_sha512(key, kl, message, ml, buf);
    const char* result;
    const char* _t661;
    _t661 = bux_bytes_to_hex(buf, 64);
    result = _t661;
    Free(buf);
    return result;
}

void Hmac_Sha512Raw(const char* key, const char* message, void* out) {
    int _t663;
    int _t665;
    unsigned int _t662;
    _t662 = String_Len(key);
    _t663 = (int)_t662;
    unsigned int _t664;
    _t664 = String_Len(message);
    _t665 = (int)_t664;
    bux_hmac_sha512(key, _t663, message, _t665, out);
}

const char* Hmac_Sha512Base64(const char* key, const char* message) {
    int _t667;
    int _t669;
    const char* _t671;
    int kl;
    unsigned int _t666;
    _t666 = String_Len(key);
    _t667 = (int)_t666;
    kl = _t667;
    int ml;
    unsigned int _t668;
    _t668 = String_Len(message);
    _t669 = (int)_t668;
    ml = _t669;
    void* buf;
    void* _t670;
    _t670 = Alloc(64);
    buf = _t670;
    bux_hmac_sha512(key, kl, message, ml, buf);
    const char* result;
    _t671 = (const char*)buf;
    const char* _t672;
    _t672 = bux_base64_encode(_t671, 64);
    result = _t672;
    Free(buf);
    return result;
}

const char* Random_Bytes(int n) {
    int _t673;
    unsigned int _t674;
    int _t677;
    const char* _t678;
    _t673 = (n <= 0);
    if (!_t673) goto endif237;
    {
    return "";
    }
    endif237:;
    void* buf;
    _t674 = (unsigned int)n;
    void* _t675;
    _t675 = Alloc(_t674);
    buf = _t675;
    int _t676;
    _t676 = bux_random_bytes(buf, n);
    _t677 = (_t676 != 1);
    if (!_t677) goto endif239;
    {
    Free(buf);
    return "";
    }
    endif239:;
    _t678 = (const char*)buf;
    return _t678;
}

const char* Random_Hex(int n) {
    int _t679;
    unsigned int _t680;
    int _t683;
    _t679 = (n <= 0);
    if (!_t679) goto endif241;
    {
    return "";
    }
    endif241:;
    void* buf;
    _t680 = (unsigned int)n;
    void* _t681;
    _t681 = Alloc(_t680);
    buf = _t681;
    int _t682;
    _t682 = bux_random_bytes(buf, n);
    _t683 = (_t682 != 1);
    if (!_t683) goto endif243;
    {
    Free(buf);
    return "";
    }
    endif243:;
    const char* result;
    const char* _t684;
    _t684 = bux_bytes_to_hex(buf, n);
    result = _t684;
    Free(buf);
    return result;
}

const char* Random_Base64(int n) {
    int _t685;
    unsigned int _t686;
    int _t689;
    const char* _t690;
    _t685 = (n <= 0);
    if (!_t685) goto endif245;
    {
    return "";
    }
    endif245:;
    void* buf;
    _t686 = (unsigned int)n;
    void* _t687;
    _t687 = Alloc(_t686);
    buf = _t687;
    int _t688;
    _t688 = bux_random_bytes(buf, n);
    _t689 = (_t688 != 1);
    if (!_t689) goto endif247;
    {
    Free(buf);
    return "";
    }
    endif247:;
    const char* result;
    _t690 = (const char*)buf;
    const char* _t691;
    _t691 = bux_base64_encode(_t690, n);
    result = _t691;
    Free(buf);
    return result;
}

unsigned int Random_Uint32(void) {
    int _t694;
    unsigned int* _t695;
    unsigned int _t696;
    void* buf;
    void* _t692;
    _t692 = Alloc(4);
    buf = _t692;
    int _t693;
    _t693 = bux_random_bytes(buf, 4);
    _t694 = (_t693 != 1);
    if (!_t694) goto endif249;
    {
    Free(buf);
    return 0;
    }
    endif249:;
    unsigned int* ptr;
    _t695 = (unsigned int*)buf;
    ptr = _t695;
    unsigned int val;
    _t696 = *ptr;
    val = _t696;
    Free(buf);
    return val;
}

const char* Aes_GenerateKey(void) {
    unsigned int _t697;
    int _t700;
    const char* _t701;
    void* buf;
    _t697 = (unsigned int)AES_KEY_SIZE;
    void* _t698;
    _t698 = Alloc(_t697);
    buf = _t698;
    int _t699;
    _t699 = bux_random_bytes(buf, AES_KEY_SIZE);
    _t700 = (_t699 != 1);
    if (!_t700) goto endif251;
    {
    Free(buf);
    return "";
    }
    endif251:;
    _t701 = (const char*)buf;
    return _t701;
}

const char* Aes_GenerateIV(void) {
    unsigned int _t702;
    int _t705;
    const char* _t706;
    void* buf;
    _t702 = (unsigned int)AES_IV_SIZE;
    void* _t703;
    _t703 = Alloc(_t702);
    buf = _t703;
    int _t704;
    _t704 = bux_random_bytes(buf, AES_IV_SIZE);
    _t705 = (_t704 != 1);
    if (!_t705) goto endif253;
    {
    Free(buf);
    return "";
    }
    endif253:;
    _t706 = (const char*)buf;
    return _t706;
}

const char* Aes_CbcEncrypt(const char* plain, const char* key, const char* iv) {
    int _t708;
    void* _t709;
    int outlen;
    outlen = 0;
    unsigned int _t707;
    _t707 = String_Len(plain);
    _t708 = (int)_t707;
    _t709 = &outlen;
    const char* _t710;
    _t710 = bux_aes_256_cbc_encrypt(plain, _t708, key, iv, _t709);
    return _t710;
}

const char* Aes_CbcDecrypt(const char* cipher, const char* key, const char* iv) {
    int _t712;
    void* _t713;
    int outlen;
    outlen = 0;
    unsigned int _t711;
    _t711 = String_Len(cipher);
    _t712 = (int)_t711;
    _t713 = &outlen;
    const char* _t714;
    _t714 = bux_aes_256_cbc_decrypt(cipher, _t712, key, iv, _t713);
    return _t714;
}

const char* Aes_GcmEncrypt(const char* plain, const char* key, const char* iv, void* tag) {
    int _t716;
    void* _t717;
    int outlen;
    outlen = 0;
    unsigned int _t715;
    _t715 = String_Len(plain);
    _t716 = (int)_t715;
    _t717 = &outlen;
    const char* _t718;
    _t718 = bux_aes_256_gcm_encrypt(plain, _t716, key, iv, tag, _t717);
    return _t718;
}

const char* Aes_GcmDecrypt(const char* cipher, const char* key, const char* iv, const char* tag) {
    int _t720;
    void* _t721;
    int outlen;
    outlen = 0;
    unsigned int _t719;
    _t719 = String_Len(cipher);
    _t720 = (int)_t719;
    _t721 = &outlen;
    const char* _t722;
    _t722 = bux_aes_256_gcm_decrypt(cipher, _t720, key, iv, tag, _t721);
    return _t722;
}

const char* Jwt_MakeHeader(JwtAlg alg) {
    int _t723;
    int _t724;
    int _t725;
    int _t726;
    int _t727;
    int _t728;
    int _t729;
    int _t730;
    int _t731;
    _t723 = (alg == JwtAlg_HS256);
    if (!_t723) goto endif255;
    {
    return "{\"alg\":\"HS256\",\"typ\":\"JWT\"}";
    }
    endif255:;
    _t724 = (alg == JwtAlg_HS384);
    if (!_t724) goto endif257;
    {
    return "{\"alg\":\"HS384\",\"typ\":\"JWT\"}";
    }
    endif257:;
    _t725 = (alg == JwtAlg_HS512);
    if (!_t725) goto endif259;
    {
    return "{\"alg\":\"HS512\",\"typ\":\"JWT\"}";
    }
    endif259:;
    _t726 = (alg == JwtAlg_RS256);
    if (!_t726) goto endif261;
    {
    return "{\"alg\":\"RS256\",\"typ\":\"JWT\"}";
    }
    endif261:;
    _t727 = (alg == JwtAlg_RS384);
    if (!_t727) goto endif263;
    {
    return "{\"alg\":\"RS384\",\"typ\":\"JWT\"}";
    }
    endif263:;
    _t728 = (alg == JwtAlg_RS512);
    if (!_t728) goto endif265;
    {
    return "{\"alg\":\"RS512\",\"typ\":\"JWT\"}";
    }
    endif265:;
    _t729 = (alg == JwtAlg_ES256);
    if (!_t729) goto endif267;
    {
    return "{\"alg\":\"ES256\",\"typ\":\"JWT\"}";
    }
    endif267:;
    _t730 = (alg == JwtAlg_ES384);
    if (!_t730) goto endif269;
    {
    return "{\"alg\":\"ES384\",\"typ\":\"JWT\"}";
    }
    endif269:;
    _t731 = (alg == JwtAlg_EdDSA);
    if (!_t731) goto endif271;
    {
    return "{\"alg\":\"EdDSA\",\"typ\":\"JWT\"}";
    }
    endif271:;
    return "{\"alg\":\"none\",\"typ\":\"JWT\"}";
}

const char* Jwt_Sign(JwtAlg alg, const char* signingInput, const char* key) {
    int _t732;
    const char* _t734;
    int _t736;
    const char* _t738;
    int _t740;
    const char* _t742;
    int _t744;
    int _t747;
    int _t749;
    int _t752;
    int _t754;
    int _t757;
    int _t759;
    int _t762;
    int _t764;
    int _t767;
    int _t769;
    _t732 = (alg == JwtAlg_HS256);
    if (!_t732) goto endif273;
    {
    void* buf;
    void* _t733;
    _t733 = Alloc(32);
    buf = _t733;
    Hmac_Sha256Raw(key, signingInput, buf);
    const char* result;
    _t734 = (const char*)buf;
    const char* _t735;
    _t735 = bux_base64_encode(_t734, 32);
    result = _t735;
    Free(buf);
    return result;
    }
    endif273:;
    _t736 = (alg == JwtAlg_HS384);
    if (!_t736) goto endif275;
    {
    void* buf;
    void* _t737;
    _t737 = Alloc(48);
    buf = _t737;
    Hmac_Sha384Raw(key, signingInput, buf);
    const char* result;
    _t738 = (const char*)buf;
    const char* _t739;
    _t739 = bux_base64_encode(_t738, 48);
    result = _t739;
    Free(buf);
    return result;
    }
    endif275:;
    _t740 = (alg == JwtAlg_HS512);
    if (!_t740) goto endif277;
    {
    void* buf;
    void* _t741;
    _t741 = Alloc(64);
    buf = _t741;
    Hmac_Sha512Raw(key, signingInput, buf);
    const char* result;
    _t742 = (const char*)buf;
    const char* _t743;
    _t743 = bux_base64_encode(_t742, 64);
    result = _t743;
    Free(buf);
    return result;
    }
    endif277:;
    _t744 = (alg == JwtAlg_RS256);
    if (!_t744) goto endif279;
    {
    const char* raw;
    const char* _t745;
    _t745 = Rsa_SignSha256(key, signingInput);
    raw = _t745;
    unsigned int _t746;
    _t746 = String_Len(raw);
    _t747 = (int)_t746;
    const char* _t748;
    _t748 = bux_base64_encode(raw, _t747);
    return _t748;
    }
    endif279:;
    _t749 = (alg == JwtAlg_RS384);
    if (!_t749) goto endif281;
    {
    const char* raw;
    const char* _t750;
    _t750 = Rsa_SignSha384(key, signingInput);
    raw = _t750;
    unsigned int _t751;
    _t751 = String_Len(raw);
    _t752 = (int)_t751;
    const char* _t753;
    _t753 = bux_base64_encode(raw, _t752);
    return _t753;
    }
    endif281:;
    _t754 = (alg == JwtAlg_RS512);
    if (!_t754) goto endif283;
    {
    const char* raw;
    const char* _t755;
    _t755 = Rsa_SignSha512(key, signingInput);
    raw = _t755;
    unsigned int _t756;
    _t756 = String_Len(raw);
    _t757 = (int)_t756;
    const char* _t758;
    _t758 = bux_base64_encode(raw, _t757);
    return _t758;
    }
    endif283:;
    _t759 = (alg == JwtAlg_ES256);
    if (!_t759) goto endif285;
    {
    const char* raw;
    const char* _t760;
    _t760 = Ecdsa_SignP256(key, signingInput);
    raw = _t760;
    unsigned int _t761;
    _t761 = String_Len(raw);
    _t762 = (int)_t761;
    const char* _t763;
    _t763 = bux_base64_encode(raw, _t762);
    return _t763;
    }
    endif285:;
    _t764 = (alg == JwtAlg_ES384);
    if (!_t764) goto endif287;
    {
    const char* raw;
    const char* _t765;
    _t765 = Ecdsa_SignP384(key, signingInput);
    raw = _t765;
    unsigned int _t766;
    _t766 = String_Len(raw);
    _t767 = (int)_t766;
    const char* _t768;
    _t768 = bux_base64_encode(raw, _t767);
    return _t768;
    }
    endif287:;
    _t769 = (alg == JwtAlg_EdDSA);
    if (!_t769) goto endif289;
    {
    const char* _t770;
    _t770 = Ed25519_Sign(key, signingInput);
    return _t770;
    }
    endif289:;
    return "";
}

bool Jwt_Verify(JwtAlg alg, const char* signingInput, const char* signatureB64, const char* key) {
    int _t771;
    const char* _t773;
    int _t776;
    const char* _t778;
    int _t781;
    const char* _t783;
    int _t786;
    int _t788;
    int _t790;
    int _t792;
    int _t794;
    int _t796;
    _t771 = (alg == JwtAlg_HS256);
    if (!_t771) goto endif291;
    {
    void* expectBuf;
    void* _t772;
    _t772 = Alloc(32);
    expectBuf = _t772;
    Hmac_Sha256Raw(key, signingInput, expectBuf);
    const char* expectB64;
    _t773 = (const char*)expectBuf;
    const char* _t774;
    _t774 = bux_base64_encode(_t773, 32);
    expectB64 = _t774;
    Free(expectBuf);
    bool _t775;
    _t775 = String_Eq(expectB64, signatureB64);
    return _t775;
    }
    endif291:;
    _t776 = (alg == JwtAlg_HS384);
    if (!_t776) goto endif293;
    {
    void* expectBuf;
    void* _t777;
    _t777 = Alloc(48);
    expectBuf = _t777;
    Hmac_Sha384Raw(key, signingInput, expectBuf);
    const char* expectB64;
    _t778 = (const char*)expectBuf;
    const char* _t779;
    _t779 = bux_base64_encode(_t778, 48);
    expectB64 = _t779;
    Free(expectBuf);
    bool _t780;
    _t780 = String_Eq(expectB64, signatureB64);
    return _t780;
    }
    endif293:;
    _t781 = (alg == JwtAlg_HS512);
    if (!_t781) goto endif295;
    {
    void* expectBuf;
    void* _t782;
    _t782 = Alloc(64);
    expectBuf = _t782;
    Hmac_Sha512Raw(key, signingInput, expectBuf);
    const char* expectB64;
    _t783 = (const char*)expectBuf;
    const char* _t784;
    _t784 = bux_base64_encode(_t783, 64);
    expectB64 = _t784;
    Free(expectBuf);
    bool _t785;
    _t785 = String_Eq(expectB64, signatureB64);
    return _t785;
    }
    endif295:;
    _t786 = (alg == JwtAlg_RS256);
    if (!_t786) goto endif297;
    {
    bool _t787;
    _t787 = Rsa_VerifySha256(key, signingInput, signatureB64);
    return _t787;
    }
    endif297:;
    _t788 = (alg == JwtAlg_RS384);
    if (!_t788) goto endif299;
    {
    bool _t789;
    _t789 = Rsa_VerifySha384(key, signingInput, signatureB64);
    return _t789;
    }
    endif299:;
    _t790 = (alg == JwtAlg_RS512);
    if (!_t790) goto endif301;
    {
    bool _t791;
    _t791 = Rsa_VerifySha512(key, signingInput, signatureB64);
    return _t791;
    }
    endif301:;
    _t792 = (alg == JwtAlg_ES256);
    if (!_t792) goto endif303;
    {
    bool _t793;
    _t793 = Ecdsa_VerifyP256(key, signingInput, signatureB64);
    return _t793;
    }
    endif303:;
    _t794 = (alg == JwtAlg_ES384);
    if (!_t794) goto endif305;
    {
    bool _t795;
    _t795 = Ecdsa_VerifyP384(key, signingInput, signatureB64);
    return _t795;
    }
    endif305:;
    _t796 = (alg == JwtAlg_EdDSA);
    if (!_t796) goto endif307;
    {
    bool _t797;
    _t797 = Ed25519_Verify(key, signatureB64, signingInput);
    return _t797;
    }
    endif307:;
    return 0;
}

const char* Jwt_Encode(const char* headerJson, const char* payloadJson, JwtAlg alg, const char* key) {
    const char* headerB64;
    const char* _t798;
    _t798 = Base64URL_Encode(headerJson);
    headerB64 = _t798;
    const char* payloadB64;
    const char* _t799;
    _t799 = Base64URL_Encode(payloadJson);
    payloadB64 = _t799;
    const char* signingInput;
    const char* _t800;
    _t800 = String_Concat(headerB64, ".");
    signingInput = _t800;
    const char* signingInputFull;
    const char* _t801;
    _t801 = String_Concat(signingInput, payloadB64);
    signingInputFull = _t801;
    const char* sigB64;
    const char* _t802;
    _t802 = Jwt_Sign(alg, signingInputFull, key);
    sigB64 = _t802;
    const char* part1;
    const char* _t803;
    _t803 = String_Concat(signingInputFull, ".");
    part1 = _t803;
    const char* _t804;
    _t804 = String_Concat(part1, sigB64);
    return _t804;
}

bool Jwt_Decode(const char* token, JwtAlg alg, const char* key, const char** headerOut, const char** payloadOut) {
    int _t806;
    int _t813;
    unsigned int partCount;
    unsigned int _t805;
    _t805 = bux_str_split_count(token, ".");
    partCount = _t805;
    _t806 = (partCount != 3);
    if (!_t806) goto endif309;
    {
    return 0;
    }
    endif309:;
    const char* headerB64;
    const char* _t807;
    _t807 = bux_str_split_part(token, ".", 0);
    headerB64 = _t807;
    const char* payloadB64;
    const char* _t808;
    _t808 = bux_str_split_part(token, ".", 1);
    payloadB64 = _t808;
    const char* sigB64;
    const char* _t809;
    _t809 = bux_str_split_part(token, ".", 2);
    sigB64 = _t809;
    const char* input;
    const char* _t810;
    _t810 = String_Concat(headerB64, ".");
    input = _t810;
    const char* signingInput;
    const char* _t811;
    _t811 = String_Concat(input, payloadB64);
    signingInput = _t811;
    bool _t812;
    _t812 = Jwt_Verify(alg, signingInput, sigB64, key);
    _t813 = !_t812;
    if (!_t813) goto endif311;
    {
    return 0;
    }
    endif311:;
    const char* _t814;
    _t814 = Base64URL_Decode(headerB64);
    headerOut[0] = _t814;
    const char* _t815;
    _t815 = Base64URL_Decode(payloadB64);
    payloadOut[0] = _t815;
    return 1;
}

const char* Jwt_EncodeHS256(const char* payloadJson, const char* secret) {
    const char* header;
    const char* _t816;
    _t816 = Jwt_MakeHeader(JwtAlg_HS256);
    header = _t816;
    const char* _t817;
    _t817 = Jwt_Encode(header, payloadJson, JwtAlg_HS256, secret);
    return _t817;
}

const char* Jwt_EncodeHS384(const char* payloadJson, const char* secret) {
    const char* header;
    const char* _t818;
    _t818 = Jwt_MakeHeader(JwtAlg_HS384);
    header = _t818;
    const char* _t819;
    _t819 = Jwt_Encode(header, payloadJson, JwtAlg_HS384, secret);
    return _t819;
}

const char* Jwt_EncodeHS512(const char* payloadJson, const char* secret) {
    const char* header;
    const char* _t820;
    _t820 = Jwt_MakeHeader(JwtAlg_HS512);
    header = _t820;
    const char* _t821;
    _t821 = Jwt_Encode(header, payloadJson, JwtAlg_HS512, secret);
    return _t821;
}

const char* Jwt_EncodeRS256(const char* payloadJson, const char* pemPrivateKey) {
    const char* header;
    const char* _t822;
    _t822 = Jwt_MakeHeader(JwtAlg_RS256);
    header = _t822;
    const char* _t823;
    _t823 = Jwt_Encode(header, payloadJson, JwtAlg_RS256, pemPrivateKey);
    return _t823;
}

const char* Jwt_EncodeES256(const char* payloadJson, const char* pemPrivateKey) {
    const char* header;
    const char* _t824;
    _t824 = Jwt_MakeHeader(JwtAlg_ES256);
    header = _t824;
    const char* _t825;
    _t825 = Jwt_Encode(header, payloadJson, JwtAlg_ES256, pemPrivateKey);
    return _t825;
}

const char* Jwt_EncodeEdDSA(const char* payloadJson, const char* rawPrivKey) {
    const char* header;
    const char* _t826;
    _t826 = Jwt_MakeHeader(JwtAlg_EdDSA);
    header = _t826;
    const char* _t827;
    _t827 = Jwt_Encode(header, payloadJson, JwtAlg_EdDSA, rawPrivKey);
    return _t827;
}

const char* Ecdsa_SignP256(const char* pemPrivateKey, const char* data) {
    int _t829;
    int _t831;
    void* _t832;
    int siglen;
    siglen = 0;
    unsigned int _t828;
    _t828 = String_Len(pemPrivateKey);
    _t829 = (int)_t828;
    unsigned int _t830;
    _t830 = String_Len(data);
    _t831 = (int)_t830;
    _t832 = &siglen;
    const char* _t833;
    _t833 = bux_ecdsa_sign_p256(pemPrivateKey, _t829, data, _t831, _t832);
    return _t833;
}

const char* Ecdsa_SignP256Base64(const char* pemPrivateKey, const char* data) {
    int _t836;
    const char* raw;
    const char* _t834;
    _t834 = Ecdsa_SignP256(pemPrivateKey, data);
    raw = _t834;
    unsigned int _t835;
    _t835 = String_Len(raw);
    _t836 = (int)_t835;
    const char* _t837;
    _t837 = bux_base64_encode(raw, _t836);
    return _t837;
}

bool Ecdsa_VerifyP256(const char* pemPublicKey, const char* data, const char* signature) {
    int _t839;
    int _t841;
    int _t843;
    int _t845;
    int r;
    unsigned int _t838;
    _t838 = String_Len(pemPublicKey);
    _t839 = (int)_t838;
    unsigned int _t840;
    _t840 = String_Len(data);
    _t841 = (int)_t840;
    unsigned int _t842;
    _t842 = String_Len(signature);
    _t843 = (int)_t842;
    int _t844;
    _t844 = bux_ecdsa_verify_p256(pemPublicKey, _t839, data, _t841, signature, _t843);
    r = _t844;
    _t845 = (r == 1);
    return _t845;
}

bool Ecdsa_VerifyP256Base64(const char* pemPublicKey, const char* data, const char* signatureB64) {
    int _t847;
    void* _t848;
    int outlen;
    outlen = 0;
    const char* sig;
    unsigned int _t846;
    _t846 = String_Len(signatureB64);
    _t847 = (int)_t846;
    _t848 = &outlen;
    const char* _t849;
    _t849 = bux_base64_decode(signatureB64, _t847, _t848);
    sig = _t849;
    bool _t850;
    _t850 = Ecdsa_VerifyP256(pemPublicKey, data, sig);
    return _t850;
}

const char* Ecdsa_SignP384(const char* pemPrivateKey, const char* data) {
    int _t852;
    int _t854;
    void* _t855;
    int siglen;
    siglen = 0;
    unsigned int _t851;
    _t851 = String_Len(pemPrivateKey);
    _t852 = (int)_t851;
    unsigned int _t853;
    _t853 = String_Len(data);
    _t854 = (int)_t853;
    _t855 = &siglen;
    const char* _t856;
    _t856 = bux_ecdsa_sign_p384(pemPrivateKey, _t852, data, _t854, _t855);
    return _t856;
}

const char* Ecdsa_SignP384Base64(const char* pemPrivateKey, const char* data) {
    int _t859;
    const char* raw;
    const char* _t857;
    _t857 = Ecdsa_SignP384(pemPrivateKey, data);
    raw = _t857;
    unsigned int _t858;
    _t858 = String_Len(raw);
    _t859 = (int)_t858;
    const char* _t860;
    _t860 = bux_base64_encode(raw, _t859);
    return _t860;
}

bool Ecdsa_VerifyP384(const char* pemPublicKey, const char* data, const char* signature) {
    int _t862;
    int _t864;
    int _t866;
    int _t868;
    int r;
    unsigned int _t861;
    _t861 = String_Len(pemPublicKey);
    _t862 = (int)_t861;
    unsigned int _t863;
    _t863 = String_Len(data);
    _t864 = (int)_t863;
    unsigned int _t865;
    _t865 = String_Len(signature);
    _t866 = (int)_t865;
    int _t867;
    _t867 = bux_ecdsa_verify_p384(pemPublicKey, _t862, data, _t864, signature, _t866);
    r = _t867;
    _t868 = (r == 1);
    return _t868;
}

bool Ecdsa_VerifyP384Base64(const char* pemPublicKey, const char* data, const char* signatureB64) {
    int _t870;
    void* _t871;
    int outlen;
    outlen = 0;
    const char* sig;
    unsigned int _t869;
    _t869 = String_Len(signatureB64);
    _t870 = (int)_t869;
    _t871 = &outlen;
    const char* _t872;
    _t872 = bux_base64_decode(signatureB64, _t870, _t871);
    sig = _t872;
    bool _t873;
    _t873 = Ecdsa_VerifyP384(pemPublicKey, data, sig);
    return _t873;
}

bool Ed25519_Keypair(void* pubKey, void* privKey) {
    int _t875;
    int r;
    int _t874;
    _t874 = bux_ed25519_keypair(pubKey, privKey);
    r = _t874;
    _t875 = (r == 1);
    return _t875;
}

const char* Ed25519_KeypairBase64(void) {
    unsigned int _t876;
    unsigned int _t878;
    int _t881;
    const char* _t882;
    const char* _t884;
    void* pubBuf;
    _t876 = (unsigned int)ED25519_PUBKEY_SIZE;
    void* _t877;
    _t877 = Alloc(_t876);
    pubBuf = _t877;
    void* priv;
    _t878 = (unsigned int)ED25519_PRIVKEY_SIZE;
    void* _t879;
    _t879 = Alloc(_t878);
    priv = _t879;
    int _t880;
    _t880 = bux_ed25519_keypair(pubBuf, priv);
    _t881 = (_t880 != 1);
    if (!_t881) goto endif313;
    {
    Free(pubBuf);
    Free(priv);
    return "";
    }
    endif313:;
    const char* pubB64;
    _t882 = (const char*)pubBuf;
    const char* _t883;
    _t883 = bux_base64_encode(_t882, ED25519_PUBKEY_SIZE);
    pubB64 = _t883;
    const char* privB64;
    _t884 = (const char*)priv;
    const char* _t885;
    _t885 = bux_base64_encode(_t884, ED25519_PRIVKEY_SIZE);
    privB64 = _t885;
    Free(pubBuf);
    Free(priv);
    const char* pair;
    const char* _t886;
    _t886 = String_Concat(pubB64, ":");
    pair = _t886;
    const char* _t887;
    _t887 = String_Concat(pair, privB64);
    return _t887;
}

const char* Ed25519_Sign(const char* privKey, const char* data) {
    unsigned int _t888;
    int _t891;
    int _t893;
    const char* _t894;
    void* sig;
    _t888 = (unsigned int)ED25519_SIG_SIZE;
    void* _t889;
    _t889 = Alloc(_t888);
    sig = _t889;
    unsigned int _t890;
    _t890 = String_Len(data);
    _t891 = (int)_t890;
    int _t892;
    _t892 = bux_ed25519_sign(privKey, data, _t891, sig);
    _t893 = (_t892 != 1);
    if (!_t893) goto endif315;
    {
    Free(sig);
    return "";
    }
    endif315:;
    _t894 = (const char*)sig;
    return _t894;
}

const char* Ed25519_SignBase64(const char* privKey, const char* data) {
    int _t897;
    const char* sig;
    const char* _t895;
    _t895 = Ed25519_Sign(privKey, data);
    sig = _t895;
    unsigned int _t896;
    _t896 = String_Len(sig);
    _t897 = (_t896 == 0);
    if (!_t897) goto endif317;
    {
    return "";
    }
    endif317:;
    const char* _t898;
    _t898 = bux_base64_encode(sig, ED25519_SIG_SIZE);
    return _t898;
}

bool Ed25519_Verify(const char* pubKey, const char* signature, const char* data) {
    int _t900;
    int _t902;
    int r;
    unsigned int _t899;
    _t899 = String_Len(data);
    _t900 = (int)_t899;
    int _t901;
    _t901 = bux_ed25519_verify(pubKey, signature, data, _t900);
    r = _t901;
    _t902 = (r == 1);
    return _t902;
}

bool Ed25519_VerifyBase64(const char* pubKey, const char* signatureB64, const char* data) {
    int _t904;
    void* _t905;
    int _t907;
    int outlen;
    outlen = 0;
    const char* sig;
    unsigned int _t903;
    _t903 = String_Len(signatureB64);
    _t904 = (int)_t903;
    _t905 = &outlen;
    const char* _t906;
    _t906 = bux_base64_decode(signatureB64, _t904, _t905);
    sig = _t906;
    _t907 = (outlen != ED25519_SIG_SIZE);
    if (!_t907) goto endif319;
    {
    return 0;
    }
    endif319:;
    bool _t908;
    _t908 = Ed25519_Verify(pubKey, sig, data);
    return _t908;
}

const char* Rsa_SignSha256(const char* pemPrivateKey, const char* data) {
    int _t910;
    int _t912;
    void* _t913;
    int siglen;
    siglen = 0;
    unsigned int _t909;
    _t909 = String_Len(pemPrivateKey);
    _t910 = (int)_t909;
    unsigned int _t911;
    _t911 = String_Len(data);
    _t912 = (int)_t911;
    _t913 = &siglen;
    const char* _t914;
    _t914 = bux_rsa_sign_sha256(pemPrivateKey, _t910, data, _t912, _t913);
    return _t914;
}

const char* Rsa_SignSha384(const char* pemPrivateKey, const char* data) {
    int _t916;
    int _t918;
    void* _t919;
    int siglen;
    siglen = 0;
    unsigned int _t915;
    _t915 = String_Len(pemPrivateKey);
    _t916 = (int)_t915;
    unsigned int _t917;
    _t917 = String_Len(data);
    _t918 = (int)_t917;
    _t919 = &siglen;
    const char* _t920;
    _t920 = bux_rsa_sign_sha384(pemPrivateKey, _t916, data, _t918, _t919);
    return _t920;
}

const char* Rsa_SignSha512(const char* pemPrivateKey, const char* data) {
    int _t922;
    int _t924;
    void* _t925;
    int siglen;
    siglen = 0;
    unsigned int _t921;
    _t921 = String_Len(pemPrivateKey);
    _t922 = (int)_t921;
    unsigned int _t923;
    _t923 = String_Len(data);
    _t924 = (int)_t923;
    _t925 = &siglen;
    const char* _t926;
    _t926 = bux_rsa_sign_sha512(pemPrivateKey, _t922, data, _t924, _t925);
    return _t926;
}

const char* Rsa_SignSha256Base64(const char* pemPrivateKey, const char* data) {
    int _t929;
    const char* raw;
    const char* _t927;
    _t927 = Rsa_SignSha256(pemPrivateKey, data);
    raw = _t927;
    unsigned int _t928;
    _t928 = String_Len(raw);
    _t929 = (int)_t928;
    const char* _t930;
    _t930 = bux_base64_encode(raw, _t929);
    return _t930;
}

const char* Rsa_SignSha384Base64(const char* pemPrivateKey, const char* data) {
    int _t933;
    const char* raw;
    const char* _t931;
    _t931 = Rsa_SignSha384(pemPrivateKey, data);
    raw = _t931;
    unsigned int _t932;
    _t932 = String_Len(raw);
    _t933 = (int)_t932;
    const char* _t934;
    _t934 = bux_base64_encode(raw, _t933);
    return _t934;
}

const char* Rsa_SignSha512Base64(const char* pemPrivateKey, const char* data) {
    int _t937;
    const char* raw;
    const char* _t935;
    _t935 = Rsa_SignSha512(pemPrivateKey, data);
    raw = _t935;
    unsigned int _t936;
    _t936 = String_Len(raw);
    _t937 = (int)_t936;
    const char* _t938;
    _t938 = bux_base64_encode(raw, _t937);
    return _t938;
}

bool Rsa_VerifySha256(const char* pemPublicKey, const char* data, const char* signature) {
    int _t940;
    int _t942;
    int _t944;
    int _t946;
    int r;
    unsigned int _t939;
    _t939 = String_Len(pemPublicKey);
    _t940 = (int)_t939;
    unsigned int _t941;
    _t941 = String_Len(data);
    _t942 = (int)_t941;
    unsigned int _t943;
    _t943 = String_Len(signature);
    _t944 = (int)_t943;
    int _t945;
    _t945 = bux_rsa_verify_sha256(pemPublicKey, _t940, data, _t942, signature, _t944);
    r = _t945;
    _t946 = (r == 1);
    return _t946;
}

bool Rsa_VerifySha384(const char* pemPublicKey, const char* data, const char* signature) {
    int _t948;
    int _t950;
    int _t952;
    int _t954;
    int r;
    unsigned int _t947;
    _t947 = String_Len(pemPublicKey);
    _t948 = (int)_t947;
    unsigned int _t949;
    _t949 = String_Len(data);
    _t950 = (int)_t949;
    unsigned int _t951;
    _t951 = String_Len(signature);
    _t952 = (int)_t951;
    int _t953;
    _t953 = bux_rsa_verify_sha384(pemPublicKey, _t948, data, _t950, signature, _t952);
    r = _t953;
    _t954 = (r == 1);
    return _t954;
}

bool Rsa_VerifySha512(const char* pemPublicKey, const char* data, const char* signature) {
    int _t956;
    int _t958;
    int _t960;
    int _t962;
    int r;
    unsigned int _t955;
    _t955 = String_Len(pemPublicKey);
    _t956 = (int)_t955;
    unsigned int _t957;
    _t957 = String_Len(data);
    _t958 = (int)_t957;
    unsigned int _t959;
    _t959 = String_Len(signature);
    _t960 = (int)_t959;
    int _t961;
    _t961 = bux_rsa_verify_sha512(pemPublicKey, _t956, data, _t958, signature, _t960);
    r = _t961;
    _t962 = (r == 1);
    return _t962;
}

bool Rsa_VerifySha256Base64(const char* pemPublicKey, const char* data, const char* signatureB64) {
    int _t964;
    void* _t965;
    int outlen;
    outlen = 0;
    const char* sig;
    unsigned int _t963;
    _t963 = String_Len(signatureB64);
    _t964 = (int)_t963;
    _t965 = &outlen;
    const char* _t966;
    _t966 = bux_base64_decode(signatureB64, _t964, _t965);
    sig = _t966;
    bool _t967;
    _t967 = Rsa_VerifySha256(pemPublicKey, data, sig);
    return _t967;
}

bool Rsa_VerifySha384Base64(const char* pemPublicKey, const char* data, const char* signatureB64) {
    int _t969;
    void* _t970;
    int outlen;
    outlen = 0;
    const char* sig;
    unsigned int _t968;
    _t968 = String_Len(signatureB64);
    _t969 = (int)_t968;
    _t970 = &outlen;
    const char* _t971;
    _t971 = bux_base64_decode(signatureB64, _t969, _t970);
    sig = _t971;
    bool _t972;
    _t972 = Rsa_VerifySha384(pemPublicKey, data, sig);
    return _t972;
}

bool Rsa_VerifySha512Base64(const char* pemPublicKey, const char* data, const char* signatureB64) {
    int _t974;
    void* _t975;
    int outlen;
    outlen = 0;
    const char* sig;
    unsigned int _t973;
    _t973 = String_Len(signatureB64);
    _t974 = (int)_t973;
    _t975 = &outlen;
    const char* _t976;
    _t976 = bux_base64_decode(signatureB64, _t974, _t975);
    sig = _t976;
    bool _t977;
    _t977 = Rsa_VerifySha512(pemPublicKey, data, sig);
    return _t977;
}

int Main(void) {
    int m1;
    int _t978;
    _t978 = Max_int(10, 20);
    m1 = _t978;
    int m2;
    int _t979;
    _t979 = Max_int(5, 3);
    m2 = _t979;
    PrintLine("Max(10, 20) = ");
    PrintInt(m1);
    PrintLine("");
    PrintLine("Max(5, 3) = ");
    PrintInt(m2);
    PrintLine("");
    return 0;
}

int Max_int(int a, int b) {
    int _t980;
    _t980 = (a > b);
    if (!_t980) goto else320;
    {
    return a;
    }
    goto endif321;
    else320:;
    {
    return b;
    }
    endif321:;
}

/* C entry point wrapper */
extern int g_argc;
extern char** g_argv;
int main(int argc, char** argv) {
    g_argc = argc;
    g_argv = argv;
    return Main();
}
