#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 */

/* Variables and functions */
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ jseval(char const *, char **, size_t *);
char *read_file_z(char *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ usage();
int /*<<< orphan*/ write_file(char *, size_t, char *);
int nacl_main(int argc, char **argv) {
  char *indata = 0;
  const char *cmd;
  char *outdata;
  size_t outdata_len;
  if ((argc != 3 && argc != 4) ||
      (strcmp(argv[1], "-f") != 0 && strcmp(argv[1], "-e") != 0)) {
    usage();
    return 1;
  }
  if (strcmp(argv[1], "-f") == 0) {
    indata = read_file_z(argv[2]);
    cmd = indata;
  } else {
    cmd = argv[2];
  }
  if (argc == 4) {
    jseval(cmd, &outdata, &outdata_len);
    write_file(outdata, outdata_len, argv[3]);
  } else {
    jseval(cmd, NULL, NULL);
  }
  if (strcmp(argv[1], "-f") == 0) {
    free(indata);
  }
  return 0;
}


x86 assembly (clang, -O0):
<nacl_main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     118b <nacl_main+0x2b>
cmpl   $0x4,-0x8(%rbp)
jne    11c7 <nacl_main+0x67>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe66(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
je     11da <nacl_main+0x7a>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe4b(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
je     11da <nacl_main+0x7a>
mov    $0x0,%al
call   1070 <usage@plt>
movl   $0x1,-0x4(%rbp)
jmp    1295 <nacl_main+0x135>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe17(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    1216 <nacl_main+0xb6>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1030 <read_file_z@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    1222 <nacl_main+0xc2>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x20(%rbp)
cmpl   $0x4,-0x8(%rbp)
jne    1257 <nacl_main+0xf7>
mov    -0x20(%rbp),%rdi
lea    -0x28(%rbp),%rsi
lea    -0x30(%rbp),%rdx
call   1080 <jseval@plt>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdx
call   1050 <write_file@plt>
jmp    1267 <nacl_main+0x107>
mov    -0x20(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%edx
mov    %rdx,%rsi
call   1080 <jseval@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xd8a(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    128e <nacl_main+0x12e>
mov    -0x18(%rbp),%rdi
call   1040 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nacl_main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
lea    -0x5(%rbx),%eax
cmp    $0xfffffffe,%eax
jb     11a0 <nacl_main+0x40>
mov    %rsi,%r14
mov    0x8(%rsi),%rdi
lea    0xe7f(%rip),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     11ae <nacl_main+0x4e>
mov    0x8(%r14),%rdi
lea    0xe6d(%rip),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     11ae <nacl_main+0x4e>
xor    %eax,%eax
call   1070 <usage@plt>
mov    $0x1,%ebx
jmp    1228 <nacl_main+0xc8>
mov    0x8(%r14),%rdi
lea    0xe47(%rip),%rsi
call   1060 <strcmp@plt>
mov    0x10(%r14),%rdi
test   %rax,%rax
je     11f0 <nacl_main+0x90>
xor    %r15d,%r15d
cmp    $0x4,%ebx
jne    1200 <nacl_main+0xa0>
lea    0x8(%rsp),%rsi
mov    %rsp,%rdx
call   1080 <jseval@plt>
mov    0x8(%rsp),%rdi
mov    (%rsp),%rsi
mov    0x18(%r14),%rdx
call   1050 <write_file@plt>
jmp    1209 <nacl_main+0xa9>
call   1030 <read_file_z@plt>
mov    %rax,%r15
mov    %rax,%rdi
cmp    $0x4,%ebx
je     11cf <nacl_main+0x6f>
xor    %esi,%esi
xor    %edx,%edx
call   1080 <jseval@plt>
mov    0x8(%r14),%rdi
lea    0xdec(%rip),%rsi
call   1060 <strcmp@plt>
xor    %ebx,%ebx
test   %rax,%rax
jne    1228 <nacl_main+0xc8>
mov    %r15,%rdi
call   1040 <free@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"-f\00"
@.str.1 = [3 x i8] c"-e\00"
define i32 @nacl_main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i64
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %6
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 3
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = load i32, i32* %4
%14 = icmp ne i32 %13, 4
br i1 %14, label %27, label %15
15: ; preds = %12, %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i64 @strcmp(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %29
21: ; preds = %15
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = call i64 @strcmp(i8* %24, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %21, %12
%28 = call i32 (...) @usage()
store i32 1, i32* %3
br label %70
29: ; preds = %21, %15
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 1
%32 = load i8*, i8** %31
%33 = call i64 @strcmp(i8* %32, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%34 = icmp eq i64 %33, 0
br i1 %34, label %35, label %41
35: ; preds = %29
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i64 2
%38 = load i8*, i8** %37
%39 = call i8* @read_file_z(i8* %38)
store i8* %39, i8** %6
%40 = load i8*, i8** %6
store i8* %40, i8** %7
br label %45
41: ; preds = %29
%42 = load i8**, i8*** %5
%43 = getelementptr inbounds i8*, i8** %42, i64 2
%44 = load i8*, i8** %43
store i8* %44, i8** %7
br label %45
45: ; preds = %41, %35
%46 = load i32, i32* %4
%47 = icmp eq i32 %46, 4
br i1 %47, label %48, label %57
48: ; preds = %45
%49 = load i8*, i8** %7
%50 = call i32 @jseval(i8* %49, i8** %8, i64* %9)
%51 = load i8*, i8** %8
%52 = load i64, i64* %9
%53 = load i8**, i8*** %5
%54 = getelementptr inbounds i8*, i8** %53, i64 3
%55 = load i8*, i8** %54
%56 = call i32 @write_file(i8* %51, i64 %52, i8* %55)
br label %60
57: ; preds = %45
%58 = load i8*, i8** %7
%59 = call i32 @jseval(i8* %58, i8** null, i64* null)
br label %60
60: ; preds = %57, %48
%61 = load i8**, i8*** %5
%62 = getelementptr inbounds i8*, i8** %61, i64 1
%63 = load i8*, i8** %62
%64 = call i64 @strcmp(i8* %63, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%65 = icmp eq i64 %64, 0
br i1 %65, label %66, label %69
66: ; preds = %60
%67 = load i8*, i8** %6
%68 = call i32 @free(i8* %67)
br label %69
69: ; preds = %66, %60
store i32 0, i32* %3
br label %70
70: ; preds = %69, %27
%71 = load i32, i32* %3
ret i32 %71
}

LLVM IR (-O2):
@.str = [3 x i8] c"-f\00"
@.str.1 = [3 x i8] c"-e\00"
define i32 @nacl_main(i32 %0, i8** nocapture %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = bitcast i8** %3 to i8*
%6 = bitcast i64* %4 to i8*
%7 = add i32 %0, -5
%8 = icmp ult i32 %7, -2
br i1 %8, label %18, label %9
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i64 @strcmp(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%13 = icmp eq i64 %12, 0
br i1 %13, label %20, label %14
14: ; preds = %9
%15 = load i8*, i8** %10
%16 = tail call i64 @strcmp(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%17 = icmp eq i64 %16, 0
br i1 %17, label %20, label %18
18: ; preds = %2, %14
%19 = tail call i32 (...) @usage()
br label %47
20: ; preds = %14, %9
%21 = load i8*, i8** %10
%22 = tail call i64 @strcmp(i8* %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%23 = icmp eq i64 %22, 0
%24 = getelementptr inbounds i8*, i8** %1, i64 2
%25 = load i8*, i8** %24
br i1 %23, label %26, label %28
26: ; preds = %20
%27 = tail call i8* @read_file_z(i8* %25)
br label %28
28: ; preds = %20, %26
%29 = phi i8* [ %27, %26 ], [ null, %20 ]
%30 = phi i8* [ %27, %26 ], [ %25, %20 ]
%31 = icmp eq i32 %0, 4
br i1 %31, label %32, label %39
32: ; preds = %28
%33 = call i32 @jseval(i8* %30, i8** %3, i64* %4)
%34 = load i8*, i8** %3
%35 = load i64, i64* %4
%36 = getelementptr inbounds i8*, i8** %1, i64 3
%37 = load i8*, i8** %36
%38 = call i32 @write_file(i8* %34, i64 %35, i8* %37)
br label %41
39: ; preds = %28
%40 = tail call i32 @jseval(i8* %30, i8** null, i64* null)
br label %41
41: ; preds = %39, %32
%42 = load i8*, i8** %10
%43 = call i64 @strcmp(i8* %42, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%44 = icmp eq i64 %43, 0
br i1 %44, label %45, label %47
45: ; preds = %41
%46 = call i32 @free(i8* %29)
br label %47
47: ; preds = %41, %45, %18
%48 = phi i32 [ 1, %18 ], [ 0, %45 ], [ 0, %41 ]
ret i32 %48
}