#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 atoi(char *);
int /*<<< orphan*/ exit(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int main(int argc, char *argv[]) {
  char buffer[10] = {0};
  int fd, i;
  if (argc != 2) {
    printf("Usage: %s <file>\n", argv[0]);
    exit(-1);
  }
  if ((fd = open(argv[1], O_RDONLY)) == -1) {
    do {
      perror("open");
      exit(-1);
    } while (0);
    ;
  }
  if (read(fd, buffer, 10) != 10) {
    do {
      perror("read");
      exit(-1);
    } while (0);
    ;
  }
  i = atoi(buffer);
  if (i == 0x0badc0de) {
    printf("ok\n");
  }
  return 0;
}


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)
lea    -0x1a(%rbp),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1040 <memset@plt>
cmpl   $0x2,-0x8(%rbp)
je     11bf <main+0x4f>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe52(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e1a(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x20(%rbp)
cmp    $0xffffffff,%eax
jne    11fc <main+0x8c>
jmp    11e6 <main+0x76>
lea    0xe25(%rip),%rdi
call   1070 <perror@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
mov    -0x20(%rbp),%edi
lea    -0x1a(%rbp),%rsi
mov    $0xa,%edx
call   1050 <read@plt>
cmp    $0xa,%eax
je     1231 <main+0xc1>
jmp    121b <main+0xab>
lea    0xdf5(%rip),%rdi
call   1070 <perror@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
lea    -0x1a(%rbp),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xbadc0de,-0x24(%rbp)
jne    1258 <main+0xe8>
lea    0xdcb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x18,%rsp
movw   $0x0,0x10(%rsp)
movq   $0x0,0x8(%rsp)
cmp    $0x2,%edi
jne    11da <main+0x6a>
mov    0x8(%rsi),%rdi
mov    0x2e54(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
cmp    $0xffffffff,%eax
je     11f5 <main+0x85>
lea    0x8(%rsp),%rsi
mov    %eax,%edi
mov    $0xa,%edx
call   1050 <read@plt>
cmp    $0xa,%eax
jne    11fe <main+0x8e>
lea    0x8(%rsp),%rdi
call   1080 <atoi@plt>
cmp    $0xbadc0de,%eax
jne    11d3 <main+0x63>
lea    0xe4e(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x18,%rsp
ret
mov    (%rsi),%rsi
lea    0xe1c(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
lea    0xe16(%rip),%rdi
jmp    1205 <main+0x95>
lea    0xe12(%rip),%rdi
call   1070 <perror@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [18 x i8] c"Usage: %s <file>\0A\00"
@O_RDONLY = global i32 0
@.str.1 = [5 x i8] c"open\00"
@.str.2 = [5 x i8] c"read\00"
@.str.3 = [4 x i8] c"ok\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [10 x i8]
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = bitcast [10 x i8]* %6 to i8*
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 2
br i1 %11, label %12, label %18
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = call i32 @exit(i32 -1)
unreachable
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = load i32, i32* @O_RDONLY
%23 = call i32 @open(i8* %21, i32 %22)
store i32 %23, i32* %7
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %30
25: ; preds = %18
br label %26
26: ; preds = %25
%27 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%28 = call i32 @exit(i32 -1)
unreachable
29: ; No predecessors!
br label %30
30: ; preds = %29, %18
%31 = load i32, i32* %7
%32 = getelementptr inbounds [10 x i8], [10 x i8]* %6, i64 0, i64 0
%33 = call i32 @read(i32 %31, i8* %32, i32 10)
%34 = icmp ne i32 %33, 10
br i1 %34, label %35, label %40
35: ; preds = %30
br label %36
36: ; preds = %35
%37 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%38 = call i32 @exit(i32 -1)
unreachable
39: ; No predecessors!
br label %40
40: ; preds = %39, %30
%41 = getelementptr inbounds [10 x i8], [10 x i8]* %6, i64 0, i64 0
%42 = call i32 @atoi(i8* %41)
store i32 %42, i32* %8
%43 = load i32, i32* %8
%44 = icmp eq i32 %43, 195936478
br i1 %44, label %45, label %47
45: ; preds = %40
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
br label %47
47: ; preds = %45, %40
ret i32 0
}

LLVM IR (-O2):
@.str = [18 x i8] c"Usage: %s <file>\0A\00"
@O_RDONLY = global i32 0
@.str.1 = [5 x i8] c"open\00"
@.str.2 = [5 x i8] c"read\00"
@str = [3 x i8] c"ok\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [10 x i8]
%4 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32 %0, 2
br i1 %5, label %10, label %6
6: ; preds = %2
%7 = load i8*, i8** %1
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = tail call i32 @exit(i32 -1)
unreachable
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = load i32, i32* @O_RDONLY
%14 = tail call i32 @open(i8* %12, i32 %13)
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %19
16: ; preds = %10
%17 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%18 = tail call i32 @exit(i32 -1)
unreachable
19: ; preds = %10
%20 = call i32 @read(i32 %14, i8* %4, i32 10)
%21 = icmp eq i32 %20, 10
br i1 %21, label %25, label %22
22: ; preds = %19
%23 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%24 = tail call i32 @exit(i32 -1)
unreachable
25: ; preds = %19
%26 = call i32 @atoi(i8* %4)
%27 = icmp eq i32 %26, 195936478
br i1 %27, label %28, label %30
28: ; preds = %25
%29 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str, i64 0, i64 0))
br label %30
30: ; preds = %28, %25
ret i32 0
}