#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 /*<<< orphan*/ errno;
int /*<<< orphan*/ *fopen(char const *, char *);
int print_absolute_relocs(int /*<<< orphan*/);
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 /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
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;
  const char *fname;
  FILE *fp;
  int i;
  int err = 0;
  show_absolute_syms = 0;
  show_absolute_relocs = 0;
  as_text = 0;
  fname = NULL;
  for (i = 1; i < argc; i++) {
    char *arg = argv[i];
    if (*arg == '-') {
      if (strcmp(argv[1], "--abs-syms") == 0) {
        show_absolute_syms = 1;
        continue;
      }
      if (strcmp(argv[1], "--abs-relocs") == 0) {
        show_absolute_relocs = 1;
        continue;
      } else if (strcmp(argv[1], "--text") == 0) {
        as_text = 1;
        continue;
      }
    } else if (!fname) {
      fname = arg;
      continue;
    }
    usage();
  }
  if (!fname) {
    usage();
  }
  regex_init();
  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(stdout);
    return 0;
  }
  err = print_absolute_relocs(stderr);
  emit_relocs(as_text);
  return err;
}


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,-0x38(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movq   $0x0,-0x28(%rbp)
movl   $0x1,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1307 <main+0x127>
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    12d5 <main+0xf5>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xda4(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    1277 <main+0x97>
movl   $0x1,-0x14(%rbp)
jmp    12f9 <main+0x119>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xd85(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    12a1 <main+0xc1>
movl   $0x1,-0x18(%rbp)
jmp    12f9 <main+0x119>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xd68(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    12cb <main+0xeb>
movl   $0x1,-0x1c(%rbp)
jmp    12f9 <main+0x119>
jmp    12d0 <main+0xf0>
jmp    12f2 <main+0x112>
cmpq   $0x0,-0x28(%rbp)
jne    12ed <main+0x10d>
mov    -0x40(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    12f9 <main+0x119>
jmp    12f2 <main+0x112>
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    1319 <main+0x139>
mov    $0x0,%al
call   10c0 <usage@plt>
mov    $0x0,%al
call   10d0 <regex_init@plt>
mov    -0x28(%rbp),%rdi
lea    0xcf4(%rip),%rsi
call   10e0 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1367 <main+0x187>
mov    -0x28(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    0x2c8a(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
mov    -0x48(%rbp),%rsi
mov    %eax,%edx
lea    0xcbf(%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     13b1 <main+0x1d1>
mov    $0x0,%al
call   1040 <print_absolute_symbols@plt>
movl   $0x0,-0x4(%rbp)
jmp    13f4 <main+0x214>
cmpl   $0x0,-0x18(%rbp)
je     13d5 <main+0x1f5>
mov    0x2c0e(%rip),%rax
mov    (%rax),%edi
call   1080 <print_absolute_relocs@plt>
movl   $0x0,-0x4(%rbp)
jmp    13f4 <main+0x214>
mov    0x2c04(%rip),%rax
mov    (%rax),%edi
call   1080 <print_absolute_relocs@plt>
mov    %eax,-0x38(%rbp)
mov    -0x1c(%rbp),%edi
call   10b0 <emit_relocs@plt>
mov    -0x38(%rbp),%eax
mov    %eax,-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
push   %rax
xor    %r14d,%r14d
mov    $0x0,%r15d
mov    $0x0,%r12d
cmp    $0x2,%edi
jl     12b8 <main+0xd8>
mov    %rsi,%rbp
mov    %edi,%r13d
mov    $0x1,%r12d
lea    0xdea(%rip),%r15
xor    %r14d,%r14d
xor    %ebx,%ebx
movl   $0x0,(%rsp)
movl   $0x0,0x4(%rsp)
jmp    1245 <main+0x65>
nopl   0x0(%rax)
test   %rbx,%rbx
je     1293 <main+0xb3>
xor    %eax,%eax
call   10c0 <usage@plt>
add    $0x1,%r12
cmp    %r12,%r13
je     12aa <main+0xca>
mov    0x0(%rbp,%r12,8),%rax
cmpb   $0x2d,(%rax)
jne    1230 <main+0x50>
mov    0x8(%rbp),%rdi
mov    %r15,%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     1298 <main+0xb8>
mov    0x8(%rbp),%rdi
lea    0xda0(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     12a0 <main+0xc0>
mov    0x8(%rbp),%rdi
lea    0xd98(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
jne    1235 <main+0x55>
movl   $0x1,(%rsp)
jmp    123c <main+0x5c>
mov    %rax,%rbx
jmp    123c <main+0x5c>
mov    $0x1,%r14d
jmp    123c <main+0x5c>
movl   $0x1,0x4(%rsp)
jmp    123c <main+0x5c>
test   %rbx,%rbx
mov    (%rsp),%r15d
mov    0x4(%rsp),%r12d
jne    12c1 <main+0xe1>
xor    %ebx,%ebx
xor    %eax,%eax
call   10c0 <usage@plt>
xor    %eax,%eax
call   10d0 <regex_init@plt>
lea    0xd50(%rip),%rsi
mov    %rbx,%rdi
call   10e0 <fopen@plt>
mov    %rax,%rbp
test   %rax,%rax
jne    12fe <main+0x11e>
mov    0x2cf2(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
lea    0xd2d(%rip),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   10f0 <die@plt>
mov    %rbp,%rdi
call   1060 <read_ehdr@plt>
mov    %rbp,%rdi
call   1050 <read_shdrs@plt>
mov    %rbp,%rdi
call   10a0 <read_strtabs@plt>
mov    %rbp,%rdi
call   1090 <read_symtabs@plt>
mov    %rbp,%rdi
call   1030 <read_relocs@plt>
test   %r14d,%r14d
je     1334 <main+0x154>
xor    %eax,%eax
call   1040 <print_absolute_symbols@plt>
jmp    1347 <main+0x167>
test   %r12d,%r12d
je     1358 <main+0x178>
mov    0x2c90(%rip),%rax
mov    (%rax),%edi
call   1080 <print_absolute_relocs@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2c81(%rip),%rax
mov    (%rax),%edi
call   1080 <print_absolute_relocs@plt>
mov    %eax,%ebx
mov    %r15d,%edi
call   10b0 <emit_relocs@plt>
mov    %ebx,%eax
jmp    1349 <main+0x169>

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

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