#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_destroy(struct JsonnetVm *);
char *jsonnet_evaluate_file(struct JsonnetVm *, char const *, int *);
struct JsonnetVm *jsonnet_make();
int /*<<< orphan*/ jsonnet_realloc(struct JsonnetVm *, char *,
                                   int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stderr;
int main(int argc, const char **argv) {
  int error;
  char *output;
  struct JsonnetVm *vm;
  if (argc != 2) {
    fprintf(stderr, "libjsonnet_test_file <file>\n");
    return EXIT_FAILURE;
  }
  vm = jsonnet_make();
  output = jsonnet_evaluate_file(vm, argv[1], &error);
  if (error) {
    fprintf(stderr, "%s", output);
    jsonnet_realloc(vm, output, 0);
    jsonnet_destroy(vm);
    return EXIT_FAILURE;
  }
  printf("%s", output);
  jsonnet_realloc(vm, output, 0);
  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   1060 <fprintf@plt>
mov    0x2e3a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    124e <main+0xee>
mov    $0x0,%al
call   1030 <jsonnet_make@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    -0x14(%rbp),%rdx
call   1070 <jsonnet_evaluate_file@plt>
mov    %rax,-0x20(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     121a <main+0xba>
mov    0x2e03(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
lea    0xe33(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
xor    %edx,%edx
call   1040 <jsonnet_realloc@plt>
mov    -0x28(%rbp),%rdi
call   1080 <jsonnet_destroy@plt>
mov    0x2dc8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    124e <main+0xee>
mov    -0x20(%rbp),%rsi
lea    0xdf8(%rip),%rdi
call   1050 <printf@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
xor    %edx,%edx
call   1040 <jsonnet_realloc@plt>
mov    -0x28(%rbp),%rdi
call   1080 <jsonnet_destroy@plt>
mov    0x2d87(%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    11c9 <main+0x69>
mov    %rsi,%rbx
xor    %eax,%eax
call   1030 <jsonnet_make@plt>
mov    %rax,%r14
mov    0x8(%rbx),%rsi
lea    0x4(%rsp),%rdx
mov    %rax,%rdi
call   1070 <jsonnet_evaluate_file@plt>
mov    %rax,%rbx
cmpl   $0x0,0x4(%rsp)
je     11e9 <main+0x89>
mov    0x2e48(%rip),%rax
mov    (%rax),%edi
lea    0xe7c(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %edx,%edx
call   1040 <jsonnet_realloc@plt>
mov    %r14,%rdi
call   1080 <jsonnet_destroy@plt>
mov    0x2e11(%rip),%rax
jmp    1214 <main+0xb4>
mov    0x2e10(%rip),%rax
mov    (%rax),%edi
lea    0xe27(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x2df1(%rip),%rax
jmp    1214 <main+0xb4>
lea    0xe2d(%rip),%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %edx,%edx
call   1040 <jsonnet_realloc@plt>
mov    %r14,%rdi
call   1080 <jsonnet_destroy@plt>
mov    0x2dbc(%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 = [29 x i8] c"libjsonnet_test_file <file>\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [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 ([29 x i8], [29 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_file(%struct.JsonnetVm* %17, 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.1, i64 0, i64 0), i8* %26)
%28 = load %struct.JsonnetVm*, %struct.JsonnetVm** %8
%29 = load i8*, i8** %7
%30 = call i32 @jsonnet_realloc(%struct.JsonnetVm* %28, i8* %29, i32 0)
%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.1, i64 0, i64 0), i8* %35)
%37 = load %struct.JsonnetVm*, %struct.JsonnetVm** %8
%38 = load i8*, i8** %7
%39 = call i32 @jsonnet_realloc(%struct.JsonnetVm* %37, i8* %38, i32 0)
%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 = [29 x i8] c"libjsonnet_test_file <file>\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [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 ([29 x i8], [29 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_file(%struct.JsonnetVm* %10, 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.1, i64 0, i64 0), i8* %13)
%19 = call i32 @jsonnet_realloc(%struct.JsonnetVm* %10, i8* %13, i32 0)
%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.1, i64 0, i64 0), i8* %13)
%23 = call i32 @jsonnet_realloc(%struct.JsonnetVm* %10, i8* %13, i32 0)
%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
}