#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 /*<<< 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();
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;
  regex_init();
  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();
  }
  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);
  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)
mov    $0x0,%al
call   10d0 <regex_init@plt>
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    -0x28(%rbp),%rdi
lea    0xcfb(%rip),%rsi
call   10e0 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1360 <main+0x180>
mov    -0x28(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    0x2c99(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
mov    -0x48(%rbp),%rsi
mov    %eax,%edx
lea    0xcc6(%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     13aa <main+0x1ca>
mov    $0x0,%al
call   1040 <print_absolute_symbols@plt>
movl   $0x0,-0x4(%rbp)
jmp    13d6 <main+0x1f6>
cmpl   $0x0,-0x18(%rbp)
je     13c7 <main+0x1e7>
mov    $0x0,%al
call   1080 <print_absolute_relocs@plt>
movl   $0x0,-0x4(%rbp)
jmp    13d6 <main+0x1f6>
mov    -0x1c(%rbp),%edi
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
push   %rax
mov    %rsi,%rbp
mov    %edi,%ebx
xor    %r14d,%r14d
xor    %eax,%eax
call   10d0 <regex_init@plt>
mov    $0x0,%r15d
mov    $0x0,%r12d
cmp    $0x2,%ebx
jl     12c8 <main+0xe8>
mov    %ebx,%r13d
mov    $0x1,%r12d
lea    0xde1(%rip),%r15
xor    %r14d,%r14d
xor    %ebx,%ebx
movl   $0x0,(%rsp)
movl   $0x0,0x4(%rsp)
jmp    1255 <main+0x75>
cs nopw 0x0(%rax,%rax,1)
nop
test   %rbx,%rbx
je     12a3 <main+0xc3>
xor    %eax,%eax
call   10c0 <usage@plt>
add    $0x1,%r12
cmp    %r12,%r13
je     12ba <main+0xda>
mov    0x0(%rbp,%r12,8),%rax
cmpb   $0x2d,(%rax)
jne    1240 <main+0x60>
mov    0x8(%rbp),%rdi
mov    %r15,%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     12a8 <main+0xc8>
mov    0x8(%rbp),%rdi
lea    0xd90(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     12b0 <main+0xd0>
mov    0x8(%rbp),%rdi
lea    0xd88(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
jne    1245 <main+0x65>
movl   $0x1,(%rsp)
jmp    124c <main+0x6c>
mov    %rax,%rbx
jmp    124c <main+0x6c>
mov    $0x1,%r14d
jmp    124c <main+0x6c>
movl   $0x1,0x4(%rsp)
jmp    124c <main+0x6c>
test   %rbx,%rbx
mov    (%rsp),%r15d
mov    0x4(%rsp),%r12d
jne    12d1 <main+0xf1>
xor    %ebx,%ebx
xor    %eax,%eax
call   10c0 <usage@plt>
lea    0xd47(%rip),%rsi
mov    %rbx,%rdi
call   10e0 <fopen@plt>
mov    %rax,%rbp
test   %rax,%rax
jne    1307 <main+0x127>
mov    0x2cf1(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
lea    0xd24(%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     133d <main+0x15d>
xor    %eax,%eax
call   1040 <print_absolute_symbols@plt>
jmp    1353 <main+0x173>
test   %r12d,%r12d
je     134b <main+0x16b>
xor    %eax,%eax
call   1080 <print_absolute_relocs@plt>
jmp    1353 <main+0x173>
mov    %r15d,%edi
call   10b0 <emit_relocs@plt>
xor    %eax,%eax
add    $0x8,%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 = [2 x i8] c"r\00"
@.str.4 = [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 i8*
%10 = alloca i32*
%11 = alloca i32
%12 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = call i32 (...) @regex_init()
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** %12
%24 = load i8*, i8** %12
%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** %12
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 = load i8*, i8** %9
%69 = call i32* @fopen(i8* %68, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %69, i32** %10
%70 = load i32*, i32** %10
%71 = icmp ne i32* %70, null
br i1 %71, label %77, label %72
72: ; preds = %67
%73 = load i8*, i8** %9
%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.4, i64 0, i64 0), i8* %73, i32 %75)
br label %77
77: ; preds = %72, %67
%78 = load i32*, i32** %10
%79 = call i32 @read_ehdr(i32* %78)
%80 = load i32*, i32** %10
%81 = call i32 @read_shdrs(i32* %80)
%82 = load i32*, i32** %10
%83 = call i32 @read_strtabs(i32* %82)
%84 = load i32*, i32** %10
%85 = call i32 @read_symtabs(i32* %84)
%86 = load i32*, i32** %10
%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 %100
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 %100
97: ; preds = %92
%98 = load i32, i32* %8
%99 = call i32 @emit_relocs(i32 %98)
store i32 0, i32* %3
br label %100
100: ; preds = %97, %95, %90
%101 = load i32, i32* %3
ret i32 %101
}

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
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = tail call i32 (...) @regex_init()
%4 = icmp sgt i32 %0, 1
br i1 %4, label %5, label %43
5: ; preds = %2
%6 = getelementptr inbounds i8*, i8** %1, i64 1
%7 = zext i32 %0 to i64
br label %8
8: ; preds = %5, %34
%9 = phi i64 [ 1, %5 ], [ %39, %34 ]
%10 = phi i32 [ 0, %5 ], [ %38, %34 ]
%11 = phi i8* [ null, %5 ], [ %37, %34 ]
%12 = phi i32 [ 0, %5 ], [ %36, %34 ]
%13 = phi i32 [ 0, %5 ], [ %35, %34 ]
%14 = getelementptr inbounds i8*, i8** %1, i64 %9
%15 = load i8*, i8** %14
%16 = load i8, i8* %15
%17 = icmp eq i8 %16, 45
br i1 %17, label %18, label %30
18: ; preds = %8
%19 = load i8*, i8** %6
%20 = tail call i64 @strcmp(i8* %19, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%21 = icmp eq i64 %20, 0
br i1 %21, label %34, label %22
22: ; preds = %18
%23 = load i8*, i8** %6
%24 = tail call i64 @strcmp(i8* %23, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%25 = icmp eq i64 %24, 0
br i1 %25, label %34, label %26
26: ; preds = %22
%27 = load i8*, i8** %6
%28 = tail call i64 @strcmp(i8* %27, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%29 = icmp eq i64 %28, 0
br i1 %29, label %34, label %32
30: ; preds = %8
%31 = icmp eq i8* %11, null
br i1 %31, label %34, label %32
32: ; preds = %30, %26
%33 = tail call i32 (...) @usage()
br label %34
34: ; preds = %30, %26, %22, %18, %32
%35 = phi i32 [ %13, %32 ], [ %13, %18 ], [ 1, %22 ], [ %13, %26 ], [ %13, %30 ]
%36 = phi i32 [ %12, %32 ], [ %12, %18 ], [ %12, %22 ], [ 1, %26 ], [ %12, %30 ]
%37 = phi i8* [ %11, %32 ], [ %11, %18 ], [ %11, %22 ], [ %11, %26 ], [ %15, %30 ]
%38 = phi i32 [ %10, %32 ], [ 1, %18 ], [ %10, %22 ], [ %10, %26 ], [ %10, %30 ]
%39 = add nuw nsw i64 %9, 1
%40 = icmp eq i64 %39, %7
br i1 %40, label %41, label %8
41: ; preds = %34
%42 = icmp eq i8* %37, null
br i1 %42, label %43, label %48
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 = tail call i32 (...) @usage()
br label %48
48: ; preds = %43, %41
%49 = phi i32 [ %44, %43 ], [ %38, %41 ]
%50 = phi i8* [ null, %43 ], [ %37, %41 ]
%51 = phi i32 [ %45, %43 ], [ %36, %41 ]
%52 = phi i32 [ %46, %43 ], [ %35, %41 ]
%53 = tail call i32* @fopen(i8* %50, 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 = %48
%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* %50, i32 %57)
br label %59
59: ; preds = %55, %48
%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 %49, 0
br i1 %65, label %68, label %66
66: ; preds = %59
%67 = tail call i32 (...) @print_absolute_symbols()
br label %74
68: ; preds = %59
%69 = icmp eq i32 %52, 0
br i1 %69, label %72, label %70
70: ; preds = %68
%71 = tail call i32 (...) @print_absolute_relocs()
br label %74
72: ; preds = %68
%73 = tail call i32 @emit_relocs(i32 %51)
br label %74
74: ; preds = %72, %70, %66
ret i32 0
}