#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 stat {
  uintptr_t st_size;
};

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ MAP_PRIVATE;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ PROT_READ;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fstat(int, struct stat *);
void *mmap(int /*<<< orphan*/ *, uintptr_t, int /*<<< orphan*/,
           int /*<<< orphan*/, int, int /*<<< orphan*/);
int /*<<< orphan*/ munmap(void *, uintptr_t);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ parse(void **, char);
int /*<<< orphan*/ printf(char *, char *);
scalar_t__ strncmp(char *, char *, int);
int /*<<< orphan*/ usage(char *);
int main(int argc, char **argv) {
  int i, fd;
  void *data, *st_data;
  const char *fname = NULL;
  struct stat st;
  char flags = 1;
  for (i = 1; i < argc; ++i) {
    if (strncmp("-d", argv[i], 2) == 0)
      flags |= 2;
    else
      fname = argv[0];
  }
  if (!fname)
    usage(argv[0]);
  if (!(fd = open(argv[1], O_RDONLY))) {
    printf("Could not open: %s\n", argv[1]);
    exit(EXIT_FAILURE);
  }
  fstat(fd, &st);
  data = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
  st_data = data;
  close(fd);
  while ((uintptr_t)data < ((uintptr_t)st_data + st.st_size))
    parse(&data, flags);
  munmap(st_data, st.st_size);
  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)
