#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*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *const);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ free(void *const);
int /*<<< orphan*/ fwrite(void *const, int, int, int /*<<< orphan*/ *const);
int /*<<< orphan*/ generate(void *const, int, double);
void *malloc(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
void createSampleFile(char *filename, double p) {
  FILE *const foutput = fopen(filename, "wb");
  if (foutput == NULL) {
    perror("dataGenerator:");
    exit(1);
  }
  {
    void *const buffer = malloc(((1 * (1 << 20)) - 1));
    generate(buffer, ((1 * (1 << 20)) - 1), p);
    fwrite(buffer, 1, ((1 * (1 << 20)) - 1), foutput);
    free(buffer);
  }
  fclose(foutput);
  fprintf(stderr, "File %s generated\n", filename);
}


x86 assembly (clang, -O0):
<createSampleFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe54(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11d6 <createSampleFile+0x46>
lea    0xe3c(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    $0xfffff,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
movsd  -0x10(%rbp),%xmm0
mov    $0xfffff,%esi
call   10b0 <generate@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
mov    $0xfffff,%edx
call   10a0 <fwrite@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    0x2db9(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xdde(%rip),%rsi
call   1050 <fprintf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<createSampleFile>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
movsd  %xmm0,0x8(%rsp)
mov    %rdi,%r14
lea    0xe57(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     121c <createSampleFile+0x8c>
mov    %rax,%r15
mov    $0xfffff,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0xfffff,%esi
movsd  0x8(%rsp),%xmm0
call   10b0 <generate@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0xfffff,%edx
mov    %r15,%rcx
call   10a0 <fwrite@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1040 <fclose@plt>
mov    0x2dde(%rip),%rax
mov    (%rax),%edi
lea    0xe07(%rip),%rsi
mov    %r14,%rdx
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
jmp    1050 <fprintf@plt>
lea    0xde0(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"wb\00"
@.str.1 = [15 x i8] c"dataGenerator:\00"
@stderr = global i32 0
@.str.2 = [19 x i8] c"File %s generated\0A\00"
define void @createSampleFile(i8* %0, double %1) {
%3 = alloca i8*
%4 = alloca double
%5 = alloca i32*
%6 = alloca i8*
store i8* %0, i8** %3
store double %1, double* %4
%7 = load i8*, i8** %3
%8 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %8, i32** %5
%9 = load i32*, i32** %5
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %2
%15 = call i8* @malloc(i32 1048575)
store i8* %15, i8** %6
%16 = load i8*, i8** %6
%17 = load double, double* %4
%18 = call i32 @generate(i8* %16, i32 1048575, double %17)
%19 = load i8*, i8** %6
%20 = load i32*, i32** %5
%21 = call i32 @fwrite(i8* %19, i32 1, i32 1048575, i32* %20)
%22 = load i8*, i8** %6
%23 = call i32 @free(i8* %22)
%24 = load i32*, i32** %5
%25 = call i32 @fclose(i32* %24)
%26 = load i32, i32* @stderr
%27 = load i8*, i8** %3
%28 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %27)
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"wb\00"
@.str.1 = [15 x i8] c"dataGenerator:\00"
@stderr = global i32 0
@.str.2 = [19 x i8] c"File %s generated\0A\00"
define void @createSampleFile(i8* %0, double %1) {
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = tail call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %2
%9 = tail call dereferenceable_or_null(1048575) i8* @malloc(i32 1048575)
%10 = tail call i32 @generate(i8* %9, i32 1048575, double %1)
%11 = tail call i32 @fwrite(i8* %9, i32 1, i32 1048575, i32* %3)
%12 = tail call i32 @free(i8* %9)
%13 = tail call i32 @fclose(i32* %3)
%14 = load i32, i32* @stderr
%15 = tail call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %0)
ret void
}