#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*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int open(char const *, int /*<<< orphan*/);
int /*<<< orphan*/ parseIvfFile(int);
int /*<<< orphan*/ printf(char *, char const *);
int main(int argc, char *argv[]) {
  if (argc != 2) {
    printf("usage: %s <filename>\r\n", argv[0]);
    return 0;
  }
  const char *fileName = argv[1];
  printf("Opening %s\r\n", fileName);
  int fd = open(fileName, O_RDONLY);
  if (fd >= 0) {
    parseIvfFile(fd);
    close(fd);
  } else {
    printf("Open [%s] failed\r\n", fileName);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     117f <main+0x3f>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe92(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11e6 <main+0xa6>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
lea    0xe81(%rip),%rdi
call   1030 <printf@plt>
mov    -0x18(%rbp),%rdi
mov    0x2e42(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jl     11cf <main+0x8f>
mov    -0x1c(%rbp),%edi
call   1050 <parseIvfFile@plt>
mov    -0x1c(%rbp),%edi
call   1040 <close@plt>
jmp    11df <main+0x9f>
mov    -0x18(%rbp),%rsi
lea    0xe4a(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
cmp    $0x2,%edi
jne    1182 <main+0x42>
mov    0x8(%rsi),%rbx
lea    0xec4(%rip),%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
mov    0x2e86(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1060 <open@plt>
test   %eax,%eax
js     118e <main+0x4e>
mov    %eax,%ebp
mov    %eax,%edi
call   1050 <parseIvfFile@plt>
mov    %ebp,%edi
call   1040 <close@plt>
jmp    119d <main+0x5d>
mov    (%rsi),%rsi
lea    0xe74(%rip),%rdi
jmp    1198 <main+0x58>
lea    0xe8f(%rip),%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [23 x i8] c"usage: %s <filename>\0D\0A\00"
@.str.1 = [13 x i8] c"Opening %s\0D\0A\00"
@O_RDONLY = global i32 0
@.str.2 = [19 x i8] c"Open [%s] failed\0D\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 2
br i1 %9, label %10, label %15
10: ; preds = %2
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 0
%13 = load i8*, i8** %12
%14 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %13)
store i32 0, i32* %3
br label %35
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
store i8* %18, i8** %6
%19 = load i8*, i8** %6
%20 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %19)
%21 = load i8*, i8** %6
%22 = load i32, i32* @O_RDONLY
%23 = call i32 @open(i8* %21, i32 %22)
store i32 %23, i32* %7
%24 = load i32, i32* %7
%25 = icmp sge i32 %24, 0
br i1 %25, label %26, label %31
26: ; preds = %15
%27 = load i32, i32* %7
%28 = call i32 @parseIvfFile(i32 %27)
%29 = load i32, i32* %7
%30 = call i32 @close(i32 %29)
br label %34
31: ; preds = %15
%32 = load i8*, i8** %6
%33 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %32)
br label %34
34: ; preds = %31, %26
store i32 0, i32* %3
br label %35
35: ; preds = %34, %10
%36 = load i32, i32* %3
ret i32 %36
}

LLVM IR (-O2):
@.str = [23 x i8] c"usage: %s <filename>\0D\0A\00"
@.str.1 = [13 x i8] c"Opening %s\0D\0A\00"
@O_RDONLY = global i32 0
@.str.2 = [19 x i8] c"Open [%s] failed\0D\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %7, label %4
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %5)
br label %19
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %9)
%11 = load i32, i32* @O_RDONLY
%12 = tail call i32 @open(i8* %9, i32 %11)
%13 = icmp sgt i32 %12, -1
br i1 %13, label %14, label %17
14: ; preds = %7
%15 = tail call i32 @parseIvfFile(i32 %12)
%16 = tail call i32 @close(i32 %12)
br label %19
17: ; preds = %7
%18 = tail call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %9)
br label %19
19: ; preds = %14, %17, %4
ret i32 0
}