#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 create_main(int max_so, int max_chain, int max_depth) {
  int i, j, k, rval;
  FILE *fp_main;
  char filename[100];
  fp_main = fopen("FOO_main.c", "w+");
  fprintf(fp_main, "//\n");
  fprintf(fp_main, "//\n");
  fprintf(fp_main, "#include <stdio.h>\n");
  fprintf(fp_main, "#include <stdlib.h>\n");
  fprintf(fp_main, "#include \"FOO.h\"\n");
  fprintf(fp_main, "\n");
  fprintf(fp_main, "int main(int argc, char* argv[])\n");
  fprintf(fp_main, "{\n");
  fprintf(fp_main, "\tlong i=0;\n");
  fprintf(fp_main, "\tlong j,k;\n");
  fprintf(fp_main, "\tj=atol(argv[1]);\n");
  fprintf(fp_main, "\tfor(k=0;k<j;k++){\n");
  for (j = 0; j < max_chain; j++) {
    for (i = 0; i < max_so; i++) {
      fprintf(fp_main, "\t\tFOO_%03d_%03d_000(i);\n", i, j);
      fprintf(fp_main, "\t\ti+=1000;\n");
    }
  }
  fprintf(fp_main, "\t}\n");
  fprintf(fp_main, "\n");
  fprintf(fp_main, "\treturn 0;\n");
  fprintf(fp_main, "}\n");
  rval = fclose(fp_main);
  return 0;
}


