#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 jx_parser {
  int dummy;
};
struct jx {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ jx_delete(struct jx *);
struct jx *jx_eval(struct jx *, struct jx *);
struct jx *jx_parse(struct jx_parser *);
struct jx_parser *jx_parser_create(int /*<<< orphan*/);
int /*<<< orphan*/ jx_parser_delete(struct jx_parser *);
char *jx_parser_error_string(struct jx_parser *);
scalar_t__ jx_parser_errors(struct jx_parser *);
int /*<<< orphan*/ jx_parser_read_stream(struct jx_parser *,
                                         int /*<<< orphan*/);
int /*<<< orphan*/ jx_print_stream(struct jx *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
int main(int argc, char *argv[]) {
  printf("Enter context expression (or {} for an empty context):\n");
  struct jx_parser *p = jx_parser_create(0);
  jx_parser_read_stream(p, stdin);
  struct jx *context = jx_parse(p);
  if (!context)
    return 1;
  if (jx_parser_errors(p)) {
    fprintf(stderr, "invalid context expression: %s\n",
            jx_parser_error_string(p));
    return 1;
  }
  printf("Now enter expressions:\n");
  while (1) {
    struct jx *j = jx_parse(p);
    if (!j) {
      break;
    } else if (!jx_parser_errors(p)) {
      printf("expression: ");
      jx_print_stream(j, stdout);
      printf("\n");
      struct jx *k = jx_eval(j, context);
      printf("value:      ");
      jx_print_stream(k, stdout);
      printf("\n\n");
      jx_delete(j);
      jx_delete(k);
    } else {
      printf("\"jx parse error: %s\"\n", jx_parser_error_string(p));
      jx_delete(j);
      jx_parser_delete(p);
      return 1;
    }
  }
  jx_parser_delete(p);
  return 0;
}


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)
lea    0xe33(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %edi,%edi
call   1050 <jx_parser_create@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2dfe(%rip),%rax
mov    (%rax),%esi
call   1090 <jx_parser_read_stream@plt>
mov    -0x18(%rbp),%rdi
call   10a0 <jx_parse@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1215 <main+0x65>
movl   $0x1,-0x4(%rbp)
jmp    136f <main+0x1bf>
mov    -0x18(%rbp),%rdi
call   1070 <jx_parser_errors@plt>
cmp    $0x0,%rax
je     125b <main+0xab>
mov    0x2da9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <jx_parser_error_string@plt>
mov    -0x34(%rbp),%edi
mov    %rax,%rdx
lea    0xdee(%rip),%rsi
call   1080 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    136f <main+0x1bf>
lea    0xdf6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
call   10a0 <jx_parse@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1286 <main+0xd6>
jmp    135f <main+0x1af>
mov    -0x18(%rbp),%rdi
call   1070 <jx_parser_errors@plt>
cmp    $0x0,%rax
jne    131d <main+0x16d>
lea    0xdd0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%rdi
mov    0x2d1e(%rip),%rax
mov    (%rax),%esi
call   1030 <jx_print_stream@plt>
lea    0xdcb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   10d0 <jx_eval@plt>
mov    %rax,-0x30(%rbp)
lea    0xd9e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x30(%rbp),%rdi
mov    0x2cdf(%rip),%rax
mov    (%rax),%esi
call   1030 <jx_print_stream@plt>
lea    0xd8b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%rdi
call   10c0 <jx_delete@plt>
mov    -0x30(%rbp),%rdi
call   10c0 <jx_delete@plt>
jmp    1355 <main+0x1a5>
mov    -0x18(%rbp),%rdi
call   1060 <jx_parser_error_string@plt>
mov    %rax,%rsi
lea    0xd5d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%rdi
call   10c0 <jx_delete@plt>
mov    -0x18(%rbp),%rdi
call   10b0 <jx_parser_delete@plt>
movl   $0x1,-0x4(%rbp)
jmp    136f <main+0x1bf>
jmp    135a <main+0x1aa>
jmp    1269 <main+0xb9>
mov    -0x18(%rbp),%rdi
call   10b0 <jx_parser_delete@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xe6e(%rip),%rdi
call   1050 <puts@plt>
xor    %edi,%edi
call   1070 <jx_parser_create@plt>
mov    %rax,%rbx
mov    0x2df0(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   10b0 <jx_parser_read_stream@plt>
mov    %rbx,%rdi
call   10c0 <jx_parse@plt>
mov    $0x1,%ebp
test   %rax,%rax
je     1343 <main+0x173>
mov    %rax,%r15
mov    %rbx,%rdi
call   1090 <jx_parser_errors@plt>
test   %rax,%rax
je     1251 <main+0x81>
mov    0x2da9(%rip),%rax
mov    (%rax),%r14d
mov    %rbx,%rdi
call   1080 <jx_parser_error_string@plt>
lea    0xdbf(%rip),%rsi
mov    %r14d,%edi
mov    %rax,%rdx
call   10a0 <fprintf@plt>
jmp    1343 <main+0x173>
lea    0xe2f(%rip),%rdi
call   1050 <puts@plt>
mov    %rbx,%rdi
call   10c0 <jx_parse@plt>
test   %rax,%rax
je     1309 <main+0x139>
mov    %rax,%rbp
mov    0x2d58(%rip),%r13
lea    0xdcf(%rip),%r14
nop
mov    %rbx,%rdi
call   1090 <jx_parser_errors@plt>
test   %rax,%rax
jne    1315 <main+0x145>
lea    0xd88(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x0(%r13),%esi
mov    %rbp,%rdi
call   1030 <jx_print_stream@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
mov    %rbp,%rdi
mov    %r15,%rsi
call   10f0 <jx_eval@plt>
mov    %rax,%r12
lea    0xd63(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x0(%r13),%esi
mov    %r12,%rdi
call   1030 <jx_print_stream@plt>
mov    %r14,%rdi
call   1050 <puts@plt>
mov    %rbp,%rdi
call   10e0 <jx_delete@plt>
mov    %r12,%rdi
call   10e0 <jx_delete@plt>
mov    %rbx,%rdi
call   10c0 <jx_parse@plt>
mov    %rax,%rbp
test   %rax,%rax
jne    1280 <main+0xb0>
mov    %rbx,%rdi
call   10d0 <jx_parser_delete@plt>
xor    %ebp,%ebp
jmp    1343 <main+0x173>
mov    %rbx,%rdi
call   1080 <jx_parser_error_string@plt>
lea    0xd16(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbp,%rdi
call   10e0 <jx_delete@plt>
mov    %rbx,%rdi
call   10d0 <jx_parser_delete@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.jx_parser = type { i32 }
%struct.jx = type { i32 }
@.str = [56 x i8] c"Enter context expression (or {} for an empty context):\0A\00"
@stdin = global i32 0
@stderr = global i32 0
@.str.1 = [32 x i8] c"invalid context expression: %s\0A\00"
@.str.2 = [24 x i8] c"Now enter expressions:\0A\00"
@.str.3 = [13 x i8] c"expression: \00"
@stdout = global i32 0
@.str.4 = [2 x i8] c"\0A\00"
@.str.5 = [13 x i8] c"value: \00"
@.str.6 = [3 x i8] c"\0A\0A\00"
@.str.7 = [22 x i8] c"\22jx parse error: %s\22\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.jx_parser*
%7 = alloca %struct.jx*
%8 = alloca %struct.jx*
%9 = alloca %struct.jx*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str, i64 0, i64 0))
%11 = call %struct.jx_parser* @jx_parser_create(i32 0)
store %struct.jx_parser* %11, %struct.jx_parser** %6
%12 = load %struct.jx_parser*, %struct.jx_parser** %6
%13 = load i32, i32* @stdin
%14 = call i32 @jx_parser_read_stream(%struct.jx_parser* %12, i32 %13)
%15 = load %struct.jx_parser*, %struct.jx_parser** %6
%16 = call %struct.jx* @jx_parse(%struct.jx_parser* %15)
store %struct.jx* %16, %struct.jx** %7
%17 = load %struct.jx*, %struct.jx** %7
%18 = icmp ne %struct.jx* %17, null
br i1 %18, label %20, label %19
19: ; preds = %2
store i32 1, i32* %3
br label %72
20: ; preds = %2
%21 = load %struct.jx_parser*, %struct.jx_parser** %6
%22 = call i64 @jx_parser_errors(%struct.jx_parser* %21)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %29
24: ; preds = %20
%25 = load i32, i32* @stderr
%26 = load %struct.jx_parser*, %struct.jx_parser** %6
%27 = call i8* @jx_parser_error_string(%struct.jx_parser* %26)
%28 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8* %27)
store i32 1, i32* %3
br label %72
29: ; preds = %20
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
br label %31
31: ; preds = %29, %68
%32 = load %struct.jx_parser*, %struct.jx_parser** %6
%33 = call %struct.jx* @jx_parse(%struct.jx_parser* %32)
store %struct.jx* %33, %struct.jx** %8
%34 = load %struct.jx*, %struct.jx** %8
%35 = icmp ne %struct.jx* %34, null
br i1 %35, label %37, label %36
36: ; preds = %31
br label %69
37: ; preds = %31
%38 = load %struct.jx_parser*, %struct.jx_parser** %6
%39 = call i64 @jx_parser_errors(%struct.jx_parser* %38)
%40 = icmp ne i64 %39, 0
br i1 %40, label %59, label %41
41: ; preds = %37
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%43 = load %struct.jx*, %struct.jx** %8
%44 = load i32, i32* @stdout
%45 = call i32 @jx_print_stream(%struct.jx* %43, i32 %44)
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%47 = load %struct.jx*, %struct.jx** %8
%48 = load %struct.jx*, %struct.jx** %7
%49 = call %struct.jx* @jx_eval(%struct.jx* %47, %struct.jx* %48)
store %struct.jx* %49, %struct.jx** %9
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
%51 = load %struct.jx*, %struct.jx** %9
%52 = load i32, i32* @stdout
%53 = call i32 @jx_print_stream(%struct.jx* %51, i32 %52)
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
%55 = load %struct.jx*, %struct.jx** %8
%56 = call i32 @jx_delete(%struct.jx* %55)
%57 = load %struct.jx*, %struct.jx** %9
%58 = call i32 @jx_delete(%struct.jx* %57)
br label %67
59: ; preds = %37
%60 = load %struct.jx_parser*, %struct.jx_parser** %6
%61 = call i8* @jx_parser_error_string(%struct.jx_parser* %60)
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.7, i64 0, i64 0), i8* %61)
%63 = load %struct.jx*, %struct.jx** %8
%64 = call i32 @jx_delete(%struct.jx* %63)
%65 = load %struct.jx_parser*, %struct.jx_parser** %6
%66 = call i32 @jx_parser_delete(%struct.jx_parser* %65)
store i32 1, i32* %3
br label %72
67: ; preds = %41
br label %68
68: ; preds = %67
br label %31
69: ; preds = %36
%70 = load %struct.jx_parser*, %struct.jx_parser** %6
%71 = call i32 @jx_parser_delete(%struct.jx_parser* %70)
store i32 0, i32* %3
br label %72
72: ; preds = %69, %59, %24, %19
%73 = load i32, i32* %3
ret i32 %73
}

