#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 EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/ *);
scalar_t__ i;
int /*<<< orphan*/ printf(char *, char const *);
void write_file_to_output(const char *filename, FILE *output,
                          FILE *define_file) {
  int c;
  static i = 0;
  FILE *input = fopen(filename, "r");
  if (!input) {
    printf("Could not open %s for reading input.\n", filename);
    return;
  }
  if (define_file) {
    fprintf(define_file, "#define byte%d \"", i++);
  }
  while ((c = fgetc(input)) != EOF) {
    fputc(c, output);
    if (define_file && c != '\n') {
      fputc(c, define_file);
    }
  }
  fputc('\n', output);
  if (define_file) {
    fputc('"', define_file);
    fputc('\n', define_file);
  }
  fclose(input);
}


x86 assembly (clang, -O0):
<write_file_to_output>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe81(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11a8 <write_file_to_output+0x48>
mov    -0x8(%rbp),%rsi
lea    0xe64(%rip),%rdi
call   1040 <printf@plt>
jmp    126a <write_file_to_output+0x10a>
cmpq   $0x0,-0x18(%rbp)
je     11d4 <write_file_to_output+0x74>
mov    -0x18(%rbp),%rdi
mov    0x2e9b(%rip),%edx
mov    %edx,%eax
add    $0x1,%eax
mov    %eax,0x2e90(%rip)
lea    0xe59(%rip),%rsi
call   1070 <fprintf@plt>
jmp    11d9 <write_file_to_output+0x79>
mov    -0x28(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2dfc(%rip),%rcx
cmp    (%rcx),%eax
je     122c <write_file_to_output+0xcc>
mov    -0x1c(%rbp),%eax
mov    -0x10(%rbp),%rsi
movsbl %al,%edi
call   1060 <fputc@plt>
cmpq   $0x0,-0x18(%rbp)
je     1227 <write_file_to_output+0xc7>
cmpl   $0xa,-0x1c(%rbp)
je     1227 <write_file_to_output+0xc7>
mov    -0x1c(%rbp),%eax
mov    -0x18(%rbp),%rsi
movsbl %al,%edi
call   1060 <fputc@plt>
jmp    11d9 <write_file_to_output+0x79>
mov    -0x10(%rbp),%rsi
mov    $0xa,%edi
call   1060 <fputc@plt>
cmpq   $0x0,-0x18(%rbp)
je     1261 <write_file_to_output+0x101>
mov    -0x18(%rbp),%rsi
mov    $0x22,%edi
call   1060 <fputc@plt>
mov    -0x18(%rbp),%rsi
mov    $0xa,%edi
call   1060 <fputc@plt>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_file_to_output>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r12
mov    %rsi,%r15
mov    %rdi,%rbp
lea    0xe85(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1202 <write_file_to_output+0xa2>
mov    %rax,%r14
test   %r12,%r12
je     11ab <write_file_to_output+0x4b>
mov    0x2ec5(%rip),%edx
lea    0x1(%rdx),%eax
mov    %eax,0x2ebc(%rip)
lea    0xe85(%rip),%rsi
mov    %r12,%rdi
call   1070 <fprintf@plt>
mov    %r14,%rdi
call   1050 <fgetc@plt>
mov    0x2e2e(%rip),%r13
cmp    0x0(%r13),%eax
jne    121f <write_file_to_output+0xbf>
mov    $0xa,%edi
mov    %r15,%rsi
call   1060 <fputc@plt>
test   %r12,%r12
je     11ec <write_file_to_output+0x8c>
mov    $0x22,%edi
mov    %r12,%rsi
call   1060 <fputc@plt>
mov    $0xa,%edi
mov    %r12,%rsi
call   1060 <fputc@plt>
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fclose@plt>
lea    0xdf9(%rip),%rdi
mov    %rbp,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <printf@plt>
mov    %eax,%ebp
jmp    1240 <write_file_to_output+0xe0>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r14,%rdi
call   1050 <fgetc@plt>
mov    %eax,%ebp
cmp    0x0(%r13),%eax
je     11c0 <write_file_to_output+0x60>
movsbl %bpl,%ebx
mov    %ebx,%edi
mov    %r15,%rsi
call   1060 <fputc@plt>
test   %r12,%r12
je     1230 <write_file_to_output+0xd0>
cmp    $0xa,%ebp
je     1230 <write_file_to_output+0xd0>
mov    %ebx,%edi
mov    %r12,%rsi
call   1060 <fputc@plt>
jmp    1230 <write_file_to_output+0xd0>

LLVM IR (-O0):
@write_file_to_output.i = internal global i32 0
@.str = [2 x i8] c"r\00"
@.str.1 = [38 x i8] c"Could not open %s for reading input.\0A\00"
@.str.2 = [17 x i8] c"#define byte%d \22\00"
@EOF = global i32 0
@i = global i64 0
define void @write_file_to_output(i8* %0, i32* %1, i32* %2) {
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32*
store i8* %0, i8** %4
store i32* %1, i32** %5
store i32* %2, i32** %6
%9 = load i8*, i8** %4
%10 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %10, i32** %8
%11 = load i32*, i32** %8
%12 = icmp ne i32* %11, null
br i1 %12, label %16, label %13
13: ; preds = %3
%14 = load i8*, i8** %4
%15 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i8* %14)
br label %59
16: ; preds = %3
%17 = load i32*, i32** %6
%18 = icmp ne i32* %17, null
br i1 %18, label %19, label %24
19: ; preds = %16
%20 = load i32*, i32** %6
%21 = load i32, i32* @write_file_to_output.i
%22 = add nsw i32 %21, 1
store i32 %22, i32* @write_file_to_output.i
%23 = call i32 @fprintf(i32* %20, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %21)
br label %24
24: ; preds = %19, %16
br label %25
25: ; preds = %45, %24
%26 = load i32*, i32** %8
%27 = call i32 @fgetc(i32* %26)
store i32 %27, i32* %7
%28 = load i32, i32* @EOF
%29 = icmp ne i32 %27, %28
br i1 %29, label %30, label %46
30: ; preds = %25
%31 = load i32, i32* %7
%32 = trunc i32 %31 to i8
%33 = load i32*, i32** %5
%34 = call i32 @fputc(i8 signext %32, i32* %33)
%35 = load i32*, i32** %6
%36 = icmp ne i32* %35, null
br i1 %36, label %37, label %45
37: ; preds = %30
%38 = load i32, i32* %7
%39 = icmp ne i32 %38, 10
br i1 %39, label %40, label %45
40: ; preds = %37
%41 = load i32, i32* %7
%42 = trunc i32 %41 to i8
%43 = load i32*, i32** %6
%44 = call i32 @fputc(i8 signext %42, i32* %43)
br label %45
45: ; preds = %40, %37, %30
br label %25
46: ; preds = %25
%47 = load i32*, i32** %5
%48 = call i32 @fputc(i8 signext 10, i32* %47)
%49 = load i32*, i32** %6
%50 = icmp ne i32* %49, null
br i1 %50, label %51, label %56
51: ; preds = %46
%52 = load i32*, i32** %6
%53 = call i32 @fputc(i8 signext 34, i32* %52)
%54 = load i32*, i32** %6
%55 = call i32 @fputc(i8 signext 10, i32* %54)
br label %56
56: ; preds = %51, %46
%57 = load i32*, i32** %8
%58 = call i32 @fclose(i32* %57)
br label %59
59: ; preds = %56, %13
ret void
}

LLVM IR (-O2):
@write_file_to_output.i = internal unnamed_addr global i32 0
@.str = [2 x i8] c"r\00"
@.str.1 = [38 x i8] c"Could not open %s for reading input.\0A\00"
@.str.2 = [17 x i8] c"#define byte%d \22\00"
@EOF = global i32 0
@i = global i64 0
define void @write_file_to_output(i8* %0, i32* nocapture %1, i32* %2) {
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %8
6: ; preds = %3
%7 = tail call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %37
8: ; preds = %3
%9 = icmp ne i32* %2, null
br i1 %9, label %10, label %14
10: ; preds = %8
%11 = load i32, i32* @write_file_to_output.i
%12 = add nsw i32 %11, 1
store i32 %12, i32* @write_file_to_output.i
%13 = tail call i32 @fprintf(i32* %2, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %11)
br label %14
14: ; preds = %10, %8
%15 = tail call i32 @fgetc(i32* %4)
%16 = load i32, i32* @EOF
%17 = icmp eq i32 %15, %16
br i1 %17, label %30, label %18
18: ; preds = %14, %26
%19 = phi i32 [ %27, %26 ], [ %15, %14 ]
%20 = trunc i32 %19 to i8
%21 = tail call i32 @fputc(i8 signext %20, i32* %1)
%22 = icmp ne i32 %19, 10
%23 = and i1 %9, %22
br i1 %23, label %24, label %26
24: ; preds = %18
%25 = tail call i32 @fputc(i8 signext %20, i32* %2)
br label %26
26: ; preds = %24, %18
%27 = tail call i32 @fgetc(i32* %4)
%28 = load i32, i32* @EOF
%29 = icmp eq i32 %27, %28
br i1 %29, label %30, label %18
30: ; preds = %26, %14
%31 = tail call i32 @fputc(i8 signext 10, i32* %1)
br i1 %9, label %32, label %35
32: ; preds = %30
%33 = tail call i32 @fputc(i8 signext 34, i32* %2)
%34 = tail call i32 @fputc(i8 signext 10, i32* %2)
br label %35
35: ; preds = %32, %30
%36 = tail call i32 @fclose(i32* %4)
br label %37
37: ; preds = %35, %6
ret void
}