#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 */
char *calloc(int, int);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
void writeStats(char *fileName, double *matrix, double *mAF, double *SNPSd,
                double *miss, int nrow, int nstat, double threshold) {
  FILE *resultFile;
  FILE *topFile;
  char *topfileName = calloc(256, sizeof(char));
  strcpy(topfileName, fileName);
  strcat(topfileName, ".top");
  int i, j;
  printf("Opening file %s...\n", fileName);
  printf("Opening file %s...\n", topfileName);
  if ((resultFile = fopen(fileName, "w")) == NULL)
    printf("ERROR, unable to open %s\n", fileName);
  if ((topFile = fopen(topfileName, "w")) == NULL)
    printf("ERROR, unable to open %s\n", topfileName);
  fprintf(resultFile, "h\'\taxis\th\tmAF\tmiss\n");
  fprintf(topFile, "snp\tPC\tscore\n");
  for (i = 0; i < nrow; i++) {
    for (j = 0; j < nstat; j++) {
      if (j != 1)
        fprintf(resultFile, "%f ", matrix[i * nstat + j]);
    }
    fprintf(resultFile, "%f %f\n", mAF[i], miss[i]);
    if (matrix[i * nstat] >= threshold) {
      fprintf(topFile, "%d %d %f\n", i + 1, (int)matrix[i * nstat + 2],
              matrix[i * nstat]);
    }
  }
}