movq   $0x0,-0x30(%rbp)
movb   $0x1,-0x39(%rbp)
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1229 <main+0x89>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xe18(%rip),%rdi
mov    $0x2,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    120b <main+0x6b>
movsbl -0x39(%rbp),%eax
or     $0x2,%eax
mov    %al,-0x39(%rbp)
jmp    1216 <main+0x76>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
jmp    121b <main+0x7b>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11c9 <main+0x29>
cmpq   $0x0,-0x30(%rbp)
jne    1240 <main+0xa0>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1080 <usage@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2d91(%rip),%rax
mov    (%rax),%esi
call   1090 <open@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jne    1284 <main+0xe4>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xd92(%rip),%rdi
call   1050 <printf@plt>
mov    0x2d53(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
mov    -0x18(%rbp),%edi
lea    -0x38(%rbp),%rsi
call   10c0 <fstat@plt>
mov    -0x38(%rbp),%rsi
mov    0x2d5d(%rip),%rax
mov    (%rax),%edx
mov    0x2d24(%rip),%rax
mov    (%rax),%ecx
mov    -0x18(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
xor    %r9d,%r9d
call   1040 <mmap@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%edi
call   1060 <close@plt>
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%rcx
add    -0x38(%rbp),%rcx
cmp    %rcx,%rax
jae    12f1 <main+0x151>
lea    -0x20(%rbp),%rdi
movsbl -0x39(%rbp),%esi
call   10a0 <parse@plt>
jmp    12ca <main+0x12a>
mov    -0x28(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   1070 <munmap@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
mov    $0x1,%r12b
cmp    $0x2,%edi
jl     11fd <main+0x5d>
mov    %edi,%r15d
mov    $0x1,%r12b
mov    $0x1,%ebp
xor    %r13d,%r13d
lea    0xe32(%rip),%r14
jmp    11dc <main+0x3c>
mov    (%rbx),%r13
add    $0x1,%rbp
cmp    %rbp,%r15
je     11f8 <main+0x58>
mov    (%rbx,%rbp,8),%rsi
mov    %r14,%rdi
mov    $0x2,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    11d0 <main+0x30>
or     $0x2,%r12b
jmp    11d3 <main+0x33>
test   %r13,%r13
jne    1205 <main+0x65>
mov    (%rbx),%rdi
call   1080 <usage@plt>
mov    0x8(%rbx),%rdi
mov    0x2dd0(%rip),%rax
mov    (%rax),%esi
call   1090 <open@plt>
test   %eax,%eax
je     12ad <main+0x10d>
mov    %eax,%ebp
lea    0x10(%rsp),%rsi
mov    %eax,%edi
call   10c0 <fstat@plt>
mov    0x10(%rsp),%r14
mov    0x2dbf(%rip),%rax
mov    (%rax),%edx
mov    0x2d86(%rip),%rax
mov    (%rax),%ecx
xor    %edi,%edi
mov    %r14,%rsi
mov    %ebp,%r8d
xor    %r9d,%r9d
call   1040 <mmap@plt>
mov    %rax,%r15
mov    %rax,0x8(%rsp)
mov    %ebp,%edi
call   1060 <close@plt>
lea    (%r14,%r15,1),%rbx
cmp    %r15,%rbx
jbe    1291 <main+0xf1>
movsbl %r12b,%ebp
lea    0x8(%rsp),%r12
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r12,%rdi
mov    %ebp,%esi
call   10a0 <parse@plt>
cmp    0x8(%rsp),%rbx
ja     1280 <main+0xe0>
mov    %r15,%rdi
mov    %r14,%rsi
call   1070 <munmap@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x8(%rbx),%rsi
lea    0xd4b(%rip),%rdi
call   1050 <printf@plt>
mov    0x2d0c(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i64 }
@.str = [3 x i8] c"-d\00"
@O_RDONLY = global i32 0
@.str.1 = [20 x i8] c"Could not open: %s\0A\00"
@EXIT_FAILURE = global i32 0
@PROT_READ = global i32 0
@MAP_PRIVATE = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca %struct.stat
%12 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %10
store i8 1, i8* %12
store i32 1, i32* %6
br label %13
13: ; preds = %35, %2
%14 = load i32, i32* %6
%15 = load i32, i32* %4
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %38
17: ; preds = %13
%18 = load i8**, i8*** %5
%19 = load i32, i32* %6
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8*, i8** %18, i64 %20
%22 = load i8*, i8** %21
%23 = call i64 @strncmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %22, i32 2)
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %30
25: ; preds = %17
%26 = load i8, i8* %12
%27 = sext i8 %26 to i32
%28 = or i32 %27, 2
%29 = trunc i32 %28 to i8
store i8 %29, i8* %12
br label %34
30: ; preds = %17
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 0
%33 = load i8*, i8** %32
store i8* %33, i8** %10
br label %34
34: ; preds = %30, %25
br label %35
35: ; preds = %34
%36 = load i32, i32* %6
%37 = add nsw i32 %36, 1
store i32 %37, i32* %6
br label %13
38: ; preds = %13
%39 = load i8*, i8** %10
%40 = icmp ne i8* %39, null
br i1 %40, label %46, label %41
41: ; preds = %38
%42 = load i8**, i8*** %5
%43 = getelementptr inbounds i8*, i8** %42, i64 0
%44 = load i8*, i8** %43
%45 = call i32 @usage(i8* %44)
br label %46
46: ; preds = %41, %38
%47 = load i8**, i8*** %5
%48 = getelementptr inbounds i8*, i8** %47, i64 1
%49 = load i8*, i8** %48
%50 = load i32, i32* @O_RDONLY
%51 = call i32 @open(i8* %49, i32 %50)
store i32 %51, i32* %7
%52 = icmp ne i32 %51, 0
br i1 %52, label %60, label %53
53: ; preds = %46
%54 = load i8**, i8*** %5
%55 = getelementptr inbounds i8*, i8** %54, i64 1
%56 = load i8*, i8** %55
%57 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %56)
%58 = load i32, i32* @EXIT_FAILURE
%59 = call i32 @exit(i32 %58)
unreachable
60: ; preds = %46
%61 = load i32, i32* %7
%62 = call i32 @fstat(i32 %61, %struct.stat* %11)
%63 = getelementptr inbounds %struct.stat, %struct.stat* %11, i32 0, i32 0
%64 = load i64, i64* %63
%65 = load i32, i32* @PROT_READ
%66 = load i32, i32* @MAP_PRIVATE
%67 = load i32, i32* %7
%68 = call i8* @mmap(i32* null, i64 %64, i32 %65, i32 %66, i32 %67, i32 0)
store i8* %68, i8** %8
%69 = load i8*, i8** %8
store i8* %69, i8** %9
%70 = load i32, i32* %7
%71 = call i32 @close(i32 %70)
br label %72
72: ; preds = %81, %60
%73 = load i8*, i8** %8
%74 = ptrtoint i8* %73 to i64
%75 = load i8*, i8** %9
%76 = ptrtoint i8* %75 to i64
%77 = getelementptr inbounds %struct.stat, %struct.stat* %11, i32 0, i32 0
%78 = load i64, i64* %77
%79 = add i64 %76, %78
%80 = icmp ult i64 %74, %79
br i1 %80, label %81, label %84
81: ; preds = %72
%82 = load i8, i8* %12
%83 = call i32 @parse(i8** %8, i8 signext %82)
br label %72
84: ; preds = %72
%85 = load i8*, i8** %9
%86 = getelementptr inbounds %struct.stat, %struct.stat* %11, i32 0, i32 0
%87 = load i64, i64* %86
%88 = call i32 @munmap(i8* %85, i64 %87)
ret i32 0
}

