#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, double);
void counter(double *array) {
  FILE *fp;
  char output[] = "simulated_nh.dat";
  int q;
  fp = fopen(output, "w");
  for (q = 0; q < 1000000; q++) {
    if (array[q] > 0) {
      fprintf(fp, "%lf\n", array[q]);
    }
  }
  fclose(fp);
}


x86 assembly (clang, -O0):
<counter>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    0xebd(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xeba(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xeb8(%rip),%al
mov    %al,-0x20(%rbp)
lea    -0x30(%rbp),%rdi
lea    0xeab(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x34(%rbp)
cmpl   $0xf4240,-0x34(%rbp)
jge    11cd <counter+0x9d>
mov    -0x8(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    11ba <counter+0x8a>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
lea    0xe5e(%rip),%rsi
call   1040 <fprintf@plt>
jmp    11bf <counter+0x8f>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1176 <counter+0x46>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<counter>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%r12
movapd 0xeba(%rip),%xmm0
movapd %xmm0,(%rsp)
movb   $0x0,0x10(%rsp)
lea    0xeba(%rip),%rsi
mov    %rsp,%rdi
call   1050 <fopen@plt>
mov    %rax,%r14
xor    %ebx,%ebx
xorpd  %xmm1,%xmm1
lea    0xea4(%rip),%r15
jmp    118d <counter+0x5d>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%rbx
cmp    $0xf4240,%rbx
je     11aa <counter+0x7a>
movsd  (%r12,%rbx,8),%xmm0
ucomisd %xmm1,%xmm0
jbe    1180 <counter+0x50>
mov    %r14,%rdi
mov    %r15,%rsi
call   1040 <fprintf@plt>
xorpd  %xmm1,%xmm1
jmp    1180 <counter+0x50>
mov    %r14,%rdi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <fclose@plt>

LLVM IR (-O0):
@__const.counter.output = [17 x i8] c"simulated_nh.dat\00"
@.str = [2 x i8] c"w\00"
@.str.1 = [5 x i8] c"%lf\0A\00"
define void @counter(double* %0) {
%2 = alloca double*
%3 = alloca i32*
%4 = alloca [17 x i8]
%5 = alloca i32
store double* %0, double** %2
%6 = bitcast [17 x i8]* %4 to i8*
%7 = getelementptr inbounds [17 x i8], [17 x i8]* %4, i64 0, i64 0
%8 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %8, i32** %3
store i32 0, i32* %5
br label %9
9: ; preds = %28, %1
%10 = load i32, i32* %5
%11 = icmp slt i32 %10, 1000000
br i1 %11, label %12, label %31
12: ; preds = %9
%13 = load double*, double** %2
%14 = load i32, i32* %5
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds double, double* %13, i64 %15
%17 = load double, double* %16
%18 = fcmp ogt double %17, 0.000000e+00
br i1 %18, label %19, label %27
19: ; preds = %12
%20 = load i32*, i32** %3
%21 = load double*, double** %2
%22 = load i32, i32* %5
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds double, double* %21, i64 %23
%25 = load double, double* %24
%26 = call i32 @fprintf(i32* %20, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), double %25)
br label %27
27: ; preds = %19, %12
br label %28
28: ; preds = %27
%29 = load i32, i32* %5
%30 = add nsw i32 %29, 1
store i32 %30, i32* %5
br label %9
31: ; preds = %9
%32 = load i32*, i32** %3
%33 = call i32 @fclose(i32* %32)
ret void
}

LLVM IR (-O2):
@__const.counter.output = [17 x i8] c"simulated_nh.dat\00"
@.str = [2 x i8] c"w\00"
@.str.1 = [5 x i8] c"%lf\0A\00"
define void @counter(double* nocapture %0) {
%2 = alloca [17 x i8]
%3 = getelementptr inbounds [17 x i8], [17 x i8]* %2, i64 0, i64 0
%4 = call i32* @fopen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %5
5: ; preds = %1, %12
%6 = phi i64 [ 0, %1 ], [ %13, %12 ]
%7 = getelementptr inbounds double, double* %0, i64 %6
%8 = load double, double* %7
%9 = fcmp ogt double %8, 0.000000e+00
br i1 %9, label %10, label %12
10: ; preds = %5
%11 = tail call i32 @fprintf(i32* %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), double %8)
br label %12
12: ; preds = %5, %10
%13 = add nuw nsw i64 %6, 1
%14 = icmp eq i64 %13, 1000000
br i1 %14, label %15, label %5
15: ; preds = %12
%16 = tail call i32 @fclose(i32* %4)
ret void
}