#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ SIGKILL;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ raise(int /*<<< orphan*/);
int /*<<< orphan*/ vuln(char *, int /*<<< orphan*/ *);
int main(int argc, char *argv[]) {
  int i, x;
  FILE *fd;
  printf("example.c: enter\n");
  printf("\targc = %d\n", argc);
  raise(SIGKILL);
  for (i = 0; i < argc; i++) {
    if (i == 2 && argv[2][0] == 'b')
      exit(2345);
    else if (i == 5) {
      if ((fd = fopen("/tmp/doesntexist.txt", "r")) == NULL)
        exit(1);
      vuln(argv[5], fd);
      fclose(fd);
    }
  }
  printf("example.c: exit\n");
  x = 1 / 0;
  printf("div by zero %d\n", x);
  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)
lea    0xe83(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x8(%rbp),%esi
lea    0xe84(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    0x2e44(%rip),%rax
mov    (%rax),%edi
call   1030 <raise@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1245 <main+0xe5>
cmpl   $0x2,-0x14(%rbp)
jne    11de <main+0x7e>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
movsbl (%rax),%eax
cmp    $0x62,%eax
jne    11de <main+0x7e>
mov    $0x929,%edi
call   1080 <exit@plt>
cmpl   $0x5,-0x14(%rbp)
jne    122d <main+0xcd>
lea    0xe2f(%rip),%rdi
lea    0xe3d(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1213 <main+0xb3>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x28(%rax),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <vuln@plt>
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
jmp    1232 <main+0xd2>
jmp    1237 <main+0xd7>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11aa <main+0x4a>
lea    0xde9(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%esi
lea    0xde6(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r12
mov    %edi,%r13d
lea    0xea9(%rip),%rdi
call   1040 <puts@plt>
lea    0xe6c(%rip),%rdi
xor    %ebp,%ebp
mov    %r13d,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x2e39(%rip),%rax
mov    (%rax),%edi
call   1030 <raise@plt>
test   %r13d,%r13d
jle    121a <main+0xaa>
lea    0xe52(%rip),%r14
lea    0xe7f(%rip),%r15
jmp    11d8 <main+0x68>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%ebp
cmp    %ebp,%r13d
je     121a <main+0xaa>
cmp    $0x5,%ebp
je     11f0 <main+0x80>
cmp    $0x2,%ebp
jne    11d0 <main+0x60>
mov    0x10(%r12),%rax
cmpb   $0x62,(%rax)
jne    11d0 <main+0x60>
jmp    1245 <main+0xd5>
xchg   %ax,%ax
mov    %r14,%rdi
mov    %r15,%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     124f <main+0xdf>
mov    %rax,%rbx
mov    0x28(%r12),%rdi
mov    %rax,%rsi
call   1050 <vuln@plt>
mov    %rbx,%rdi
call   1060 <fclose@plt>
jmp    11d0 <main+0x60>
lea    0xe21(%rip),%rdi
call   1040 <puts@plt>
lea    0xdf4(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x929,%edi
call   1090 <exit@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [18 x i8] c"example.c: enter\0A\00"
@.str.1 = [12 x i8] c"\09argc = %d\0A\00"
@SIGKILL = global i32 0
@.str.2 = [21 x i8] c"/tmp/doesntexist.txt\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [17 x i8] c"example.c: exit\0A\00"
@.str.5 = [16 x i8] c"div by zero %d\0A\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 i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%10 = load i32, i32* %4
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %10)
%12 = load i32, i32* @SIGKILL
%13 = call i32 @raise(i32 %12)
store i32 0, i32* %6
br label %14
14: ; preds = %49, %2
%15 = load i32, i32* %6
%16 = load i32, i32* %4
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %52
18: ; preds = %14
%19 = load i32, i32* %6
%20 = icmp eq i32 %19, 2
br i1 %20, label %21, label %31
21: ; preds = %18
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 2
%24 = load i8*, i8** %23
%25 = getelementptr inbounds i8, i8* %24, i64 0
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp eq i32 %27, 98
br i1 %28, label %29, label %31
29: ; preds = %21
%30 = call i32 @exit(i32 2345)
unreachable
31: ; preds = %21, %18
%32 = load i32, i32* %6
%33 = icmp eq i32 %32, 5
br i1 %33, label %34, label %47
34: ; preds = %31
%35 = call i32* @fopen(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %35, i32** %8
%36 = icmp eq i32* %35, null
br i1 %36, label %37, label %39
37: ; preds = %34
%38 = call i32 @exit(i32 1)
unreachable
39: ; preds = %34
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i64 5
%42 = load i8*, i8** %41
%43 = load i32*, i32** %8
%44 = call i32 @vuln(i8* %42, i32* %43)
%45 = load i32*, i32** %8
%46 = call i32 @fclose(i32* %45)
br label %47
47: ; preds = %39, %31
br label %48
48: ; preds = %47
br label %49
49: ; preds = %48
%50 = load i32, i32* %6
%51 = add nsw i32 %50, 1
store i32 %51, i32* %6
br label %14
52: ; preds = %14
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
store i32 poison, i32* %7
%54 = load i32, i32* %7
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), i32 %54)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [12 x i8] c"\09argc = %d\0A\00"
@SIGKILL = global i32 0
@.str.2 = [21 x i8] c"/tmp/doesntexist.txt\00"
@.str.3 = [2 x i8] c"r\00"
@.str.5 = [16 x i8] c"div by zero %d\0A\00"
@str = [17 x i8] c"example.c: enter\00"
@str.6 = [16 x i8] c"example.c: exit\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %0)
%5 = load i32, i32* @SIGKILL
%6 = tail call i32 @raise(i32 %5)
%7 = icmp sgt i32 %0, 0
br i1 %7, label %8, label %31
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 5
%10 = getelementptr inbounds i8*, i8** %1, i64 2
br label %11
11: ; preds = %8, %28
%12 = phi i32 [ 0, %8 ], [ %29, %28 ]
switch i32 %12, label %28 [
i32 2, label %13
i32 5, label %19
]
13: ; preds = %11
%14 = load i8*, i8** %10
%15 = load i8, i8* %14
%16 = icmp eq i8 %15, 98
br i1 %16, label %17, label %28
17: ; preds = %13
%18 = tail call i32 @exit(i32 2345)
unreachable
19: ; preds = %11
%20 = tail call i32* @fopen(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %24
22: ; preds = %19
%23 = tail call i32 @exit(i32 1)
unreachable
24: ; preds = %19
%25 = load i8*, i8** %9
%26 = tail call i32 @vuln(i8* %25, i32* %20)
%27 = tail call i32 @fclose(i32* %20)
br label %28
28: ; preds = %13, %11, %24
%29 = add nuw nsw i32 %12, 1
%30 = icmp eq i32 %29, %0
br i1 %30, label %31, label %11
31: ; preds = %28, %2
%32 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.6, i64 0, i64 0))
%33 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), i32 poison)
ret i32 0
}