#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;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int atoi(char *);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ jx_delete(struct jx *);
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*/ *);
struct jx *jx_parser_yield(struct jx_parser *);
char *jx_print_string(struct jx *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
char *strerror(int /*<<< orphan*/);
int main(int argc, char **argv) {
  if (argc < 3) {
    fprintf(stderr, "Usage:\n%s expected-number-of-objects input-file\n",
            argv[0]);
    exit(1);
  }
  int n = atoi(argv[1]);
  const char *filename = argv[2];
  FILE *stream = fopen(filename, "r");
  if (!stream) {
    fprintf(stderr, "%s: Could not open file '%s' (%s)\n", argv[0], filename,
            strerror(errno));
    exit(1);
  }
  int count = 0;
  struct jx *j;
  struct jx_parser *p = jx_parser_create(0);
  jx_parser_read_stream(p, stream);
  while ((j = jx_parser_yield(p))) {
    char *str = jx_print_string(j);
    fprintf(stdout, "%s\n", str);
    jx_delete(j);
    free(str);
    count++;
  }
  if (jx_parser_errors(p)) {
    fprintf(stderr, "%s error: %s\n", argv[0], jx_parser_error_string(p));
  }
  jx_parser_delete(p);
  if (count == n) {
    exit(0);
  } else {
    fprintf(stderr, "%s: Expected %d objects, got %d.\n", argv[0], n, count);
    exit(2);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    1228 <main+0x48>
mov    0x2dd9(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xde9(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10c0 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xde2(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    12b6 <main+0xd6>
mov    0x2d76(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x5c(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x58(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    0x2d4f(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
mov    -0x5c(%rbp),%edi
mov    -0x58(%rbp),%rdx
mov    -0x50(%rbp),%rcx
mov    %rax,%r8
lea    0xd8e(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
movl   $0x0,-0x2c(%rbp)
xor    %edi,%edi
call   1050 <jx_parser_create@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   10a0 <jx_parser_read_stream@plt>
mov    -0x40(%rbp),%rdi
call   1090 <jx_parser_yield@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
je     1334 <main+0x154>
mov    -0x38(%rbp),%rdi
call   1040 <jx_print_string@plt>
mov    %rax,-0x48(%rbp)
mov    0x2cd0(%rip),%rax
mov    (%rax),%edi
mov    -0x48(%rbp),%rdx
lea    0xd53(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x38(%rbp),%rdi
call   1100 <jx_delete@plt>
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    12d5 <main+0xf5>
mov    -0x40(%rbp),%rdi
call   1070 <jx_parser_errors@plt>
cmp    $0x0,%rax
je     137f <main+0x19f>
mov    0x2c92(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x6c(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x68(%rbp)
mov    -0x40(%rbp),%rdi
call   1060 <jx_parser_error_string@plt>
mov    -0x6c(%rbp),%edi
mov    -0x68(%rbp),%rdx
mov    %rax,%rcx
lea    0xcde(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x40(%rbp),%rdi
call   10e0 <jx_parser_delete@plt>
mov    -0x2c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jne    139b <main+0x1bb>
xor    %edi,%edi
call   10d0 <exit@plt>
mov    0x2c3e(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x14(%rbp),%ecx
mov    -0x2c(%rbp),%r8d
lea    0xcab(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x2,%edi
call   10d0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbp
cmp    $0x2,%edi
jg     121b <main+0x3b>
mov    0x2de3(%rip),%rax
mov    (%rax),%edi
mov    0x0(%rbp),%rdx
lea    0xdf6(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    0x8(%rbp),%rdi
call   10c0 <atoi@plt>
mov    %eax,%r14d
mov    0x10(%rbp),%r15
lea    0xdff(%rip),%rsi
mov    %r15,%rdi
call   10b0 <fopen@plt>
test   %rax,%rax
jne    127d <main+0x9d>
mov    0x2d9a(%rip),%rax
mov    (%rax),%ebx
mov    0x0(%rbp),%r14
mov    0x2d85(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
lea    0xdd2(%rip),%rsi
mov    %ebx,%edi
mov    %r14,%rdx
mov    %r15,%rcx
mov    %rax,%r8
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    %rax,%rbx
mov    %r14d,0xc(%rsp)
mov    %rbp,0x10(%rsp)
xor    %ebp,%ebp
xor    %edi,%edi
call   1050 <jx_parser_create@plt>
mov    %rax,%r13
mov    %rax,%rdi
mov    %rbx,%rsi
call   10a0 <jx_parser_read_stream@plt>
mov    %r13,%rdi
call   1090 <jx_parser_yield@plt>
test   %rax,%rax
je     130e <main+0x12e>
mov    %rax,%rbx
mov    0x2d18(%rip),%r15
lea    0xda1(%rip),%r12
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1040 <jx_print_string@plt>
mov    %rax,%r14
mov    (%r15),%edi
mov    %r12,%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    %rbx,%rdi
call   1100 <jx_delete@plt>
mov    %r14,%rdi
call   1030 <free@plt>
add    $0x1,%ebp
mov    %r13,%rdi
call   1090 <jx_parser_yield@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    12d0 <main+0xf0>
mov    %r13,%rdi
call   1070 <jx_parser_errors@plt>
test   %rax,%rax
mov    0x10(%rsp),%rbx
je     134c <main+0x16c>
mov    0x2cb9(%rip),%rax
mov    (%rax),%r15d
mov    (%rbx),%r14
mov    %r13,%rdi
call   1060 <jx_parser_error_string@plt>
lea    0xd1a(%rip),%rsi
mov    %r15d,%edi
mov    %r14,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    %r13,%rdi
call   10e0 <jx_parser_delete@plt>
mov    0xc(%rsp),%ecx
cmp    %ecx,%ebp
jne    1363 <main+0x183>
xor    %edi,%edi
call   10d0 <exit@plt>
mov    0x2c76(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xcee(%rip),%rsi
mov    %ebp,%r8d
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0x2,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
%struct.jx = type { i32 }
%struct.jx_parser = type { i32 }
@stderr = global i32 0
@.str = [49 x i8] c"Usage:\0A%s expected-number-of-objects input-file\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [35 x i8] c"%s: Could not open file '%s' (%s)\0A\00"
@errno = global i32 0
@stdout = global i32 0
@.str.3 = [4 x i8] c"%s\0A\00"
@.str.4 = [14 x i8] c"%s error: %s\0A\00"
@.str.5 = [34 x i8] c"%s: Expected %d objects, got %d.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32*
%9 = alloca i32
%10 = alloca %struct.jx*
%11 = alloca %struct.jx_parser*
%12 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i32, i32* %4
%14 = icmp slt i32 %13, 3
br i1 %14, label %15, label %22
15: ; preds = %2
%16 = load i32, i32* @stderr
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 0
%19 = load i8*, i8** %18
%20 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i8* %19)
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %2
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = call i32 @atoi(i8* %25)
store i32 %26, i32* %6
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 2
%29 = load i8*, i8** %28
store i8* %29, i8** %7
%30 = load i8*, i8** %7
%31 = call i32* @fopen(i8* %30, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %31, i32** %8
%32 = load i32*, i32** %8
%33 = icmp ne i32* %32, null
br i1 %33, label %44, label %34
34: ; preds = %22
%35 = load i32, i32* @stderr
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i64 0
%38 = load i8*, i8** %37
%39 = load i8*, i8** %7
%40 = load i32, i32* @errno
%41 = call i8* @strerror(i32 %40)
%42 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i8* %38, i8* %39, i8* %41)
%43 = call i32 @exit(i32 1)
unreachable
44: ; preds = %22
store i32 0, i32* %9
%45 = call %struct.jx_parser* @jx_parser_create(i32 0)
store %struct.jx_parser* %45, %struct.jx_parser** %11
%46 = load %struct.jx_parser*, %struct.jx_parser** %11
%47 = load i32*, i32** %8
%48 = call i32 @jx_parser_read_stream(%struct.jx_parser* %46, i32* %47)
br label %49
49: ; preds = %53, %44
%50 = load %struct.jx_parser*, %struct.jx_parser** %11
%51 = call %struct.jx* @jx_parser_yield(%struct.jx_parser* %50)
store %struct.jx* %51, %struct.jx** %10
%52 = icmp ne %struct.jx* %51, null
br i1 %52, label %53, label %65
53: ; preds = %49
%54 = load %struct.jx*, %struct.jx** %10
%55 = call i8* @jx_print_string(%struct.jx* %54)
store i8* %55, i8** %12
%56 = load i32, i32* @stdout
%57 = load i8*, i8** %12
%58 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %56, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %57)
%59 = load %struct.jx*, %struct.jx** %10
%60 = call i32 @jx_delete(%struct.jx* %59)
%61 = load i8*, i8** %12
%62 = call i32 @free(i8* %61)
%63 = load i32, i32* %9
%64 = add nsw i32 %63, 1
store i32 %64, i32* %9
br label %49
65: ; preds = %49
%66 = load %struct.jx_parser*, %struct.jx_parser** %11
%67 = call i64 @jx_parser_errors(%struct.jx_parser* %66)
%68 = icmp ne i64 %67, 0
br i1 %68, label %69, label %77
69: ; preds = %65
%70 = load i32, i32* @stderr
%71 = load i8**, i8*** %5
%72 = getelementptr inbounds i8*, i8** %71, i64 0
%73 = load i8*, i8** %72
%74 = load %struct.jx_parser*, %struct.jx_parser** %11
%75 = call i8* @jx_parser_error_string(%struct.jx_parser* %74)
%76 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %70, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i8* %73, i8* %75)
br label %77
77: ; preds = %69, %65
%78 = load %struct.jx_parser*, %struct.jx_parser** %11
%79 = call i32 @jx_parser_delete(%struct.jx_parser* %78)
%80 = load i32, i32* %9
%81 = load i32, i32* %6
%82 = icmp eq i32 %80, %81
br i1 %82, label %83, label %85
83: ; preds = %77
%84 = call i32 @exit(i32 0)
unreachable
85: ; preds = %77
%86 = load i32, i32* @stderr
%87 = load i8**, i8*** %5
%88 = getelementptr inbounds i8*, i8** %87, i64 0
%89 = load i8*, i8** %88
%90 = load i32, i32* %6
%91 = load i32, i32* %9
%92 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %86, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0), i8* %89, i32 %90, i32 %91)
%93 = call i32 @exit(i32 2)
unreachable
}

LLVM IR (-O2):
%struct.jx_parser = type { i32 }
%struct.jx = type { i32 }
@stderr = global i32 0
@.str = [49 x i8] c"Usage:\0A%s expected-number-of-objects input-file\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [35 x i8] c"%s: Could not open file '%s' (%s)\0A\00"
@errno = global i32 0
@stdout = global i32 0
@.str.3 = [4 x i8] c"%s\0A\00"
@.str.4 = [14 x i8] c"%s error: %s\0A\00"
@.str.5 = [34 x i8] c"%s: Expected %d objects, got %d.\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 3
br i1 %3, label %4, label %9
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = load i8*, i8** %1
%7 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32 @atoi(i8* %11)
%13 = getelementptr inbounds i8*, i8** %1, i64 2
%14 = load i8*, i8** %13
%15 = tail call i32* @fopen(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %24
17: ; preds = %9
%18 = load i32, i32* @stderr
%19 = load i8*, i8** %1
%20 = load i32, i32* @errno
%21 = tail call i8* @strerror(i32 %20)
%22 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i8* %19, i8* %14, i8* %21)
%23 = tail call i32 @exit(i32 1)
unreachable
24: ; preds = %9
%25 = tail call %struct.jx_parser* @jx_parser_create(i32 0)
%26 = tail call i32 @jx_parser_read_stream(%struct.jx_parser* %25, i32* %15)
%27 = tail call %struct.jx* @jx_parser_yield(%struct.jx_parser* %25)
%28 = icmp eq %struct.jx* %27, null
br i1 %28, label %40, label %29
29: ; preds = %24, %29
%30 = phi %struct.jx* [ %38, %29 ], [ %27, %24 ]
%31 = phi i32 [ %37, %29 ], [ 0, %24 ]
%32 = tail call i8* @jx_print_string(%struct.jx* %30)
%33 = load i32, i32* @stdout
%34 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %32)
%35 = tail call i32 @jx_delete(%struct.jx* %30)
%36 = tail call i32 @free(i8* %32)
%37 = add nuw nsw i32 %31, 1
%38 = tail call %struct.jx* @jx_parser_yield(%struct.jx_parser* %25)
%39 = icmp eq %struct.jx* %38, null
br i1 %39, label %40, label %29
40: ; preds = %29, %24
%41 = phi i32 [ 0, %24 ], [ %37, %29 ]
%42 = tail call i64 @jx_parser_errors(%struct.jx_parser* %25)
%43 = icmp eq i64 %42, 0
br i1 %43, label %49, label %44
44: ; preds = %40
%45 = load i32, i32* @stderr
%46 = load i8*, i8** %1
%47 = tail call i8* @jx_parser_error_string(%struct.jx_parser* %25)
%48 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %45, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i8* %46, i8* %47)
br label %49
49: ; preds = %44, %40
%50 = tail call i32 @jx_parser_delete(%struct.jx_parser* %25)
%51 = icmp eq i32 %41, %12
br i1 %51, label %52, label %54
52: ; preds = %49
%53 = tail call i32 @exit(i32 0)
unreachable
54: ; preds = %49
%55 = load i32, i32* @stderr
%56 = load i8*, i8** %1
%57 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %55, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0), i8* %56, i32 %12, i32 %41)
%58 = tail call i32 @exit(i32 2)
unreachable
}