#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 fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int genC(int, int, int, int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ sprintf(char *, char *, int, int, int);
int create_source(int max_so, int max_chain, int max_depth) {
  int i, j, k, rval;
  FILE *fp, *fp_header;
  char filename[100];
  fp_header = fopen("FOO.h", "w+");
  for (i = 0; i < max_so; i++) {
    for (j = 0; j < max_chain; j++) {
      for (k = 0; k < max_depth; k++) {
        sprintf(filename, "FOO_%03d_%03d_%03d.c", i, j, k);
        fp = fopen(filename, "w+");
        rval = genC(i, j, k, fp, fp_header);
        rval = fclose(fp);
      }
    }
  }
  rval = fclose(fp_header);
  return 0;
}


x86 assembly (clang, -O0):
<create_source>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
lea    0xea5(%rip),%rdi
lea    0xea4(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1231 <create_source+0xf1>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    121e <create_source+0xde>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    120b <create_source+0xcb>
lea    -0xa0(%rbp),%rdi
mov    -0x10(%rbp),%edx
mov    -0x14(%rbp),%ecx
mov    -0x18(%rbp),%r8d
lea    0xe4d(%rip),%rsi
call   1060 <sprintf@plt>
lea    -0xa0(%rbp),%rdi
lea    0xe37(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%edi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x28(%rbp),%rcx
mov    -0x30(%rbp),%r8
call   1040 <genC@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1198 <create_source+0x58>
jmp    1210 <create_source+0xd0>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1185 <create_source+0x45>
jmp    1223 <create_source+0xe3>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1172 <create_source+0x32>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
mov    %eax,-0x1c(%rbp)
xor    %eax,%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_source>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x88,%rsp
mov    %edx,0x10(%rsp)
mov    %esi,0x8(%rsp)
mov    %edi,%ebx
lea    0xe9e(%rip),%rdi
lea    0xe9d(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,0x18(%rsp)
mov    %ebx,0x14(%rsp)
test   %ebx,%ebx
jle    1246 <create_source+0x106>
xor    %eax,%eax
lea    0xe81(%rip),%r14
lea    0x20(%rsp),%rbx
lea    0xe72(%rip),%r12
jmp    11b1 <create_source+0x71>
cs nopw 0x0(%rax,%rax,1)
mov    0xc(%rsp),%eax
add    $0x1,%eax
cmp    0x14(%rsp),%eax
je     1246 <create_source+0x106>
mov    %eax,0xc(%rsp)
cmpl   $0x0,0x8(%rsp)
jle    11a0 <create_source+0x60>
xor    %r13d,%r13d
jmp    11db <create_source+0x9b>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%r13d
cmp    0x8(%rsp),%r13d
je     11a0 <create_source+0x60>
cmpl   $0x0,0x10(%rsp)
mov    0xc(%rsp),%ebp
jle    11d0 <create_source+0x90>
xor    %r15d,%r15d
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
mov    %r13d,%ecx
mov    %r15d,%r8d
call   1060 <sprintf@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1050 <fopen@plt>
mov    %r12,%rbx
mov    %rax,%r12
mov    %ebp,%edi
mov    %r13d,%esi
mov    %r15d,%edx
mov    %rax,%rcx
mov    0x18(%rsp),%r8
call   1040 <genC@plt>
mov    %r12,%rdi
mov    %rbx,%r12
lea    0x20(%rsp),%rbx
call   1030 <fclose@plt>
add    $0x1,%r15d
cmp    %r15d,0x10(%rsp)
jne    11f0 <create_source+0xb0>
jmp    11d0 <create_source+0x90>
mov    0x18(%rsp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x88,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"FOO.h\00"
@.str.1 = [3 x i8] c"w+\00"
@.str.2 = [21 x i8] c"FOO_%03d_%03d_%03d.c\00"
define i32 @create_source(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32*
%12 = alloca i32*
%13 = alloca [100 x i8]
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%14 = call i32* @fopen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %14, i32** %12
store i32 0, i32* %7
br label %15
15: ; preds = %53, %3
%16 = load i32, i32* %7
%17 = load i32, i32* %4
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %56
19: ; preds = %15
store i32 0, i32* %8
br label %20
20: ; preds = %49, %19
%21 = load i32, i32* %8
%22 = load i32, i32* %5
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %52
24: ; preds = %20
store i32 0, i32* %9
br label %25
25: ; preds = %45, %24
%26 = load i32, i32* %9
%27 = load i32, i32* %6
%28 = icmp slt i32 %26, %27
br i1 %28, label %29, label %48
29: ; preds = %25
%30 = getelementptr inbounds [100 x i8], [100 x i8]* %13, i64 0, i64 0
%31 = load i32, i32* %7
%32 = load i32, i32* %8
%33 = load i32, i32* %9
%34 = call i32 @sprintf(i8* %30, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 %31, i32 %32, i32 %33)
%35 = getelementptr inbounds [100 x i8], [100 x i8]* %13, i64 0, i64 0
%36 = call i32* @fopen(i8* %35, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %36, i32** %11
%37 = load i32, i32* %7
%38 = load i32, i32* %8
%39 = load i32, i32* %9
%40 = load i32*, i32** %11
%41 = load i32*, i32** %12
%42 = call i32 @genC(i32 %37, i32 %38, i32 %39, i32* %40, i32* %41)
store i32 %42, i32* %10
%43 = load i32*, i32** %11
%44 = call i32 @fclose(i32* %43)
store i32 %44, i32* %10
br label %45
45: ; preds = %29
%46 = load i32, i32* %9
%47 = add nsw i32 %46, 1
store i32 %47, i32* %9
br label %25
48: ; preds = %25
br label %49
49: ; preds = %48
%50 = load i32, i32* %8
%51 = add nsw i32 %50, 1
store i32 %51, i32* %8
br label %20
52: ; preds = %20
br label %53
53: ; preds = %52
%54 = load i32, i32* %7
%55 = add nsw i32 %54, 1
store i32 %55, i32* %7
br label %15
56: ; preds = %15
%57 = load i32*, i32** %12
%58 = call i32 @fclose(i32* %57)
store i32 %58, i32* %10
ret i32 0
}

LLVM IR (-O2):
@.str = [6 x i8] c"FOO.h\00"
@.str.1 = [3 x i8] c"w+\00"
@.str.2 = [21 x i8] c"FOO_%03d_%03d_%03d.c\00"
define i32 @create_source(i32 %0, i32 %1, i32 %2) {
%4 = alloca [100 x i8]
%5 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%6 = tail call i32* @fopen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%7 = icmp sgt i32 %0, 0
br i1 %7, label %8, label %29
8: ; preds = %3
%9 = icmp sgt i32 %1, 0
%10 = icmp sgt i32 %2, 0
br label %11
11: ; preds = %8, %26
%12 = phi i32 [ 0, %8 ], [ %27, %26 ]
br i1 %9, label %13, label %26
13: ; preds = %11, %23
%14 = phi i32 [ %24, %23 ], [ 0, %11 ]
br i1 %10, label %15, label %23
15: ; preds = %13, %15
%16 = phi i32 [ %21, %15 ], [ 0, %13 ]
%17 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 %12, i32 %14, i32 %16)
%18 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%19 = tail call i32 @genC(i32 %12, i32 %14, i32 %16, i32* %18, i32* %6)
%20 = tail call i32 @fclose(i32* %18)
%21 = add nuw nsw i32 %16, 1
%22 = icmp eq i32 %21, %2
br i1 %22, label %23, label %15
23: ; preds = %15, %13
%24 = add nuw nsw i32 %14, 1
%25 = icmp eq i32 %24, %1
br i1 %25, label %26, label %13
26: ; preds = %23, %11
%27 = add nuw nsw i32 %12, 1
%28 = icmp eq i32 %27, %0
br i1 %28, label %29, label %11
29: ; preds = %26, %3
%30 = tail call i32 @fclose(i32* %6)
ret i32 0
}