LLVM IR (-O2):
%struct.jx_parser = type { i32 }
%struct.jx = type { i32 }
@stdin = global i32 0
@stderr = global i32 0
@.str.1 = [32 x i8] c"invalid context expression: %s\0A\00"
@.str.3 = [13 x i8] c"expression: \00"
@stdout = global i32 0
@.str.5 = [13 x i8] c"value: \00"
@.str.7 = [22 x i8] c"\22jx parse error: %s\22\0A\00"
@str = [55 x i8] c"Enter context expression (or {} for an empty context):\00"
@str.8 = [23 x i8] c"Now enter expressions:\00"
@str.9 = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([55 x i8], [55 x i8]* @str, i64 0, i64 0))
%4 = tail call %struct.jx_parser* @jx_parser_create(i32 0)
%5 = load i32, i32* @stdin
%6 = tail call i32 @jx_parser_read_stream(%struct.jx_parser* %4, i32 %5)
%7 = tail call %struct.jx* @jx_parse(%struct.jx_parser* %4)
%8 = icmp eq %struct.jx* %7, null
br i1 %8, label %45, label %9
9: ; preds = %2
%10 = tail call i64 @jx_parser_errors(%struct.jx_parser* %4)
%11 = icmp eq i64 %10, 0
br i1 %11, label %16, label %12
12: ; preds = %9
%13 = load i32, i32* @stderr
%14 = tail call i8* @jx_parser_error_string(%struct.jx_parser* %4)
%15 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8* %14)
br label %45
16: ; preds = %9
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.8, i64 0, i64 0))
%18 = tail call %struct.jx* @jx_parse(%struct.jx_parser* %4)
%19 = icmp eq %struct.jx* %18, null
br i1 %19, label %43, label %20
20: ; preds = %16, %29
%21 = phi %struct.jx* [ %41, %29 ], [ %18, %16 ]
%22 = tail call i64 @jx_parser_errors(%struct.jx_parser* %4)
%23 = icmp eq i64 %22, 0
br i1 %23, label %29, label %24
24: ; preds = %20
%25 = tail call i8* @jx_parser_error_string(%struct.jx_parser* %4)
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.7, i64 0, i64 0), i8* %25)
%27 = tail call i32 @jx_delete(%struct.jx* %21)
%28 = tail call i32 @jx_parser_delete(%struct.jx_parser* %4)
br label %45
29: ; preds = %20
%30 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%31 = load i32, i32* @stdout
%32 = tail call i32 @jx_print_stream(%struct.jx* %21, i32 %31)
%33 = tail call i32 @putchar(i32 10)
%34 = tail call %struct.jx* @jx_eval(%struct.jx* %21, %struct.jx* %7)
%35 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
%36 = load i32, i32* @stdout
%37 = tail call i32 @jx_print_stream(%struct.jx* %34, i32 %36)
%38 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str.9, i64 0, i64 0))
%39 = tail call i32 @jx_delete(%struct.jx* %21)
%40 = tail call i32 @jx_delete(%struct.jx* %34)
%41 = tail call %struct.jx* @jx_parse(%struct.jx_parser* %4)
%42 = icmp eq %struct.jx* %41, null
br i1 %42, label %43, label %20
43: ; preds = %29, %16
%44 = tail call i32 @jx_parser_delete(%struct.jx_parser* %4)
br label %45
45: ; preds = %24, %2, %43, %12
%46 = phi i32 [ 1, %12 ], [ 0, %43 ], [ 1, %2 ], [ 1, %24 ]
ret i32 %46
}