#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ printf(char *, char const *);
int /*<<< orphan*/ sprintf(char *, char *, char const *);
int /*<<< orphan*/ write_file_to_output(char *, int /*<<< orphan*/ *,
                                        int /*<<< orphan*/ *);
void generate_file(const char *input_filename, const char *output_filename,
                   char use_define) {
  char file0[64];
  char file1[64];
  char file2[64];
  char file3[64];
  char define_filename[128];
  FILE *output, *define_file;
  sprintf(file0, "%s.i0", input_filename);
  sprintf(file1, "%s.i1", input_filename);
  sprintf(file2, "%s.i2", input_filename);
  sprintf(file3, "%s.i3", input_filename);
  sprintf(define_filename, "%s-defines.h", output_filename);
  output = fopen(output_filename, "w+");
  if (!output) {
    printf("Could not create %s for output.\n", output_filename);
    return;
  }
  if (use_define) {
    define_file = fopen(define_filename, "w+");
  }
  write_file_to_output(file0, output, define_file);
  write_file_to_output(file1, output, define_file);
  write_file_to_output(file2, output, define_file);
  write_file_to_output(file3, output, define_file);
  fclose(output);
  if (use_define && define_file) {
    fclose(define_file);
  }
}


x86 assembly (clang, -O0):
<generate_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1b0,%rsp
mov    %dl,%al
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %al,-0x11(%rbp)
lea    -0x60(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xe89(%rip),%rsi
call   1070 <sprintf@plt>
lea    -0xa0(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xe78(%rip),%rsi
call   1070 <sprintf@plt>
lea    -0xe0(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xe67(%rip),%rsi
call   1070 <sprintf@plt>
lea    -0x120(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xe56(%rip),%rsi
call   1070 <sprintf@plt>
lea    -0x1a0(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe45(%rip),%rsi
call   1070 <sprintf@plt>
mov    -0x10(%rbp),%rdi
lea    0xe42(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x1a8(%rbp)
cmpq   $0x0,-0x1a8(%rbp)
jne    1212 <generate_file+0xc2>
mov    -0x10(%rbp),%rsi
lea    0xe20(%rip),%rdi
call   1050 <printf@plt>
jmp    12ce <generate_file+0x17e>
cmpb   $0x0,-0x11(%rbp)
je     1236 <generate_file+0xe6>
lea    -0x1a0(%rbp),%rdi
lea    0xdfb(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x1b0(%rbp)
lea    -0x60(%rbp),%rdi
mov    -0x1a8(%rbp),%rsi
mov    -0x1b0(%rbp),%rdx
call   1030 <write_file_to_output@plt>
lea    -0xa0(%rbp),%rdi
mov    -0x1a8(%rbp),%rsi
mov    -0x1b0(%rbp),%rdx
call   1030 <write_file_to_output@plt>
lea    -0xe0(%rbp),%rdi
mov    -0x1a8(%rbp),%rsi
mov    -0x1b0(%rbp),%rdx
call   1030 <write_file_to_output@plt>
lea    -0x120(%rbp),%rdi
mov    -0x1a8(%rbp),%rsi
mov    -0x1b0(%rbp),%rdx
call   1030 <write_file_to_output@plt>
mov    -0x1a8(%rbp),%rdi
call   1040 <fclose@plt>
movsbl -0x11(%rbp),%eax
cmp    $0x0,%eax
je     12ce <generate_file+0x17e>
cmpq   $0x0,-0x1b0(%rbp)
je     12ce <generate_file+0x17e>
mov    -0x1b0(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x1b0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<generate_file>:
push   %rbp
push   %r14
push   %rbx
sub    $0x180,%rsp
mov    %edx,%r14d
mov    %rsi,%rbx
mov    %rdi,%rbp
lea    0xe95(%rip),%rsi
lea    0xc0(%rsp),%rdi
mov    %rbp,%rdx
call   1070 <sprintf@plt>
lea    0xe84(%rip),%rsi
lea    0x80(%rsp),%rdi
mov    %rbp,%rdx
call   1070 <sprintf@plt>
lea    0xe73(%rip),%rsi
lea    0x40(%rsp),%rdi
mov    %rbp,%rdx
call   1070 <sprintf@plt>
lea    0xe65(%rip),%rsi
mov    %rsp,%rdi
mov    %rbp,%rdx
call   1070 <sprintf@plt>
lea    0xe59(%rip),%rsi
lea    0x100(%rsp),%rdi
mov    %rbx,%rdx
call   1070 <sprintf@plt>
lea    0xe4f(%rip),%rsi
mov    %rbx,%rdi
call   1060 <fopen@plt>
test   %rax,%rax
je     1204 <generate_file+0xb4>
mov    %rax,%rbp
test   %r14b,%r14b
je     121e <generate_file+0xce>
lea    0xe33(%rip),%rsi
lea    0x100(%rsp),%rdi
call   1060 <fopen@plt>
mov    %rax,%rbx
jmp    121e <generate_file+0xce>
lea    0xe1d(%rip),%rdi
mov    %rbx,%rsi
add    $0x180,%rsp
pop    %rbx
pop    %r14
pop    %rbp
jmp    1050 <printf@plt>
lea    0xc0(%rsp),%rdi
mov    %rbp,%rsi
mov    %rbx,%rdx
call   1030 <write_file_to_output@plt>
lea    0x80(%rsp),%rdi
mov    %rbp,%rsi
mov    %rbx,%rdx
call   1030 <write_file_to_output@plt>
lea    0x40(%rsp),%rdi
mov    %rbp,%rsi
mov    %rbx,%rdx
call   1030 <write_file_to_output@plt>
mov    %rsp,%rdi
mov    %rbp,%rsi
mov    %rbx,%rdx
call   1030 <write_file_to_output@plt>
mov    %rbp,%rdi
call   1040 <fclose@plt>
test   %r14b,%r14b
je     127c <generate_file+0x12c>
test   %rbx,%rbx
je     127c <generate_file+0x12c>
mov    %rbx,%rdi
call   1040 <fclose@plt>
add    $0x180,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%s.i0\00"
@.str.1 = [6 x i8] c"%s.i1\00"
@.str.2 = [6 x i8] c"%s.i2\00"
@.str.3 = [6 x i8] c"%s.i3\00"
@.str.4 = [13 x i8] c"%s-defines.h\00"
@.str.5 = [3 x i8] c"w+\00"
@.str.6 = [33 x i8] c"Could not create %s for output.\0A\00"
define void @generate_file(i8* %0, i8* %1, i8 signext %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8
%7 = alloca [64 x i8]
%8 = alloca [64 x i8]
%9 = alloca [64 x i8]
%10 = alloca [64 x i8]
%11 = alloca [128 x i8]
%12 = alloca i32*
%13 = alloca i32*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8 %2, i8* %6
%14 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%15 = load i8*, i8** %4
%16 = call i32 @sprintf(i8* %14, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = getelementptr inbounds [64 x i8], [64 x i8]* %8, i64 0, i64 0
%18 = load i8*, i8** %4
%19 = call i32 @sprintf(i8* %17, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %18)
%20 = getelementptr inbounds [64 x i8], [64 x i8]* %9, i64 0, i64 0
%21 = load i8*, i8** %4
%22 = call i32 @sprintf(i8* %20, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %21)
%23 = getelementptr inbounds [64 x i8], [64 x i8]* %10, i64 0, i64 0
%24 = load i8*, i8** %4
%25 = call i32 @sprintf(i8* %23, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %24)
%26 = getelementptr inbounds [128 x i8], [128 x i8]* %11, i64 0, i64 0
%27 = load i8*, i8** %5
%28 = call i32 @sprintf(i8* %26, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i8* %27)
%29 = load i8*, i8** %5
%30 = call i32* @fopen(i8* %29, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
store i32* %30, i32** %12
%31 = load i32*, i32** %12
%32 = icmp ne i32* %31, null
br i1 %32, label %36, label %33
33: ; preds = %3
%34 = load i8*, i8** %5
%35 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.6, i64 0, i64 0), i8* %34)
br label %70
36: ; preds = %3
%37 = load i8, i8* %6
%38 = icmp ne i8 %37, 0
br i1 %38, label %39, label %42
39: ; preds = %36
%40 = getelementptr inbounds [128 x i8], [128 x i8]* %11, i64 0, i64 0
%41 = call i32* @fopen(i8* %40, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
store i32* %41, i32** %13
br label %42
42: ; preds = %39, %36
%43 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%44 = load i32*, i32** %12
%45 = load i32*, i32** %13
%46 = call i32 @write_file_to_output(i8* %43, i32* %44, i32* %45)
%47 = getelementptr inbounds [64 x i8], [64 x i8]* %8, i64 0, i64 0
%48 = load i32*, i32** %12
%49 = load i32*, i32** %13
%50 = call i32 @write_file_to_output(i8* %47, i32* %48, i32* %49)
%51 = getelementptr inbounds [64 x i8], [64 x i8]* %9, i64 0, i64 0
%52 = load i32*, i32** %12
%53 = load i32*, i32** %13
%54 = call i32 @write_file_to_output(i8* %51, i32* %52, i32* %53)
%55 = getelementptr inbounds [64 x i8], [64 x i8]* %10, i64 0, i64 0
%56 = load i32*, i32** %12
%57 = load i32*, i32** %13
%58 = call i32 @write_file_to_output(i8* %55, i32* %56, i32* %57)
%59 = load i32*, i32** %12
%60 = call i32 @fclose(i32* %59)
%61 = load i8, i8* %6
%62 = sext i8 %61 to i32
%63 = icmp ne i32 %62, 0
br i1 %63, label %64, label %70
64: ; preds = %42
%65 = load i32*, i32** %13
%66 = icmp ne i32* %65, null
br i1 %66, label %67, label %70
67: ; preds = %64
%68 = load i32*, i32** %13
%69 = call i32 @fclose(i32* %68)
br label %70
70: ; preds = %33, %67, %64, %42
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c"%s.i0\00"
@.str.1 = [6 x i8] c"%s.i1\00"
@.str.2 = [6 x i8] c"%s.i2\00"
@.str.3 = [6 x i8] c"%s.i3\00"
@.str.4 = [13 x i8] c"%s-defines.h\00"
@.str.5 = [3 x i8] c"w+\00"
@.str.6 = [33 x i8] c"Could not create %s for output.\0A\00"
define void @generate_file(i8* %0, i8* %1, i8 signext %2) {
%4 = alloca [64 x i8]
%5 = alloca [64 x i8]
%6 = alloca [64 x i8]
%7 = alloca [64 x i8]
%8 = alloca [128 x i8]
%9 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%10 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%11 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
%12 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%13 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%14 = call i32 @sprintf(i8* %9, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %0)
%15 = call i32 @sprintf(i8* %10, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%16 = call i32 @sprintf(i8* %11, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %0)
%17 = call i32 @sprintf(i8* %12, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %0)
%18 = call i32 @sprintf(i8* %13, i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i8* %1)
%19 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %23
21: ; preds = %3
%22 = tail call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.6, i64 0, i64 0), i8* %1)
br label %39
23: ; preds = %3
%24 = icmp eq i8 %2, 0
br i1 %24, label %27, label %25
25: ; preds = %23
%26 = call i32* @fopen(i8* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
br label %27
27: ; preds = %25, %23
%28 = phi i32* [ %26, %25 ], [ undef, %23 ]
%29 = call i32 @write_file_to_output(i8* %9, i32* %19, i32* %28)
%30 = call i32 @write_file_to_output(i8* %10, i32* %19, i32* %28)
%31 = call i32 @write_file_to_output(i8* %11, i32* %19, i32* %28)
%32 = call i32 @write_file_to_output(i8* %12, i32* %19, i32* %28)
%33 = call i32 @fclose(i32* %19)
%34 = icmp ne i8 %2, 0
%35 = icmp ne i32* %28, null
%36 = and i1 %34, %35
br i1 %36, label %37, label %39
37: ; preds = %27
%38 = call i32 @fclose(i32* %28)
br label %39
39: ; preds = %27, %37, %21
ret void
}