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

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ free(char *);
struct json_parser *jp_create();
int /*<<< orphan*/ jp_destroy(struct json_parser *);
char *jp_get_err(struct json_parser *);
int /*<<< orphan*/ *jp_parse(struct json_parser *, char *, size_t);
char *load_json(char *, size_t *);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  if (argc != 2) {
    fprintf(stderr, "usage: argv[0] json-file\n");
    return 1;
  }
  size_t len;
  char *json = load_json(argv[1], &len);
  struct json_parser *jp = jp_create();
  if (!jp) {
    fprintf(stderr, "WTF\n");
    return 1;
  }
  int i = 0;
  int ret = 0;
  for (; i < 10000; i++) {
    if (jp_parse(jp, json, len) == NULL) {
      ret = 1;
      fprintf(stderr, "parsing failed: %s\n", jp_get_err(jp));
      break;
    }
  }
  jp_destroy(jp);
  free(json);
  return ret;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11b3 <main+0x43>
mov    0x2e49(%rip),%rax
mov    (%rax),%edi
lea    0xe60(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1297 <main+0x127>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x18(%rbp),%rsi
call   1040 <load_json@plt>
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   1050 <jp_create@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1201 <main+0x91>
mov    0x2dfb(%rip),%rax
mov    (%rax),%edi
lea    0xe2c(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1297 <main+0x127>
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
cmpl   $0x2710,-0x2c(%rbp)
jge    127f <main+0x10f>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1070 <jp_parse@plt>
cmp    $0x0,%rax
jne    126c <main+0xfc>
movl   $0x1,-0x30(%rbp)
mov    0x2d9b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    -0x28(%rbp),%rdi
call   1080 <jp_get_err@plt>
mov    -0x34(%rbp),%edi
mov    %rax,%rdx
lea    0xdbf(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    127f <main+0x10f>
jmp    1271 <main+0x101>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    120f <main+0x9f>
mov    -0x28(%rbp),%rdi
call   1090 <jp_destroy@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
cmp    $0x2,%edi
jne    11ce <main+0x5e>
mov    0x8(%rsi),%rdi
lea    0x8(%rsp),%rsi
call   1040 <load_json@plt>
mov    %rax,%r14
xor    %eax,%eax
call   1050 <jp_create@plt>
test   %rax,%rax
je     11e0 <main+0x70>
mov    %rax,%rbx
mov    $0x2710,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    0x8(%rsp),%rdx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1070 <jp_parse@plt>
test   %rax,%rax
je     11fe <main+0x8e>
add    $0xffffffff,%ebp
jne    11b0 <main+0x40>
xor    %ebp,%ebp
jmp    1227 <main+0xb7>
mov    0x2e0b(%rip),%rax
mov    (%rax),%edi
lea    0xe22(%rip),%rsi
jmp    11f0 <main+0x80>
mov    0x2df9(%rip),%rax
mov    (%rax),%edi
lea    0xe2a(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%ebp
jmp    1237 <main+0xc7>
mov    0x2ddb(%rip),%rax
mov    (%rax),%ebp
mov    %rbx,%rdi
call   1080 <jp_get_err@plt>
lea    0xe09(%rip),%rsi
mov    %ebp,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%ebp
mov    %rbx,%rdi
call   1090 <jp_destroy@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.json_parser = type { i32 }
@stderr = global i32 0
@.str = [26 x i8] c"usage: argv[0] json-file\0A\00"
@.str.1 = [5 x i8] c"WTF\0A\00"
@.str.2 = [20 x i8] c"parsing failed: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i8*
%8 = alloca %struct.json_parser*
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 2
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %52
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i8* @load_json(i8* %19, i64* %6)
store i8* %20, i8** %7
%21 = call %struct.json_parser* (...) @jp_create()
store %struct.json_parser* %21, %struct.json_parser** %8
%22 = load %struct.json_parser*, %struct.json_parser** %8
%23 = icmp ne %struct.json_parser* %22, null
br i1 %23, label %27, label %24
24: ; preds = %16
%25 = load i32, i32* @stderr
%26 = call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %52
27: ; preds = %16
store i32 0, i32* %9
store i32 0, i32* %10
br label %28
28: ; preds = %43, %27
%29 = load i32, i32* %9
%30 = icmp slt i32 %29, 10000
br i1 %30, label %31, label %46
31: ; preds = %28
%32 = load %struct.json_parser*, %struct.json_parser** %8
%33 = load i8*, i8** %7
%34 = load i64, i64* %6
%35 = call i32* @jp_parse(%struct.json_parser* %32, i8* %33, i64 %34)
%36 = icmp eq i32* %35, null
br i1 %36, label %37, label %42
37: ; preds = %31
store i32 1, i32* %10
%38 = load i32, i32* @stderr
%39 = load %struct.json_parser*, %struct.json_parser** %8
%40 = call i8* @jp_get_err(%struct.json_parser* %39)
%41 = call i32 (i32, i8*, ...) @fprintf(i32 %38, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %40)
br label %46
42: ; preds = %31
br label %43
43: ; preds = %42
%44 = load i32, i32* %9
%45 = add nsw i32 %44, 1
store i32 %45, i32* %9
br label %28
46: ; preds = %37, %28
%47 = load %struct.json_parser*, %struct.json_parser** %8
%48 = call i32 @jp_destroy(%struct.json_parser* %47)
%49 = load i8*, i8** %7
%50 = call i32 @free(i8* %49)
%51 = load i32, i32* %10
store i32 %51, i32* %3
br label %52
52: ; preds = %46, %24, %13
%53 = load i32, i32* %3
ret i32 %53
}

LLVM IR (-O2):
%struct.json_parser = type { i32 }
@stderr = global i32 0
@.str = [26 x i8] c"usage: argv[0] json-file\0A\00"
@.str.1 = [5 x i8] c"WTF\0A\00"
@.str.2 = [20 x i8] c"parsing failed: %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i64
%4 = icmp eq i32 %0, 2
br i1 %4, label %8, label %5
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = tail call i32 (i32, i8*, ...) @fprintf(i32 %6, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %36
8: ; preds = %2
%9 = bitcast i64* %3 to i8*
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = call i8* @load_json(i8* %11, i64* %3)
%13 = call %struct.json_parser* (...) @jp_create()
%14 = icmp eq %struct.json_parser* %13, null
br i1 %14, label %15, label %21
15: ; preds = %8
%16 = load i32, i32* @stderr
%17 = call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %34
18: ; preds = %21
%19 = add nuw nsw i32 %22, 1
%20 = icmp eq i32 %19, 10000
br i1 %20, label %30, label %21
21: ; preds = %8, %18
%22 = phi i32 [ %19, %18 ], [ 0, %8 ]
%23 = load i64, i64* %3
%24 = call i32* @jp_parse(%struct.json_parser* %13, i8* %12, i64 %23)
%25 = icmp eq i32* %24, null
br i1 %25, label %26, label %18
26: ; preds = %21
%27 = load i32, i32* @stderr
%28 = call i8* @jp_get_err(%struct.json_parser* %13)
%29 = call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %28)
br label %30
30: ; preds = %18, %26
%31 = phi i32 [ 1, %26 ], [ 0, %18 ]
%32 = call i32 @jp_destroy(%struct.json_parser* %13)
%33 = call i32 @free(i8* %12)
br label %34
34: ; preds = %30, %15
%35 = phi i32 [ %31, %30 ], [ 1, %15 ]
br label %36
36: ; preds = %34, %5
%37 = phi i32 [ 1, %5 ], [ %35, %34 ]
ret i32 %37
}