/* Generated by Nim Compiler v1.4.0 */
/*   (c) 2020 Andreas Rumpf */
/* The generated code is subject to the original license. */
#define NIM_INTBITS 32

/* section: NIM_merge_HEADERS */

#include "nimbase.h"
#include <string.h>
#undef LANGUAGE_C
#undef MIPSEB
#undef MIPSEL
#undef PPC
#undef R3000
#undef R4000
#undef i386
#undef linux
#undef mips
#undef near
#undef far
#undef powerpc
#undef unix

/* section: NIM_merge_FRAME_DEFINES */
#define nimfr_(x, y)
#define nimln_(x, y)

/* section: NIM_merge_FORWARD_TYPES */
typedef struct NimStringDesc NimStringDesc;
typedef struct TGenericSeq TGenericSeq;

/* section: NIM_merge_TYPES */
struct TGenericSeq {
NI len;
NI reserved;
};
struct NimStringDesc {
  TGenericSeq Sup;
NIM_CHAR data[SEQ_DECL_SIZE];
};

/* section: NIM_merge_PROC_HEADERS */
N_LIB_PRIVATE N_NIMCALL(void, failedAssertImpl__W9cjVocn1tjhW7p7xohJj6A)(NimStringDesc* msg);
N_LIB_PRIVATE N_NIMCALL(void, openDefaultBrowserImpl__lhAiGWV9cJtbG6lYE4tGA3A_2)(NimStringDesc* url);
N_LIB_PRIVATE N_NIMCALL(NI, nosexecShellCmd)(NimStringDesc* command);
static N_INLINE(void, appendString)(NimStringDesc* dest, NimStringDesc* src);
static N_INLINE(void, copyMem__M04YC71iJg1N7gBF3HZTngsystem)(void* dest, void* source, NI size);
static N_INLINE(void, nimCopyMem)(void* dest, void* source, NI size);
N_LIB_PRIVATE N_NIMCALL(NimStringDesc*, nospquoteShell)(NimStringDesc* s);
N_LIB_PRIVATE N_NIMCALL(NimStringDesc*, prepare__w0beoDPQKB8sTRhzxkmwzw)(NimStringDesc* s);
N_LIB_PRIVATE N_NIMCALL(NIM_BOOL, contains__KV0xCsBzaN9coqb7PG9au0oQ)(NimStringDesc* s, NimStringDesc* sub);
N_LIB_PRIVATE N_NIMCALL(NimStringDesc*, copyString)(NimStringDesc* src);
N_LIB_PRIVATE N_NIMCALL(NimStringDesc*, absolutePath__I16hivp0o49aEba9bSd0N6ng)(NimStringDesc* path, NimStringDesc* root);
N_LIB_PRIVATE N_NIMCALL(NimStringDesc*, nosgetCurrentDir)(void);
N_LIB_PRIVATE N_NIMCALL(NimStringDesc*, rawNewString)(NI space);

/* section: NIM_merge_DATA */
STRING_LITERAL(TM__CZNeKGdQ8AWxD1HSDIq5DQ_2, "browsers.nim(67, 12) `url.len > 0` URL must not be empty string", 63);
STRING_LITERAL(TM__CZNeKGdQ8AWxD1HSDIq5DQ_3, "open ", 5);
STRING_LITERAL(TM__CZNeKGdQ8AWxD1HSDIq5DQ_4, "://", 3);
STRING_LITERAL(TM__CZNeKGdQ8AWxD1HSDIq5DQ_5, "file://", 7);

/* section: NIM_merge_PROCS */
static N_INLINE(void, nimCopyMem)(void* dest, void* source, NI size) {
	void* T1_;
	T1_ = (void*)0;
	T1_ = memcpy(dest, source, ((size_t) (size)));
}
static N_INLINE(void, copyMem__M04YC71iJg1N7gBF3HZTngsystem)(void* dest, void* source, NI size) {
	nimCopyMem(dest, source, size);
}
static N_INLINE(void, appendString)(NimStringDesc* dest, NimStringDesc* src) {
	{
		void* T5_;
		void* T6_;
		if (!!((src == NIM_NIL))) goto LA3_;
		T5_ = (void*)0;
		T5_ = ((void*) ((&(*dest).data[(*dest).Sup.len])));
		T6_ = (void*)0;
		T6_ = ((void*) ((*src).data));
		copyMem__M04YC71iJg1N7gBF3HZTngsystem(T5_, T6_, ((NI) ((NI)((*src).Sup.len + ((NI) 1)))));
		(*dest).Sup.len += (*src).Sup.len;
	}
	LA3_: ;
}
N_LIB_PRIVATE N_NIMCALL(NimStringDesc*, prepare__w0beoDPQKB8sTRhzxkmwzw)(NimStringDesc* s) {
	NimStringDesc* result;
	result = (NimStringDesc*)0;
	{
		NIM_BOOL T3_;
		T3_ = (NIM_BOOL)0;
		T3_ = contains__KV0xCsBzaN9coqb7PG9au0oQ(s, ((NimStringDesc*) &TM__CZNeKGdQ8AWxD1HSDIq5DQ_4));
		if (!T3_) goto LA4_;
		result = copyString(s);
	}
	goto LA1_;
	LA4_: ;
	{
		NimStringDesc* T7_;
		NimStringDesc* T8_;
		NimStringDesc* T9_;
		T7_ = (NimStringDesc*)0;
		T8_ = (NimStringDesc*)0;
		T8_ = nosgetCurrentDir();
		T9_ = (NimStringDesc*)0;
		T9_ = absolutePath__I16hivp0o49aEba9bSd0N6ng(s, T8_);
		T7_ = rawNewString((T9_ ? T9_->Sup.len : 0) + 7);
appendString(T7_, ((NimStringDesc*) &TM__CZNeKGdQ8AWxD1HSDIq5DQ_5));
appendString(T7_, T9_);
		result = T7_;
	}
	LA1_: ;
	return result;
}
N_LIB_PRIVATE N_NIMCALL(void, openDefaultBrowserImpl__lhAiGWV9cJtbG6lYE4tGA3A_2)(NimStringDesc* url) {
	NimStringDesc* T1_;
	NimStringDesc* T2_;
	NimStringDesc* T3_;
	NI T4_;
	T1_ = (NimStringDesc*)0;
	T2_ = (NimStringDesc*)0;
	T2_ = prepare__w0beoDPQKB8sTRhzxkmwzw(url);
	T3_ = (NimStringDesc*)0;
	T3_ = nospquoteShell(T2_);
	T1_ = rawNewString((T3_ ? T3_->Sup.len : 0) + 5);
appendString(T1_, ((NimStringDesc*) &TM__CZNeKGdQ8AWxD1HSDIq5DQ_3));
appendString(T1_, T3_);
	T4_ = (NI)0;
	T4_ = nosexecShellCmd(T1_);
	(void)(T4_);
}
N_LIB_PRIVATE N_NIMCALL(void, openDefaultBrowser__lhAiGWV9cJtbG6lYE4tGA3A)(NimStringDesc* url) {
	{
		if (!!((((NI) 0) < (url ? url->Sup.len : 0)))) goto LA3_;
		failedAssertImpl__W9cjVocn1tjhW7p7xohJj6A(((NimStringDesc*) &TM__CZNeKGdQ8AWxD1HSDIq5DQ_2));
	}
	LA3_: ;
	openDefaultBrowserImpl__lhAiGWV9cJtbG6lYE4tGA3A_2(url);
}
