#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 EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ O_RDONLY;
int analyze(int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ free(char *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
char *realpath(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  if (argc < 2) {
    printf("Usage: %s </path/to/ihex>\n", argv[0]);
    exit(EXIT_SUCCESS);
  }
  char *path = realpath(argv[1], NULL);
  if (!path)
    exit(EXIT_FAILURE);
  int fd = open(path, O_RDONLY);
  free(path);
  if (fd == -1) {
    fprintf(stderr, "Unable to open \"%s\"\n", argv[1]);
    exit(EXIT_FAILURE);
  }
  int res;
  do {
    res = analyze(fd);
  } while (res == 0);
  close(fd);
  return res == 1 ? EXIT_SUCCESS : EXIT_FAILURE;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11c1 <main+0x41>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe52(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e0e(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1080 <realpath@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11ef <main+0x6f>
mov    0x2de8(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x18(%rbp),%rdi
mov    0x2dee(%rip),%rax
mov    (%rax),%esi
call   1090 <open@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
cmpl   $0xffffffff,-0x1c(%rbp)
jne    1242 <main+0xc2>
mov    0x2dba(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xdec(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2d95(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
jmp    1247 <main+0xc7>
mov    -0x1c(%rbp),%edi
call   1050 <analyze@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
je     1247 <main+0xc7>
mov    -0x1c(%rbp),%edi
call   1060 <close@plt>
cmpl   $0x1,-0x20(%rbp)
jne    127f <main+0xff>
mov    0x2d53(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
jmp    128b <main+0x10b>
mov    0x2d4a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
cmp    $0x1,%edi
jle    1200 <main+0x80>
mov    0x8(%r14),%rdi
xor    %esi,%esi
call   1080 <realpath@plt>
test   %rax,%rax
je     1236 <main+0xb6>
mov    %rax,%rbx
mov    0x2e3e(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1090 <open@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <free@plt>
cmp    $0xffffffff,%ebp
je     121d <main+0x9d>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %ebp,%edi
call   1050 <analyze@plt>
test   %eax,%eax
je     11d0 <main+0x50>
mov    %eax,%ebx
mov    %ebp,%edi
call   1060 <close@plt>
cmp    $0x1,%ebx
jne    11f2 <main+0x72>
mov    0x2dd8(%rip),%rax
jmp    11f9 <main+0x79>
mov    0x2dd7(%rip),%rax
mov    (%rax),%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    (%r14),%rsi
lea    0xdf6(%rip),%rdi
call   1040 <printf@plt>
mov    0x2db2(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    0x2db4(%rip),%rax
mov    (%rax),%edi
mov    0x8(%r14),%rdx
lea    0xdea(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2d93(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [27 x i8] c"Usage: %s </path/to/ihex>\0A\00"
@EXIT_SUCCESS = global i32 0
@EXIT_FAILURE = global i32 0
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str.1 = [21 x i8] c"Unable to open \22%s\22\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 2
br i1 %10, label %11, label %18
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = load i32, i32* @EXIT_SUCCESS
%17 = call i32 @exit(i32 %16)
unreachable
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call i8* @realpath(i8* %21, i32* null)
store i8* %22, i8** %6
%23 = load i8*, i8** %6
%24 = icmp ne i8* %23, null
br i1 %24, label %28, label %25
25: ; preds = %18
%26 = load i32, i32* @EXIT_FAILURE
%27 = call i32 @exit(i32 %26)
unreachable
28: ; preds = %18
%29 = load i8*, i8** %6
%30 = load i32, i32* @O_RDONLY
%31 = call i32 @open(i8* %29, i32 %30)
store i32 %31, i32* %7
%32 = load i8*, i8** %6
%33 = call i32 @free(i8* %32)
%34 = load i32, i32* %7
%35 = icmp eq i32 %34, -1
br i1 %35, label %36, label %44
36: ; preds = %28
%37 = load i32, i32* @stderr
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 1
%40 = load i8*, i8** %39
%41 = call i32 @fprintf(i32 %37, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %40)
%42 = load i32, i32* @EXIT_FAILURE
%43 = call i32 @exit(i32 %42)
unreachable
44: ; preds = %28
br label %45
45: ; preds = %48, %44
%46 = load i32, i32* %7
%47 = call i32 @analyze(i32 %46)
store i32 %47, i32* %8
br label %48
48: ; preds = %45
%49 = load i32, i32* %8
%50 = icmp eq i32 %49, 0
br i1 %50, label %45, label %51
51: ; preds = %48
%52 = load i32, i32* %7
%53 = call i32 @close(i32 %52)
%54 = load i32, i32* %8
%55 = icmp eq i32 %54, 1
br i1 %55, label %56, label %58
56: ; preds = %51
%57 = load i32, i32* @EXIT_SUCCESS
br label %60
58: ; preds = %51
%59 = load i32, i32* @EXIT_FAILURE
br label %60
60: ; preds = %58, %56
%61 = phi i32 [ %57, %56 ], [ %59, %58 ]
ret i32 %61
}

LLVM IR (-O2):
@.str = [27 x i8] c"Usage: %s </path/to/ihex>\0A\00"
@EXIT_SUCCESS = global i32 0
@EXIT_FAILURE = global i32 0
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str.1 = [21 x i8] c"Unable to open \22%s\22\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %9
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %5)
%7 = load i32, i32* @EXIT_SUCCESS
%8 = tail call i32 @exit(i32 %7)
unreachable
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i8* @realpath(i8* %11, i32* null)
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %17
14: ; preds = %9
%15 = load i32, i32* @EXIT_FAILURE
%16 = tail call i32 @exit(i32 %15)
unreachable
17: ; preds = %9
%18 = load i32, i32* @O_RDONLY
%19 = tail call i32 @open(i8* %12, i32 %18)
%20 = tail call i32 @free(i8* %12)
%21 = icmp eq i32 %19, -1
br i1 %21, label %22, label %28
22: ; preds = %17
%23 = load i32, i32* @stderr
%24 = load i8*, i8** %10
%25 = tail call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %24)
%26 = load i32, i32* @EXIT_FAILURE
%27 = tail call i32 @exit(i32 %26)
unreachable
28: ; preds = %17, %28
%29 = tail call i32 @analyze(i32 %19)
%30 = icmp eq i32 %29, 0
br i1 %30, label %28, label %31
31: ; preds = %28
%32 = tail call i32 @close(i32 %19)
%33 = icmp eq i32 %29, 1
%34 = load i32, i32* @EXIT_SUCCESS
%35 = load i32, i32* @EXIT_FAILURE
%36 = select i1 %33, i32 %34, i32 %35
ret i32 %36
}