#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 /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, 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+");
  fprintf(fp_header, "typedef long (*FOO_pt) (long);\n");
  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    0xe95(%rip),%rdi
lea    0xe94(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
lea    0xe83(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1251 <create_source+0x101>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    123e <create_source+0xee>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    122b <create_source+0xdb>
lea    -0xa0(%rbp),%rdi
mov    -0x10(%rbp),%edx
mov    -0x14(%rbp),%ecx
mov    -0x18(%rbp),%r8d
lea    0xe4d(%rip),%rsi
call   1070 <sprintf@plt>
lea    -0xa0(%rbp),%rdi
lea    0xe17(%rip),%rsi
call   1060 <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    11b8 <create_source+0x68>
jmp    1230 <create_source+0xe0>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11a5 <create_source+0x55>
jmp    1243 <create_source+0xf3>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1192 <create_source+0x42>
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    0xe8e(%rip),%rdi
lea    0xe8d(%rip),%rsi
call   1050 <fopen@plt>
lea    0xe84(%rip),%rdi
mov    $0x1f,%esi
mov    $0x1,%edx
mov    %rax,0x18(%rsp)
mov    %rax,%rcx
call   1070 <fwrite@plt>
mov    %ebx,0x14(%rsp)
test   %ebx,%ebx
jle    1266 <create_source+0x116>
xor    %eax,%eax
lea    0xe78(%rip),%r14
lea    0x20(%rsp),%rbx
lea    0xe49(%rip),%r12
jmp    11d1 <create_source+0x81>
nop
mov    0xc(%rsp),%eax
add    $0x1,%eax
cmp    0x14(%rsp),%eax
je     1266 <create_source+0x116>
mov    %eax,0xc(%rsp)
cmpl   $0x0,0x8(%rsp)
jle    11c0 <create_source+0x70>
xor    %r13d,%r13d
jmp    11fb <create_source+0xab>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%r13d
cmp    0x8(%rsp),%r13d
je     11c0 <create_source+0x70>
cmpl   $0x0,0x10(%rsp)
mov    0xc(%rsp),%ebp
jle    11f0 <create_source+0xa0>
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    1210 <create_source+0xc0>
jmp    11f0 <create_source+0xa0>
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 = [32 x i8] c"typedef long (*FOO_pt) (long);\0A\00"
@.str.3 = [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
%15 = load i32*, i32** %12
%16 = call i32 @fprintf(i32* %15, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %7
br label %17
17: ; preds = %55, %3
%18 = load i32, i32* %7
%19 = load i32, i32* %4
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %58
21: ; preds = %17
store i32 0, i32* %8
br label %22
22: ; preds = %51, %21
%23 = load i32, i32* %8
%24 = load i32, i32* %5
%25 = icmp slt i32 %23, %24
br i1 %25, label %26, label %54
26: ; preds = %22
store i32 0, i32* %9
br label %27
27: ; preds = %47, %26
%28 = load i32, i32* %9
%29 = load i32, i32* %6
%30 = icmp slt i32 %28, %29
br i1 %30, label %31, label %50
31: ; preds = %27
%32 = getelementptr inbounds [100 x i8], [100 x i8]* %13, i64 0, i64 0
%33 = load i32, i32* %7
%34 = load i32, i32* %8
%35 = load i32, i32* %9
%36 = call i32 @sprintf(i8* %32, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32 %33, i32 %34, i32 %35)
%37 = getelementptr inbounds [100 x i8], [100 x i8]* %13, i64 0, i64 0
%38 = call i32* @fopen(i8* %37, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %38, i32** %11
%39 = load i32, i32* %7
%40 = load i32, i32* %8
%41 = load i32, i32* %9
%42 = load i32*, i32** %11
%43 = load i32*, i32** %12
%44 = call i32 @genC(i32 %39, i32 %40, i32 %41, i32* %42, i32* %43)
store i32 %44, i32* %10
%45 = load i32*, i32** %11
%46 = call i32 @fclose(i32* %45)
store i32 %46, i32* %10
br label %47
47: ; preds = %31
%48 = load i32, i32* %9
%49 = add nsw i32 %48, 1
store i32 %49, i32* %9
br label %27
50: ; preds = %27
br label %51
51: ; preds = %50
%52 = load i32, i32* %8
%53 = add nsw i32 %52, 1
store i32 %53, i32* %8
br label %22
54: ; preds = %22
br label %55
55: ; preds = %54
%56 = load i32, i32* %7
%57 = add nsw i32 %56, 1
store i32 %57, i32* %7
br label %17
58: ; preds = %17
%59 = load i32*, i32** %12
%60 = call i32 @fclose(i32* %59)
store i32 %60, 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 = [32 x i8] c"typedef long (*FOO_pt) (long);\0A\00"
@.str.3 = [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 = tail call i64 @fwrite(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i64 31, i64 1, i32* %6)
%8 = icmp sgt i32 %0, 0
br i1 %8, label %9, label %30
9: ; preds = %3
%10 = icmp sgt i32 %1, 0
%11 = icmp sgt i32 %2, 0
br label %12
12: ; preds = %9, %27
%13 = phi i32 [ 0, %9 ], [ %28, %27 ]
br i1 %10, label %14, label %27
14: ; preds = %12, %24
%15 = phi i32 [ %25, %24 ], [ 0, %12 ]
br i1 %11, label %16, label %24
16: ; preds = %14, %16
%17 = phi i32 [ %22, %16 ], [ 0, %14 ]
%18 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32 %13, i32 %15, i32 %17)
%19 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%20 = tail call i32 @genC(i32 %13, i32 %15, i32 %17, i32* %19, i32* %6)
%21 = tail call i32 @fclose(i32* %19)
%22 = add nuw nsw i32 %17, 1
%23 = icmp eq i32 %22, %2
br i1 %23, label %24, label %16
24: ; preds = %16, %14
%25 = add nuw nsw i32 %15, 1
%26 = icmp eq i32 %25, %1
br i1 %26, label %27, label %14
27: ; preds = %24, %12
%28 = add nuw nsw i32 %13, 1
%29 = icmp eq i32 %28, %0
br i1 %29, label %30, label %12
30: ; preds = %27, %3
%31 = tail call i32 @fclose(i32* %6)
ret i32 0
}