#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 && !jx_parser_errors(p)) {
      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_delete(context);
  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    138b <main+0x1db>
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    138b <main+0x1db>
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    1299 <main+0xe9>
mov    -0x18(%rbp),%rdi
call   1070 <jx_parser_errors@plt>
cmp    $0x0,%rax
jne    1299 <main+0xe9>
jmp    1372 <main+0x1c2>
mov    -0x18(%rbp),%rdi
call   1070 <jx_parser_errors@plt>
cmp    $0x0,%rax
jne    1330 <main+0x180>
lea    0xdbd(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%rdi
mov    0x2d0b(%rip),%rax
mov    (%rax),%esi
call   1030 <jx_print_stream@plt>
lea    0xdb8(%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    0xd8b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x30(%rbp),%rdi
mov    0x2ccc(%rip),%rax
mov    (%rax),%esi
call   1030 <jx_print_stream@plt>
lea    0xd78(%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    1368 <main+0x1b8>
mov    -0x18(%rbp),%rdi
call   1060 <jx_parser_error_string@plt>
mov    %rax,%rsi
lea    0xd4a(%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    138b <main+0x1db>
jmp    136d <main+0x1bd>
jmp    1269 <main+0xb9>
mov    -0x20(%rbp),%rdi
call   10c0 <jx_delete@plt>
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     1349 <main+0x179>
mov    %rax,%r12
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    1349 <main+0x179>
lea    0xe2f(%rip),%rdi
call   1050 <puts@plt>
mov    0x2d6c(%rip),%r13
lea    0xde3(%rip),%r14
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   10c0 <jx_parse@plt>
mov    %rax,%rbp
test   %rax,%rax
jne    1291 <main+0xc1>
mov    %rbx,%rdi
call   1090 <jx_parser_errors@plt>
test   %rax,%rax
je     1337 <main+0x167>
mov    %rbx,%rdi
call   1090 <jx_parser_errors@plt>
test   %rax,%rax
jne    1307 <main+0x137>
lea    0xd7b(%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    %r12,%rsi
call   10f0 <jx_eval@plt>
mov    %rax,%r15
lea    0xd56(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x0(%r13),%esi
mov    %r15,%rdi
call   1030 <jx_print_stream@plt>
mov    %r14,%rdi
call   1050 <puts@plt>
mov    %rbp,%rdi
call   10e0 <jx_delete@plt>
mov    %r15,%rdi
call   10e0 <jx_delete@plt>
jmp    1270 <main+0xa0>
mov    %rbx,%rdi
call   1080 <jx_parser_error_string@plt>
lea    0xd24(%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
jmp    1349 <main+0x179>
mov    %r12,%rdi
call   10e0 <jx_delete@plt>
mov    %rbx,%rdi
call   10d0 <jx_parser_delete@plt>
xor    %ebp,%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 %78
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 %78
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, %72
%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 %41, label %36
36: ; preds = %31
%37 = load %struct.jx_parser*, %struct.jx_parser** %6
%38 = call i64 @jx_parser_errors(%struct.jx_parser* %37)
%39 = icmp ne i64 %38, 0
br i1 %39, label %41, label %40
40: ; preds = %36
br label %73
41: ; preds = %36, %31
%42 = load %struct.jx_parser*, %struct.jx_parser** %6
%43 = call i64 @jx_parser_errors(%struct.jx_parser* %42)
%44 = icmp ne i64 %43, 0
br i1 %44, label %63, label %45
45: ; preds = %41
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%47 = load %struct.jx*, %struct.jx** %8
%48 = load i32, i32* @stdout
%49 = call i32 @jx_print_stream(%struct.jx* %47, i32 %48)
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%51 = load %struct.jx*, %struct.jx** %8
%52 = load %struct.jx*, %struct.jx** %7
%53 = call %struct.jx* @jx_eval(%struct.jx* %51, %struct.jx* %52)
store %struct.jx* %53, %struct.jx** %9
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
%55 = load %struct.jx*, %struct.jx** %9
%56 = load i32, i32* @stdout
%57 = call i32 @jx_print_stream(%struct.jx* %55, i32 %56)
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
%59 = load %struct.jx*, %struct.jx** %8
%60 = call i32 @jx_delete(%struct.jx* %59)
%61 = load %struct.jx*, %struct.jx** %9
%62 = call i32 @jx_delete(%struct.jx* %61)
br label %71
63: ; preds = %41
%64 = load %struct.jx_parser*, %struct.jx_parser** %6
%65 = call i8* @jx_parser_error_string(%struct.jx_parser* %64)
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.7, i64 0, i64 0), i8* %65)
%67 = load %struct.jx*, %struct.jx** %8
%68 = call i32 @jx_delete(%struct.jx* %67)
%69 = load %struct.jx_parser*, %struct.jx_parser** %6
%70 = call i32 @jx_parser_delete(%struct.jx_parser* %69)
store i32 1, i32* %3
br label %78
71: ; preds = %45
br label %72
72: ; preds = %71
br label %31
73: ; preds = %40
%74 = load %struct.jx*, %struct.jx** %7
%75 = call i32 @jx_delete(%struct.jx* %74)
%76 = load %struct.jx_parser*, %struct.jx_parser** %6
%77 = call i32 @jx_parser_delete(%struct.jx_parser* %76)
store i32 0, i32* %3
br label %78
78: ; preds = %73, %63, %24, %19
%79 = load i32, i32* %3
ret i32 %79
}

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 %47, 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 %47
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))
br label %18
18: ; preds = %32, %16
%19 = tail call %struct.jx* @jx_parse(%struct.jx_parser* %4)
%20 = icmp eq %struct.jx* %19, null
br i1 %20, label %21, label %24
21: ; preds = %18
%22 = tail call i64 @jx_parser_errors(%struct.jx_parser* %4)
%23 = icmp eq i64 %22, 0
br i1 %23, label %44, label %24
24: ; preds = %21, %18
%25 = tail call i64 @jx_parser_errors(%struct.jx_parser* %4)
%26 = icmp eq i64 %25, 0
br i1 %26, label %32, label %27
27: ; preds = %24
%28 = tail call i8* @jx_parser_error_string(%struct.jx_parser* %4)
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.7, i64 0, i64 0), i8* %28)
%30 = tail call i32 @jx_delete(%struct.jx* %19)
%31 = tail call i32 @jx_parser_delete(%struct.jx_parser* %4)
br label %47
32: ; preds = %24
%33 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%34 = load i32, i32* @stdout
%35 = tail call i32 @jx_print_stream(%struct.jx* %19, i32 %34)
%36 = tail call i32 @putchar(i32 10)
%37 = tail call %struct.jx* @jx_eval(%struct.jx* %19, %struct.jx* %7)
%38 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
%39 = load i32, i32* @stdout
%40 = tail call i32 @jx_print_stream(%struct.jx* %37, i32 %39)
%41 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str.9, i64 0, i64 0))
%42 = tail call i32 @jx_delete(%struct.jx* %19)
%43 = tail call i32 @jx_delete(%struct.jx* %37)
br label %18
44: ; preds = %21
%45 = tail call i32 @jx_delete(%struct.jx* %7)
%46 = tail call i32 @jx_parser_delete(%struct.jx_parser* %4)
br label %47
47: ; preds = %27, %2, %44, %12
%48 = phi i32 [ 1, %12 ], [ 0, %44 ], [ 1, %2 ], [ 1, %27 ]
ret i32 %48
}