#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 */
struct VariableDensity {
  int dummy;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
int /*<<< orphan*/ fwrite(float *, int, int, int /*<<< orphan*/ *);
float getScale(struct VariableDensity const *, float);
int /*<<< orphan*/ stderr;
int writeVariableDensity(const char *filename, const struct VariableDensity *v,
                         float krMax, int points) {
  FILE *file;
  int n;
  float kr;
  float scale;
  file = fopen(filename, "wb");
  if (!file) {
    fprintf(stderr, "Error opening %s for read", filename);
    return 1;
  }
  for (n = 0; n < points; n++) {
    kr = n * krMax / points;
    fwrite(&kr, sizeof(float), 1, file);
    scale = getScale(v, kr);
    fwrite(&scale, sizeof(float), 1, file);
  }
  fclose(file);
  return 0;
}


x86 assembly (clang, -O0):
<writeVariableDensity>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movss  %xmm0,-0x1c(%rbp)
mov    %edx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe8d(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11ac <writeVariableDensity+0x5c>
mov    0x2e52(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe68(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1236 <writeVariableDensity+0xe6>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    1226 <writeVariableDensity+0xd6>
cvtsi2ssl -0x2c(%rbp),%xmm0
mulss  -0x1c(%rbp),%xmm0
cvtsi2ssl -0x20(%rbp),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x30(%rbp)
mov    -0x28(%rbp),%rcx
lea    -0x30(%rbp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1070 <fwrite@plt>
mov    -0x18(%rbp),%rdi
movss  -0x30(%rbp),%xmm0
call   1040 <getScale@plt>
movss  %xmm0,-0x34(%rbp)
mov    -0x28(%rbp),%rcx
lea    -0x34(%rbp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1070 <fwrite@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11b3 <writeVariableDensity+0x63>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<writeVariableDensity>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edx,%r13d
movss  %xmm0,0x8(%rsp)
mov    %rsi,%r14
mov    %rdi,%r15
lea    0xe8c(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     121f <writeVariableDensity+0xcf>
mov    %rax,%rbx
test   %r13d,%r13d
movss  0x8(%rsp),%xmm1
jle    1213 <writeVariableDensity+0xc3>
xorps  %xmm0,%xmm0
cvtsi2ss %r13d,%xmm0
movss  %xmm0,0x10(%rsp)
xor    %ebp,%ebp
lea    0xc(%rsp),%r15
lea    0x14(%rsp),%r12
xchg   %ax,%ax
xorps  %xmm0,%xmm0
cvtsi2ss %ebp,%xmm0
mulss  %xmm1,%xmm0
divss  0x10(%rsp),%xmm0
movss  %xmm0,0xc(%rsp)
mov    %r15,%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1070 <fwrite@plt>
movss  0xc(%rsp),%xmm0
mov    %r14,%rdi
call   1040 <getScale@plt>
movss  %xmm0,0x14(%rsp)
mov    %r12,%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1070 <fwrite@plt>
movss  0x8(%rsp),%xmm1
add    $0x1,%ebp
cmp    %ebp,%r13d
jne    11b0 <writeVariableDensity+0x60>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
jmp    123c <writeVariableDensity+0xec>
mov    0x2dba(%rip),%rax
mov    (%rax),%edi
lea    0xdd4(%rip),%rsi
mov    %r15,%rdx
call   1050 <fprintf@plt>
mov    $0x1,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.VariableDensity = type { i32 }
@.str = [3 x i8] c"wb\00"
@stderr = global i32 0
@.str.1 = [26 x i8] c"Error opening %s for read\00"
define i32 @writeVariableDensity(i8* %0, %struct.VariableDensity* %1, float %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca %struct.VariableDensity*
%8 = alloca float
%9 = alloca i32
%10 = alloca i32*
%11 = alloca i32
%12 = alloca float
%13 = alloca float
store i8* %0, i8** %6
store %struct.VariableDensity* %1, %struct.VariableDensity** %7
store float %2, float* %8
store i32 %3, i32* %9
%14 = load i8*, i8** %6
%15 = call i32* @fopen(i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %15, i32** %10
%16 = load i32*, i32** %10
%17 = icmp ne i32* %16, null
br i1 %17, label %22, label %18
18: ; preds = %4
%19 = load i32, i32* @stderr
%20 = load i8*, i8** %6
%21 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %20)
store i32 1, i32* %5
br label %48
22: ; preds = %4
store i32 0, i32* %11
br label %23
23: ; preds = %42, %22
%24 = load i32, i32* %11
%25 = load i32, i32* %9
%26 = icmp slt i32 %24, %25
br i1 %26, label %27, label %45
27: ; preds = %23
%28 = load i32, i32* %11
%29 = sitofp i32 %28 to float
%30 = load float, float* %8
%31 = fmul float %29, %30
%32 = load i32, i32* %9
%33 = sitofp i32 %32 to float
%34 = fdiv float %31, %33
store float %34, float* %12
%35 = load i32*, i32** %10
%36 = call i32 @fwrite(float* %12, i32 4, i32 1, i32* %35)
%37 = load %struct.VariableDensity*, %struct.VariableDensity** %7
%38 = load float, float* %12
%39 = call float @getScale(%struct.VariableDensity* %37, float %38)
store float %39, float* %13
%40 = load i32*, i32** %10
%41 = call i32 @fwrite(float* %13, i32 4, i32 1, i32* %40)
br label %42
42: ; preds = %27
%43 = load i32, i32* %11
%44 = add nsw i32 %43, 1
store i32 %44, i32* %11
br label %23
45: ; preds = %23
%46 = load i32*, i32** %10
%47 = call i32 @fclose(i32* %46)
store i32 0, i32* %5
br label %48
48: ; preds = %45, %18
%49 = load i32, i32* %5
ret i32 %49
}

LLVM IR (-O2):
%struct.VariableDensity = type { i32 }
@.str = [3 x i8] c"wb\00"
@stderr = global i32 0
@.str.1 = [26 x i8] c"Error opening %s for read\00"
define i32 @writeVariableDensity(i8* %0, %struct.VariableDensity* %1, float %2, i32 %3) {
%5 = alloca float
%6 = alloca float
%7 = bitcast float* %5 to i8*
%8 = bitcast float* %6 to i8*
%9 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %15, label %11
11: ; preds = %4
%12 = icmp sgt i32 %3, 0
br i1 %12, label %13, label %29
13: ; preds = %11
%14 = sitofp i32 %3 to float
br label %18
15: ; preds = %4
%16 = load i32, i32* @stderr
%17 = tail call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %31
18: ; preds = %13, %18
%19 = phi i32 [ 0, %13 ], [ %27, %18 ]
%20 = sitofp i32 %19 to float
%21 = fmul float %20, %2
%22 = fdiv float %21, %14
store float %22, float* %5
%23 = call i32 @fwrite(float* %5, i32 4, i32 1, i32* %9)
%24 = load float, float* %5
%25 = tail call float @getScale(%struct.VariableDensity* %1, float %24)
store float %25, float* %6
%26 = call i32 @fwrite(float* %6, i32 4, i32 1, i32* %9)
%27 = add nuw nsw i32 %19, 1
%28 = icmp eq i32 %27, %3
br i1 %28, label %29, label %18
29: ; preds = %18, %11
%30 = tail call i32 @fclose(i32* %9)
br label %31
31: ; preds = %29, %15
%32 = phi i32 [ 0, %29 ], [ 1, %15 ]
ret i32 %32
}