#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*/ uint32_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ copy_comment(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                                int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ read_data(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ read_descriptions(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                                     char, int /*<<< orphan*/,
                                     int /*<<< orphan*/);
int /*<<< orphan*/ read_header(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                               char *, int /*<<< orphan*/ *,
                               int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                               int /*<<< orphan*/ *);
int /*<<< orphan*/ read_units(int /*<<< orphan*/ *, int /*<<< orphan*/ *, char,
                              int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  FILE *ifp, *ofp;
  char little_endian;
  uint32_t num_objs, num_bytes_comment, num_bytes_descs, num_bytes_units;
  int r = EXIT_FAILURE;
  if (argc < 3) {
    fprintf(stderr, "usage: %s INPUT OUTPUT\n", argv[0]);
    return r;
  }
  ifp = fopen(argv[1], "rb");
  if (!ifp) {
    fprintf(stderr, "could not open input file: %s\n", argv[1]);
    return r;
  }
  ofp = fopen(argv[2], "wb");
  if (!ofp) {
    fclose(ifp);
    fprintf(stderr, "could not open output file: %s\n", argv[2]);
    return r;
  }
  if (!read_header(ifp, ofp, &little_endian, &num_objs, &num_bytes_comment,
                   &num_bytes_descs, &num_bytes_units)) {
    goto bail;
  }
  if (!copy_comment(ifp, ofp, num_bytes_comment)) {
    goto bail;
  }
  if (!read_descriptions(ifp, ofp, little_endian, num_objs, num_bytes_descs)) {
    goto bail;
  }
  if (!read_units(ifp, ofp, little_endian, num_objs, num_bytes_units)) {
    goto bail;
  }
  if (!read_data(ifp, ofp)) {
    goto bail;
  }
  r = EXIT_SUCCESS;
bail:
  fclose(ofp);
  fclose(ifp);
  return r;
}


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)
mov    0x2e3b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    11d3 <main+0x53>
mov    0x2e2d(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe3d(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x38(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1352 <main+0x1d2>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe36(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    121e <main+0x9e>
mov    0x2de3(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe0d(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x38(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1352 <main+0x1d2>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe0d(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1272 <main+0xf2>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    0x2d8f(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdx
lea    0xddb(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x38(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1352 <main+0x1d2>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
lea    -0x21(%rbp),%rdx
lea    -0x28(%rbp),%rcx
lea    -0x2c(%rbp),%r8
lea    -0x30(%rbp),%r9
lea    -0x34(%rbp),%rax
mov    %rax,(%rsp)
call   10a0 <read_header@plt>
cmp    $0x0,%eax
jne    12a5 <main+0x125>
jmp    133a <main+0x1ba>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x2c(%rbp),%edx
call   1050 <copy_comment@plt>
cmp    $0x0,%eax
jne    12c3 <main+0x143>
jmp    133a <main+0x1ba>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x21(%rbp),%al
mov    -0x28(%rbp),%ecx
mov    -0x30(%rbp),%r8d
movsbl %al,%edx
call   1080 <read_descriptions@plt>
cmp    $0x0,%eax
jne    12eb <main+0x16b>
jmp    133a <main+0x1ba>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x21(%rbp),%al
mov    -0x28(%rbp),%ecx
mov    -0x34(%rbp),%r8d
movsbl %al,%edx
call   1060 <read_units@plt>
cmp    $0x0,%eax
jne    1313 <main+0x193>
jmp    133a <main+0x1ba>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <read_data@plt>
cmp    $0x0,%eax
jne    132e <main+0x1ae>
jmp    133a <main+0x1ba>
mov    0x2c9b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x38(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%rbp
mov    0x2e44(%rip),%rax
mov    (%rax),%r14d
cmp    $0x2,%edi
jg     11b5 <main+0x35>
mov    0x2e3d(%rip),%rax
mov    (%rax),%edi
mov    0x0(%rbp),%rdx
lea    0xe50(%rip),%rsi
jmp    12c3 <main+0x143>
mov    0x8(%rbp),%rdi
lea    0xe58(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     1291 <main+0x111>
mov    %rax,%rbx
mov    0x10(%rbp),%rdi
lea    0xe5e(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     12a7 <main+0x127>
mov    %rax,%r15
lea    0x1c(%rsp),%rax
mov    %rax,(%rsp)
lea    0x17(%rsp),%rdx
lea    0x18(%rsp),%rcx
lea    0x24(%rsp),%r8
lea    0x20(%rsp),%r9
mov    %rbx,%rdi
mov    %r15,%rsi
call   10a0 <read_header@plt>
test   %eax,%eax
je     127f <main+0xff>
mov    0x24(%rsp),%edx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1050 <copy_comment@plt>
test   %eax,%eax
je     127f <main+0xff>
movsbl 0x17(%rsp),%edx
mov    0x18(%rsp),%ecx
mov    0x20(%rsp),%r8d
mov    %rbx,%rdi
mov    %r15,%rsi
call   1080 <read_descriptions@plt>
test   %eax,%eax
je     127f <main+0xff>
movsbl 0x17(%rsp),%edx
mov    0x18(%rsp),%ecx
mov    0x1c(%rsp),%r8d
mov    %rbx,%rdi
mov    %r15,%rsi
call   1060 <read_units@plt>
test   %eax,%eax
je     127f <main+0xff>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1030 <read_data@plt>
test   %eax,%eax
je     127f <main+0xff>
mov    0x2d54(%rip),%rax
mov    (%rax),%r14d
mov    %r15,%rdi
call   1040 <fclose@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
jmp    12c8 <main+0x148>
mov    0x2d48(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rbp),%rdx
lea    0xd76(%rip),%rsi
jmp    12c3 <main+0x143>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    0x2d2a(%rip),%rax
mov    (%rax),%edi
mov    0x10(%rbp),%rdx
lea    0xd7a(%rip),%rsi
call   1070 <fprintf@plt>
mov    %r14d,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@EXIT_FAILURE = global i32 0
@stderr = global i32 0
@.str = [24 x i8] c"usage: %s INPUT OUTPUT\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [31 x i8] c"could not open input file: %s\0A\00"
@.str.3 = [3 x i8] c"wb\00"
@.str.4 = [32 x i8] c"could not open output file: %s\0A\00"
@EXIT_SUCCESS = 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 i32
%12 = alloca i32
%13 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = load i32, i32* @EXIT_FAILURE
store i32 %14, i32* %13
%15 = load i32, i32* %4
%16 = icmp slt i32 %15, 3
br i1 %16, label %17, label %24
17: ; preds = %2
%18 = load i32, i32* @stderr
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 0
%21 = load i8*, i8** %20
%22 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %21)
%23 = load i32, i32* %13
store i32 %23, i32* %3
br label %99
24: ; preds = %2
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = call i32* @fopen(i8* %27, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %28, i32** %6
%29 = load i32*, i32** %6
%30 = icmp ne i32* %29, null
br i1 %30, label %38, label %31
31: ; preds = %24
%32 = load i32, i32* @stderr
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 1
%35 = load i8*, i8** %34
%36 = call i32 @fprintf(i32 %32, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i8* %35)
%37 = load i32, i32* %13
store i32 %37, i32* %3
br label %99
38: ; preds = %24
%39 = load i8**, i8*** %5
%40 = getelementptr inbounds i8*, i8** %39, i64 2
%41 = load i8*, i8** %40
%42 = call i32* @fopen(i8* %41, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %42, i32** %7
%43 = load i32*, i32** %7
%44 = icmp ne i32* %43, null
br i1 %44, label %54, label %45
45: ; preds = %38
%46 = load i32*, i32** %6
%47 = call i32 @fclose(i32* %46)
%48 = load i32, i32* @stderr
%49 = load i8**, i8*** %5
%50 = getelementptr inbounds i8*, i8** %49, i64 2
%51 = load i8*, i8** %50
%52 = call i32 @fprintf(i32 %48, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i8* %51)
%53 = load i32, i32* %13
store i32 %53, i32* %3
br label %99
54: ; preds = %38
%55 = load i32*, i32** %6
%56 = load i32*, i32** %7
%57 = call i32 @read_header(i32* %55, i32* %56, i8* %8, i32* %9, i32* %10, i32* %11, i32* %12)
%58 = icmp ne i32 %57, 0
br i1 %58, label %60, label %59
59: ; preds = %54
br label %93
60: ; preds = %54
%61 = load i32*, i32** %6
%62 = load i32*, i32** %7
%63 = load i32, i32* %10
%64 = call i32 @copy_comment(i32* %61, i32* %62, i32 %63)
%65 = icmp ne i32 %64, 0
br i1 %65, label %67, label %66
66: ; preds = %60
br label %93
67: ; preds = %60
%68 = load i32*, i32** %6
%69 = load i32*, i32** %7
%70 = load i8, i8* %8
%71 = load i32, i32* %9
%72 = load i32, i32* %11
%73 = call i32 @read_descriptions(i32* %68, i32* %69, i8 signext %70, i32 %71, i32 %72)
%74 = icmp ne i32 %73, 0
br i1 %74, label %76, label %75
75: ; preds = %67
br label %93
76: ; preds = %67
%77 = load i32*, i32** %6
%78 = load i32*, i32** %7
%79 = load i8, i8* %8
%80 = load i32, i32* %9
%81 = load i32, i32* %12
%82 = call i32 @read_units(i32* %77, i32* %78, i8 signext %79, i32 %80, i32 %81)
%83 = icmp ne i32 %82, 0
br i1 %83, label %85, label %84
84: ; preds = %76
br label %93
85: ; preds = %76
%86 = load i32*, i32** %6
%87 = load i32*, i32** %7
%88 = call i32 @read_data(i32* %86, i32* %87)
%89 = icmp ne i32 %88, 0
br i1 %89, label %91, label %90
90: ; preds = %85
br label %93
91: ; preds = %85
%92 = load i32, i32* @EXIT_SUCCESS
store i32 %92, i32* %13
br label %93
93: ; preds = %91, %90, %84, %75, %66, %59
%94 = load i32*, i32** %7
%95 = call i32 @fclose(i32* %94)
%96 = load i32*, i32** %6
%97 = call i32 @fclose(i32* %96)
%98 = load i32, i32* %13
store i32 %98, i32* %3
br label %99
99: ; preds = %93, %45, %31, %17
%100 = load i32, i32* %3
ret i32 %100
}

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
@stderr = global i32 0
@.str = [24 x i8] c"usage: %s INPUT OUTPUT\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [31 x i8] c"could not open input file: %s\0A\00"
@.str.3 = [3 x i8] c"wb\00"
@.str.4 = [32 x i8] c"could not open output file: %s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = bitcast i32* %4 to i8*
%9 = bitcast i32* %5 to i8*
%10 = bitcast i32* %6 to i8*
%11 = bitcast i32* %7 to i8*
%12 = load i32, i32* @EXIT_FAILURE
%13 = icmp slt i32 %0, 3
br i1 %13, label %14, label %18
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = load i8*, i8** %1
%17 = tail call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %16)
br label %65
18: ; preds = %2
%19 = getelementptr inbounds i8*, i8** %1, i64 1
%20 = load i8*, i8** %19
%21 = tail call i32* @fopen(i8* %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %27
23: ; preds = %18
%24 = load i32, i32* @stderr
%25 = load i8*, i8** %19
%26 = tail call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i8* %25)
br label %65
27: ; preds = %18
%28 = getelementptr inbounds i8*, i8** %1, i64 2
%29 = load i8*, i8** %28
%30 = tail call i32* @fopen(i8* %29, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%31 = icmp eq i32* %30, null
br i1 %31, label %32, label %37
32: ; preds = %27
%33 = tail call i32 @fclose(i32* %21)
%34 = load i32, i32* @stderr
%35 = load i8*, i8** %28
%36 = tail call i32 @fprintf(i32 %34, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i8* %35)
br label %65
37: ; preds = %27
%38 = call i32 @read_header(i32* %21, i32* %30, i8* %3, i32* %4, i32* %5, i32* %6, i32* %7)
%39 = icmp eq i32 %38, 0
br i1 %39, label %61, label %40
40: ; preds = %37
%41 = load i32, i32* %5
%42 = call i32 @copy_comment(i32* %21, i32* %30, i32 %41)
%43 = icmp eq i32 %42, 0
br i1 %43, label %61, label %44
44: ; preds = %40
%45 = load i8, i8* %3
%46 = load i32, i32* %4
%47 = load i32, i32* %6
%48 = call i32 @read_descriptions(i32* %21, i32* %30, i8 signext %45, i32 %46, i32 %47)
%49 = icmp eq i32 %48, 0
br i1 %49, label %61, label %50
50: ; preds = %44
%51 = load i8, i8* %3
%52 = load i32, i32* %4
%53 = load i32, i32* %7
%54 = call i32 @read_units(i32* %21, i32* %30, i8 signext %51, i32 %52, i32 %53)
%55 = icmp eq i32 %54, 0
br i1 %55, label %61, label %56
56: ; preds = %50
%57 = call i32 @read_data(i32* %21, i32* %30)
%58 = icmp eq i32 %57, 0
%59 = load i32, i32* @EXIT_SUCCESS
%60 = select i1 %58, i32 %12, i32 %59
br label %61
61: ; preds = %56, %50, %44, %40, %37
%62 = phi i32 [ %12, %50 ], [ %12, %44 ], [ %12, %40 ], [ %12, %37 ], [ %60, %56 ]
%63 = call i32 @fclose(i32* %30)
%64 = call i32 @fclose(i32* %21)
br label %65
65: ; preds = %61, %32, %23, %14
%66 = phi i32 [ %12, %14 ], [ %62, %61 ], [ %12, %32 ], [ %12, %23 ]
ret i32 %66
}