#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*/ SEEK_CUR;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *);
int fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ write_byte(unsigned char, int /*<<< orphan*/ *, int *);
char convert_soudbank_file(const char *input_file, const char *output_file) {
  FILE *ifile = NULL;
  FILE *ofile = NULL;
  int count = 0;
  unsigned char b;
  ifile = fopen(input_file, "rb");
  if (!ifile) {
    printf("Unable to open input_file");
    return 0;
  }
  ofile = fopen(output_file, "w");
  if (!ofile) {
    printf("Unable to open output_file");
    return 0;
  }
  fprintf(ofile, "static const unsigned char soundbank[] = {\n");
  while (fread(&b, 1, 1, ifile) == 1) {
    write_byte(b, ofile, &count);
  }
  fseek(ofile, -1, SEEK_CUR);
  fprintf(ofile, "};\n\n");
  fclose(ofile);
  fclose(ifile);
  printf("Bytes read: %d\n", count);
  return 1;
}


x86 assembly (clang, -O0):
<convert_soudbank_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe5e(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11cd <convert_soudbank_file+0x5d>
lea    0xe46(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movb   $0x0,-0x1(%rbp)
jmp    1296 <convert_soudbank_file+0x126>
mov    -0x18(%rbp),%rdi
lea    0xe45(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1203 <convert_soudbank_file+0x93>
lea    0xe2c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movb   $0x0,-0x1(%rbp)
jmp    1296 <convert_soudbank_file+0x126>
mov    -0x28(%rbp),%rdi
lea    0xe2c(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x20(%rbp),%rcx
lea    -0x2d(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1030 <fread@plt>
cmp    $0x1,%eax
jne    1248 <convert_soudbank_file+0xd8>
mov    -0x2d(%rbp),%al
mov    -0x28(%rbp),%rsi
lea    -0x2c(%rbp),%rdx
movzbl %al,%edi
call   1090 <write_byte@plt>
jmp    1213 <convert_soudbank_file+0xa3>
mov    -0x28(%rbp),%rdi
mov    0x2d95(%rip),%rax
mov    (%rax),%edx
mov    $0xffffffff,%esi
call   1070 <fseek@plt>
mov    -0x28(%rbp),%rdi
lea    0xdfc(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x2c(%rbp),%esi
lea    0xde0(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movb   $0x1,-0x1(%rbp)
movsbl -0x1(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<convert_soudbank_file>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
movl   $0x0,0x4(%rsp)
lea    0xe76(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     127f <convert_soudbank_file+0x10f>
mov    %rax,%r14
lea    0xe7b(%rip),%rsi
mov    %rbx,%rdi
call   1070 <fopen@plt>
test   %rax,%rax
je     1288 <convert_soudbank_file+0x118>
mov    %rax,%rbx
lea    0xe7d(%rip),%rdi
mov    $0x2b,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1080 <fwrite@plt>
lea    0x3(%rsp),%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1030 <fread@plt>
cmp    $0x1,%eax
jne    122a <convert_soudbank_file+0xba>
lea    0x4(%rsp),%r15
lea    0x3(%rsp),%r12
cs nopw 0x0(%rax,%rax,1)
nop
movzbl 0x3(%rsp),%edi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1090 <write_byte@plt>
mov    %r12,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1030 <fread@plt>
cmp    $0x1,%eax
je     1200 <convert_soudbank_file+0x90>
mov    0x2db7(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    $0xffffffff,%esi
call   1060 <fseek@plt>
lea    0xe1f(%rip),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1080 <fwrite@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    0x4(%rsp),%esi
lea    0xdf7(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%bl
jmp    1298 <convert_soudbank_file+0x128>
lea    0xd7d(%rip),%rdi
jmp    128f <convert_soudbank_file+0x11f>
lea    0xd90(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@.str.1 = [26 x i8] c"Unable to open input_file\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [27 x i8] c"Unable to open output_file\00"
@.str.4 = [44 x i8] c"static const unsigned char soundbank[] = {\0A\00"
@SEEK_CUR = global i32 0
@.str.5 = [5 x i8] c"};\0A\0A\00"
@.str.6 = [16 x i8] c"Bytes read: %d\0A\00"
define signext i8 @convert_soudbank_file(i8* %0, i8* %1) {
%3 = alloca i8
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i8
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32* null, i32** %6
store i32* null, i32** %7
store i32 0, i32* %8
%10 = load i8*, i8** %4
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %11, i32** %6
%12 = load i32*, i32** %6
%13 = icmp ne i32* %12, null
br i1 %13, label %16, label %14
14: ; preds = %2
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
store i8 0, i8* %3
br label %46
16: ; preds = %2
%17 = load i8*, i8** %5
%18 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %18, i32** %7
%19 = load i32*, i32** %7
%20 = icmp ne i32* %19, null
br i1 %20, label %23, label %21
21: ; preds = %16
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
store i8 0, i8* %3
br label %46
23: ; preds = %16
%24 = load i32*, i32** %7
%25 = call i32 @fprintf(i32* %24, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.4, i64 0, i64 0))
br label %26
26: ; preds = %30, %23
%27 = load i32*, i32** %6
%28 = call i32 @fread(i8* %9, i32 1, i32 1, i32* %27)
%29 = icmp eq i32 %28, 1
br i1 %29, label %30, label %34
30: ; preds = %26
%31 = load i8, i8* %9
%32 = load i32*, i32** %7
%33 = call i32 @write_byte(i8 zeroext %31, i32* %32, i32* %8)
br label %26
34: ; preds = %26
%35 = load i32*, i32** %7
%36 = load i32, i32* @SEEK_CUR
%37 = call i32 @fseek(i32* %35, i32 -1, i32 %36)
%38 = load i32*, i32** %7
%39 = call i32 @fprintf(i32* %38, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%40 = load i32*, i32** %7
%41 = call i32 @fclose(i32* %40)
%42 = load i32*, i32** %6
%43 = call i32 @fclose(i32* %42)
%44 = load i32, i32* %8
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0), i32 %44)
store i8 1, i8* %3
br label %46
46: ; preds = %34, %21, %14
%47 = load i8, i8* %3
ret i8 %47
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@.str.1 = [26 x i8] c"Unable to open input_file\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [27 x i8] c"Unable to open output_file\00"
@.str.4 = [44 x i8] c"static const unsigned char soundbank[] = {\0A\00"
@SEEK_CUR = global i32 0
@.str.5 = [5 x i8] c"};\0A\0A\00"
@.str.6 = [16 x i8] c"Bytes read: %d\0A\00"
define signext i8 @convert_soudbank_file(i8* nocapture %0, i8* nocapture %1) {
%3 = alloca i32
%4 = alloca i8
%5 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%6 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
br label %32
10: ; preds = %2
%11 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %15
13: ; preds = %10
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
br label %32
15: ; preds = %10
%16 = tail call i64 @fwrite(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.4, i64 0, i64 0), i64 43, i64 1, i32* %11)
%17 = call i32 @fread(i8* %4, i32 1, i32 1, i32* %6)
%18 = icmp eq i32 %17, 1
br i1 %18, label %19, label %24
19: ; preds = %15, %19
%20 = load i8, i8* %4
%21 = call i32 @write_byte(i8 zeroext %20, i32* %11, i32* %3)
%22 = call i32 @fread(i8* %4, i32 1, i32 1, i32* %6)
%23 = icmp eq i32 %22, 1
br i1 %23, label %19, label %24
24: ; preds = %19, %15
%25 = load i32, i32* @SEEK_CUR
%26 = call i32 @fseek(i32* %11, i32 -1, i32 %25)
%27 = call i64 @fwrite(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i64 4, i64 1, i32* %11)
%28 = call i32 @fclose(i32* %11)
%29 = call i32 @fclose(i32* %6)
%30 = load i32, i32* %3
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0), i32 %30)
br label %32
32: ; preds = %24, %13, %8
%33 = phi i8 [ 1, %24 ], [ 0, %13 ], [ 0, %8 ]
ret i8 %33
}