#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,
                            double);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ localtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
void write_cluster_statistics_to_file(
    const char *path, const int *cluster_sizes, const int *cluster_sizes_counts,
    const int *cluster_sizes_percolated, int cluster_sizes_total_count,
    int rows, int columns, double probability, unsigned int seed,
    int realizations, const char *other) {
  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, "clusters", rows, columns, seed, probability);
  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, ";probability:%.*e\n", DBL_DIG - 1, probability);
  fprintf(file_handler, ";realizations:%d\n", realizations);
  if (other) {
    fprintf(file_handler, "%s", other);
  }
  fprintf(file_handler, ";date:%s", asctime(localtime(&current_time)));
  for (i = 0; i < cluster_sizes_total_count; i++) {
    fprintf(file_handler, "%d,%d,%d\n", cluster_sizes[i],
            cluster_sizes_counts[i], cluster_sizes_percolated[i]);
  }
  fclose(file_handler);
  free(file_full_path);
}


x86 assembly (clang, -O0):
<write_cluster_statistics_to_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    0x28(%rbp),%rax
mov    0x20(%rbp),%eax
mov    0x18(%rbp),%eax
mov    0x10(%rbp),%eax
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    %r9d,-0x28(%rbp)
movsd  %xmm0,-0x30(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1080 <time@plt>
mov    %eax,-0x38(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%edx
mov    0x10(%rbp),%ecx
mov    0x18(%rbp),%r8d
movsd  -0x30(%rbp),%xmm0
lea    0xe28(%rip),%rsi
call   1090 <format_file_full_path@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
lea    0xe1d(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rdi
mov    -0x28(%rbp),%edx
lea    0xe08(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x48(%rbp),%rdi
mov    0x10(%rbp),%edx
lea    0xdfd(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x48(%rbp),%rdi
mov    0x18(%rbp),%edx
lea    0xdf5(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x48(%rbp),%rdi
mov    0x2da9(%rip),%rax
mov    (%rax),%edx
sub    $0x1,%edx
movsd  -0x30(%rbp),%xmm0
lea    0xddc(%rip),%rsi
mov    $0x1,%al
call   1070 <fprintf@plt>
mov    -0x48(%rbp),%rdi
mov    0x20(%rbp),%edx
lea    0xdda(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
cmpq   $0x0,0x28(%rbp)
je     128d <write_cluster_statistics_to_file+0x10d>
mov    -0x48(%rbp),%rdi
mov    0x28(%rbp),%rdx
lea    0xdd1(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x48(%rbp),%rax
mov    %rax,-0x50(%rbp)
lea    -0x38(%rbp),%rdi
call   1040 <localtime@plt>
mov    %eax,%edi
call   1060 <asctime@plt>
mov    -0x50(%rbp),%rdi
mov    %rax,%rdx
lea    0xd9e(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    130f <write_cluster_statistics_to_file+0x18f>
mov    -0x48(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
mov    -0x18(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,4),%ecx
mov    -0x20(%rbp),%rax
movslq -0x34(%rbp),%rsi
mov    (%rax,%rsi,4),%r8d
lea    0xd60(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    12c1 <write_cluster_statistics_to_file+0x141>
mov    -0x48(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_cluster_statistics_to_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
movsd  %xmm0,0x8(%rsp)
mov    %r9d,%ebx
mov    %r8d,%r12d
mov    %rcx,0x18(%rsp)
mov    %rdx,0x10(%rsp)
mov    %rsi,%r14
mov    %rdi,%rbp
mov    0x60(%rsp),%r13d
mov    0x68(%rsp),%r15d
xor    %edi,%edi
call   1090 <time@plt>
mov    %eax,0x4(%rsp)
lea    0xe2a(%rip),%rsi
mov    %rbp,%rdi
mov    %ebx,%edx
mov    %r13d,%ecx
mov    %r15d,%r8d
movsd  0x8(%rsp),%xmm0
call   10a0 <format_file_full_path@plt>
lea    0xe16(%rip),%rsi
mov    %rax,0x20(%rsp)
mov    %rax,%rdi
call   10b0 <fopen@plt>
mov    %rax,%rbp
lea    0xe01(%rip),%rsi
mov    %rax,%rdi
mov    %ebx,%edx
xor    %eax,%eax
call   1080 <fprintf@plt>
lea    0xdf8(%rip),%rsi
mov    %rbp,%rdi
mov    %r13d,%edx
xor    %eax,%eax
call   1080 <fprintf@plt>
lea    0xdf1(%rip),%rsi
mov    %rbp,%rdi
mov    %r15d,%edx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    0x2da3(%rip),%rax
mov    (%rax),%edx
add    $0xffffffff,%edx
lea    0xddb(%rip),%rsi
mov    %rbp,%rdi
movsd  0x8(%rsp),%xmm0
mov    $0x1,%al
call   1080 <fprintf@plt>
lea    0xdd7(%rip),%rsi
mov    %rbp,%rdi
mov    0x70(%rsp),%edx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    0x78(%rsp),%rdi
test   %rdi,%rdi
je     1288 <write_cluster_statistics_to_file+0xf8>
mov    %rbp,%rsi
call   1070 <fputs@plt>
lea    0x4(%rsp),%rdi
call   1040 <localtime@plt>
mov    %eax,%edi
call   1060 <asctime@plt>
lea    0xdb1(%rip),%rsi
mov    %rbp,%rdi
mov    %rax,%rdx
xor    %eax,%eax
call   1080 <fprintf@plt>
test   %r12d,%r12d
mov    0x18(%rsp),%r15
mov    0x10(%rsp),%r13
mov    %rbp,%rbx
jle    12f7 <write_cluster_statistics_to_file+0x167>
mov    %r12d,%eax
mov    %r14,%r12
mov    %eax,%ebp
xor    %r14d,%r14d
nopw   0x0(%rax,%rax,1)
mov    (%r12,%r14,4),%edx
mov    0x0(%r13,%r14,4),%ecx
mov    (%r15,%r14,4),%r8d
mov    %rbx,%rdi
lea    0xd73(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
add    $0x1,%r14
cmp    %r14,%rbp
jne    12d0 <write_cluster_statistics_to_file+0x140>
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    0x20(%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 = [9 x i8] c"clusters\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 = [19 x i8] c";probability:%.*e\0A\00"
@DBL_DIG = global i32 0
@.str.6 = [18 x i8] c";realizations:%d\0A\00"
@.str.7 = [3 x i8] c"%s\00"
@.str.8 = [9 x i8] c";date:%s\00"
@.str.9 = [10 x i8] c"%d,%d,%d\0A\00"
define void @write_cluster_statistics_to_file(i8* %0, i32* %1, i32* %2, i32* %3, i32 %4, i32 %5, i32 %6, double %7, i32 %8, i32 %9, i8* %10) {
%12 = alloca i8*
%13 = alloca i32*
%14 = alloca i32*
%15 = alloca i32*
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca double
%20 = alloca i32
%21 = alloca i32
%22 = alloca i8*
%23 = alloca i32
%24 = alloca i32
%25 = alloca i8*
%26 = alloca i32*
store i8* %0, i8** %12
store i32* %1, i32** %13
store i32* %2, i32** %14
store i32* %3, i32** %15
store i32 %4, i32* %16
store i32 %5, i32* %17
store i32 %6, i32* %18
store double %7, double* %19
store i32 %8, i32* %20
store i32 %9, i32* %21
store i8* %10, i8** %22
%27 = call i32 @time(i32* null)
store i32 %27, i32* %24
%28 = load i8*, i8** %12
%29 = load i32, i32* %17
%30 = load i32, i32* %18
%31 = load i32, i32* %20
%32 = load double, double* %19
%33 = call i8* @format_file_full_path(i8* %28, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %29, i32 %30, i32 %31, double %32)
store i8* %33, i8** %25
%34 = load i8*, i8** %25
%35 = call i32* @fopen(i8* %34, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %35, i32** %26
%36 = load i32*, i32** %26
%37 = load i32, i32* %17
%38 = call i32 (i32*, i8*, ...) @fprintf(i32* %36, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 %37)
%39 = load i32*, i32** %26
%40 = load i32, i32* %18
%41 = call i32 (i32*, i8*, ...) @fprintf(i32* %39, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i32 %40)
%42 = load i32*, i32** %26
%43 = load i32, i32* %20
%44 = call i32 (i32*, i8*, ...) @fprintf(i32* %42, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i32 %43)
%45 = load i32*, i32** %26
%46 = load i32, i32* @DBL_DIG
%47 = sub nsw i32 %46, 1
%48 = load double, double* %19
%49 = call i32 (i32*, i8*, ...) @fprintf(i32* %45, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i32 %47, double %48)
%50 = load i32*, i32** %26
%51 = load i32, i32* %21
%52 = call i32 (i32*, i8*, ...) @fprintf(i32* %50, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0), i32 %51)
%53 = load i8*, i8** %22
%54 = icmp ne i8* %53, null
br i1 %54, label %55, label %59
55: ; preds = %11
%56 = load i32*, i32** %26
%57 = load i8*, i8** %22
%58 = call i32 (i32*, i8*, ...) @fprintf(i32* %56, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i8* %57)
br label %59
59: ; preds = %55, %11
%60 = load i32*, i32** %26
%61 = call i32 @localtime(i32* %24)
%62 = call i8* @asctime(i32 %61)
%63 = call i32 (i32*, i8*, ...) @fprintf(i32* %60, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i64 0, i64 0), i8* %62)
store i32 0, i32* %23
br label %64
64: ; preds = %86, %59
%65 = load i32, i32* %23
%66 = load i32, i32* %16
%67 = icmp slt i32 %65, %66
br i1 %67, label %68, label %89
68: ; preds = %64
%69 = load i32*, i32** %26
%70 = load i32*, i32** %13
%71 = load i32, i32* %23
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds i32, i32* %70, i64 %72
%74 = load i32, i32* %73
%75 = load i32*, i32** %14
%76 = load i32, i32* %23
%77 = sext i32 %76 to i64
%78 = getelementptr inbounds i32, i32* %75, i64 %77
%79 = load i32, i32* %78
%80 = load i32*, i32** %15
%81 = load i32, i32* %23
%82 = sext i32 %81 to i64
%83 = getelementptr inbounds i32, i32* %80, i64 %82
%84 = load i32, i32* %83
%85 = call i32 (i32*, i8*, ...) @fprintf(i32* %69, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.9, i64 0, i64 0), i32 %74, i32 %79, i32 %84)
br label %86
86: ; preds = %68
%87 = load i32, i32* %23
%88 = add nsw i32 %87, 1
store i32 %88, i32* %23
br label %64
89: ; preds = %64
%90 = load i32*, i32** %26
%91 = call i32 @fclose(i32* %90)
%92 = load i8*, i8** %25
%93 = call i32 @free(i8* %92)
ret void
}

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