#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 *);
int /*<<< orphan*/ get_rand(int *, int);
int /*<<< orphan*/ sprintf(char *, char *, int, int, int);
int create_source(int max_so, int max_chain, int max_depth, int *rand_array) {
  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,long);\n");
  for (i = 0; i < max_so; i++) {
    for (j = 0; j < max_chain; j++) {
      get_rand(rand_array, max_depth);
      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, rand_array);
        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)
mov    %rcx,-0x18(%rbp)
lea    0xe81(%rip),%rdi
lea    0xe80(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
lea    0xe6f(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1275 <create_source+0x115>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1262 <create_source+0x102>
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1040 <get_rand@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    124f <create_source+0xef>
lea    -0xa0(%rbp),%rdi
mov    -0x1c(%rbp),%edx
mov    -0x20(%rbp),%ecx
mov    -0x24(%rbp),%r8d
lea    0xe32(%rip),%rsi
call   1080 <sprintf@plt>
lea    -0xa0(%rbp),%rdi
lea    0xdf7(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x1c(%rbp),%edi
mov    -0x20(%rbp),%esi
mov    -0x24(%rbp),%edx
mov    -0x30(%rbp),%rcx
mov    -0x38(%rbp),%r8
mov    -0x18(%rbp),%r9
call   1050 <genC@plt>
mov    %eax,-0x28(%rbp)
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11d8 <create_source+0x78>
jmp    1254 <create_source+0xf4>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11b9 <create_source+0x59>
jmp    1267 <create_source+0x107>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11a6 <create_source+0x46>
mov    -0x38(%rbp),%rdi
call   1030 <fclose@plt>
mov    %eax,-0x28(%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    %rcx,%r12
mov    %edx,0x8(%rsp)
mov    %esi,(%rsp)
mov    %edi,%ebx
lea    0xe7c(%rip),%rdi
lea    0xe7b(%rip),%rsi
call   1060 <fopen@plt>
lea    0xe72(%rip),%rdi
mov    $0x24,%esi
mov    $0x1,%edx
mov    %rax,0x10(%rsp)
mov    %rax,%rcx
call   1080 <fwrite@plt>
mov    %ebx,0xc(%rsp)
test   %ebx,%ebx
jle    1290 <create_source+0x130>
xor    %eax,%eax
lea    0xe6b(%rip),%rbx
lea    0x20(%rsp),%r13
lea    0xe37(%rip),%r14
mov    %r12,0x18(%rsp)
jmp    11f1 <create_source+0x91>
cs nopw 0x0(%rax,%rax,1)
mov    0x4(%rsp),%eax
add    $0x1,%eax
cmp    0xc(%rsp),%eax
je     1290 <create_source+0x130>
mov    %eax,0x4(%rsp)
cmpl   $0x0,(%rsp)
jle    11e0 <create_source+0x80>
xor    %r15d,%r15d
jmp    120f <create_source+0xaf>
add    $0x1,%r15d
cmp    (%rsp),%r15d
mov    0x18(%rsp),%r12
je     11e0 <create_source+0x80>
mov    %r12,%rdi
mov    0x8(%rsp),%r12d
mov    %r12d,%esi
call   1040 <get_rand@plt>
test   %r12d,%r12d
mov    0x4(%rsp),%ebp
jle    1200 <create_source+0xa0>
xor    %r12d,%r12d
nopl   0x0(%rax,%rax,1)
mov    %r13,%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
mov    %r15d,%ecx
mov    %r12d,%r8d
call   1070 <sprintf@plt>
mov    %r13,%rdi
mov    %r14,%rsi
call   1060 <fopen@plt>
mov    %r13,%r14
mov    %rax,%r13
mov    %ebp,%edi
mov    %r15d,%esi
mov    %r12d,%edx
mov    %rax,%rcx
mov    0x10(%rsp),%r8
mov    0x18(%rsp),%r9
call   1050 <genC@plt>
mov    %r13,%rdi
mov    %r14,%r13
lea    0xd8b(%rip),%r14
call   1030 <fclose@plt>
add    $0x1,%r12d
cmp    %r12d,0x8(%rsp)
jne    1230 <create_source+0xd0>
jmp    1200 <create_source+0xa0>
mov    0x10(%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 = [37 x i8] c"typedef long (*FOO_pt) (long,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, i32* %3) {
%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 i32*
%14 = alloca i32*
%15 = alloca [100 x i8]
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32* %3, i32** %8
%16 = 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* %16, i32** %14
%17 = load i32*, i32** %14
%18 = call i32 @fprintf(i32* %17, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %9
br label %19
19: ; preds = %61, %4
%20 = load i32, i32* %9
%21 = load i32, i32* %5
%22 = icmp slt i32 %20, %21
br i1 %22, label %23, label %64
23: ; preds = %19
store i32 0, i32* %10
br label %24
24: ; preds = %57, %23
%25 = load i32, i32* %10
%26 = load i32, i32* %6
%27 = icmp slt i32 %25, %26
br i1 %27, label %28, label %60
28: ; preds = %24
%29 = load i32*, i32** %8
%30 = load i32, i32* %7
%31 = call i32 @get_rand(i32* %29, i32 %30)
store i32 0, i32* %11
br label %32
32: ; preds = %53, %28
%33 = load i32, i32* %11
%34 = load i32, i32* %7
%35 = icmp slt i32 %33, %34
br i1 %35, label %36, label %56
36: ; preds = %32
%37 = getelementptr inbounds [100 x i8], [100 x i8]* %15, i64 0, i64 0
%38 = load i32, i32* %9
%39 = load i32, i32* %10
%40 = load i32, i32* %11
%41 = call i32 @sprintf(i8* %37, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32 %38, i32 %39, i32 %40)
%42 = getelementptr inbounds [100 x i8], [100 x i8]* %15, i64 0, i64 0
%43 = call i32* @fopen(i8* %42, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %43, i32** %13
%44 = load i32, i32* %9
%45 = load i32, i32* %10
%46 = load i32, i32* %11
%47 = load i32*, i32** %13
%48 = load i32*, i32** %14
%49 = load i32*, i32** %8
%50 = call i32 @genC(i32 %44, i32 %45, i32 %46, i32* %47, i32* %48, i32* %49)
store i32 %50, i32* %12
%51 = load i32*, i32** %13
%52 = call i32 @fclose(i32* %51)
store i32 %52, i32* %12
br label %53
53: ; preds = %36
%54 = load i32, i32* %11
%55 = add nsw i32 %54, 1
store i32 %55, i32* %11
br label %32
56: ; preds = %32
br label %57
57: ; preds = %56
%58 = load i32, i32* %10
%59 = add nsw i32 %58, 1
store i32 %59, i32* %10
br label %24
60: ; preds = %24
br label %61
61: ; preds = %60
%62 = load i32, i32* %9
%63 = add nsw i32 %62, 1
store i32 %63, i32* %9
br label %19
64: ; preds = %19
%65 = load i32*, i32** %14
%66 = call i32 @fclose(i32* %65)
store i32 %66, i32* %12
ret i32 0
}

LLVM IR (-O2):
@.str = [6 x i8] c"FOO.h\00"
@.str.1 = [3 x i8] c"w+\00"
@.str.2 = [37 x i8] c"typedef long (*FOO_pt) (long,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, i32* %3) {
%5 = alloca [100 x i8]
%6 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%7 = 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))
%8 = tail call i64 @fwrite(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i64 36, i64 1, i32* %7)
%9 = icmp sgt i32 %0, 0
br i1 %9, label %10, label %32
10: ; preds = %4
%11 = icmp sgt i32 %1, 0
%12 = icmp sgt i32 %2, 0
br label %13
13: ; preds = %10, %29
%14 = phi i32 [ 0, %10 ], [ %30, %29 ]
br i1 %11, label %15, label %29
15: ; preds = %13, %26
%16 = phi i32 [ %27, %26 ], [ 0, %13 ]
%17 = tail call i32 @get_rand(i32* %3, i32 %2)
br i1 %12, label %18, label %26
18: ; preds = %15, %18
%19 = phi i32 [ %24, %18 ], [ 0, %15 ]
%20 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32 %14, i32 %16, i32 %19)
%21 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%22 = tail call i32 @genC(i32 %14, i32 %16, i32 %19, i32* %21, i32* %7, i32* %3)
%23 = tail call i32 @fclose(i32* %21)
%24 = add nuw nsw i32 %19, 1
%25 = icmp eq i32 %24, %2
br i1 %25, label %26, label %18
26: ; preds = %18, %15
%27 = add nuw nsw i32 %16, 1
%28 = icmp eq i32 %27, %1
br i1 %28, label %29, label %15
29: ; preds = %26, %13
%30 = add nuw nsw i32 %14, 1
%31 = icmp eq i32 %30, %0
br i1 %31, label %32, label %13
32: ; preds = %29, %4
%33 = tail call i32 @fclose(i32* %7)
ret i32 0
}