#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 */
scalar_t__ bef2elf(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ dohelp(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ puts(char *);
int main(int argc, const char *argv[]) {
  FILE *in, *out;
  if (argc != 3)
    dohelp(1);
  in = fopen(argv[1], "r");
  if (in == NULL)
    dohelp(0);
  out = fopen(argv[2], "wb");
  if (out == NULL)
    dohelp(0);
  if (bef2elf(in, out) != 0)
    puts("An error was encountered while processing the file.");
  fclose(in);
  fclose(out);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     117a <main+0x2a>
mov    $0x1,%edi
call   1060 <dohelp@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe77(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11a4 <main+0x54>
xor    %edi,%edi
call   1060 <dohelp@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe4f(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11ce <main+0x7e>
xor    %edi,%edi
call   1060 <dohelp@plt>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <bef2elf@plt>
cmp    $0x0,%rax
je     11f1 <main+0xa1>
lea    0xe19(%rip),%rdi
call   1040 <puts@plt>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
cmp    $0x3,%edi
je     1166 <main+0x16>
mov    $0x1,%edi
call   1060 <dohelp@plt>
mov    0x8(%rbx),%rdi
lea    0xe8f(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%r14
test   %rax,%rax
jne    1185 <main+0x35>
xor    %edi,%edi
call   1060 <dohelp@plt>
mov    0x10(%rbx),%rdi
lea    0xe72(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11a4 <main+0x54>
xor    %edi,%edi
call   1060 <dohelp@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <bef2elf@plt>
test   %rax,%rax
je     11c0 <main+0x70>
lea    0xe4a(%rip),%rdi
call   1040 <puts@plt>
mov    %r14,%rdi
call   1050 <fclose@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [3 x i8] c"wb\00"
@.str.2 = [52 x i8] c"An error was encountered while processing the file.\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 3
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = call i32 @dohelp(i32 1)
br label %12
12: ; preds = %10, %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
%16 = call i32* @fopen(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %16, i32** %6
%17 = load i32*, i32** %6
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %21
19: ; preds = %12
%20 = call i32 @dohelp(i32 0)
br label %21
21: ; preds = %19, %12
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 2
%24 = load i8*, i8** %23
%25 = call i32* @fopen(i8* %24, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %25, i32** %7
%26 = load i32*, i32** %7
%27 = icmp eq i32* %26, null
br i1 %27, label %28, label %30
28: ; preds = %21
%29 = call i32 @dohelp(i32 0)
br label %30
30: ; preds = %28, %21
%31 = load i32*, i32** %6
%32 = load i32*, i32** %7
%33 = call i64 @bef2elf(i32* %31, i32* %32)
%34 = icmp ne i64 %33, 0
br i1 %34, label %35, label %37
35: ; preds = %30
%36 = call i32 @puts(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.2, i64 0, i64 0))
br label %37
37: ; preds = %35, %30
%38 = load i32*, i32** %6
%39 = call i32 @fclose(i32* %38)
%40 = load i32*, i32** %7
%41 = call i32 @fclose(i32* %40)
ret i32 0
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [3 x i8] c"wb\00"
@.str.2 = [52 x i8] c"An error was encountered while processing the file.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 3
br i1 %3, label %6, label %4
4: ; preds = %2
%5 = tail call i32 @dohelp(i32 1)
br label %6
6: ; preds = %4, %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %13
11: ; preds = %6
%12 = tail call i32 @dohelp(i32 0)
br label %13
13: ; preds = %11, %6
%14 = getelementptr inbounds i8*, i8** %1, i64 2
%15 = load i8*, i8** %14
%16 = tail call i32* @fopen(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %20
18: ; preds = %13
%19 = tail call i32 @dohelp(i32 0)
br label %20
20: ; preds = %18, %13
%21 = tail call i64 @bef2elf(i32* %9, i32* %16)
%22 = icmp eq i64 %21, 0
br i1 %22, label %25, label %23
23: ; preds = %20
%24 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @.str.2, i64 0, i64 0))
br label %25
25: ; preds = %23, %20
%26 = tail call i32 @fclose(i32* %9)
%27 = tail call i32 @fclose(i32* %16)
ret i32 0
}