#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 /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int);
int rand();
void createFile(char *filename, int len) {
  int tmp;
  FILE *f;
  f = fopen(filename, "w");
  for (; len > 0; len--) {
    tmp = rand();
    fprintf(f, "%d\n", tmp);
  }
  fclose(f);
}


x86 assembly (clang, -O0):
<createFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xea6(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpl   $0x0,-0xc(%rbp)
jle    1198 <createFile+0x58>
mov    $0x0,%al
call   1060 <rand@plt>
mov    %eax,-0x10(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%edx
lea    0xe7d(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    1163 <createFile+0x23>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<createFile>:
push   %r15
push   %r14
push   %rbx
mov    %esi,%ebx
lea    0xeb2(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,%r14
test   %ebx,%ebx
jle    118c <createFile+0x4c>
add    $0x1,%ebx
lea    0xe9e(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %eax,%eax
call   1060 <rand@plt>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %eax,%edx
call   1040 <fprintf@plt>
add    $0xffffffff,%ebx
cmp    $0x1,%ebx
ja     1170 <createFile+0x30>
mov    %r14,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <fclose@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"w\00"
@.str.1 = [4 x i8] c"%d\0A\00"
define void @createFile(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
store i8* %0, i8** %3
store i32 %1, i32* %4
%7 = load i8*, i8** %3
%8 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %8, i32** %6
br label %9
9: ; preds = %17, %2
%10 = load i32, i32* %4
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %20
12: ; preds = %9
%13 = call i32 (...) @rand()
store i32 %13, i32* %5
%14 = load i32*, i32** %6
%15 = load i32, i32* %5
%16 = call i32 @fprintf(i32* %14, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %15)
br label %17
17: ; preds = %12
%18 = load i32, i32* %4
%19 = add nsw i32 %18, -1
store i32 %19, i32* %4
br label %9
20: ; preds = %9
%21 = load i32*, i32** %6
%22 = call i32 @fclose(i32* %21)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"w\00"
@.str.1 = [4 x i8] c"%d\0A\00"
define void @createFile(i8* nocapture %0, i32 %1) {
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = icmp sgt i32 %1, 0
br i1 %4, label %5, label %11
5: ; preds = %2, %5
%6 = phi i32 [ %9, %5 ], [ %1, %2 ]
%7 = tail call i32 (...) @rand()
%8 = tail call i32 @fprintf(i32* %3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %7)
%9 = add nsw i32 %6, -1
%10 = icmp ugt i32 %6, 1
br i1 %10, label %5, label %11
11: ; preds = %5, %2
%12 = tail call i32 @fclose(i32* %3)
ret void
}