#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 */
int DBL_DIG;
char *asctime(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
char *format_file_full_path(char const *, char *, int, int, unsigned int, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ localtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
void write_probability_sweep_percolation_probability(
    const char *path, const double *probability_grid,
    const int *percolation_counts, int grid_npoints, double probability_center,
    double decay, int *realizations, int rows, int columns, unsigned int seed) {
  int i;
  time_t current_time;
  char *file_full_path;
  FILE *file_handler;
  current_time = time(NULL);
  file_full_path = format_file_full_path(path, "percolation_probability", rows,
                                         columns, seed, grid_npoints);
  file_handler = fopen(file_full_path, "w");
  fprintf(file_handler, ";rows:%d\n", rows);
  fprintf(file_handler, ";columns:%d\n", columns);
  fprintf(file_handler, ";seed:%u\n", seed);
  fprintf(file_handler, ";grid_npoints:%d\n", grid_npoints);
  fprintf(file_handler, ";grid_center:%.*e\n", DBL_DIG - 1, probability_center);
  fprintf(file_handler, ";grid_decay:%.*e\n", DBL_DIG - 1, decay);
  fprintf(file_handler, ";date:%s", asctime(localtime(&current_time)));
  for (i = 0; i < grid_npoints; i++) {
    fprintf(file_handler, "%.*e,%d,%d,%.*e\n", DBL_DIG - 1, probability_grid[i],
            percolation_counts[i], realizations[i], DBL_DIG - 1,
            ((double)percolation_counts[i]) / realizations[i]);
  }
  fclose(file_handler);
  free(file_full_path);
}


x86 assembly (clang, -O0):
<write_probability_sweep_percolation_probability>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    0x18(%rbp),%eax
mov    0x10(%rbp),%eax
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
movsd  %xmm0,-0x28(%rbp)
movsd  %xmm1,-0x30(%rbp)
mov    %r8,-0x38(%rbp)
mov    %r9d,-0x3c(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1080 <time@plt>
mov    %eax,-0x44(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x3c(%rbp),%edx
mov    0x10(%rbp),%ecx
mov    0x18(%rbp),%r8d
mov    -0x1c(%rbp),%r9d
lea    0xe2c(%rip),%rsi
call   1090 <format_file_full_path@plt>
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rdi
lea    0xe30(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x58(%rbp)
mov    -0x58(%rbp),%rdi
mov    -0x3c(%rbp),%edx
lea    0xe1b(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x58(%rbp),%rdi
mov    0x10(%rbp),%edx
lea    0xe10(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x58(%rbp),%rdi
mov    0x18(%rbp),%edx
lea    0xe08(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x58(%rbp),%rdi
mov    -0x1c(%rbp),%edx
lea    0xdfd(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x58(%rbp),%rdi
mov    0x2d98(%rip),%rax
mov    (%rax),%edx
sub    $0x1,%edx
movsd  -0x28(%rbp),%xmm0
lea    0xdec(%rip),%rsi
mov    $0x1,%al
call   1070 <fprintf@plt>
mov    -0x58(%rbp),%rdi
mov    0x2d75(%rip),%rax
mov    (%rax),%edx
sub    $0x1,%edx
movsd  -0x30(%rbp),%xmm0
lea    0xddc(%rip),%rsi
mov    $0x1,%al
call   1070 <fprintf@plt>
mov    -0x58(%rbp),%rax
mov    %rax,-0x60(%rbp)
lea    -0x44(%rbp),%rdi
call   1040 <localtime@plt>
mov    %eax,%edi
call   1060 <asctime@plt>
mov    -0x60(%rbp),%rdi
mov    %rax,%rdx
lea    0xdc1(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0x0,-0x40(%rbp)
mov    -0x40(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1347 <write_probability_sweep_percolation_probability+0x1c7>
mov    -0x58(%rbp),%rdi
mov    0x2d12(%rip),%rax
mov    (%rax),%edx
sub    $0x1,%edx
mov    -0x10(%rbp),%rax
movslq -0x40(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x40(%rbp),%rcx
mov    (%rax,%rcx,4),%ecx
mov    -0x38(%rbp),%rax
movslq -0x40(%rbp),%rsi
mov    (%rax,%rsi,4),%r8d
mov    0x2ce2(%rip),%rax
mov    (%rax),%r9d
sub    $0x1,%r9d
mov    -0x18(%rbp),%rax
movslq -0x40(%rbp),%rsi
cvtsi2sdl (%rax,%rsi,4),%xmm1
mov    -0x38(%rbp),%rax
movslq -0x40(%rbp),%rsi
cvtsi2sdl (%rax,%rsi,4),%xmm2
divsd  %xmm2,%xmm1
lea    0xd49(%rip),%rsi
mov    $0x2,%al
call   1070 <fprintf@plt>
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
jmp    12bf <write_probability_sweep_percolation_probability+0x13f>
mov    -0x58(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x50(%rbp),%rdi
call   1030 <free@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_probability_sweep_percolation_probability>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r9d,%r12d
mov    %r8,0x20(%rsp)
movsd  %xmm1,0x10(%rsp)
movsd  %xmm0,0x8(%rsp)
mov    %ecx,%r14d
mov    %rdx,%r15
mov    %rsi,%r13
mov    %rdi,%rbx
mov    0x60(%rsp),%ebp
xor    %edi,%edi
call   1080 <time@plt>
mov    %eax,0x4(%rsp)
lea    0xe3c(%rip),%rsi
mov    %rbx,%rdi
mov    %r12d,%edx
mov    %ebp,%ecx
mov    0x68(%rsp),%r8d
mov    %r14d,%r9d
call   1090 <format_file_full_path@plt>
lea    0xe38(%rip),%rsi
mov    %rax,0x18(%rsp)
mov    %rax,%rdi
call   10a0 <fopen@plt>
mov    %rax,%rbx
lea    0xe23(%rip),%rsi
mov    %rax,%rdi
mov    %r12d,%edx
xor    %eax,%eax
call   1070 <fprintf@plt>
lea    0xe19(%rip),%rsi
mov    %rbx,%rdi
mov    %ebp,%edx
xor    %eax,%eax
call   1070 <fprintf@plt>
lea    0xe13(%rip),%rsi
mov    %rbx,%rdi
mov    0x68(%rsp),%edx
xor    %eax,%eax
call   1070 <fprintf@plt>
lea    0xe08(%rip),%rsi
mov    %rbx,%rdi
mov    %r14d,%edx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    0x2da1(%rip),%rbp
mov    0x0(%rbp),%edx
add    $0xffffffff,%edx
lea    0xdf9(%rip),%rsi
mov    %rbx,%rdi
movsd  0x8(%rsp),%xmm0
mov    $0x1,%al
call   1070 <fprintf@plt>
mov    0x0(%rbp),%edx
add    $0xffffffff,%edx
lea    0xdef(%rip),%rsi
mov    %rbx,%rdi
movsd  0x10(%rsp),%xmm0
mov    $0x1,%al
call   1070 <fprintf@plt>
lea    0x4(%rsp),%rdi
call   1040 <localtime@plt>
mov    %eax,%edi
call   1060 <asctime@plt>
lea    0xdd9(%rip),%rsi
mov    %rbx,%rdi
mov    %rax,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
test   %r14d,%r14d
jle    130c <write_probability_sweep_percolation_probability+0x18c>
mov    %r14d,%r12d
xor    %r14d,%r14d
lea    0xdc3(%rip),%rbp
nopl   0x0(%rax,%rax,1)
mov    0x2d21(%rip),%rax
mov    (%rax),%edx
add    $0xffffffff,%edx
movsd  0x0(%r13,%r14,8),%xmm0
mov    (%r15,%r14,4),%ecx
xorps  %xmm1,%xmm1
cvtsi2sd %ecx,%xmm1
mov    0x20(%rsp),%rax
mov    (%rax,%r14,4),%r8d
xorps  %xmm2,%xmm2
cvtsi2sd %r8d,%xmm2
divsd  %xmm2,%xmm1
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %edx,%r9d
mov    $0x2,%al
call   1070 <fprintf@plt>
add    $0x1,%r14
cmp    %r14,%r12
jne    12c0 <write_probability_sweep_percolation_probability+0x140>
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    0x18(%rsp),%rdi
call   1030 <free@plt>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [24 x i8] c"percolation_probability\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [10 x i8] c";rows:%d\0A\00"
@.str.3 = [13 x i8] c";columns:%d\0A\00"
@.str.4 = [10 x i8] c";seed:%u\0A\00"
@.str.5 = [18 x i8] c";grid_npoints:%d\0A\00"
@.str.6 = [19 x i8] c";grid_center:%.*e\0A\00"
@DBL_DIG = global i32 0
@.str.7 = [18 x i8] c";grid_decay:%.*e\0A\00"
@.str.8 = [9 x i8] c";date:%s\00"
@.str.9 = [17 x i8] c"%.*e,%d,%d,%.*e\0A\00"
define void @write_probability_sweep_percolation_probability(i8* %0, double* %1, i32* %2, i32 %3, double %4, double %5, i32* %6, i32 %7, i32 %8, i32 %9) {
%11 = alloca i8*
%12 = alloca double*
%13 = alloca i32*
%14 = alloca i32
%15 = alloca double
%16 = alloca double
%17 = alloca i32*
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32
%21 = alloca i32
%22 = alloca i32
%23 = alloca i8*
%24 = alloca i32*
store i8* %0, i8** %11
store double* %1, double** %12
store i32* %2, i32** %13
store i32 %3, i32* %14
store double %4, double* %15
store double %5, double* %16
store i32* %6, i32** %17
store i32 %7, i32* %18
store i32 %8, i32* %19
store i32 %9, i32* %20
%25 = call i32 @time(i32* null)
store i32 %25, i32* %22
%26 = load i8*, i8** %11
%27 = load i32, i32* %18
%28 = load i32, i32* %19
%29 = load i32, i32* %20
%30 = load i32, i32* %14
%31 = call i8* @format_file_full_path(i8* %26, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %27, i32 %28, i32 %29, i32 %30)
store i8* %31, i8** %23
%32 = load i8*, i8** %23
%33 = call i32* @fopen(i8* %32, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %33, i32** %24
%34 = load i32*, i32** %24
%35 = load i32, i32* %18
%36 = call i32 (i32*, i8*, ...) @fprintf(i32* %34, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 %35)
%37 = load i32*, i32** %24
%38 = load i32, i32* %19
%39 = call i32 (i32*, i8*, ...) @fprintf(i32* %37, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i32 %38)
%40 = load i32*, i32** %24
%41 = load i32, i32* %20
%42 = call i32 (i32*, i8*, ...) @fprintf(i32* %40, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i32 %41)
%43 = load i32*, i32** %24
%44 = load i32, i32* %14
%45 = call i32 (i32*, i8*, ...) @fprintf(i32* %43, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i32 %44)
%46 = load i32*, i32** %24
%47 = load i32, i32* @DBL_DIG
%48 = sub nsw i32 %47, 1
%49 = load double, double* %15
%50 = call i32 (i32*, i8*, ...) @fprintf(i32* %46, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0), i32 %48, double %49)
%51 = load i32*, i32** %24
%52 = load i32, i32* @DBL_DIG
%53 = sub nsw i32 %52, 1
%54 = load double, double* %16
%55 = call i32 (i32*, i8*, ...) @fprintf(i32* %51, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.7, i64 0, i64 0), i32 %53, double %54)
%56 = load i32*, i32** %24
%57 = call i32 @localtime(i32* %22)
%58 = call i8* @asctime(i32 %57)
%59 = call i32 (i32*, i8*, ...) @fprintf(i32* %56, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i64 0, i64 0), i8* %58)
store i32 0, i32* %21
br label %60
60: ; preds = %99, %10
%61 = load i32, i32* %21
%62 = load i32, i32* %14
%63 = icmp slt i32 %61, %62
br i1 %63, label %64, label %102
64: ; preds = %60
%65 = load i32*, i32** %24
%66 = load i32, i32* @DBL_DIG
%67 = sub nsw i32 %66, 1
%68 = load double*, double** %12
%69 = load i32, i32* %21
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds double, double* %68, i64 %70
%72 = load double, double* %71
%73 = load i32*, i32** %13
%74 = load i32, i32* %21
%75 = sext i32 %74 to i64
%76 = getelementptr inbounds i32, i32* %73, i64 %75
%77 = load i32, i32* %76
%78 = load i32*, i32** %17
%79 = load i32, i32* %21
%80 = sext i32 %79 to i64
%81 = getelementptr inbounds i32, i32* %78, i64 %80
%82 = load i32, i32* %81
%83 = load i32, i32* @DBL_DIG
%84 = sub nsw i32 %83, 1
%85 = load i32*, i32** %13
%86 = load i32, i32* %21
%87 = sext i32 %86 to i64
%88 = getelementptr inbounds i32, i32* %85, i64 %87
%89 = load i32, i32* %88
%90 = sitofp i32 %89 to double
%91 = load i32*, i32** %17
%92 = load i32, i32* %21
%93 = sext i32 %92 to i64
%94 = getelementptr inbounds i32, i32* %91, i64 %93
%95 = load i32, i32* %94
%96 = sitofp i32 %95 to double
%97 = fdiv double %90, %96
%98 = call i32 (i32*, i8*, ...) @fprintf(i32* %65, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.9, i64 0, i64 0), i32 %67, double %72, i32 %77, i32 %82, i32 %84, double %97)
br label %99
99: ; preds = %64
%100 = load i32, i32* %21
%101 = add nsw i32 %100, 1
store i32 %101, i32* %21
br label %60
102: ; preds = %60
%103 = load i32*, i32** %24
%104 = call i32 @fclose(i32* %103)
%105 = load i8*, i8** %23
%106 = call i32 @free(i8* %105)
ret void
}

LLVM IR (-O2):
@.str = [24 x i8] c"percolation_probability\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [10 x i8] c";rows:%d\0A\00"
@.str.3 = [13 x i8] c";columns:%d\0A\00"
@.str.4 = [10 x i8] c";seed:%u\0A\00"
@.str.5 = [18 x i8] c";grid_npoints:%d\0A\00"
@.str.6 = [19 x i8] c";grid_center:%.*e\0A\00"
@DBL_DIG = global i32 0
@.str.7 = [18 x i8] c";grid_decay:%.*e\0A\00"
@.str.8 = [9 x i8] c";date:%s\00"
@.str.9 = [17 x i8] c"%.*e,%d,%d,%.*e\0A\00"
define void @write_probability_sweep_percolation_probability(i8* %0, double* nocapture %1, i32* nocapture %2, i32 %3, double %4, double %5, i32* nocapture %6, i32 %7, i32 %8, i32 %9) {
%11 = alloca i32
%12 = bitcast i32* %11 to i8*
%13 = tail call i32 @time(i32* null)
store i32 %13, i32* %11
%14 = tail call i8* @format_file_full_path(i8* %0, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %7, i32 %8, i32 %9, i32 %3)
%15 = tail call i32* @fopen(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%16 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %15, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 %7)
%17 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %15, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i32 %8)
%18 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %15, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i32 %9)
%19 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %15, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i32 %3)
%20 = load i32, i32* @DBL_DIG
%21 = add nsw i32 %20, -1
%22 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %15, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0), i32 %21, double %4)
%23 = load i32, i32* @DBL_DIG
%24 = add nsw i32 %23, -1
%25 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %15, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.7, i64 0, i64 0), i32 %24, double %5)
%26 = call i32 @localtime(i32* %11)
%27 = call i8* @asctime(i32 %26)
%28 = call i32 (i32*, i8*, ...) @fprintf(i32* %15, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i64 0, i64 0), i8* %27)
%29 = icmp sgt i32 %3, 0
br i1 %29, label %30, label %48
30: ; preds = %10
%31 = zext i32 %3 to i64
br label %32
32: ; preds = %30, %32
%33 = phi i64 [ 0, %30 ], [ %46, %32 ]
%34 = load i32, i32* @DBL_DIG
%35 = add nsw i32 %34, -1
%36 = getelementptr inbounds double, double* %1, i64 %33
%37 = load double, double* %36
%38 = getelementptr inbounds i32, i32* %2, i64 %33
%39 = load i32, i32* %38
%40 = getelementptr inbounds i32, i32* %6, i64 %33
%41 = load i32, i32* %40
%42 = sitofp i32 %39 to double
%43 = sitofp i32 %41 to double
%44 = fdiv double %42, %43
%45 = call i32 (i32*, i8*, ...) @fprintf(i32* %15, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.9, i64 0, i64 0), i32 %35, double %37, i32 %39, i32 %41, i32 %35, double %44)
%46 = add nuw nsw i64 %33, 1
%47 = icmp eq i64 %46, %31
br i1 %47, label %48, label %32
48: ; preds = %32, %10
%49 = call i32 @fclose(i32* %15)
%50 = call i32 @free(i8* %14)
ret void
}