#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
struct JsonlangVm {
  int dummy;
};

/* Variables and functions */
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ jsonlang_destroy(struct JsonlangVm *);
char *jsonlang_evaluate_snippet(struct JsonlangVm *, char *, char const *,
                                int *);
struct JsonlangVm *jsonlang_make();
int /*<<< orphan*/ jsonlang_realloc(struct JsonlangVm *, char *,
                                    int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stderr;
int main(int argc, const char **argv) {
  int error;
  char *output;
  struct JsonlangVm *vm;
  if (argc != 2) {
    fprintf(stderr, "libjsonlang_test_snippet <string>\n");
    return EXIT_FAILURE;
  }
  vm = jsonlang_make();
  output = jsonlang_evaluate_snippet(vm, "snippet", argv[1], &error);
  if (error) {
    fprintf(stderr, "%s", output);
    jsonlang_realloc(vm, output, 0);
    jsonlang_destroy(vm);
    return EXIT_FAILURE;
  }
  printf("%s", output);
  jsonlang_realloc(vm, output, 0);
  jsonlang_destroy(vm);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11a8 <main+0x48>
mov    0x2e59(%rip),%rax
mov    (%rax),%edi
lea    0xe70(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2e3a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1255 <main+0xf5>
mov    $0x0,%al
call   1070 <jsonlang_make@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe5d(%rip),%rsi
lea    -0x14(%rbp),%rcx
call   1050 <jsonlang_evaluate_snippet@plt>
mov    %rax,-0x20(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1221 <main+0xc1>
mov    0x2dfc(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
lea    0xe3a(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
xor    %edx,%edx
call   1080 <jsonlang_realloc@plt>
mov    -0x28(%rbp),%rdi
call   1030 <jsonlang_destroy@plt>
mov    0x2dc1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1255 <main+0xf5>
mov    -0x20(%rbp),%rsi
lea    0xdff(%rip),%rdi
call   1040 <printf@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
xor    %edx,%edx
call   1080 <jsonlang_realloc@plt>
mov    -0x28(%rbp),%rdi
call   1030 <jsonlang_destroy@plt>
mov    0x2d80(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
cmp    $0x2,%edi
jne    11d0 <main+0x70>
mov    %rsi,%rbx
xor    %eax,%eax
call   1070 <jsonlang_make@plt>
mov    %rax,%r14
mov    0x8(%rbx),%rdx
lea    0xea2(%rip),%rsi
lea    0x4(%rsp),%rcx
mov    %rax,%rdi
call   1050 <jsonlang_evaluate_snippet@plt>
mov    %rax,%rbx
cmpl   $0x0,0x4(%rsp)
je     11f0 <main+0x90>
mov    0x2e41(%rip),%rax
mov    (%rax),%edi
lea    0xe83(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %edx,%edx
call   1080 <jsonlang_realloc@plt>
mov    %r14,%rdi
call   1030 <jsonlang_destroy@plt>
mov    0x2e0a(%rip),%rax
jmp    121b <main+0xbb>
mov    0x2e09(%rip),%rax
mov    (%rax),%edi
lea    0xe20(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x2dea(%rip),%rax
jmp    121b <main+0xbb>
lea    0xe34(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %edx,%edx
call   1080 <jsonlang_realloc@plt>
mov    %r14,%rdi
call   1030 <jsonlang_destroy@plt>
mov    0x2db5(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.JsonlangVm = type { i32 }
@stderr = global i32 0
@.str = [35 x i8] c"libjsonlang_test_snippet <string>\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [8 x i8] c"snippet\00"
@.str.2 = [3 x i8] c"%s\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca %struct.JsonlangVm*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 2
br i1 %10, label %11, label %15
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
%14 = load i32, i32* @EXIT_FAILURE
store i32 %14, i32* %3
br label %43
15: ; preds = %2
%16 = call %struct.JsonlangVm* (...) @jsonlang_make()
store %struct.JsonlangVm* %16, %struct.JsonlangVm** %8
%17 = load %struct.JsonlangVm*, %struct.JsonlangVm** %8
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i8* @jsonlang_evaluate_snippet(%struct.JsonlangVm* %17, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %20, i32* %6)
store i8* %21, i8** %7
%22 = load i32, i32* %6
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %34
24: ; preds = %15
%25 = load i32, i32* @stderr
%26 = load i8*, i8** %7
%27 = call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %26)
%28 = load %struct.JsonlangVm*, %struct.JsonlangVm** %8
%29 = load i8*, i8** %7
%30 = call i32 @jsonlang_realloc(%struct.JsonlangVm* %28, i8* %29, i32 0)
%31 = load %struct.JsonlangVm*, %struct.JsonlangVm** %8
%32 = call i32 @jsonlang_destroy(%struct.JsonlangVm* %31)
%33 = load i32, i32* @EXIT_FAILURE
store i32 %33, i32* %3
br label %43
34: ; preds = %15
%35 = load i8*, i8** %7
%36 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %35)
%37 = load %struct.JsonlangVm*, %struct.JsonlangVm** %8
%38 = load i8*, i8** %7
%39 = call i32 @jsonlang_realloc(%struct.JsonlangVm* %37, i8* %38, i32 0)
%40 = load %struct.JsonlangVm*, %struct.JsonlangVm** %8
%41 = call i32 @jsonlang_destroy(%struct.JsonlangVm* %40)
%42 = load i32, i32* @EXIT_SUCCESS
store i32 %42, i32* %3
br label %43
43: ; preds = %34, %24, %11
%44 = load i32, i32* %3
ret i32 %44
}

LLVM IR (-O2):
%struct.JsonlangVm = type { i32 }
@stderr = global i32 0
@.str = [35 x i8] c"libjsonlang_test_snippet <string>\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [8 x i8] c"snippet\00"
@.str.2 = [3 x i8] c"%s\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = icmp eq i32 %0, 2
br i1 %5, label %9, label %6
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = tail call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
br label %25
9: ; preds = %2
%10 = tail call %struct.JsonlangVm* (...) @jsonlang_make()
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = call i8* @jsonlang_evaluate_snippet(%struct.JsonlangVm* %10, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %12, i32* %3)
%14 = load i32, i32* %3
%15 = icmp eq i32 %14, 0
br i1 %15, label %21, label %16
16: ; preds = %9
%17 = load i32, i32* @stderr
%18 = call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %13)
%19 = call i32 @jsonlang_realloc(%struct.JsonlangVm* %10, i8* %13, i32 0)
%20 = call i32 @jsonlang_destroy(%struct.JsonlangVm* %10)
br label %25
21: ; preds = %9
%22 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %13)
%23 = call i32 @jsonlang_realloc(%struct.JsonlangVm* %10, i8* %13, i32 0)
%24 = call i32 @jsonlang_destroy(%struct.JsonlangVm* %10)
br label %25
25: ; preds = %21, %16, %6
%26 = phi i32* [ @EXIT_FAILURE, %6 ], [ @EXIT_FAILURE, %16 ], [ @EXIT_SUCCESS, %21 ]
%27 = load i32, i32* %26
ret i32 %27
}