LLVM IR (-O2):
%struct.stat = type { i64 }
@.str = [3 x i8] c"-d\00"
@O_RDONLY = global i32 0
@.str.1 = [20 x i8] c"Could not open: %s\0A\00"
@EXIT_FAILURE = global i32 0
@PROT_READ = global i32 0
@MAP_PRIVATE = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8*
%4 = alloca %struct.stat
%5 = bitcast i8** %3 to i8*
%6 = bitcast %struct.stat* %4 to i8*
%7 = icmp sgt i32 %0, 1
br i1 %7, label %8, label %29
8: ; preds = %2
%9 = zext i32 %0 to i64
br label %10
10: ; preds = %8, %22
%11 = phi i64 [ 1, %8 ], [ %25, %22 ]
%12 = phi i8 [ 1, %8 ], [ %24, %22 ]
%13 = phi i8* [ null, %8 ], [ %23, %22 ]
%14 = getelementptr inbounds i8*, i8** %1, i64 %11
%15 = load i8*, i8** %14
%16 = tail call i64 @strncmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %15, i32 2)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %10
%19 = or i8 %12, 2
br label %22
20: ; preds = %10
%21 = load i8*, i8** %1
br label %22
22: ; preds = %18, %20
%23 = phi i8* [ %13, %18 ], [ %21, %20 ]
%24 = phi i8 [ %19, %18 ], [ %12, %20 ]
%25 = add nuw nsw i64 %11, 1
%26 = icmp eq i64 %25, %9
br i1 %26, label %27, label %10
27: ; preds = %22
%28 = icmp eq i8* %23, null
br i1 %28, label %29, label %33
29: ; preds = %2, %27
%30 = phi i8 [ %24, %27 ], [ 1, %2 ]
%31 = load i8*, i8** %1
%32 = tail call i32 @usage(i8* %31)
br label %33
33: ; preds = %29, %27
%34 = phi i8 [ %30, %29 ], [ %24, %27 ]
%35 = getelementptr inbounds i8*, i8** %1, i64 1
%36 = load i8*, i8** %35
%37 = load i32, i32* @O_RDONLY
%38 = tail call i32 @open(i8* %36, i32 %37)
%39 = icmp eq i32 %38, 0
br i1 %39, label %40, label %45
40: ; preds = %33
%41 = load i8*, i8** %35
%42 = tail call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %41)
%43 = load i32, i32* @EXIT_FAILURE
%44 = tail call i32 @exit(i32 %43)
unreachable
45: ; preds = %33
%46 = call i32 @fstat(i32 %38, %struct.stat* %4)
%47 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
%48 = load i64, i64* %47
%49 = load i32, i32* @PROT_READ
%50 = load i32, i32* @MAP_PRIVATE
%51 = tail call i8* @mmap(i32* null, i64 %48, i32 %49, i32 %50, i32 %38, i32 0)
store i8* %51, i8** %3
%52 = tail call i32 @close(i32 %38)
%53 = ptrtoint i8* %51 to i64
%54 = add i64 %48, %53
%55 = icmp ugt i64 %54, %53
br i1 %55, label %56, label %61
56: ; preds = %45, %56
%57 = call i32 @parse(i8** %3, i8 signext %34)
%58 = load i8*, i8** %3
%59 = ptrtoint i8* %58 to i64
%60 = icmp ugt i64 %54, %59
br i1 %60, label %56, label %61
61: ; preds = %56, %45
%62 = call i32 @munmap(i8* %51, i64 %48)
ret i32 0
}