#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 */
struct stat {
  int /*<<< orphan*/ st_size;
};

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ close(int);
int create_file(char *);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int lseek(int, int /*<<< orphan*/, int /*<<< orphan*/);
int odirure(int, int, int, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int reveal(int, int, int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ snprintf(char *, int, char *, char *, char *);
int stat(char *, struct stat *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int /*<<< orphan*/ strstr(char *, char *);
int /*<<< orphan*/ unlink(char *);
int main(int argc, char **argv) {
  struct stat st, map_st;
  int fd, newfd, mapfd, ret;
  char newfile[256], mapfile[256];
  if (argc != 2) {
    fprintf(stderr, "usage: %s <file>\n", argv[0]);
    return -1;
  }
  fd = open(argv[1], O_RDONLY);
  if (!fd) {
    perror("open");
    return -1;
  }
  ret = stat(argv[1], &st);
  if (ret == -1) {
    perror("stat");
    return -1;
  }
  ret = lseek(fd, 0, SEEK_SET);
  if (ret == -1) {
    perror("lseek");
    return -1;
  }
  if (!strstr(argv[1], ".bh")) {
    snprintf(newfile, 256, "%s%s", argv[1], ".bh");
    snprintf(mapfile, 256, "%s%s", newfile, ".map");
    newfd = create_file(newfile);
    if (newfd == -1)
      return -1;
    printf("Generating odirure file: %s...\n", newfile);
    mapfd = create_file(mapfile);
    if (mapfd == -1)
      goto unlink_newfile;
    printf("Generating map file: %s...\n", mapfile);
    ret = odirure(fd, newfd, mapfd, st.st_size);
    if (ret == -1) {
      fprintf(stderr, "odirure failed!\n");
      goto unlink_mapfile;
    }
  } else {
    snprintf(newfile, 256, "%s%s", argv[1], ".out");
    snprintf(mapfile, 256, "%s%s", argv[1], ".map");
    mapfd = open(mapfile, O_RDONLY);
    if (mapfd == -1) {
      fprintf(stderr, "open: %s: %s\n", mapfile, strerror(errno));
      return -1;
    }
    ret = stat(mapfile, &map_st);
    if (ret == -1) {
      perror("stat");
      return -1;
    }
    ret = lseek(mapfd, 0, SEEK_SET);
    if (ret == -1) {
      perror("lseek");
      return -1;
    }
    newfd = create_file(newfile);
    if (newfd == -1)
      return -1;
    printf("Generating output file: %s...\n", newfile);
    ret = reveal(fd, newfd, mapfd, st.st_size, map_st.st_size);
    if (ret == -1) {
      fprintf(stderr, "reveal failed!\n");
      goto unlink_newfile;
    }
  }
  close(fd);
  close(newfd);
  close(mapfd);
  return 0;
unlink_mapfile:
  unlink(mapfile);
unlink_newfile:
  unlink(newfile);
  return -1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x240,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     122d <main+0x4d>
mov    0x2dce(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xde6(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    15d8 <main+0x3f8>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2dac(%rip),%rax
mov    (%rax),%esi
call   10b0 <open@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jne    1268 <main+0x88>
lea    0xdbb(%rip),%rdi
call   10c0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    15d8 <main+0x3f8>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x18(%rbp),%rsi
call   1090 <stat@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0xffffffff,-0x30(%rbp)
jne    129e <main+0xbe>
lea    0xd8a(%rip),%rdi
call   10c0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    15d8 <main+0x3f8>
mov    -0x24(%rbp),%edi
mov    0x2d20(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1060 <lseek@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0xffffffff,-0x30(%rbp)
jne    12d6 <main+0xf6>
lea    0xd57(%rip),%rdi
call   10c0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    15d8 <main+0x3f8>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xd3d(%rip),%rsi
call   10f0 <strstr@plt>
cmp    $0x0,%eax
jne    13e8 <main+0x208>
lea    -0x130(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rcx
mov    $0x100,%esi
lea    0xd18(%rip),%rdx
lea    0xd0d(%rip),%r8
call   1050 <snprintf@plt>
lea    -0x230(%rbp),%rdi
lea    -0x130(%rbp),%rcx
mov    $0x100,%esi
lea    0xcf2(%rip),%rdx
lea    0xcf0(%rip),%r8
call   1050 <snprintf@plt>
lea    -0x130(%rbp),%rdi
call   10d0 <create_file@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0xffffffff,-0x28(%rbp)
jne    1365 <main+0x185>
movl   $0xffffffff,-0x4(%rbp)
jmp    15d8 <main+0x3f8>
lea    -0x130(%rbp),%rsi
lea    0xcbd(%rip),%rdi
call   1040 <printf@plt>
lea    -0x230(%rbp),%rdi
call   10d0 <create_file@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0xffffffff,-0x2c(%rbp)
jne    1396 <main+0x1b6>
jmp    15c5 <main+0x3e5>
lea    -0x230(%rbp),%rsi
lea    0xcac(%rip),%rdi
call   1040 <printf@plt>
mov    -0x24(%rbp),%edi
mov    -0x28(%rbp),%esi
mov    -0x2c(%rbp),%edx
mov    -0x18(%rbp),%ecx
call   10a0 <odirure@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0xffffffff,-0x30(%rbp)
jne    13e3 <main+0x203>
mov    0x2c0a(%rip),%rax
mov    (%rax),%edi
lea    0xc95(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
jmp    15b9 <main+0x3d9>
jmp    1595 <main+0x3b5>
lea    -0x130(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rcx
mov    $0x100,%esi
lea    0xc23(%rip),%rdx
lea    0xc73(%rip),%r8
call   1050 <snprintf@plt>
lea    -0x230(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rcx
mov    $0x100,%esi
lea    0xbfc(%rip),%rdx
lea    0xbfa(%rip),%r8
call   1050 <snprintf@plt>
lea    -0x230(%rbp),%rdi
mov    0x2ba4(%rip),%rax
mov    (%rax),%esi
call   10b0 <open@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0xffffffff,-0x2c(%rbp)
jne    14ad <main+0x2cd>
mov    0x2b79(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x23c(%rbp)
lea    -0x230(%rbp),%rax
mov    %rax,-0x238(%rbp)
mov    0x2b54(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
mov    -0x23c(%rbp),%edi
mov    -0x238(%rbp),%rdx
mov    %rax,%rcx
lea    0xbe8(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    15d8 <main+0x3f8>
lea    -0x230(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1090 <stat@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0xffffffff,-0x30(%rbp)
jne    14e2 <main+0x302>
lea    0xb46(%rip),%rdi
call   10c0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    15d8 <main+0x3f8>
mov    -0x2c(%rbp),%edi
mov    0x2adc(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1060 <lseek@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0xffffffff,-0x30(%rbp)
jne    151a <main+0x33a>
lea    0xb13(%rip),%rdi
call   10c0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    15d8 <main+0x3f8>
lea    -0x130(%rbp),%rdi
call   10d0 <create_file@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0xffffffff,-0x28(%rbp)
jne    153f <main+0x35f>
movl   $0xffffffff,-0x4(%rbp)
jmp    15d8 <main+0x3f8>
lea    -0x130(%rbp),%rsi
lea    0xb43(%rip),%rdi
call   1040 <printf@plt>
mov    -0x24(%rbp),%edi
mov    -0x28(%rbp),%esi
mov    -0x2c(%rbp),%edx
mov    -0x18(%rbp),%ecx
mov    -0x20(%rbp),%r8d
call   1100 <reveal@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0xffffffff,-0x30(%rbp)
jne    1590 <main+0x3b0>
mov    0x2a5d(%rip),%rax
mov    (%rax),%edi
lea    0xb2b(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
jmp    15c5 <main+0x3e5>
jmp    1595 <main+0x3b5>
mov    -0x24(%rbp),%edi
call   1070 <close@plt>
mov    -0x28(%rbp),%edi
call   1070 <close@plt>
mov    -0x2c(%rbp),%edi
call   1070 <close@plt>
movl   $0x0,-0x4(%rbp)
jmp    15d8 <main+0x3f8>
lea    -0x230(%rbp),%rdi
call   1030 <unlink@plt>
lea    -0x130(%rbp),%rdi
call   1030 <unlink@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x240,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x210,%rsp
mov    %rsi,%rbx
cmp    $0x2,%edi
jne    1350 <main+0x170>
mov    0x8(%rbx),%rdi
mov    0x2de2(%rip),%r15
mov    (%r15),%esi
call   10b0 <open@plt>
test   %eax,%eax
je     1495 <main+0x2b5>
mov    %eax,%r14d
mov    0x8(%rbx),%rdi
mov    %rsp,%rsi
call   1090 <stat@plt>
cmp    $0xffffffff,%eax
je     1473 <main+0x293>
mov    0x2d93(%rip),%r12
mov    (%r12),%edx
mov    %r14d,%edi
xor    %esi,%esi
call   1060 <lseek@plt>
cmp    $0xffffffff,%eax
je     1484 <main+0x2a4>
mov    0x8(%rbx),%rdi
lea    0xdcb(%rip),%rsi
call   10f0 <strstr@plt>
mov    0x8(%rbx),%rcx
test   %eax,%eax
je     137f <main+0x19f>
lea    0xdb7(%rip),%rbp
lea    0xe07(%rip),%r8
lea    0x110(%rsp),%rdi
mov    $0x100,%esi
mov    %rbp,%rdx
call   1050 <snprintf@plt>
mov    0x8(%rbx),%rcx
lea    0xd95(%rip),%r8
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x100,%esi
mov    %rbp,%rdx
call   1050 <snprintf@plt>
mov    (%r15),%esi
mov    %rbx,%rdi
call   10b0 <open@plt>
cmp    $0xffffffff,%eax
je     143f <main+0x25f>
mov    %eax,%ebp
lea    0x10(%rsp),%rdi
lea    0x8(%rsp),%rsi
call   1090 <stat@plt>
cmp    $0xffffffff,%eax
je     1473 <main+0x293>
mov    (%r12),%edx
mov    %ebp,%edi
xor    %esi,%esi
call   1060 <lseek@plt>
cmp    $0xffffffff,%eax
je     1484 <main+0x2a4>
lea    0x110(%rsp),%rdi
call   10d0 <create_file@plt>
cmp    $0xffffffff,%eax
je     136a <main+0x18a>
mov    %eax,%ebx
lea    0xd86(%rip),%rdi
lea    0x110(%rsp),%rsi
call   1040 <printf@plt>
mov    (%rsp),%ecx
mov    0x8(%rsp),%r8d
mov    %r14d,%edi
mov    %ebx,%esi
mov    %ebp,%edx
call   1100 <reveal@plt>
cmp    $0xffffffff,%eax
jne    1422 <main+0x242>
mov    0x2c9d(%rip),%rax
mov    (%rax),%edi
lea    0xd6b(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
jmp    14c7 <main+0x2e7>
mov    0x2c81(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xc9d(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x210,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xca0(%rip),%rbx
lea    0xc95(%rip),%r8
lea    0x110(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x100,%esi
mov    %rbx,%rdx
call   1050 <snprintf@plt>
lea    0xc7f(%rip),%r8
lea    0x10(%rsp),%rdi
mov    $0x100,%esi
mov    %rbx,%rdx
mov    %rbp,%rcx
call   1050 <snprintf@plt>
mov    %rbp,%rdi
call   10d0 <create_file@plt>
cmp    $0xffffffff,%eax
je     136a <main+0x18a>
mov    %eax,%ebx
lea    0xc59(%rip),%rdi
lea    0x110(%rsp),%rsi
call   1040 <printf@plt>
lea    0x10(%rsp),%rdi
call   10d0 <create_file@plt>
cmp    $0xffffffff,%eax
je     14c7 <main+0x2e7>
mov    %eax,%ebp
lea    0xc50(%rip),%rdi
lea    0x10(%rsp),%rsi
call   1040 <printf@plt>
mov    (%rsp),%ecx
mov    %r14d,%edi
mov    %ebx,%esi
mov    %ebp,%edx
call   10a0 <odirure@plt>
cmp    $0xffffffff,%eax
je     14a6 <main+0x2c6>
mov    %r14d,%edi
call   1070 <close@plt>
mov    %ebx,%edi
call   1070 <close@plt>
mov    %ebp,%edi
call   1070 <close@plt>
xor    %eax,%eax
jmp    136f <main+0x18f>
mov    0x2b92(%rip),%rax
mov    (%rax),%ebx
mov    0x2b81(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
lea    0xc25(%rip),%rsi
lea    0x10(%rsp),%rdx
mov    %ebx,%edi
mov    %rax,%rcx
xor    %eax,%eax
call   1080 <fprintf@plt>
jmp    136a <main+0x18a>
lea    0xb9d(%rip),%rdi
call   10c0 <perror@plt>
jmp    136a <main+0x18a>
lea    0xb91(%rip),%rdi
call   10c0 <perror@plt>
jmp    136a <main+0x18a>
lea    0xb76(%rip),%rdi
call   10c0 <perror@plt>
jmp    136a <main+0x18a>
mov    0x2b2b(%rip),%rax
mov    (%rax),%edi
lea    0xbb6(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
lea    0x10(%rsp),%rdi
call   1030 <unlink@plt>
lea    0x110(%rsp),%rdi
call   1030 <unlink@plt>
jmp    136a <main+0x18a>

LLVM IR (-O0):
%struct.stat = type { i32 }
@stderr = global i32 0
@.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"stat\00"
@SEEK_SET = global i32 0
@.str.3 = [6 x i8] c"lseek\00"
@.str.4 = [4 x i8] c".bh\00"
@.str.5 = [5 x i8] c"%s%s\00"
@.str.6 = [5 x i8] c".map\00"
@.str.7 = [32 x i8] c"Generating odirure file: %s...\0A\00"
@.str.8 = [28 x i8] c"Generating map file: %s...\0A\00"
@.str.9 = [17 x i8] c"odirure failed!\0A\00"
@.str.10 = [5 x i8] c".out\00"
@.str.11 = [14 x i8] c"open: %s: %s\0A\00"
@errno = global i32 0
@.str.12 = [31 x i8] c"Generating output file: %s...\0A\00"
@.str.13 = [16 x i8] c"reveal failed!\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.stat
%7 = alloca %struct.stat
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca [256 x i8]
%13 = alloca [256 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = load i32, i32* %4
%15 = icmp ne i32 %14, 2
br i1 %15, label %16, label %22
16: ; preds = %2
%17 = load i32, i32* @stderr
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 0
%20 = load i8*, i8** %19
%21 = call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %20)
store i32 -1, i32* %3
br label %165
22: ; preds = %2
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = load i32, i32* @O_RDONLY
%27 = call i32 @open(i8* %25, i32 %26)
store i32 %27, i32* %8
%28 = load i32, i32* %8
%29 = icmp ne i32 %28, 0
br i1 %29, label %32, label %30
30: ; preds = %22
%31 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %165
32: ; preds = %22
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 1
%35 = load i8*, i8** %34
%36 = call i32 @stat(i8* %35, %struct.stat* %6)
store i32 %36, i32* %11
%37 = load i32, i32* %11
%38 = icmp eq i32 %37, -1
br i1 %38, label %39, label %41
39: ; preds = %32
%40 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %3
br label %165
41: ; preds = %32
%42 = load i32, i32* %8
%43 = load i32, i32* @SEEK_SET
%44 = call i32 @lseek(i32 %42, i32 0, i32 %43)
store i32 %44, i32* %11
%45 = load i32, i32* %11
%46 = icmp eq i32 %45, -1
br i1 %46, label %47, label %49
47: ; preds = %41
%48 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %3
br label %165
49: ; preds = %41
%50 = load i8**, i8*** %5
%51 = getelementptr inbounds i8*, i8** %50, i64 1
%52 = load i8*, i8** %51
%53 = call i32 @strstr(i8* %52, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%54 = icmp ne i32 %53, 0
br i1 %54, label %92, label %55
55: ; preds = %49
%56 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%57 = load i8**, i8*** %5
%58 = getelementptr inbounds i8*, i8** %57, i64 1
%59 = load i8*, i8** %58
%60 = call i32 @snprintf(i8* %56, i32 256, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8* %59, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%61 = getelementptr inbounds [256 x i8], [256 x i8]* %13, i64 0, i64 0
%62 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%63 = call i32 @snprintf(i8* %61, i32 256, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8* %62, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
%64 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%65 = call i32 @create_file(i8* %64)
store i32 %65, i32* %9
%66 = load i32, i32* %9
%67 = icmp eq i32 %66, -1
br i1 %67, label %68, label %69
68: ; preds = %55
store i32 -1, i32* %3
br label %165
69: ; preds = %55
%70 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%71 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.7, i64 0, i64 0), i8* %70)
%72 = getelementptr inbounds [256 x i8], [256 x i8]* %13, i64 0, i64 0
%73 = call i32 @create_file(i8* %72)
store i32 %73, i32* %10
%74 = load i32, i32* %10
%75 = icmp eq i32 %74, -1
br i1 %75, label %76, label %77
76: ; preds = %69
br label %162
77: ; preds = %69
%78 = getelementptr inbounds [256 x i8], [256 x i8]* %13, i64 0, i64 0
%79 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.8, i64 0, i64 0), i8* %78)
%80 = load i32, i32* %8
%81 = load i32, i32* %9
%82 = load i32, i32* %10
%83 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%84 = load i32, i32* %83
%85 = call i32 @odirure(i32 %80, i32 %81, i32 %82, i32 %84)
store i32 %85, i32* %11
%86 = load i32, i32* %11
%87 = icmp eq i32 %86, -1
br i1 %87, label %88, label %91
88: ; preds = %77
%89 = load i32, i32* @stderr
%90 = call i32 (i32, i8*, ...) @fprintf(i32 %89, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.9, i64 0, i64 0))
br label %159
91: ; preds = %77
br label %152
92: ; preds = %49
%93 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%94 = load i8**, i8*** %5
%95 = getelementptr inbounds i8*, i8** %94, i64 1
%96 = load i8*, i8** %95
%97 = call i32 @snprintf(i8* %93, i32 256, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8* %96, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.10, i64 0, i64 0))
%98 = getelementptr inbounds [256 x i8], [256 x i8]* %13, i64 0, i64 0
%99 = load i8**, i8*** %5
%100 = getelementptr inbounds i8*, i8** %99, i64 1
%101 = load i8*, i8** %100
%102 = call i32 @snprintf(i8* %98, i32 256, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8* %101, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
%103 = getelementptr inbounds [256 x i8], [256 x i8]* %13, i64 0, i64 0
%104 = load i32, i32* @O_RDONLY
%105 = call i32 @open(i8* %103, i32 %104)
store i32 %105, i32* %10
%106 = load i32, i32* %10
%107 = icmp eq i32 %106, -1
br i1 %107, label %108, label %114
108: ; preds = %92
%109 = load i32, i32* @stderr
%110 = getelementptr inbounds [256 x i8], [256 x i8]* %13, i64 0, i64 0
%111 = load i32, i32* @errno
%112 = call i8* @strerror(i32 %111)
%113 = call i32 (i32, i8*, ...) @fprintf(i32 %109, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.11, i64 0, i64 0), i8* %110, i8* %112)
store i32 -1, i32* %3
br label %165
114: ; preds = %92
%115 = getelementptr inbounds [256 x i8], [256 x i8]* %13, i64 0, i64 0
%116 = call i32 @stat(i8* %115, %struct.stat* %7)
store i32 %116, i32* %11
%117 = load i32, i32* %11
%118 = icmp eq i32 %117, -1
br i1 %118, label %119, label %121
119: ; preds = %114
%120 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %3
br label %165
121: ; preds = %114
%122 = load i32, i32* %10
%123 = load i32, i32* @SEEK_SET
%124 = call i32 @lseek(i32 %122, i32 0, i32 %123)
store i32 %124, i32* %11
%125 = load i32, i32* %11
%126 = icmp eq i32 %125, -1
br i1 %126, label %127, label %129
127: ; preds = %121
%128 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %3
br label %165
129: ; preds = %121
%130 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%131 = call i32 @create_file(i8* %130)
store i32 %131, i32* %9
%132 = load i32, i32* %9
%133 = icmp eq i32 %132, -1
br i1 %133, label %134, label %135
134: ; preds = %129
store i32 -1, i32* %3
br label %165
135: ; preds = %129
%136 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%137 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.12, i64 0, i64 0), i8* %136)
%138 = load i32, i32* %8
%139 = load i32, i32* %9
%140 = load i32, i32* %10
%141 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%142 = load i32, i32* %141
%143 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 0
%144 = load i32, i32* %143
%145 = call i32 @reveal(i32 %138, i32 %139, i32 %140, i32 %142, i32 %144)
store i32 %145, i32* %11
%146 = load i32, i32* %11
%147 = icmp eq i32 %146, -1
br i1 %147, label %148, label %151
148: ; preds = %135
%149 = load i32, i32* @stderr
%150 = call i32 (i32, i8*, ...) @fprintf(i32 %149, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.13, i64 0, i64 0))
br label %162
151: ; preds = %135
br label %152
152: ; preds = %151, %91
%153 = load i32, i32* %8
%154 = call i32 @close(i32 %153)
%155 = load i32, i32* %9
%156 = call i32 @close(i32 %155)
%157 = load i32, i32* %10
%158 = call i32 @close(i32 %157)
store i32 0, i32* %3
br label %165
159: ; preds = %88
%160 = getelementptr inbounds [256 x i8], [256 x i8]* %13, i64 0, i64 0
%161 = call i32 @unlink(i8* %160)
br label %162
162: ; preds = %159, %148, %76
%163 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%164 = call i32 @unlink(i8* %163)
store i32 -1, i32* %3
br label %165
165: ; preds = %162, %152, %134, %127, %119, %108, %68, %47, %39, %30, %16
%166 = load i32, i32* %3
ret i32 %166
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@stderr = global i32 0
@.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"stat\00"
@SEEK_SET = global i32 0
@.str.3 = [6 x i8] c"lseek\00"
@.str.4 = [4 x i8] c".bh\00"
@.str.5 = [5 x i8] c"%s%s\00"
@.str.6 = [5 x i8] c".map\00"
@.str.7 = [32 x i8] c"Generating odirure file: %s...\0A\00"
@.str.8 = [28 x i8] c"Generating map file: %s...\0A\00"
@.str.9 = [17 x i8] c"odirure failed!\0A\00"
@.str.10 = [5 x i8] c".out\00"
@.str.11 = [14 x i8] c"open: %s: %s\0A\00"
@errno = global i32 0
@.str.12 = [31 x i8] c"Generating output file: %s...\0A\00"
@.str.13 = [16 x i8] c"reveal failed!\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.stat
%4 = alloca %struct.stat
%5 = alloca [256 x i8]
%6 = alloca [256 x i8]
%7 = bitcast %struct.stat* %3 to i8*
%8 = bitcast %struct.stat* %4 to i8*
%9 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%10 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%11 = icmp eq i32 %0, 2
br i1 %11, label %16, label %12
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = load i8*, i8** %1
%15 = tail call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %14)
br label %105
16: ; preds = %2
%17 = getelementptr inbounds i8*, i8** %1, i64 1
%18 = load i8*, i8** %17
%19 = load i32, i32* @O_RDONLY
%20 = tail call i32 @open(i8* %18, i32 %19)
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %16
%23 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %105
24: ; preds = %16
%25 = load i8*, i8** %17
%26 = call i32 @stat(i8* %25, %struct.stat* %3)
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %30
28: ; preds = %24
%29 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %105
30: ; preds = %24
%31 = load i32, i32* @SEEK_SET
%32 = tail call i32 @lseek(i32 %20, i32 0, i32 %31)
%33 = icmp eq i32 %32, -1
br i1 %33, label %34, label %36
34: ; preds = %30
%35 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
br label %105
36: ; preds = %30
%37 = load i8*, i8** %17
%38 = tail call i32 @strstr(i8* %37, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%39 = icmp eq i32 %38, 0
%40 = load i8*, i8** %17
br i1 %39, label %41, label %60
41: ; preds = %36
%42 = call i32 @snprintf(i8* %9, i32 256, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8* %40, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%43 = call i32 @snprintf(i8* %10, i32 256, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8* %9, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
%44 = call i32 @create_file(i8* %9)
%45 = icmp eq i32 %44, -1
br i1 %45, label %105, label %46
46: ; preds = %41
%47 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.7, i64 0, i64 0), i8* %9)
%48 = call i32 @create_file(i8* %10)
%49 = icmp eq i32 %48, -1
br i1 %49, label %103, label %50
50: ; preds = %46
%51 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.8, i64 0, i64 0), i8* %10)
%52 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%53 = load i32, i32* %52
%54 = call i32 @odirure(i32 %20, i32 %44, i32 %48, i32 %53)
%55 = icmp eq i32 %54, -1
br i1 %55, label %56, label %97
56: ; preds = %50
%57 = load i32, i32* @stderr
%58 = call i32 (i32, i8*, ...) @fprintf(i32 %57, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.9, i64 0, i64 0))
%59 = call i32 @unlink(i8* %10)
br label %103
60: ; preds = %36
%61 = call i32 @snprintf(i8* %9, i32 256, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8* %40, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.10, i64 0, i64 0))
%62 = load i8*, i8** %17
%63 = call i32 @snprintf(i8* %10, i32 256, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8* %62, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
%64 = load i32, i32* @O_RDONLY
%65 = call i32 @open(i8* %10, i32 %64)
%66 = icmp eq i32 %65, -1
br i1 %66, label %67, label %72
67: ; preds = %60
%68 = load i32, i32* @stderr
%69 = load i32, i32* @errno
%70 = call i8* @strerror(i32 %69)
%71 = call i32 (i32, i8*, ...) @fprintf(i32 %68, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.11, i64 0, i64 0), i8* %10, i8* %70)
br label %105
72: ; preds = %60
%73 = call i32 @stat(i8* %10, %struct.stat* %4)
%74 = icmp eq i32 %73, -1
br i1 %74, label %75, label %77
75: ; preds = %72
%76 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %105
77: ; preds = %72
%78 = load i32, i32* @SEEK_SET
%79 = call i32 @lseek(i32 %65, i32 0, i32 %78)
%80 = icmp eq i32 %79, -1
br i1 %80, label %81, label %83
81: ; preds = %77
%82 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
br label %105
83: ; preds = %77
%84 = call i32 @create_file(i8* %9)
%85 = icmp eq i32 %84, -1
br i1 %85, label %105, label %86
86: ; preds = %83
%87 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.12, i64 0, i64 0), i8* %9)
%88 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%89 = load i32, i32* %88
%90 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
%91 = load i32, i32* %90
%92 = call i32 @reveal(i32 %20, i32 %84, i32 %65, i32 %89, i32 %91)
%93 = icmp eq i32 %92, -1
br i1 %93, label %94, label %97
94: ; preds = %86
%95 = load i32, i32* @stderr
%96 = call i32 (i32, i8*, ...) @fprintf(i32 %95, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.13, i64 0, i64 0))
br label %103
97: ; preds = %86, %50
%98 = phi i32 [ %84, %86 ], [ %44, %50 ]
%99 = phi i32 [ %65, %86 ], [ %48, %50 ]
%100 = call i32 @close(i32 %20)
%101 = call i32 @close(i32 %98)
%102 = call i32 @close(i32 %99)
br label %105
103: ; preds = %46, %56, %94
%104 = call i32 @unlink(i8* %9)
br label %105
105: ; preds = %83, %41, %103, %97, %81, %75, %67, %34, %28, %22, %12
%106 = phi i32 [ -1, %12 ], [ -1, %28 ], [ -1, %34 ], [ -1, %67 ], [ -1, %75 ], [ -1, %81 ], [ -1, %103 ], [ 0, %97 ], [ -1, %22 ], [ -1, %41 ], [ -1, %83 ]
ret i32 %106
}