#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*/ die(char *, char const *, int /*<<< orphan*/);
int /*<<< orphan*/ emit_relocs(int, int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ print_absolute_relocs();
int /*<<< orphan*/ print_absolute_symbols();
int /*<<< orphan*/ read_ehdr(int /*<<< orphan*/ *);
int /*<<< orphan*/ read_relocs(int /*<<< orphan*/ *);
int /*<<< orphan*/ read_shdrs(int /*<<< orphan*/ *);
int /*<<< orphan*/ read_strtabs(int /*<<< orphan*/ *);
int /*<<< orphan*/ read_symtabs(int /*<<< orphan*/ *);
int /*<<< orphan*/ regex_init(int);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int /*<<< orphan*/ usage();
int main(int argc, char **argv) {
  int show_absolute_syms, show_absolute_relocs;
  int as_text, use_real_mode;
  const char *fname;
  FILE *fp;
  int i;
  show_absolute_syms = 0;
  show_absolute_relocs = 0;
  as_text = 0;
  use_real_mode = 0;
  fname = NULL;
  for (i = 1; i < argc; i++) {
    char *arg = argv[i];
    if (*arg == '-') {
      if (strcmp(arg, "--abs-syms") == 0) {
        show_absolute_syms = 1;
        continue;
      }
      if (strcmp(arg, "--abs-relocs") == 0) {
        show_absolute_relocs = 1;
        continue;
      }
      if (strcmp(arg, "--text") == 0) {
        as_text = 1;
        continue;
      }
      if (strcmp(arg, "--realmode") == 0) {
        use_real_mode = 1;
        continue;
      }
    } else if (!fname) {
      fname = arg;
      continue;
    }
    usage();
  }
  if (!fname) {
    usage();
  }
  regex_init(use_real_mode);
  fp = fopen(fname, "r");
  if (!fp) {
    die("Cannot open %s: %s\n", fname, strerror(errno));
  }
  read_ehdr(fp);
  read_shdrs(fp);
  read_strtabs(fp);
  read_symtabs(fp);
  read_relocs(fp);
  if (show_absolute_syms) {
    print_absolute_symbols();
    return 0;
  }
  if (show_absolute_relocs) {
    print_absolute_relocs();
    return 0;
  }
  emit_relocs(as_text, use_real_mode);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movl   $0x1,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    131c <main+0x13c>
mov    -0x10(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
jne    12ea <main+0x10a>
mov    -0x40(%rbp),%rdi
lea    0xda8(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    1273 <main+0x93>
movl   $0x1,-0x14(%rbp)
jmp    130e <main+0x12e>
mov    -0x40(%rbp),%rdi
lea    0xd8d(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    1299 <main+0xb9>
movl   $0x1,-0x18(%rbp)
jmp    130e <main+0x12e>
mov    -0x40(%rbp),%rdi
lea    0xd74(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    12bf <main+0xdf>
movl   $0x1,-0x1c(%rbp)
jmp    130e <main+0x12e>
mov    -0x40(%rbp),%rdi
lea    0xd55(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    12e5 <main+0x105>
movl   $0x1,-0x20(%rbp)
jmp    130e <main+0x12e>
jmp    1307 <main+0x127>
cmpq   $0x0,-0x28(%rbp)
jne    1302 <main+0x122>
mov    -0x40(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    130e <main+0x12e>
jmp    1307 <main+0x127>
mov    $0x0,%al
call   10c0 <usage@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1221 <main+0x41>
cmpq   $0x0,-0x28(%rbp)
jne    132e <main+0x14e>
mov    $0x0,%al
call   10c0 <usage@plt>
mov    -0x20(%rbp),%edi
call   10d0 <regex_init@plt>
mov    -0x28(%rbp),%rdi
lea    0xce9(%rip),%rsi
call   10e0 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    137d <main+0x19d>
mov    -0x28(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    0x2c7c(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
mov    -0x48(%rbp),%rsi
mov    %eax,%edx
lea    0xcb4(%rip),%rdi
call   10f0 <die@plt>
mov    -0x30(%rbp),%rdi
call   1060 <read_ehdr@plt>
mov    -0x30(%rbp),%rdi
call   1050 <read_shdrs@plt>
mov    -0x30(%rbp),%rdi
call   10a0 <read_strtabs@plt>
mov    -0x30(%rbp),%rdi
call   1090 <read_symtabs@plt>
mov    -0x30(%rbp),%rdi
call   1030 <read_relocs@plt>
cmpl   $0x0,-0x14(%rbp)
je     13c7 <main+0x1e7>
mov    $0x0,%al
call   1040 <print_absolute_symbols@plt>
movl   $0x0,-0x4(%rbp)
jmp    13f6 <main+0x216>
cmpl   $0x0,-0x18(%rbp)
je     13e4 <main+0x204>
mov    $0x0,%al
call   1080 <print_absolute_relocs@plt>
movl   $0x0,-0x4(%rbp)
jmp    13f6 <main+0x216>
mov    -0x1c(%rbp),%edi
mov    -0x20(%rbp),%esi
call   10b0 <emit_relocs@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
xor    %ebp,%ebp
mov    $0x0,%r12d
mov    $0x0,%r15d
mov    $0x0,%r13d
cmp    $0x2,%edi
jl     130a <main+0x12a>
mov    %rsi,%rbx
mov    %edi,%r13d
mov    $0x1,%r15d
lea    0xde2(%rip),%r12
movl   $0x0,0x14(%rsp)
xor    %r14d,%r14d
movl   $0x0,0x8(%rsp)
movl   $0x0,0xc(%rsp)
movl   $0x0,0x10(%rsp)
jmp    1269 <main+0x89>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
test   %r14,%r14
je     12c9 <main+0xe9>
xor    %eax,%eax
call   10c0 <usage@plt>
add    $0x1,%r15
cmp    %r15,%r13
je     12f2 <main+0x112>
mov    (%rbx,%r15,8),%rbp
cmpb   $0x2d,0x0(%rbp)
jne    1250 <main+0x70>
mov    %rbp,%rdi
mov    %r12,%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     12ce <main+0xee>
mov    %rbp,%rdi
lea    0xd7e(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     12d8 <main+0xf8>
mov    %rbp,%rdi
lea    0xd77(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     12e5 <main+0x105>
mov    %rbp,%rdi
lea    0xd6a(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
jne    1255 <main+0x75>
movl   $0x1,0x8(%rsp)
jmp    125c <main+0x7c>
mov    %rbp,%r14
jmp    125c <main+0x7c>
movl   $0x1,0x14(%rsp)
jmp    125c <main+0x7c>
movl   $0x1,0x10(%rsp)
jmp    125c <main+0x7c>
movl   $0x1,0xc(%rsp)
jmp    125c <main+0x7c>
test   %r14,%r14
mov    0x8(%rsp),%r12d
mov    0xc(%rsp),%r15d
mov    0x14(%rsp),%ebp
mov    0x10(%rsp),%r13d
jne    1314 <main+0x134>
xor    %r14d,%r14d
xor    %eax,%eax
call   10c0 <usage@plt>
mov    %r12d,%edi
call   10d0 <regex_init@plt>
lea    0xd07(%rip),%rsi
mov    %r14,%rdi
call   10e0 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1352 <main+0x172>
mov    0x2ca6(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
lea    0xce4(%rip),%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   10f0 <die@plt>
mov    %rbx,%rdi
call   1060 <read_ehdr@plt>
mov    %rbx,%rdi
call   1050 <read_shdrs@plt>
mov    %rbx,%rdi
call   10a0 <read_strtabs@plt>
mov    %rbx,%rdi
call   1090 <read_symtabs@plt>
mov    %rbx,%rdi
call   1030 <read_relocs@plt>
test   %ebp,%ebp
je     1387 <main+0x1a7>
xor    %eax,%eax
call   1040 <print_absolute_symbols@plt>
jmp    13a0 <main+0x1c0>
test   %r13d,%r13d
je     1395 <main+0x1b5>
xor    %eax,%eax
call   1080 <print_absolute_relocs@plt>
jmp    13a0 <main+0x1c0>
mov    %r15d,%edi
mov    %r12d,%esi
call   10b0 <emit_relocs@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"--abs-syms\00"
@.str.1 = [13 x i8] c"--abs-relocs\00"
@.str.2 = [7 x i8] c"--text\00"
@.str.3 = [11 x i8] c"--realmode\00"
@.str.4 = [2 x i8] c"r\00"
@.str.5 = [20 x i8] c"Cannot open %s: %s\0A\00"
@errno = global i32 0
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
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i32*
%12 = alloca i32
%13 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
store i32 0, i32* %7
store i32 0, i32* %8
store i32 0, i32* %9
store i8* null, i8** %10
store i32 1, i32* %12
br label %14
14: ; preds = %57, %2
%15 = load i32, i32* %12
%16 = load i32, i32* %4
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %60
18: ; preds = %14
%19 = load i8**, i8*** %5
%20 = load i32, i32* %12
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8*, i8** %19, i64 %21
%23 = load i8*, i8** %22
store i8* %23, i8** %13
%24 = load i8*, i8** %13
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp eq i32 %26, 45
br i1 %27, label %28, label %49
28: ; preds = %18
%29 = load i8*, i8** %13
%30 = call i64 @strcmp(i8* %29, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %33
32: ; preds = %28
store i32 1, i32* %6
br label %57
33: ; preds = %28
%34 = load i8*, i8** %13
%35 = call i64 @strcmp(i8* %34, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%36 = icmp eq i64 %35, 0
br i1 %36, label %37, label %38
37: ; preds = %33
store i32 1, i32* %7
br label %57
38: ; preds = %33
%39 = load i8*, i8** %13
%40 = call i64 @strcmp(i8* %39, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%41 = icmp eq i64 %40, 0
br i1 %41, label %42, label %43
42: ; preds = %38
store i32 1, i32* %8
br label %57
43: ; preds = %38
%44 = load i8*, i8** %13
%45 = call i64 @strcmp(i8* %44, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
%46 = icmp eq i64 %45, 0
br i1 %46, label %47, label %48
47: ; preds = %43
store i32 1, i32* %9
br label %57
48: ; preds = %43
br label %55
49: ; preds = %18
%50 = load i8*, i8** %10
%51 = icmp ne i8* %50, null
br i1 %51, label %54, label %52
52: ; preds = %49
%53 = load i8*, i8** %13
store i8* %53, i8** %10
br label %57
54: ; preds = %49
br label %55
55: ; preds = %54, %48
%56 = call i32 (...) @usage()
br label %57
57: ; preds = %55, %52, %47, %42, %37, %32
%58 = load i32, i32* %12
%59 = add nsw i32 %58, 1
store i32 %59, i32* %12
br label %14
60: ; preds = %14
%61 = load i8*, i8** %10
%62 = icmp ne i8* %61, null
br i1 %62, label %65, label %63
63: ; preds = %60
%64 = call i32 (...) @usage()
br label %65
65: ; preds = %63, %60
%66 = load i32, i32* %9
%67 = call i32 @regex_init(i32 %66)
%68 = load i8*, i8** %10
%69 = call i32* @fopen(i8* %68, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %69, i32** %11
%70 = load i32*, i32** %11
%71 = icmp ne i32* %70, null
br i1 %71, label %77, label %72
72: ; preds = %65
%73 = load i8*, i8** %10
%74 = load i32, i32* @errno
%75 = call i32 @strerror(i32 %74)
%76 = call i32 @die(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0), i8* %73, i32 %75)
br label %77
77: ; preds = %72, %65
%78 = load i32*, i32** %11
%79 = call i32 @read_ehdr(i32* %78)
%80 = load i32*, i32** %11
%81 = call i32 @read_shdrs(i32* %80)
%82 = load i32*, i32** %11
%83 = call i32 @read_strtabs(i32* %82)
%84 = load i32*, i32** %11
%85 = call i32 @read_symtabs(i32* %84)
%86 = load i32*, i32** %11
%87 = call i32 @read_relocs(i32* %86)
%88 = load i32, i32* %6
%89 = icmp ne i32 %88, 0
br i1 %89, label %90, label %92
90: ; preds = %77
%91 = call i32 (...) @print_absolute_symbols()
store i32 0, i32* %3
br label %101
92: ; preds = %77
%93 = load i32, i32* %7
%94 = icmp ne i32 %93, 0
br i1 %94, label %95, label %97
95: ; preds = %92
%96 = call i32 (...) @print_absolute_relocs()
store i32 0, i32* %3
br label %101
97: ; preds = %92
%98 = load i32, i32* %8
%99 = load i32, i32* %9
%100 = call i32 @emit_relocs(i32 %98, i32 %99)
store i32 0, i32* %3
br label %101
101: ; preds = %97, %95, %90
%102 = load i32, i32* %3
ret i32 %102
}

LLVM IR (-O2):
@.str = [11 x i8] c"--abs-syms\00"
@.str.1 = [13 x i8] c"--abs-relocs\00"
@.str.2 = [7 x i8] c"--text\00"
@.str.3 = [11 x i8] c"--realmode\00"
@.str.4 = [2 x i8] c"r\00"
@.str.5 = [20 x i8] c"Cannot open %s: %s\0A\00"
@errno = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp sgt i32 %0, 1
br i1 %3, label %4, label %43
4: ; preds = %2
%5 = zext i32 %0 to i64
br label %6
6: ; preds = %4, %33
%7 = phi i64 [ 1, %4 ], [ %39, %33 ]
%8 = phi i32 [ 0, %4 ], [ %38, %33 ]
%9 = phi i8* [ null, %4 ], [ %37, %33 ]
%10 = phi i32 [ 0, %4 ], [ %36, %33 ]
%11 = phi i32 [ 0, %4 ], [ %35, %33 ]
%12 = phi i32 [ 0, %4 ], [ %34, %33 ]
%13 = getelementptr inbounds i8*, i8** %1, i64 %7
%14 = load i8*, i8** %13
%15 = load i8, i8* %14
%16 = icmp eq i8 %15, 45
br i1 %16, label %17, label %29
17: ; preds = %6
%18 = tail call i64 @strcmp(i8* %14, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%19 = icmp eq i64 %18, 0
br i1 %19, label %33, label %20
20: ; preds = %17
%21 = tail call i64 @strcmp(i8* %14, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%22 = icmp eq i64 %21, 0
br i1 %22, label %33, label %23
23: ; preds = %20
%24 = tail call i64 @strcmp(i8* %14, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%25 = icmp eq i64 %24, 0
br i1 %25, label %33, label %26
26: ; preds = %23
%27 = tail call i64 @strcmp(i8* %14, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
%28 = icmp eq i64 %27, 0
br i1 %28, label %33, label %31
29: ; preds = %6
%30 = icmp eq i8* %9, null
br i1 %30, label %33, label %31
31: ; preds = %29, %26
%32 = tail call i32 (...) @usage()
br label %33
33: ; preds = %29, %26, %23, %20, %17, %31
%34 = phi i32 [ %12, %31 ], [ %12, %17 ], [ 1, %20 ], [ %12, %23 ], [ %12, %26 ], [ %12, %29 ]
%35 = phi i32 [ %11, %31 ], [ %11, %17 ], [ %11, %20 ], [ 1, %23 ], [ %11, %26 ], [ %11, %29 ]
%36 = phi i32 [ %10, %31 ], [ %10, %17 ], [ %10, %20 ], [ %10, %23 ], [ 1, %26 ], [ %10, %29 ]
%37 = phi i8* [ %9, %31 ], [ %9, %17 ], [ %9, %20 ], [ %9, %23 ], [ %9, %26 ], [ %14, %29 ]
%38 = phi i32 [ %8, %31 ], [ 1, %17 ], [ %8, %20 ], [ %8, %23 ], [ %8, %26 ], [ %8, %29 ]
%39 = add nuw nsw i64 %7, 1
%40 = icmp eq i64 %39, %5
br i1 %40, label %41, label %6
41: ; preds = %33
%42 = icmp eq i8* %37, null
br i1 %42, label %43, label %49
43: ; preds = %2, %41
%44 = phi i32 [ %38, %41 ], [ 0, %2 ]
%45 = phi i32 [ %36, %41 ], [ 0, %2 ]
%46 = phi i32 [ %35, %41 ], [ 0, %2 ]
%47 = phi i32 [ %34, %41 ], [ 0, %2 ]
%48 = tail call i32 (...) @usage()
br label %49
49: ; preds = %43, %41
%50 = phi i32 [ %44, %43 ], [ %38, %41 ]
%51 = phi i8* [ null, %43 ], [ %37, %41 ]
%52 = phi i32 [ %45, %43 ], [ %36, %41 ]
%53 = phi i32 [ %46, %43 ], [ %35, %41 ]
%54 = phi i32 [ %47, %43 ], [ %34, %41 ]
%55 = tail call i32 @regex_init(i32 %52)
%56 = tail call i32* @fopen(i8* %51, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%57 = icmp eq i32* %56, null
br i1 %57, label %58, label %62
58: ; preds = %49
%59 = load i32, i32* @errno
%60 = tail call i32 @strerror(i32 %59)
%61 = tail call i32 @die(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0), i8* %51, i32 %60)
br label %62
62: ; preds = %58, %49
%63 = tail call i32 @read_ehdr(i32* %56)
%64 = tail call i32 @read_shdrs(i32* %56)
%65 = tail call i32 @read_strtabs(i32* %56)
%66 = tail call i32 @read_symtabs(i32* %56)
%67 = tail call i32 @read_relocs(i32* %56)
%68 = icmp eq i32 %50, 0
br i1 %68, label %71, label %69
69: ; preds = %62
%70 = tail call i32 (...) @print_absolute_symbols()
br label %77
71: ; preds = %62
%72 = icmp eq i32 %54, 0
br i1 %72, label %75, label %73
73: ; preds = %71
%74 = tail call i32 (...) @print_absolute_relocs()
br label %77
75: ; preds = %71
%76 = tail call i32 @emit_relocs(i32 %53, i32 %52)
br label %77
77: ; preds = %75, %73, %69
ret i32 0
}