#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 *, double, double);
scalar_t__ rand();
void create_random_file(char *filename, int problem_size) {
  FILE *fp;
  fp = fopen(filename, "w");
  double tmp = 0, previous = 0;
  for (int i = 0; i < problem_size; i++) {
    while (tmp <= previous)
      tmp = (double)rand() / (double)rand();
    previous = tmp;
    fprintf(fp, "%f %f ", tmp, (double)rand() / (double)rand());
  }
  fclose(fp);
}


x86 assembly (clang, -O0):
<create_random_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%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)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1234 <create_random_file+0xf4>
jmp    118b <create_random_file+0x4b>
movsd  -0x20(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jb     11cf <create_random_file+0x8f>
mov    $0x0,%al
call   1060 <rand@plt>
cvtsi2sd %rax,%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    $0x0,%al
call   1060 <rand@plt>
movsd  -0x38(%rbp),%xmm0
cvtsi2sd %rax,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    118b <create_random_file+0x4b>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x48(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    $0x0,%al
call   1060 <rand@plt>
cvtsi2sd %rax,%xmm0
movsd  %xmm0,-0x50(%rbp)
mov    $0x0,%al
call   1060 <rand@plt>
movsd  -0x50(%rbp),%xmm1
mov    -0x48(%rbp),%rdi
movsd  -0x40(%rbp),%xmm0
cvtsi2sd %rax,%xmm2
divsd  %xmm2,%xmm1
lea    0xde1(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    117a <create_random_file+0x3a>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_random_file>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %esi,%r15d
lea    0xeac(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,%rbx
test   %r15d,%r15d
jle    1237 <create_random_file+0xf7>
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x8(%rsp)
lea    0xe8c(%rip),%r14
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
movsd  0x8(%rsp),%xmm0
ucomisd %xmm0,%xmm0
jp     1229 <create_random_file+0xe9>
xor    %eax,%eax
call   1060 <rand@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  %xmm0,0x10(%rsp)
xor    %eax,%eax
call   1060 <rand@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  0x10(%rsp),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,0x10(%rsp)
movsd  0x8(%rsp),%xmm0
ucomisd %xmm1,%xmm0
jae    1190 <create_random_file+0x50>
xor    %eax,%eax
call   1060 <rand@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  %xmm0,0x8(%rsp)
xor    %eax,%eax
call   1060 <rand@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  0x8(%rsp),%xmm1
divsd  %xmm0,%xmm1
mov    %rbx,%rdi
mov    %r14,%rsi
movsd  0x10(%rsp),%xmm0
call   1040 <fprintf@plt>
add    $0x1,%ebp
movsd  0x10(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
cmp    %r15d,%ebp
jne    1180 <create_random_file+0x40>
jmp    1237 <create_random_file+0xf7>
movsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x10(%rsp)
jmp    11d0 <create_random_file+0x90>
mov    %rbx,%rdi
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fclose@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"w\00"
@.str.1 = [7 x i8] c"%f %f \00"
define void @create_random_file(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32*
%6 = alloca double
%7 = alloca double
%8 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%9 = load i8*, i8** %3
%10 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %10, i32** %5
store double 0.000000e+00, double* %6
store double 0.000000e+00, double* %7
store i32 0, i32* %8
br label %11
11: ; preds = %36, %2
%12 = load i32, i32* %8
%13 = load i32, i32* %4
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %39
15: ; preds = %11
br label %16
16: ; preds = %20, %15
%17 = load double, double* %6
%18 = load double, double* %7
%19 = fcmp ole double %17, %18
br i1 %19, label %20, label %26
20: ; preds = %16
%21 = call i64 (...) @rand()
%22 = sitofp i64 %21 to double
%23 = call i64 (...) @rand()
%24 = sitofp i64 %23 to double
%25 = fdiv double %22, %24
store double %25, double* %6
br label %16
26: ; preds = %16
%27 = load double, double* %6
store double %27, double* %7
%28 = load i32*, i32** %5
%29 = load double, double* %6
%30 = call i64 (...) @rand()
%31 = sitofp i64 %30 to double
%32 = call i64 (...) @rand()
%33 = sitofp i64 %32 to double
%34 = fdiv double %31, %33
%35 = call i32 @fprintf(i32* %28, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), double %29, double %34)
br label %36
36: ; preds = %26
%37 = load i32, i32* %8
%38 = add nsw i32 %37, 1
store i32 %38, i32* %8
br label %11
39: ; preds = %11
%40 = load i32*, i32** %5
%41 = call i32 @fclose(i32* %40)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"w\00"
@.str.1 = [7 x i8] c"%f %f \00"
define void @create_random_file(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 %9
5: ; preds = %2, %18
%6 = phi i32 [ %26, %18 ], [ 0, %2 ]
%7 = phi double [ %19, %18 ], [ 0.000000e+00, %2 ]
%8 = fcmp uno double %7, 0.000000e+00
br i1 %8, label %18, label %11
9: ; preds = %18, %2
%10 = tail call i32 @fclose(i32* %3)
ret void
11: ; preds = %5, %11
%12 = tail call i64 (...) @rand()
%13 = sitofp i64 %12 to double
%14 = tail call i64 (...) @rand()
%15 = sitofp i64 %14 to double
%16 = fdiv double %13, %15
%17 = fcmp ugt double %16, %7
br i1 %17, label %18, label %11
18: ; preds = %11, %5
%19 = phi double [ %7, %5 ], [ %16, %11 ]
%20 = tail call i64 (...) @rand()
%21 = sitofp i64 %20 to double
%22 = tail call i64 (...) @rand()
%23 = sitofp i64 %22 to double
%24 = fdiv double %21, %23
%25 = tail call i32 @fprintf(i32* %3, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), double %19, double %24)
%26 = add nuw nsw i32 %6, 1
%27 = icmp eq i32 %26, %1
br i1 %27, label %9, label %5
}