#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 JsonnetVM {
  int dummy;
};

/* Variables and functions */
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ jsonnet_cleanup_string(struct JsonnetVM *, char const *);
int /*<<< orphan*/ jsonnet_destroy(struct JsonnetVM *);
char *jsonnet_evaluate_snippet(struct JsonnetVM *, char *, char const *, int *);
struct JsonnetVM *jsonnet_make();
int /*<<< orphan*/ printf(char *, char const *);
int /*<<< orphan*/ stderr;
int main(int argc, const char **argv) {
  int error;
  const char *output;
  struct JsonnetVM *vm;
  if (argc != 2) {
    fprintf(stderr, "libjsonnet_test_snippet <string>\n");
    return EXIT_FAILURE;
  }
  vm = jsonnet_make();
  output = jsonnet_evaluate_snippet(vm, "snippet", argv[1], &error);
  if (error) {
    fprintf(stderr, "%s", output);
    jsonnet_cleanup_string(vm, output);
    jsonnet_destroy(vm);
    return EXIT_FAILURE;
  }
  printf("%s", output);
  jsonnet_cleanup_string(vm, output);
  jsonnet_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   1050 <fprintf@plt>
mov    0x2e3a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1251 <main+0xf1>
mov    $0x0,%al
call   1030 <jsonnet_make@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe5c(%rip),%rsi
lea    -0x14(%rbp),%rcx
call   1060 <jsonnet_evaluate_snippet@plt>
mov    %rax,-0x20(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     121f <main+0xbf>
mov    0x2dfc(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
lea    0xe39(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1070 <jsonnet_cleanup_string@plt>
mov    -0x28(%rbp),%rdi
call   1080 <jsonnet_destroy@plt>
mov    0x2dc3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1251 <main+0xf1>
mov    -0x20(%rbp),%rsi
lea    0xe00(%rip),%rdi
call   1040 <printf@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1070 <jsonnet_cleanup_string@plt>
mov    -0x28(%rbp),%rdi
call   1080 <jsonnet_destroy@plt>
mov    0x2d84(%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    11ce <main+0x6e>
mov    %rsi,%rbx
xor    %eax,%eax
call   1030 <jsonnet_make@plt>
mov    %rax,%r14
mov    0x8(%rbx),%rdx
lea    0xea1(%rip),%rsi
lea    0x4(%rsp),%rcx
mov    %rax,%rdi
call   1060 <jsonnet_evaluate_snippet@plt>
mov    %rax,%rbx
cmpl   $0x0,0x4(%rsp)
je     11ee <main+0x8e>
mov    0x2e41(%rip),%rax
mov    (%rax),%edi
lea    0xe82(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1070 <jsonnet_cleanup_string@plt>
mov    %r14,%rdi
call   1080 <jsonnet_destroy@plt>
mov    0x2e0c(%rip),%rax
jmp    1217 <main+0xb7>
mov    0x2e0b(%rip),%rax
mov    (%rax),%edi
lea    0xe22(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    0x2dec(%rip),%rax
jmp    1217 <main+0xb7>
lea    0xe35(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1070 <jsonnet_cleanup_string@plt>
mov    %r14,%rdi
call   1080 <jsonnet_destroy@plt>
mov    0x2db9(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.JsonnetVM = type { i32 }
@stderr = global i32 0
@.str = [34 x i8] c"libjsonnet_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.JsonnetVM*
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 ([34 x i8], [34 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.JsonnetVM* (...) @jsonnet_make()
store %struct.JsonnetVM* %16, %struct.JsonnetVM** %8
%17 = load %struct.JsonnetVM*, %struct.JsonnetVM** %8
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i8* @jsonnet_evaluate_snippet(%struct.JsonnetVM* %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.JsonnetVM*, %struct.JsonnetVM** %8
%29 = load i8*, i8** %7
%30 = call i32 @jsonnet_cleanup_string(%struct.JsonnetVM* %28, i8* %29)
%31 = load %struct.JsonnetVM*, %struct.JsonnetVM** %8
%32 = call i32 @jsonnet_destroy(%struct.JsonnetVM* %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.JsonnetVM*, %struct.JsonnetVM** %8
%38 = load i8*, i8** %7
%39 = call i32 @jsonnet_cleanup_string(%struct.JsonnetVM* %37, i8* %38)
%40 = load %struct.JsonnetVM*, %struct.JsonnetVM** %8
%41 = call i32 @jsonnet_destroy(%struct.JsonnetVM* %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.JsonnetVM = type { i32 }
@stderr = global i32 0
@.str = [34 x i8] c"libjsonnet_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 ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
br label %25
9: ; preds = %2
%10 = tail call %struct.JsonnetVM* (...) @jsonnet_make()
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = call i8* @jsonnet_evaluate_snippet(%struct.JsonnetVM* %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 @jsonnet_cleanup_string(%struct.JsonnetVM* %10, i8* %13)
%20 = call i32 @jsonnet_destroy(%struct.JsonnetVM* %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 @jsonnet_cleanup_string(%struct.JsonnetVM* %10, i8* %13)
%24 = call i32 @jsonnet_destroy(%struct.JsonnetVM* %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
}