#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 */
typedef int /*<<< orphan*/ ssize_t;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ boom(char *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ read(int, char **, int);
int main(int argc, char *argv[]) {
  int fd;
  ssize_t ret;
  char buffer[8192] = {0};
  fd = open(argv[1], O_RDONLY);
  if (fd == -1) {
    perror("open");
    return 1;
  }
  ret = read(fd, &buffer, 8192);
  if (buffer[0] == 'A') {
    if (buffer[2] == 'X') {
      boom(buffer);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2020,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x2020(%rbp),%rdi
xor    %esi,%esi
mov    $0x2000,%edx
call   1030 <memset@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e5d(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11b7 <main+0x67>
lea    0xe5a(%rip),%rdi
call   1060 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1206 <main+0xb6>
mov    -0x14(%rbp),%edi
lea    -0x2020(%rbp),%rsi
mov    $0x2000,%edx
call   1040 <read@plt>
mov    %eax,-0x18(%rbp)
movsbl -0x2020(%rbp),%eax
cmp    $0x41,%eax
jne    11ff <main+0xaf>
movsbl -0x201e(%rbp),%eax
cmp    $0x58,%eax
jne    11fa <main+0xaa>
lea    -0x2020(%rbp),%rdi
call   1070 <boom@plt>
jmp    11ff <main+0xaf>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x2020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x2008,%rsp
mov    %rsi,%rbx
mov    %rsp,%rdi
xor    %ebp,%ebp
mov    $0x2000,%edx
xor    %esi,%esi
call   1030 <memset@plt>
mov    0x8(%rbx),%rdi
mov    0x2e70(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
cmp    $0xffffffff,%eax
je     11b4 <main+0x64>
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x2000,%edx
call   1040 <read@plt>
cmpb   $0x41,(%rsp)
jne    11a8 <main+0x58>
cmpb   $0x58,0x2(%rsp)
jne    11a8 <main+0x58>
mov    %rsp,%rdi
call   1070 <boom@plt>
mov    %ebp,%eax
add    $0x2008,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe45(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%ebp
jmp    11a8 <main+0x58>

LLVM IR (-O0):
@O_RDONLY = global i32 0
@.str = [5 x i8] c"open\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca [8192 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = bitcast [8192 x i8]* %8 to i8*
%10 = load i8**, i8*** %5
%11 = getelementptr inbounds i8*, i8** %10, i64 1
%12 = load i8*, i8** %11
%13 = load i32, i32* @O_RDONLY
%14 = call i32 @open(i8* %12, i32 %13)
store i32 %14, i32* %6
%15 = load i32, i32* %6
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %19
17: ; preds = %2
%18 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %37
19: ; preds = %2
%20 = load i32, i32* %6
%21 = bitcast [8192 x i8]* %8 to i8**
%22 = call i32 @read(i32 %20, i8** %21, i32 8192)
store i32 %22, i32* %7
%23 = getelementptr inbounds [8192 x i8], [8192 x i8]* %8, i64 0, i64 0
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp eq i32 %25, 65
br i1 %26, label %27, label %36
27: ; preds = %19
%28 = getelementptr inbounds [8192 x i8], [8192 x i8]* %8, i64 0, i64 2
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = icmp eq i32 %30, 88
br i1 %31, label %32, label %35
32: ; preds = %27
%33 = getelementptr inbounds [8192 x i8], [8192 x i8]* %8, i64 0, i64 0
%34 = call i32 @boom(i8* %33)
br label %35
35: ; preds = %32, %27
br label %36
36: ; preds = %35, %19
store i32 0, i32* %3
br label %37
37: ; preds = %36, %17
%38 = load i32, i32* %3
ret i32 %38
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@.str = [5 x i8] c"open\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [8192 x i8]
%4 = getelementptr inbounds [8192 x i8], [8192 x i8]* %3, i64 0, i64 0
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = load i32, i32* @O_RDONLY
%8 = tail call i32 @open(i8* %6, i32 %7)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %23
12: ; preds = %2
%13 = bitcast [8192 x i8]* %3 to i8**
%14 = call i32 @read(i32 %8, i8** %13, i32 8192)
%15 = load i8, i8* %4
%16 = icmp eq i8 %15, 65
%17 = getelementptr inbounds [8192 x i8], [8192 x i8]* %3, i64 0, i64 2
%18 = load i8, i8* %17
%19 = icmp eq i8 %18, 88
%20 = select i1 %16, i1 %19, i1 false
br i1 %20, label %21, label %23
21: ; preds = %12
%22 = call i32 @boom(i8* %4)
br label %23
23: ; preds = %12, %21, %10
%24 = phi i32 [ 1, %10 ], [ 0, %21 ], [ 0, %12 ]
ret i32 %24
}