#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*/ time_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
double difftime(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ gen_random(char *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, double);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main() {
  int i;
  FILE *f;
  char fname[15];
  time_t start, end;
  time(&start);
  for (i = 0; i < 100000; i++) {
    gen_random(fname, 15);
    f = fopen(fname, "w");
    if (f != NULL) {
      fclose(f);
    } else {
      perror("Error creating file\n");
      exit(1);
    }
  }
  time(&end);
  printf("Time taken %f\n", difftime(end, start));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x24(%rbp),%rdi
call   1060 <time@plt>
movl   $0x0,-0x8(%rbp)
cmpl   $0x186a0,-0x8(%rbp)
jge    1210 <main+0x90>
lea    -0x1f(%rbp),%rdi
mov    $0xf,%esi
call   1070 <gen_random@plt>
lea    -0x1f(%rbp),%rdi
lea    0xe3b(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11e7 <main+0x67>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
jmp    11fd <main+0x7d>
lea    0xe14(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
jmp    1202 <main+0x82>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    119f <main+0x1f>
lea    -0x28(%rbp),%rdi
call   1060 <time@plt>
mov    -0x28(%rbp),%edi
mov    -0x24(%rbp),%esi
call   1050 <difftime@plt>
lea    0xdec(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
lea    0xc(%rsp),%rdi
call   1060 <time@plt>
mov    $0x186a0,%ebp
lea    0x11(%rsp),%rbx
lea    0xe5d(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
mov    $0xf,%esi
call   1070 <gen_random@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1208 <main+0x88>
mov    %rax,%rdi
call   1030 <fclose@plt>
add    $0xffffffff,%ebp
jne    11b0 <main+0x30>
lea    0x8(%rsp),%rdi
call   1060 <time@plt>
mov    0x8(%rsp),%edi
mov    0xc(%rsp),%esi
call   1050 <difftime@plt>
lea    0xe1f(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xdf3(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"w\00"
@.str.1 = [21 x i8] c"Error creating file\0A\00"
@.str.2 = [15 x i8] c"Time taken %f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32*
%4 = alloca [15 x i8]
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
%7 = call i32 @time(i32* %5)
store i32 0, i32* %2
br label %8
8: ; preds = %25, %0
%9 = load i32, i32* %2
%10 = icmp slt i32 %9, 100000
br i1 %10, label %11, label %28
11: ; preds = %8
%12 = getelementptr inbounds [15 x i8], [15 x i8]* %4, i64 0, i64 0
%13 = call i32 @gen_random(i8* %12, i32 15)
%14 = getelementptr inbounds [15 x i8], [15 x i8]* %4, i64 0, i64 0
%15 = call i32* @fopen(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %15, i32** %3
%16 = load i32*, i32** %3
%17 = icmp ne i32* %16, null
br i1 %17, label %18, label %21
18: ; preds = %11
%19 = load i32*, i32** %3
%20 = call i32 @fclose(i32* %19)
br label %24
21: ; preds = %11
%22 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%23 = call i32 @exit(i32 1)
unreachable
24: ; preds = %18
br label %25
25: ; preds = %24
%26 = load i32, i32* %2
%27 = add nsw i32 %26, 1
store i32 %27, i32* %2
br label %8
28: ; preds = %8
%29 = call i32 @time(i32* %6)
%30 = load i32, i32* %6
%31 = load i32, i32* %5
%32 = call double @difftime(i32 %30, i32 %31)
%33 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), double %32)
ret i32 0
}

LLVM IR (-O2):
@.str = [2 x i8] c"w\00"
@.str.1 = [21 x i8] c"Error creating file\0A\00"
@.str.2 = [15 x i8] c"Time taken %f\0A\00"
define i32 @main() {
%1 = alloca [15 x i8]
%2 = alloca i32
%3 = alloca i32
%4 = getelementptr inbounds [15 x i8], [15 x i8]* %1, i64 0, i64 0
%5 = bitcast i32* %2 to i8*
%6 = bitcast i32* %3 to i8*
%7 = call i32 @time(i32* %2)
br label %8
8: ; preds = %0, %13
%9 = phi i32 [ 0, %0 ], [ %15, %13 ]
%10 = call i32 @gen_random(i8* %4, i32 15)
%11 = call i32* @fopen(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %17, label %13
13: ; preds = %8
%14 = call i32 @fclose(i32* %11)
%15 = add nuw nsw i32 %9, 1
%16 = icmp eq i32 %15, 100000
br i1 %16, label %20, label %8
17: ; preds = %8
%18 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %13
%21 = call i32 @time(i32* %3)
%22 = load i32, i32* %3
%23 = load i32, i32* %2
%24 = call double @difftime(i32 %22, i32 %23)
%25 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), double %24)
ret i32 0
}