x86 assembly (clang, -O0):
<create_main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
lea    0xeb5(%rip),%rdi
lea    0xeb9(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
lea    0xea8(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x28(%rbp),%rdi
lea    0xe96(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x28(%rbp),%rdi
lea    0xe88(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x28(%rbp),%rdi
lea    0xe8a(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x28(%rbp),%rdi
lea    0xe8d(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x28(%rbp),%rdi
lea    0xe8b(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x28(%rbp),%rdi
lea    0xe7b(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x28(%rbp),%rdi
lea    0xec7(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x28(%rbp),%rdi
lea    0xe79(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x28(%rbp),%rdi
lea    0xe73(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x28(%rbp),%rdi
lea    0xe6d(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x28(%rbp),%rdi
lea    0xe6e(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    12a4 <create_main+0x174>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1291 <create_main+0x161>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%edx
mov    -0x14(%rbp),%ecx
lea    0xe44(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x28(%rbp),%rdi
lea    0xe4b(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    124d <create_main+0x11d>
jmp    1296 <create_main+0x166>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    123a <create_main+0x10a>
mov    -0x28(%rbp),%rdi
lea    0xe24(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x28(%rbp),%rdi
lea    0xd8a(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x28(%rbp),%rdi
lea    0xe04(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x28(%rbp),%rdi
lea    0xdef(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
mov    %eax,-0x1c(%rbp)
xor    %eax,%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %edi,%r15d
lea    0xe98(%rip),%rdi
lea    0xe9c(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
lea    0xe90(%rip),%rbp
mov    $0x3,%esi
mov    $0x1,%edx
mov    %rbp,%rdi
mov    %rax,%rcx
call   1070 <fwrite@plt>
mov    $0x3,%esi
mov    $0x1,%edx
mov    %rbp,%rdi
mov    %rbx,%rcx
call   1070 <fwrite@plt>
lea    0xe63(%rip),%rdi
mov    $0x13,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1070 <fwrite@plt>
lea    0xe5e(%rip),%rdi
mov    $0x14,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1070 <fwrite@plt>
lea    0xe5a(%rip),%rdi
mov    $0x11,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1070 <fwrite@plt>
mov    $0xa,%edi
mov    %rbx,%rsi
call   1040 <fputc@plt>
lea    0xe46(%rip),%rdi
mov    $0x21,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1070 <fwrite@plt>
lea    0xe8b(%rip),%rdi
mov    $0x2,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1070 <fwrite@plt>
lea    0xe36(%rip),%rdi
mov    $0xb,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1070 <fwrite@plt>
lea    0xe29(%rip),%rdi
mov    $0xb,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1070 <fwrite@plt>
lea    0xe1c(%rip),%rdi
mov    $0x12,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1070 <fwrite@plt>
lea    0xe16(%rip),%rdi
mov    $0x13,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1070 <fwrite@plt>
mov    %r14d,0x4(%rsp)
test   %r14d,%r14d
jle    1312 <create_main+0x1c2>
lea    0xe07(%rip),%r12
lea    0xe19(%rip),%r13
xor    %ebp,%ebp
jmp    12c9 <create_main+0x179>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0x1,%ebp
cmp    0x4(%rsp),%ebp
je     1312 <create_main+0x1c2>
test   %r15d,%r15d
jle    12c0 <create_main+0x170>
xor    %r14d,%r14d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r14d,%edx
mov    %ebp,%ecx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0xb,%esi
mov    $0x1,%edx
mov    %r13,%rdi
mov    %rbx,%rcx
call   1070 <fwrite@plt>
add    $0x1,%r14d
cmp    %r14d,%r15d
jne    12e0 <create_main+0x190>
jmp    12c0 <create_main+0x170>
lea    0xdba(%rip),%rdi
mov    $0x3,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1070 <fwrite@plt>
mov    $0xa,%edi
mov    %rbx,%rsi
call   1040 <fputc@plt>
lea    0xd98(%rip),%rdi
mov    $0xb,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1070 <fwrite@plt>
lea    0xd7c(%rip),%rdi
mov    $0x2,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1070 <fwrite@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"FOO_main.c\00"
@.str.1 = [3 x i8] c"w+\00"
@.str.2 = [4 x i8] c"//\0A\00"
@.str.3 = [20 x i8] c"#include <stdio.h>\0A\00"
@.str.4 = [21 x i8] c"#include <stdlib.h>\0A\00"
@.str.5 = [18 x i8] c"#include \22FOO.h\22\0A\00"
@.str.6 = [2 x i8] c"\0A\00"
@.str.7 = [34 x i8] c"int main(int argc, char* argv[])\0A\00"
@.str.8 = [3 x i8] c"{\0A\00"
@.str.9 = [12 x i8] c"\09long i=0;\0A\00"
@.str.10 = [12 x i8] c"\09long j,k;\0A\00"
@.str.11 = [19 x i8] c"\09j=atol(argv[1]);\0A\00"
@.str.12 = [20 x i8] c"\09for(k=0;k<j;k++){\0A\00"
@.str.13 = [25 x i8] c"\09\09FOO_%03d_%03d_000(i);\0A\00"
@.str.14 = [12 x i8] c"\09\09i+=1000;\0A\00"
@.str.15 = [4 x i8] c"\09}\0A\00"
@.str.16 = [12 x i8] c"\09return 0;\0A\00"
@.str.17 = [3 x i8] c"}\0A\00"
define i32 @create_main(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 [100 x i8]
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%13 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %13, i32** %11
%14 = load i32*, i32** %11
%15 = call i32 (i32*, i8*, ...) @fprintf(i32* %14, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%16 = load i32*, i32** %11
%17 = call i32 (i32*, i8*, ...) @fprintf(i32* %16, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%18 = load i32*, i32** %11
%19 = call i32 (i32*, i8*, ...) @fprintf(i32* %18, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
%20 = load i32*, i32** %11
%21 = call i32 (i32*, i8*, ...) @fprintf(i32* %20, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0))
%22 = load i32*, i32** %11
%23 = call i32 (i32*, i8*, ...) @fprintf(i32* %22, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0))
%24 = load i32*, i32** %11
%25 = call i32 (i32*, i8*, ...) @fprintf(i32* %24, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%26 = load i32*, i32** %11
%27 = call i32 (i32*, i8*, ...) @fprintf(i32* %26, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.7, i64 0, i64 0))
%28 = load i32*, i32** %11
%29 = call i32 (i32*, i8*, ...) @fprintf(i32* %28, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0))
%30 = load i32*, i32** %11
%31 = call i32 (i32*, i8*, ...) @fprintf(i32* %30, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.9, i64 0, i64 0))
%32 = load i32*, i32** %11
%33 = call i32 (i32*, i8*, ...) @fprintf(i32* %32, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.10, i64 0, i64 0))
%34 = load i32*, i32** %11
%35 = call i32 (i32*, i8*, ...) @fprintf(i32* %34, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.11, i64 0, i64 0))
%36 = load i32*, i32** %11
%37 = call i32 (i32*, i8*, ...) @fprintf(i32* %36, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.12, i64 0, i64 0))
store i32 0, i32* %8
br label %38
38: ; preds = %58, %3
%39 = load i32, i32* %8
%40 = load i32, i32* %5
%41 = icmp slt i32 %39, %40
br i1 %41, label %42, label %61
42: ; preds = %38
store i32 0, i32* %7
br label %43
43: ; preds = %54, %42
%44 = load i32, i32* %7
%45 = load i32, i32* %4
%46 = icmp slt i32 %44, %45
br i1 %46, label %47, label %57
47: ; preds = %43
%48 = load i32*, i32** %11
%49 = load i32, i32* %7
%50 = load i32, i32* %8
%51 = call i32 (i32*, i8*, ...) @fprintf(i32* %48, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.13, i64 0, i64 0), i32 %49, i32 %50)
%52 = load i32*, i32** %11
%53 = call i32 (i32*, i8*, ...) @fprintf(i32* %52, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.14, i64 0, i64 0))
br label %54
54: ; preds = %47
%55 = load i32, i32* %7
%56 = add nsw i32 %55, 1
store i32 %56, i32* %7
br label %43
57: ; preds = %43
br label %58
58: ; preds = %57
%59 = load i32, i32* %8
%60 = add nsw i32 %59, 1
store i32 %60, i32* %8
br label %38
61: ; preds = %38
%62 = load i32*, i32** %11
%63 = call i32 (i32*, i8*, ...) @fprintf(i32* %62, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.15, i64 0, i64 0))
%64 = load i32*, i32** %11
%65 = call i32 (i32*, i8*, ...) @fprintf(i32* %64, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%66 = load i32*, i32** %11
%67 = call i32 (i32*, i8*, ...) @fprintf(i32* %66, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.16, i64 0, i64 0))
%68 = load i32*, i32** %11
%69 = call i32 (i32*, i8*, ...) @fprintf(i32* %68, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.17, i64 0, i64 0))
%70 = load i32*, i32** %11
%71 = call i32 @fclose(i32* %70)
store i32 %71, i32* %10
ret i32 0
}

LLVM IR (-O2):
@.str = [11 x i8] c"FOO_main.c\00"
@.str.1 = [3 x i8] c"w+\00"
@.str.2 = [4 x i8] c"//\0A\00"
@.str.3 = [20 x i8] c"#include <stdio.h>\0A\00"
@.str.4 = [21 x i8] c"#include <stdlib.h>\0A\00"
@.str.5 = [18 x i8] c"#include \22FOO.h\22\0A\00"
@.str.7 = [34 x i8] c"int main(int argc, char* argv[])\0A\00"
@.str.8 = [3 x i8] c"{\0A\00"
@.str.9 = [12 x i8] c"\09long i=0;\0A\00"
@.str.10 = [12 x i8] c"\09long j,k;\0A\00"
@.str.11 = [19 x i8] c"\09j=atol(argv[1]);\0A\00"
@.str.12 = [20 x i8] c"\09for(k=0;k<j;k++){\0A\00"
@.str.13 = [25 x i8] c"\09\09FOO_%03d_%03d_000(i);\0A\00"
@.str.14 = [12 x i8] c"\09\09i+=1000;\0A\00"
@.str.15 = [4 x i8] c"\09}\0A\00"
@.str.16 = [12 x i8] c"\09return 0;\0A\00"
@.str.17 = [3 x i8] c"}\0A\00"
define i32 @create_main(i32 %0, i32 %1, i32 %2) {
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%5 = tail call i64 @fwrite(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i64 3, i64 1, i32* %4)
%6 = tail call i64 @fwrite(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i64 3, i64 1, i32* %4)
%7 = tail call i64 @fwrite(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i64 19, i64 1, i32* %4)
%8 = tail call i64 @fwrite(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i64 20, i64 1, i32* %4)
%9 = tail call i64 @fwrite(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i64 17, i64 1, i32* %4)
%10 = tail call i32 @fputc(i32 10, i32* %4)
%11 = tail call i64 @fwrite(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.7, i64 0, i64 0), i64 33, i64 1, i32* %4)
%12 = tail call i64 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i64 2, i64 1, i32* %4)
%13 = tail call i64 @fwrite(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.9, i64 0, i64 0), i64 11, i64 1, i32* %4)
%14 = tail call i64 @fwrite(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.10, i64 0, i64 0), i64 11, i64 1, i32* %4)
%15 = tail call i64 @fwrite(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.11, i64 0, i64 0), i64 18, i64 1, i32* %4)
%16 = tail call i64 @fwrite(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.12, i64 0, i64 0), i64 19, i64 1, i32* %4)
%17 = icmp sgt i32 %1, 0
br i1 %17, label %18, label %31
18: ; preds = %3
%19 = icmp sgt i32 %0, 0
br label %20
20: ; preds = %18, %28
%21 = phi i32 [ 0, %18 ], [ %29, %28 ]
br i1 %19, label %22, label %28
22: ; preds = %20, %22
%23 = phi i32 [ %26, %22 ], [ 0, %20 ]
%24 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %4, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.13, i64 0, i64 0), i32 %23, i32 %21)
%25 = tail call i64 @fwrite(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.14, i64 0, i64 0), i64 11, i64 1, i32* %4)
%26 = add nuw nsw i32 %23, 1
%27 = icmp eq i32 %26, %0
br i1 %27, label %28, label %22
28: ; preds = %22, %20
%29 = add nuw nsw i32 %21, 1
%30 = icmp eq i32 %29, %1
br i1 %30, label %31, label %20
31: ; preds = %28, %3
%32 = tail call i64 @fwrite(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.15, i64 0, i64 0), i64 3, i64 1, i32* %4)
%33 = tail call i32 @fputc(i32 10, i32* %4)
%34 = tail call i64 @fwrite(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.16, i64 0, i64 0), i64 11, i64 1, i32* %4)
%35 = tail call i64 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.17, i64 0, i64 0), i64 2, i64 1, i32* %4)
%36 = tail call i32 @fclose(i32* %4)
ret i32 0
}