#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;
  int as_text;
  const char *fname;
  FILE *fp;
  int i;
  show_absolute = 0;
  as_text = 0;
  fname = NULL;
  for (i = 1; i < argc; i++) {
    char *arg = argv[i];
    if (*arg == '-') {
      if (strcmp(argv[1], "--abs") == 0) {
        show_absolute = 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) {
    print_absolute_symbols();
    print_absolute_relocs();
    return 0;
  }
  emit_relocs(as_text);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movl   $0x1,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    12bf <main+0xef>
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
jne    128d <main+0xbd>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdc2(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    1259 <main+0x89>
movl   $0x1,-0x14(%rbp)
jmp    12b1 <main+0xe1>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xd9e(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    1283 <main+0xb3>
movl   $0x1,-0x18(%rbp)
jmp    12b1 <main+0xe1>
jmp    1288 <main+0xb8>
jmp    12aa <main+0xda>
cmpq   $0x0,-0x20(%rbp)
jne    12a5 <main+0xd5>
mov    -0x38(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    12b1 <main+0xe1>
jmp    12aa <main+0xda>
mov    $0x0,%al
call   10c0 <usage@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1203 <main+0x33>
cmpq   $0x0,-0x20(%rbp)
jne    12d1 <main+0x101>
mov    $0x0,%al
call   10c0 <usage@plt>
mov    -0x20(%rbp),%rdi
lea    0xd31(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1318 <main+0x148>
mov    -0x20(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    0x2ce1(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
mov    -0x40(%rbp),%rsi
mov    %eax,%edx
lea    0xcfc(%rip),%rdi
call   10e0 <die@plt>
mov    -0x28(%rbp),%rdi
call   1060 <read_ehdr@plt>
mov    -0x28(%rbp),%rdi
call   1050 <read_shdrs@plt>
mov    -0x28(%rbp),%rdi
call   10a0 <read_strtabs@plt>
mov    -0x28(%rbp),%rdi
call   1090 <read_symtabs@plt>
mov    -0x28(%rbp),%rdi
call   1030 <read_relocs@plt>
cmpl   $0x0,-0x14(%rbp)
je     1369 <main+0x199>
mov    $0x0,%al
call   1040 <print_absolute_symbols@plt>
mov    $0x0,%al
call   1080 <print_absolute_relocs@plt>
movl   $0x0,-0x4(%rbp)
jmp    1378 <main+0x1a8>
mov    -0x18(%rbp),%edi
call   10b0 <emit_relocs@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %r13d,%r13d
mov    $0x0,%r14d
cmp    $0x2,%edi
jl     1276 <main+0xa6>
mov    %rsi,%rbp
mov    %edi,%r14d
mov    $0x1,%r12d
lea    0xe00(%rip),%r15
xor    %r13d,%r13d
xor    %ebx,%ebx
movl   $0x0,0x4(%rsp)
jmp    1225 <main+0x55>
nop
test   %rbx,%rbx
je     125f <main+0x8f>
xor    %eax,%eax
call   10c0 <usage@plt>
add    $0x1,%r12
cmp    %r12,%r14
je     126c <main+0x9c>
mov    0x0(%rbp,%r12,8),%rax
cmpb   $0x2d,(%rax)
jne    1210 <main+0x40>
mov    0x8(%rbp),%rdi
mov    %r15,%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     1264 <main+0x94>
mov    0x8(%rbp),%rdi
lea    0xdbb(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
jne    1215 <main+0x45>
movl   $0x1,0x4(%rsp)
jmp    121c <main+0x4c>
mov    %rax,%rbx
jmp    121c <main+0x4c>
mov    $0x1,%r13d
jmp    121c <main+0x4c>
test   %rbx,%rbx
mov    0x4(%rsp),%r14d
jne    127f <main+0xaf>
xor    %ebx,%ebx
xor    %eax,%eax
call   10c0 <usage@plt>
lea    0xd87(%rip),%rsi
mov    %rbx,%rdi
call   10d0 <fopen@plt>
mov    %rax,%rbp
test   %rax,%rax
jne    12b5 <main+0xe5>
mov    0x2d43(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
lea    0xd64(%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   %r13d,%r13d
je     12f2 <main+0x122>
xor    %eax,%eax
call   1040 <print_absolute_symbols@plt>
xor    %eax,%eax
call   1080 <print_absolute_relocs@plt>
jmp    12fa <main+0x12a>
mov    %r14d,%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 = [6 x i8] c"--abs\00"
@.str.1 = [7 x i8] c"--text\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [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 i8*
%9 = alloca i32*
%10 = alloca i32
%11 = 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 i8* null, i8** %8
store i32 1, i32* %10
br label %12
12: ; preds = %50, %2
%13 = load i32, i32* %10
%14 = load i32, i32* %4
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %53
16: ; preds = %12
%17 = load i8**, i8*** %5
%18 = load i32, i32* %10
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8*, i8** %17, i64 %19
%21 = load i8*, i8** %20
store i8* %21, i8** %11
%22 = load i8*, i8** %11
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp eq i32 %24, 45
br i1 %25, label %26, label %42
26: ; preds = %16
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 1
%29 = load i8*, i8** %28
%30 = call i64 @strcmp(i8* %29, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %33
32: ; preds = %26
store i32 1, i32* %6
br label %50
33: ; preds = %26
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 1
%36 = load i8*, i8** %35
%37 = call i64 @strcmp(i8* %36, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%38 = icmp eq i64 %37, 0
br i1 %38, label %39, label %40
39: ; preds = %33
store i32 1, i32* %7
br label %50
40: ; preds = %33
br label %41
41: ; preds = %40
br label %48
42: ; preds = %16
%43 = load i8*, i8** %8
%44 = icmp ne i8* %43, null
br i1 %44, label %47, label %45
45: ; preds = %42
%46 = load i8*, i8** %11
store i8* %46, i8** %8
br label %50
47: ; preds = %42
br label %48
48: ; preds = %47, %41
%49 = call i32 (...) @usage()
br label %50
50: ; preds = %48, %45, %39, %32
%51 = load i32, i32* %10
%52 = add nsw i32 %51, 1
store i32 %52, i32* %10
br label %12
53: ; preds = %12
%54 = load i8*, i8** %8
%55 = icmp ne i8* %54, null
br i1 %55, label %58, label %56
56: ; preds = %53
%57 = call i32 (...) @usage()
br label %58
58: ; preds = %56, %53
%59 = load i8*, i8** %8
%60 = call i32* @fopen(i8* %59, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %60, i32** %9
%61 = load i32*, i32** %9
%62 = icmp ne i32* %61, null
br i1 %62, label %68, label %63
63: ; preds = %58
%64 = load i8*, i8** %8
%65 = load i32, i32* @errno
%66 = call i32 @strerror(i32 %65)
%67 = call i32 @die(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i8* %64, i32 %66)
br label %68
68: ; preds = %63, %58
%69 = load i32*, i32** %9
%70 = call i32 @read_ehdr(i32* %69)
%71 = load i32*, i32** %9
%72 = call i32 @read_shdrs(i32* %71)
%73 = load i32*, i32** %9
%74 = call i32 @read_strtabs(i32* %73)
%75 = load i32*, i32** %9
%76 = call i32 @read_symtabs(i32* %75)
%77 = load i32*, i32** %9
%78 = call i32 @read_relocs(i32* %77)
%79 = load i32, i32* %6
%80 = icmp ne i32 %79, 0
br i1 %80, label %81, label %84
81: ; preds = %68
%82 = call i32 (...) @print_absolute_symbols()
%83 = call i32 (...) @print_absolute_relocs()
store i32 0, i32* %3
br label %87
84: ; preds = %68
%85 = load i32, i32* %7
%86 = call i32 @emit_relocs(i32 %85)
store i32 0, i32* %3
br label %87
87: ; preds = %84, %81
%88 = load i32, i32* %3
ret i32 %88
}

LLVM IR (-O2):
@.str = [6 x i8] c"--abs\00"
@.str.1 = [7 x i8] c"--text\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [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 %36
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = zext i32 %0 to i64
br label %7
7: ; preds = %4, %28
%8 = phi i64 [ 1, %4 ], [ %32, %28 ]
%9 = phi i32 [ 0, %4 ], [ %31, %28 ]
%10 = phi i8* [ null, %4 ], [ %30, %28 ]
%11 = phi i32 [ 0, %4 ], [ %29, %28 ]
%12 = getelementptr inbounds i8*, i8** %1, i64 %8
%13 = load i8*, i8** %12
%14 = load i8, i8* %13
%15 = icmp eq i8 %14, 45
br i1 %15, label %16, label %24
16: ; preds = %7
%17 = load i8*, i8** %5
%18 = tail call i64 @strcmp(i8* %17, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%19 = icmp eq i64 %18, 0
br i1 %19, label %28, label %20
20: ; preds = %16
%21 = load i8*, i8** %5
%22 = tail call i64 @strcmp(i8* %21, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%23 = icmp eq i64 %22, 0
br i1 %23, label %28, label %26
24: ; preds = %7
%25 = icmp eq i8* %10, null
br i1 %25, label %28, label %26
26: ; preds = %24, %20
%27 = tail call i32 (...) @usage()
br label %28
28: ; preds = %24, %20, %16, %26
%29 = phi i32 [ %11, %26 ], [ %11, %16 ], [ 1, %20 ], [ %11, %24 ]
%30 = phi i8* [ %10, %26 ], [ %10, %16 ], [ %10, %20 ], [ %13, %24 ]
%31 = phi i32 [ %9, %26 ], [ 1, %16 ], [ %9, %20 ], [ %9, %24 ]
%32 = add nuw nsw i64 %8, 1
%33 = icmp eq i64 %32, %6
br i1 %33, label %34, label %7
34: ; preds = %28
%35 = icmp eq i8* %30, null
br i1 %35, label %36, label %40
36: ; preds = %2, %34
%37 = phi i32 [ %31, %34 ], [ 0, %2 ]
%38 = phi i32 [ %29, %34 ], [ 0, %2 ]
%39 = tail call i32 (...) @usage()
br label %40
40: ; preds = %36, %34
%41 = phi i32 [ %37, %36 ], [ %31, %34 ]
%42 = phi i8* [ null, %36 ], [ %30, %34 ]
%43 = phi i32 [ %38, %36 ], [ %29, %34 ]
%44 = tail call i32* @fopen(i8* %42, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%45 = icmp eq i32* %44, null
br i1 %45, label %46, label %50
46: ; preds = %40
%47 = load i32, i32* @errno
%48 = tail call i32 @strerror(i32 %47)
%49 = tail call i32 @die(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i8* %42, i32 %48)
br label %50
50: ; preds = %46, %40
%51 = tail call i32 @read_ehdr(i32* %44)
%52 = tail call i32 @read_shdrs(i32* %44)
%53 = tail call i32 @read_strtabs(i32* %44)
%54 = tail call i32 @read_symtabs(i32* %44)
%55 = tail call i32 @read_relocs(i32* %44)
%56 = icmp eq i32 %41, 0
br i1 %56, label %60, label %57
57: ; preds = %50
%58 = tail call i32 (...) @print_absolute_symbols()
%59 = tail call i32 (...) @print_absolute_relocs()
br label %62
60: ; preds = %50
%61 = tail call i32 @emit_relocs(i32 %43)
br label %62
62: ; preds = %60, %57
ret i32 0
}