#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*/ dump(int /*<<< orphan*/ *, char const *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ *stdin;
void fdump(char *fn, const char *n) {
  FILE *f = (fn == NULL) ? stdin : fopen(fn, "rb");
  if (f == NULL) {
    fprintf(stderr, "bin2c: cannot open ");
    perror(fn);
    exit(1);
  } else {
    if (fn != NULL)
      printf("/* %s */\n", fn);
    dump(f, n);
    fclose(f);
  }
}


x86 assembly (clang, -O0):
<fdump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    119e <fdump+0x2e>
mov    0x2e56(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
jmp    11b2 <fdump+0x42>
mov    -0x8(%rbp),%rdi
lea    0xe57(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11ed <fdump+0x7d>
mov    0x2e0c(%rip),%rax
mov    (%rax),%edi
lea    0xe2e(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x8(%rbp),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
cmpq   $0x0,-0x8(%rbp)
je     1208 <fdump+0x98>
mov    -0x8(%rbp),%rsi
lea    0xe14(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <dump@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fdump>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
test   %rdi,%rdi
je     11a8 <fdump+0x38>
lea    0xe79(%rip),%rsi
mov    %r15,%rdi
call   1070 <fopen@plt>
test   %rax,%rax
je     11cf <fdump+0x5f>
mov    %rax,%rbx
lea    0xe79(%rip),%rdi
mov    %r15,%rsi
call   1040 <printf@plt>
jmp    11b7 <fdump+0x47>
mov    0x2e39(%rip),%rax
mov    (%rax),%rbx
test   %rbx,%rbx
je     11cf <fdump+0x5f>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <dump@plt>
mov    %rbx,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <fclose@plt>
mov    0x2e02(%rip),%rax
mov    (%rax),%edi
lea    0xe24(%rip),%rsi
call   1060 <fprintf@plt>
mov    %r15,%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@stdin = global i32* null
@.str = [3 x i8] c"rb\00"
@stderr = global i32 0
@.str.1 = [20 x i8] c"bin2c: cannot open \00"
@.str.2 = [10 x i8] c"/* %s */\0A\00"
define void @fdump(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32*
store i8* %0, i8** %3
store i8* %1, i8** %4
%6 = load i8*, i8** %3
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = load i32*, i32** @stdin
br label %13
10: ; preds = %2
%11 = load i8*, i8** %3
%12 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %10, %8
%14 = phi i32* [ %9, %8 ], [ %12, %10 ]
store i32* %14, i32** %5
%15 = load i32*, i32** %5
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %23
17: ; preds = %13
%18 = load i32, i32* @stderr
%19 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%20 = load i8*, i8** %3
%21 = call i32 @perror(i8* %20)
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %13
%24 = load i8*, i8** %3
%25 = icmp ne i8* %24, null
br i1 %25, label %26, label %29
26: ; preds = %23
%27 = load i8*, i8** %3
%28 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %27)
br label %29
29: ; preds = %26, %23
%30 = load i32*, i32** %5
%31 = load i8*, i8** %4
%32 = call i32 @dump(i32* %30, i8* %31)
%33 = load i32*, i32** %5
%34 = call i32 @fclose(i32* %33)
br label %35
35: ; preds = %29
ret void
}

LLVM IR (-O2):
@stdin = global i32* null
@.str = [3 x i8] c"rb\00"
@stderr = global i32 0
@.str.1 = [20 x i8] c"bin2c: cannot open \00"
@.str.2 = [10 x i8] c"/* %s */\0A\00"
define void @fdump(i8* %0, i8* %1) {
%3 = icmp eq i8* %0, null
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = load i32*, i32** @stdin
%6 = icmp eq i32* %5, null
br i1 %6, label %10, label %17
7: ; preds = %2
%8 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %15
10: ; preds = %7, %4
%11 = load i32, i32* @stderr
%12 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%13 = tail call i32 @perror(i8* %0)
%14 = tail call i32 @exit(i32 1)
unreachable
15: ; preds = %7
%16 = tail call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %0)
br label %17
17: ; preds = %4, %15
%18 = phi i32* [ %8, %15 ], [ %5, %4 ]
%19 = tail call i32 @dump(i32* %18, i8* %1)
%20 = tail call i32 @fclose(i32* %18)
ret void
}