#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 *);
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+");
  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    0xe91(%rip),%rdi
lea    0xe90(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1255 <create_source+0x105>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1242 <create_source+0xf2>
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    122f <create_source+0xdf>
lea    -0xa0(%rbp),%rdi
mov    -0x1c(%rbp),%edx
mov    -0x20(%rbp),%ecx
mov    -0x24(%rbp),%r8d
lea    0xe2d(%rip),%rsi
call   1070 <sprintf@plt>
lea    -0xa0(%rbp),%rdi
lea    0xe17(%rip),%rsi
call   1060 <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    11b8 <create_source+0x68>
jmp    1234 <create_source+0xe4>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1199 <create_source+0x49>
jmp    1247 <create_source+0xf7>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1186 <create_source+0x36>
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    0xe8c(%rip),%rdi
lea    0xe8b(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,0x10(%rsp)
mov    %ebx,0xc(%rsp)
test   %ebx,%ebx
jle    1260 <create_source+0x110>
xor    %eax,%eax
lea    0xe6f(%rip),%rbx
lea    0x20(%rsp),%r13
lea    0xe60(%rip),%r14
mov    %r12,0x18(%rsp)
jmp    11c1 <create_source+0x71>
nopl   (%rax)
mov    0x4(%rsp),%eax
add    $0x1,%eax
cmp    0xc(%rsp),%eax
je     1260 <create_source+0x110>
mov    %eax,0x4(%rsp)
cmpl   $0x0,(%rsp)
jle    11b0 <create_source+0x60>
xor    %r15d,%r15d
jmp    11df <create_source+0x8f>
add    $0x1,%r15d
cmp    (%rsp),%r15d
mov    0x18(%rsp),%r12
je     11b0 <create_source+0x60>
mov    %r12,%rdi
mov    0x8(%rsp),%r12d
mov    %r12d,%esi
call   1040 <get_rand@plt>
test   %r12d,%r12d
mov    0x4(%rsp),%ebp
jle    11d0 <create_source+0x80>
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    0xdbb(%rip),%r14
call   1030 <fclose@plt>
add    $0x1,%r12d
cmp    %r12d,0x8(%rsp)
jne    1200 <create_source+0xb0>
jmp    11d0 <create_source+0x80>
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 = [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
store i32 0, i32* %9
br label %17
17: ; preds = %59, %4
%18 = load i32, i32* %9
%19 = load i32, i32* %5
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %62
21: ; preds = %17
store i32 0, i32* %10
br label %22
22: ; preds = %55, %21
%23 = load i32, i32* %10
%24 = load i32, i32* %6
%25 = icmp slt i32 %23, %24
br i1 %25, label %26, label %58
26: ; preds = %22
%27 = load i32*, i32** %8
%28 = load i32, i32* %7
%29 = call i32 @get_rand(i32* %27, i32 %28)
store i32 0, i32* %11
br label %30
30: ; preds = %51, %26
%31 = load i32, i32* %11
%32 = load i32, i32* %7
%33 = icmp slt i32 %31, %32
br i1 %33, label %34, label %54
34: ; preds = %30
%35 = getelementptr inbounds [100 x i8], [100 x i8]* %15, i64 0, i64 0
%36 = load i32, i32* %9
%37 = load i32, i32* %10
%38 = load i32, i32* %11
%39 = call i32 @sprintf(i8* %35, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 %36, i32 %37, i32 %38)
%40 = getelementptr inbounds [100 x i8], [100 x i8]* %15, i64 0, i64 0
%41 = call i32* @fopen(i8* %40, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %41, i32** %13
%42 = load i32, i32* %9
%43 = load i32, i32* %10
%44 = load i32, i32* %11
%45 = load i32*, i32** %13
%46 = load i32*, i32** %14
%47 = load i32*, i32** %8
%48 = call i32 @genC(i32 %42, i32 %43, i32 %44, i32* %45, i32* %46, i32* %47)
store i32 %48, i32* %12
%49 = load i32*, i32** %13
%50 = call i32 @fclose(i32* %49)
store i32 %50, i32* %12
br label %51
51: ; preds = %34
%52 = load i32, i32* %11
%53 = add nsw i32 %52, 1
store i32 %53, i32* %11
br label %30
54: ; preds = %30
br label %55
55: ; preds = %54
%56 = load i32, i32* %10
%57 = add nsw i32 %56, 1
store i32 %57, i32* %10
br label %22
58: ; preds = %22
br label %59
59: ; preds = %58
%60 = load i32, i32* %9
%61 = add nsw i32 %60, 1
store i32 %61, i32* %9
br label %17
62: ; preds = %17
%63 = load i32*, i32** %14
%64 = call i32 @fclose(i32* %63)
store i32 %64, 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 = [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 = icmp sgt i32 %0, 0
br i1 %8, label %9, label %31
9: ; preds = %4
%10 = icmp sgt i32 %1, 0
%11 = icmp sgt i32 %2, 0
br label %12
12: ; preds = %9, %28
%13 = phi i32 [ 0, %9 ], [ %29, %28 ]
br i1 %10, label %14, label %28
14: ; preds = %12, %25
%15 = phi i32 [ %26, %25 ], [ 0, %12 ]
%16 = tail call i32 @get_rand(i32* %3, i32 %2)
br i1 %11, label %17, label %25
17: ; preds = %14, %17
%18 = phi i32 [ %23, %17 ], [ 0, %14 ]
%19 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 %13, i32 %15, i32 %18)
%20 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%21 = tail call i32 @genC(i32 %13, i32 %15, i32 %18, i32* %20, i32* %7, i32* %3)
%22 = tail call i32 @fclose(i32* %20)
%23 = add nuw nsw i32 %18, 1
%24 = icmp eq i32 %23, %2
br i1 %24, label %25, label %17
25: ; preds = %17, %14
%26 = add nuw nsw i32 %15, 1
%27 = icmp eq i32 %26, %1
br i1 %27, label %28, label %14
28: ; preds = %25, %12
%29 = add nuw nsw i32 %13, 1
%30 = icmp eq i32 %29, %0
br i1 %30, label %31, label %12
31: ; preds = %28, %4
%32 = tail call i32 @fclose(i32* %7)
ret i32 0
}