#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*/ *);
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;
  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)
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    12f0 <main+0x120>
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    12be <main+0xee>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdbb(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    1260 <main+0x90>
movl   $0x1,-0x14(%rbp)
jmp    12e2 <main+0x112>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xd9c(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    128a <main+0xba>
movl   $0x1,-0x18(%rbp)
jmp    12e2 <main+0x112>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xd7f(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    12b4 <main+0xe4>
movl   $0x1,-0x1c(%rbp)
jmp    12e2 <main+0x112>
jmp    12b9 <main+0xe9>
jmp    12db <main+0x10b>
cmpq   $0x0,-0x28(%rbp)
jne    12d6 <main+0x106>
mov    -0x40(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    12e2 <main+0x112>
jmp    12db <main+0x10b>
mov    $0x0,%al
call   10c0 <usage@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    120a <main+0x3a>
cmpq   $0x0,-0x28(%rbp)
jne    1302 <main+0x132>
mov    $0x0,%al
call   10c0 <usage@plt>
mov    -0x28(%rbp),%rdi
lea    0xd12(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1349 <main+0x179>
mov    -0x28(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    0x2cb0(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
mov    -0x48(%rbp),%rsi
mov    %eax,%edx
lea    0xcdd(%rip),%rdi
call   10e0 <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     1393 <main+0x1c3>
mov    $0x0,%al
call   1040 <print_absolute_symbols@plt>
movl   $0x0,-0x4(%rbp)
jmp    13bf <main+0x1ef>
cmpl   $0x0,-0x18(%rbp)
je     13b0 <main+0x1e0>
mov    $0x0,%al
call   1080 <print_absolute_relocs@plt>
movl   $0x0,-0x4(%rbp)
jmp    13bf <main+0x1ef>
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
xor    %r14d,%r14d
mov    $0x0,%r15d
mov    $0x0,%r12d
cmp    $0x2,%edi
jl     12a8 <main+0xd8>
mov    %rsi,%rbp
mov    %edi,%r13d
mov    $0x1,%r12d
lea    0xdfa(%rip),%r15
xor    %r14d,%r14d
xor    %ebx,%ebx
movl   $0x0,(%rsp)
movl   $0x0,0x4(%rsp)
jmp    1235 <main+0x65>
nopl   0x0(%rax)
test   %rbx,%rbx
je     1283 <main+0xb3>
xor    %eax,%eax
call   10c0 <usage@plt>
add    $0x1,%r12
cmp    %r12,%r13
je     129a <main+0xca>
mov    0x0(%rbp,%r12,8),%rax
cmpb   $0x2d,(%rax)
jne    1220 <main+0x50>
mov    0x8(%rbp),%rdi
mov    %r15,%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     1288 <main+0xb8>
mov    0x8(%rbp),%rdi
lea    0xdb0(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     1290 <main+0xc0>
mov    0x8(%rbp),%rdi
lea    0xda8(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
jne    1225 <main+0x55>
movl   $0x1,(%rsp)
jmp    122c <main+0x5c>
mov    %rax,%rbx
jmp    122c <main+0x5c>
mov    $0x1,%r14d
jmp    122c <main+0x5c>
movl   $0x1,0x4(%rsp)
jmp    122c <main+0x5c>
test   %rbx,%rbx
mov    (%rsp),%r15d
mov    0x4(%rsp),%r12d
jne    12b1 <main+0xe1>
xor    %ebx,%ebx
xor    %eax,%eax
call   10c0 <usage@plt>
lea    0xd67(%rip),%rsi
mov    %rbx,%rdi
call   10d0 <fopen@plt>
mov    %rax,%rbp
test   %rax,%rax
jne    12e7 <main+0x117>
mov    0x2d11(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
lea    0xd44(%rip),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   10e0 <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     131d <main+0x14d>
xor    %eax,%eax
call   1040 <print_absolute_symbols@plt>
jmp    1333 <main+0x163>
test   %r12d,%r12d
je     132b <main+0x15b>
xor    %eax,%eax
call   1080 <print_absolute_relocs@plt>
jmp    1333 <main+0x163>
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
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 %13
13: ; preds = %58, %2
%14 = load i32, i32* %11
%15 = load i32, i32* %4
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %61
17: ; preds = %13
%18 = load i8**, i8*** %5
%19 = load i32, i32* %11
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8*, i8** %18, i64 %20
%22 = load i8*, i8** %21
store i8* %22, i8** %12
%23 = load i8*, i8** %12
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp eq i32 %25, 45
br i1 %26, label %27, label %50
27: ; preds = %17
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 1
%30 = load i8*, i8** %29
%31 = call i64 @strcmp(i8* %30, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %34
33: ; preds = %27
store i32 1, i32* %6
br label %58
34: ; preds = %27
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 1
%37 = load i8*, i8** %36
%38 = call i64 @strcmp(i8* %37, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%39 = icmp eq i64 %38, 0
br i1 %39, label %40, label %41
40: ; preds = %34
store i32 1, i32* %7
br label %58
41: ; preds = %34
%42 = load i8**, i8*** %5
%43 = getelementptr inbounds i8*, i8** %42, i64 1
%44 = load i8*, i8** %43
%45 = call i64 @strcmp(i8* %44, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%46 = icmp eq i64 %45, 0
br i1 %46, label %47, label %48
47: ; preds = %41
store i32 1, i32* %8
br label %58
48: ; preds = %41
br label %49
49: ; preds = %48
br label %56
50: ; preds = %17
%51 = load i8*, i8** %9
%52 = icmp ne i8* %51, null
br i1 %52, label %55, label %53
53: ; preds = %50
%54 = load i8*, i8** %12
store i8* %54, i8** %9
br label %58
55: ; preds = %50
br label %56
56: ; preds = %55, %49
%57 = call i32 (...) @usage()
br label %58
58: ; preds = %56, %53, %47, %40, %33
%59 = load i32, i32* %11
%60 = add nsw i32 %59, 1
store i32 %60, i32* %11
br label %13
61: ; preds = %13
%62 = load i8*, i8** %9
%63 = icmp ne i8* %62, null
br i1 %63, label %66, label %64
64: ; preds = %61
%65 = call i32 (...) @usage()
br label %66
66: ; preds = %64, %61
%67 = load i8*, i8** %9
%68 = call i32* @fopen(i8* %67, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %68, i32** %10
%69 = load i32*, i32** %10
%70 = icmp ne i32* %69, null
br i1 %70, label %76, label %71
71: ; preds = %66
%72 = load i8*, i8** %9
%73 = load i32, i32* @errno
%74 = call i32 @strerror(i32 %73)
%75 = call i32 @die(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i8* %72, i32 %74)
br label %76
76: ; preds = %71, %66
%77 = load i32*, i32** %10
%78 = call i32 @read_ehdr(i32* %77)
%79 = load i32*, i32** %10
%80 = call i32 @read_shdrs(i32* %79)
%81 = load i32*, i32** %10
%82 = call i32 @read_strtabs(i32* %81)
%83 = load i32*, i32** %10
%84 = call i32 @read_symtabs(i32* %83)
%85 = load i32*, i32** %10
%86 = call i32 @read_relocs(i32* %85)
%87 = load i32, i32* %6
%88 = icmp ne i32 %87, 0
br i1 %88, label %89, label %91
89: ; preds = %76
%90 = call i32 (...) @print_absolute_symbols()
store i32 0, i32* %3
br label %99
91: ; preds = %76
%92 = load i32, i32* %7
%93 = icmp ne i32 %92, 0
br i1 %93, label %94, label %96
94: ; preds = %91
%95 = call i32 (...) @print_absolute_relocs()
store i32 0, i32* %3
br label %99
96: ; preds = %91
%97 = load i32, i32* %8
%98 = call i32 @emit_relocs(i32 %97)
store i32 0, i32* %3
br label %99
99: ; preds = %96, %94, %89
%100 = load i32, i32* %3
ret i32 %100
}

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 = 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* @fopen(i8* %49, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%53 = icmp eq i32* %52, null
br i1 %53, label %54, label %58
54: ; preds = %47
%55 = load i32, i32* @errno
%56 = tail call i32 @strerror(i32 %55)
%57 = tail call i32 @die(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i8* %49, i32 %56)
br label %58
58: ; preds = %54, %47
%59 = tail call i32 @read_ehdr(i32* %52)
%60 = tail call i32 @read_shdrs(i32* %52)
%61 = tail call i32 @read_strtabs(i32* %52)
%62 = tail call i32 @read_symtabs(i32* %52)
%63 = tail call i32 @read_relocs(i32* %52)
%64 = icmp eq i32 %48, 0
br i1 %64, label %67, label %65
65: ; preds = %58
%66 = tail call i32 (...) @print_absolute_symbols()
br label %73
67: ; preds = %58
%68 = icmp eq i32 %51, 0
br i1 %68, label %71, label %69
69: ; preds = %67
%70 = tail call i32 (...) @print_absolute_relocs()
br label %73
71: ; preds = %67
%72 = tail call i32 @emit_relocs(i32 %50)
br label %73
73: ; preds = %71, %69, %65
ret i32 0
}