x86 assembly (clang, -O0):
<writeStats>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    0x10(%rbp),%eax
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9d,-0x2c(%rbp)
movsd  %xmm0,-0x38(%rbp)
mov    $0x100,%edi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x50(%rbp),%rdi
lea    0xe4d(%rip),%rsi
call   1080 <strcat@plt>
mov    -0x8(%rbp),%rsi
lea    0xe42(%rip),%rdi
call   1040 <printf@plt>
mov    -0x50(%rbp),%rsi
lea    0xe32(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
lea    0xe36(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x40(%rbp)
cmp    $0x0,%rax
jne    1206 <writeStats+0xa6>
mov    -0x8(%rbp),%rsi
lea    0xe1a(%rip),%rdi
call   1040 <printf@plt>
mov    -0x50(%rbp),%rdi
lea    0xe08(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x48(%rbp)
cmp    $0x0,%rax
jne    1234 <writeStats+0xd4>
mov    -0x50(%rbp),%rsi
lea    0xdec(%rip),%rdi
call   1040 <printf@plt>
mov    -0x40(%rbp),%rdi
lea    0xdf6(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x48(%rbp),%rdi
lea    0xdf8(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x0,-0x54(%rbp)
mov    -0x54(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jge    1361 <writeStats+0x201>
movl   $0x0,-0x58(%rbp)
mov    -0x58(%rbp),%eax
cmp    0x10(%rbp),%eax
jge    12c3 <writeStats+0x163>
cmpl   $0x1,-0x58(%rbp)
je     12b0 <writeStats+0x150>
mov    -0x40(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    -0x54(%rbp),%ecx
imul   0x10(%rbp),%ecx
add    -0x58(%rbp),%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
lea    0xdae(%rip),%rsi
mov    $0x1,%al
call   1060 <fprintf@plt>
jmp    12b5 <writeStats+0x155>
mov    -0x58(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x58(%rbp)
jmp    1272 <writeStats+0x112>
mov    -0x40(%rbp),%rdi
mov    -0x18(%rbp),%rax
movslq -0x54(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x28(%rbp),%rax
movslq -0x54(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
lea    0xd73(%rip),%rsi
mov    $0x2,%al
call   1060 <fprintf@plt>
mov    -0x10(%rbp),%rax
mov    -0x54(%rbp),%ecx
imul   0x10(%rbp),%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
ucomisd -0x38(%rbp),%xmm0
jb     134e <writeStats+0x1ee>
mov    -0x48(%rbp),%rdi
mov    -0x54(%rbp),%edx
add    $0x1,%edx
mov    -0x10(%rbp),%rax
mov    -0x54(%rbp),%ecx
imul   0x10(%rbp),%ecx
add    $0x2,%ecx
movslq %ecx,%rcx
cvttsd2si (%rax,%rcx,8),%ecx
mov    -0x10(%rbp),%rax
mov    -0x54(%rbp),%esi
imul   0x10(%rbp),%esi
movslq %esi,%rsi
movsd  (%rax,%rsi,8),%xmm0
lea    0xd1b(%rip),%rsi
mov    $0x1,%al
call   1060 <fprintf@plt>
jmp    1353 <writeStats+0x1f3>
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    125f <writeStats+0xff>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<writeStats>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
movsd  %xmm0,0x48(%rsp)
mov    %r9d,%r15d
mov    %r8,0x40(%rsp)
mov    %rdx,0x38(%rsp)
mov    %rsi,(%rsp)
mov    %rdi,%r13
mov    $0x100,%edi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    %r13,%rsi
call   1030 <strcpy@plt>
lea    0xe44(%rip),%rsi
mov    %r14,%rdi
call   1080 <strcat@plt>
lea    0xe3a(%rip),%rbx
mov    %rbx,%rdi
mov    %r13,%rsi
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <printf@plt>
lea    0xe31(%rip),%rsi
mov    %r13,%rdi
call   1070 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1207 <writeStats+0x97>
lea    0xe1c(%rip),%rdi
mov    %r13,%rsi
call   1040 <printf@plt>
lea    0xe0b(%rip),%rsi
mov    %r14,%rdi
call   1070 <fopen@plt>
mov    %rax,%rbp
test   %rax,%rax
jne    122d <writeStats+0xbd>
lea    0xdf6(%rip),%rdi
mov    %r14,%rsi
call   1040 <printf@plt>
lea    0xe01(%rip),%rdi
mov    $0x13,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1090 <fwrite@plt>
lea    0xdfc(%rip),%rdi
mov    $0xd,%esi
mov    $0x1,%edx
mov    %rbp,0x18(%rsp)
mov    %rbp,%rcx
call   1090 <fwrite@plt>
test   %r15d,%r15d
jle    1398 <writeStats+0x228>
mov    0x90(%rsp),%eax
cltq
mov    %r15d,%ecx
mov    %rcx,0x28(%rsp)
mov    %eax,%r15d
lea    -0x1(%rax),%ecx
mov    %ecx,0xc(%rsp)
mov    %rax,0x30(%rsp)
lea    0x0(,%rax,8),%rax
mov    %rax,0x20(%rsp)
xor    %ebp,%ebp
mov    (%rsp),%r12
jmp    12c0 <writeStats+0x150>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    0x20(%rsp),%r12
cmp    0x28(%rsp),%rbp
je     1398 <writeStats+0x228>
mov    %rbp,0x50(%rsp)
mov    0x30(%rsp),%rax
imul   %rax,%rbp
mov    %rbp,0x10(%rsp)
test   %eax,%eax
lea    0xd7b(%rip),%r14
jle    132c <writeStats+0x1bc>
mov    (%rsp),%rax
mov    0x10(%rsp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x1,%al
call   1060 <fprintf@plt>
cmpl   $0x2,0xc(%rsp)
jb     132c <writeStats+0x1bc>
mov    $0x2,%r13d
cs nopw 0x0(%rax,%rax,1)
movsd  (%r12,%r13,8),%xmm0
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x1,%al
call   1060 <fprintf@plt>
add    $0x1,%r13
cmp    %r13,%r15
jne    1310 <writeStats+0x1a0>
mov    0x38(%rsp),%rax
mov    0x50(%rsp),%rbp
movsd  (%rax,%rbp,8),%xmm0
mov    0x40(%rsp),%rax
movsd  (%rax,%rbp,8),%xmm1
mov    %rbx,%rdi
lea    0xd0c(%rip),%rsi
mov    $0x2,%al
call   1060 <fprintf@plt>
mov    (%rsp),%rax
mov    0x10(%rsp),%rcx
movsd  (%rax,%rcx,8),%xmm0
add    $0x1,%rbp
ucomisd 0x48(%rsp),%xmm0
jb     12b0 <writeStats+0x140>
mov    (%rsp),%rax
cvttsd2si 0x10(%rax,%rcx,8),%ecx
mov    0x18(%rsp),%rdi
lea    0xcd8(%rip),%rsi
mov    %ebp,%edx
mov    $0x1,%al
call   1060 <fprintf@plt>
jmp    12b0 <writeStats+0x140>
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c".top\00"
@.str.1 = [20 x i8] c"Opening file %s...\0A\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [26 x i8] c"ERROR, unable to open %s\0A\00"
@.str.4 = [20 x i8] c"h'\09axis\09h\09mAF\09miss\0A\00"
@.str.5 = [14 x i8] c"snp\09PC\09score\0A\00"
@.str.6 = [4 x i8] c"%f \00"
@.str.7 = [7 x i8] c"%f %f\0A\00"
@.str.8 = [10 x i8] c"%d %d %f\0A\00"
define void @writeStats(i8* %0, double* %1, double* %2, double* %3, double* %4, i32 %5, i32 %6, double %7) {
%9 = alloca i8*
%10 = alloca double*
%11 = alloca double*
%12 = alloca double*
%13 = alloca double*
%14 = alloca i32
%15 = alloca i32
%16 = alloca double
%17 = alloca i32*
%18 = alloca i32*
%19 = alloca i8*
%20 = alloca i32
%21 = alloca i32
store i8* %0, i8** %9
store double* %1, double** %10
store double* %2, double** %11
store double* %3, double** %12
store double* %4, double** %13
store i32 %5, i32* %14
store i32 %6, i32* %15
store double %7, double* %16
%22 = call i8* @calloc(i32 256, i32 1)
store i8* %22, i8** %19
%23 = load i8*, i8** %19
%24 = load i8*, i8** %9
%25 = call i32 @strcpy(i8* %23, i8* %24)
%26 = load i8*, i8** %19
%27 = call i32 @strcat(i8* %26, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%28 = load i8*, i8** %9
%29 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %28)
%30 = load i8*, i8** %19
%31 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %30)
%32 = load i8*, i8** %9
%33 = call i32* @fopen(i8* %32, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %33, i32** %17
%34 = icmp eq i32* %33, null
br i1 %34, label %35, label %38
35: ; preds = %8
%36 = load i8*, i8** %9
%37 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i8* %36)
br label %38
38: ; preds = %35, %8
%39 = load i8*, i8** %19
%40 = call i32* @fopen(i8* %39, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %40, i32** %18
%41 = icmp eq i32* %40, null
br i1 %41, label %42, label %45
42: ; preds = %38
%43 = load i8*, i8** %19
%44 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i8* %43)
br label %45
45: ; preds = %42, %38
%46 = load i32*, i32** %17
%47 = call i32 (i32*, i8*, ...) @fprintf(i32* %46, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
%48 = load i32*, i32** %18
%49 = call i32 (i32*, i8*, ...) @fprintf(i32* %48, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %20
br label %50
50: ; preds = %122, %45
%51 = load i32, i32* %20
%52 = load i32, i32* %14
%53 = icmp slt i32 %51, %52
br i1 %53, label %54, label %125
54: ; preds = %50
store i32 0, i32* %21
br label %55
55: ; preds = %75, %54
%56 = load i32, i32* %21
%57 = load i32, i32* %15
%58 = icmp slt i32 %56, %57
br i1 %58, label %59, label %78
59: ; preds = %55
%60 = load i32, i32* %21
%61 = icmp ne i32 %60, 1
br i1 %61, label %62, label %74
62: ; preds = %59
%63 = load i32*, i32** %17
%64 = load double*, double** %10
%65 = load i32, i32* %20
%66 = load i32, i32* %15
%67 = mul nsw i32 %65, %66
%68 = load i32, i32* %21
%69 = add nsw i32 %67, %68
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds double, double* %64, i64 %70
%72 = load double, double* %71
%73 = call i32 (i32*, i8*, ...) @fprintf(i32* %63, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), double %72)
br label %74
74: ; preds = %62, %59
br label %75
75: ; preds = %74
%76 = load i32, i32* %21
%77 = add nsw i32 %76, 1
store i32 %77, i32* %21
br label %55
78: ; preds = %55
%79 = load i32*, i32** %17
%80 = load double*, double** %11
%81 = load i32, i32* %20
%82 = sext i32 %81 to i64
%83 = getelementptr inbounds double, double* %80, i64 %82
%84 = load double, double* %83
%85 = load double*, double** %13
%86 = load i32, i32* %20
%87 = sext i32 %86 to i64
%88 = getelementptr inbounds double, double* %85, i64 %87
%89 = load double, double* %88
%90 = call i32 (i32*, i8*, ...) @fprintf(i32* %79, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0), double %84, double %89)
%91 = load double*, double** %10
%92 = load i32, i32* %20
%93 = load i32, i32* %15
%94 = mul nsw i32 %92, %93
%95 = sext i32 %94 to i64
%96 = getelementptr inbounds double, double* %91, i64 %95
%97 = load double, double* %96
%98 = load double, double* %16
%99 = fcmp oge double %97, %98
br i1 %99, label %100, label %121
100: ; preds = %78
%101 = load i32*, i32** %18
%102 = load i32, i32* %20
%103 = add nsw i32 %102, 1
%104 = load double*, double** %10
%105 = load i32, i32* %20
%106 = load i32, i32* %15
%107 = mul nsw i32 %105, %106
%108 = add nsw i32 %107, 2
%109 = sext i32 %108 to i64
%110 = getelementptr inbounds double, double* %104, i64 %109
%111 = load double, double* %110
%112 = fptosi double %111 to i32
%113 = load double*, double** %10
%114 = load i32, i32* %20
%115 = load i32, i32* %15
%116 = mul nsw i32 %114, %115
%117 = sext i32 %116 to i64
%118 = getelementptr inbounds double, double* %113, i64 %117
%119 = load double, double* %118
%120 = call i32 (i32*, i8*, ...) @fprintf(i32* %101, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0), i32 %103, i32 %112, double %119)
br label %121
121: ; preds = %100, %78
br label %122
122: ; preds = %121
%123 = load i32, i32* %20
%124 = add nsw i32 %123, 1
store i32 %124, i32* %20
br label %50
125: ; preds = %50
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c".top\00"
@.str.1 = [20 x i8] c"Opening file %s...\0A\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [26 x i8] c"ERROR, unable to open %s\0A\00"
@.str.4 = [20 x i8] c"h'\09axis\09h\09mAF\09miss\0A\00"
@.str.5 = [14 x i8] c"snp\09PC\09score\0A\00"
@.str.6 = [4 x i8] c"%f \00"
@.str.7 = [7 x i8] c"%f %f\0A\00"
@.str.8 = [10 x i8] c"%d %d %f\0A\00"
define void @writeStats(i8* %0, double* nocapture %1, double* nocapture %2, double* nocapture readnone %3, double* nocapture %4, i32 %5, i32 %6, double %7) {
%9 = tail call dereferenceable_or_null(256) i8* @calloc(i32 256, i32 1)
%10 = tail call i32 @strcpy(i8* %9, i8* %0)
%11 = tail call i32 @strcat(i8* %9, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%12 = tail call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%13 = tail call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %9)
%14 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %18
16: ; preds = %8
%17 = tail call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i8* %0)
br label %18
18: ; preds = %16, %8
%19 = tail call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %23
21: ; preds = %18
%22 = tail call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i8* %9)
br label %23
23: ; preds = %21, %18
%24 = tail call i64 @fwrite(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i64 19, i64 1, i32* %14)
%25 = tail call i64 @fwrite(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i64 13, i64 1, i32* %19)
%26 = icmp sgt i32 %5, 0
br i1 %26, label %27, label %68
27: ; preds = %23
%28 = icmp sgt i32 %6, 0
%29 = sext i32 %6 to i64
%30 = zext i32 %5 to i64
%31 = zext i32 %6 to i64
%32 = add i32 %6, -1
%33 = icmp ult i32 %32, 2
br label %34
34: ; preds = %27, %66
%35 = phi i64 [ 0, %27 ], [ %58, %66 ]
%36 = mul nsw i64 %35, %29
br i1 %28, label %37, label %49
37: ; preds = %34
%38 = getelementptr inbounds double, double* %1, i64 %36
%39 = load double, double* %38
%40 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %14, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), double %39)
br i1 %33, label %49, label %41
41: ; preds = %37, %41
%42 = phi i64 [ %47, %41 ], [ 2, %37 ]
%43 = add nsw i64 %42, %36
%44 = getelementptr inbounds double, double* %1, i64 %43
%45 = load double, double* %44
%46 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %14, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), double %45)
%47 = add nuw nsw i64 %42, 1
%48 = icmp eq i64 %47, %31
br i1 %48, label %49, label %41
49: ; preds = %41, %37, %34
%50 = getelementptr inbounds double, double* %2, i64 %35
%51 = load double, double* %50
%52 = getelementptr inbounds double, double* %4, i64 %35
%53 = load double, double* %52
%54 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %14, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0), double %51, double %53)
%55 = getelementptr inbounds double, double* %1, i64 %36
%56 = load double, double* %55
%57 = fcmp ult double %56, %7
%58 = add nuw nsw i64 %35, 1
br i1 %57, label %66, label %59
59: ; preds = %49
%60 = add nsw i64 %36, 2
%61 = getelementptr inbounds double, double* %1, i64 %60
%62 = load double, double* %61
%63 = fptosi double %62 to i32
%64 = trunc i64 %58 to i32
%65 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %19, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0), i32 %64, i32 %63, double %56)
br label %66
66: ; preds = %49, %59
%67 = icmp eq i64 %58, %30
br i1 %67, label %68, label %34
68: ; preds = %66, %23
ret void
}