#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*/ assert(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int, double);
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
void count_freq(FILE *fout, int (*pdist)(double *, int *, int), int lcutoff,
                int rcutoff, double *prob_accum, int *energy, int nsample) {
  int i;
  int freq[(1 << 12)];
  int rand_nr;
  int range = rcutoff - lcutoff;
  assert(range > 0);
  srand(time(NULL));
  for (i = 0; i < (1 << 12); i++)
    freq[i] = 0.0;
  for (i = 0; i < (1 << 17); i++) {
    rand_nr = pdist(prob_accum, energy, nsample);
    if ((rand_nr < lcutoff) || (rand_nr > rcutoff))
      continue;
    freq[(rand_nr - lcutoff) * (1 << 12) / range]++;
  }
  for (i = 0; i < (1 << 12); i++) {
    fprintf(fout, "%.12f %.12f\n",
            lcutoff + (double)(range * i) / (double)(1 << 12),
            ((double)freq[i] / (double)(1 << 17)));
  }
}


x86 assembly (clang, -O0):
<count_freq>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4040,%rsp
mov    0x10(%rbp),%eax
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
mov    %r9,-0x28(%rbp)
mov    -0x18(%rbp),%eax
sub    -0x14(%rbp),%eax
mov    %eax,-0x4038(%rbp)
cmpl   $0x0,-0x4038(%rbp)
setg   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1060 <time@plt>
mov    %eax,%edi
call   1030 <srand@plt>
movl   $0x0,-0x2c(%rbp)
cmpl   $0x1000,-0x2c(%rbp)
jge    11c5 <count_freq+0x85>
movslq -0x2c(%rbp),%rax
movl   $0x0,-0x4030(%rbp,%rax,4)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    119b <count_freq+0x5b>
movl   $0x0,-0x2c(%rbp)
cmpl   $0x20000,-0x2c(%rbp)
jge    1247 <count_freq+0x107>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    0x10(%rbp),%edx
call   *%rax
mov    %eax,-0x4034(%rbp)
mov    -0x4034(%rbp),%eax
cmp    -0x14(%rbp),%eax
jl     120e <count_freq+0xce>
mov    -0x4034(%rbp),%eax
cmp    -0x18(%rbp),%eax
jle    1213 <count_freq+0xd3>
jmp    1239 <count_freq+0xf9>
mov    -0x4034(%rbp),%eax
sub    -0x14(%rbp),%eax
shl    $0xc,%eax
cltd
idivl  -0x4038(%rbp)
cltq
mov    -0x4030(%rbp,%rax,4),%ecx
add    $0x1,%ecx
mov    %ecx,-0x4030(%rbp,%rax,4)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11cc <count_freq+0x8c>
movl   $0x0,-0x2c(%rbp)
cmpl   $0x1000,-0x2c(%rbp)
jge    12b9 <count_freq+0x179>
mov    -0x8(%rbp),%rdi
cvtsi2sdl -0x14(%rbp),%xmm0
mov    -0x4038(%rbp),%eax
imul   -0x2c(%rbp),%eax
cvtsi2sd %eax,%xmm1
movsd  0xd8e(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edx
movslq -0x2c(%rbp),%rax
cvtsi2sdl -0x4030(%rbp,%rax,4),%xmm0
ff ff
movsd  0xd65(%rip),%xmm1
divsd  %xmm1,%xmm0
lea    0xd6a(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    124e <count_freq+0x10e>
add    $0x4040,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<count_freq>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x4018,%rsp
mov    %r9,%r15
mov    %r8,%r13
mov    %ecx,%r12d
mov    %edx,%ebp
mov    %rsi,%rbx
mov    %rdi,0x8(%rsp)
xor    %edi,%edi
mov    %ecx,(%rsp)
sub    %edx,%r12d
setg   %dil
call   1050 <assert@plt>
xor    %edi,%edi
call   1070 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
lea    0x10(%rsp),%rdi
mov    $0x4000,%edx
xor    %esi,%esi
call   1030 <memset@plt>
mov    $0x20000,%r14d
jmp    11b6 <count_freq+0x66>
nopl   0x0(%rax)
add    $0xffffffff,%r14d
je     11e0 <count_freq+0x90>
mov    %r13,%rdi
mov    %r15,%rsi
mov    0x4050(%rsp),%edx
call   *%rbx
mov    %eax,%ecx
sub    %ebp,%eax
jl     11b0 <count_freq+0x60>
cmp    (%rsp),%ecx
jg     11b0 <count_freq+0x60>
shl    $0xc,%eax
cltd
idiv   %r12d
cltq
addl   $0x1,0x10(%rsp,%rax,4)
jmp    11b0 <count_freq+0x60>
cvtsi2sd %ebp,%xmm0
movsd  %xmm0,(%rsp)
xor    %ebp,%ebp
lea    0xe1e(%rip),%r14
xor    %ebx,%ebx
mov    0x8(%rsp),%r15
nopl   0x0(%rax)
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
mulsd  0xdf1(%rip),%xmm0
addsd  (%rsp),%xmm0
cvttsd2si %xmm0,%edx
xorps  %xmm0,%xmm0
cvtsi2sdl 0x10(%rsp,%rbx,4),%xmm0
mulsd  0xddf(%rip),%xmm0
mov    %r15,%rdi
mov    %r14,%rsi
call   1060 <fprintf@plt>
add    $0x1,%rbx
add    %r12d,%ebp
cmp    $0x1000,%rbx
jne    1200 <count_freq+0xb0>
add    $0x4018,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"%.12f %.12f\0A\00"
define void @count_freq(i32* %0, i32 (double*, i32*, i32)* %1, i32 %2, i32 %3, double* %4, i32* %5, i32 %6) {
%8 = alloca i32*
%9 = alloca i32 (double*, i32*, i32)*
%10 = alloca i32
%11 = alloca i32
%12 = alloca double*
%13 = alloca i32*
%14 = alloca i32
%15 = alloca i32
%16 = alloca [4096 x i32]
%17 = alloca i32
%18 = alloca i32
store i32* %0, i32** %8
store i32 (double*, i32*, i32)* %1, i32 (double*, i32*, i32)** %9
store i32 %2, i32* %10
store i32 %3, i32* %11
store double* %4, double** %12
store i32* %5, i32** %13
store i32 %6, i32* %14
%19 = load i32, i32* %11
%20 = load i32, i32* %10
%21 = sub nsw i32 %19, %20
store i32 %21, i32* %18
%22 = load i32, i32* %18
%23 = icmp sgt i32 %22, 0
%24 = zext i1 %23 to i32
%25 = call i32 @assert(i32 %24)
%26 = call i32 @time(i32* null)
%27 = call i32 @srand(i32 %26)
store i32 0, i32* %15
br label %28
28: ; preds = %35, %7
%29 = load i32, i32* %15
%30 = icmp slt i32 %29, 4096
br i1 %30, label %31, label %38
31: ; preds = %28
%32 = load i32, i32* %15
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [4096 x i32], [4096 x i32]* %16, i64 0, i64 %33
store i32 0, i32* %34
br label %35
35: ; preds = %31
%36 = load i32, i32* %15
%37 = add nsw i32 %36, 1
store i32 %37, i32* %15
br label %28
38: ; preds = %28
store i32 0, i32* %15
br label %39
39: ; preds = %67, %38
%40 = load i32, i32* %15
%41 = icmp slt i32 %40, 131072
br i1 %41, label %42, label %70
42: ; preds = %39
%43 = load i32 (double*, i32*, i32)*, i32 (double*, i32*, i32)** %9
%44 = load double*, double** %12
%45 = load i32*, i32** %13
%46 = load i32, i32* %14
%47 = call i32 %43(double* %44, i32* %45, i32 %46)
store i32 %47, i32* %17
%48 = load i32, i32* %17
%49 = load i32, i32* %10
%50 = icmp slt i32 %48, %49
br i1 %50, label %55, label %51
51: ; preds = %42
%52 = load i32, i32* %17
%53 = load i32, i32* %11
%54 = icmp sgt i32 %52, %53
br i1 %54, label %55, label %56
55: ; preds = %51, %42
br label %67
56: ; preds = %51
%57 = load i32, i32* %17
%58 = load i32, i32* %10
%59 = sub nsw i32 %57, %58
%60 = mul nsw i32 %59, 4096
%61 = load i32, i32* %18
%62 = sdiv i32 %60, %61
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds [4096 x i32], [4096 x i32]* %16, i64 0, i64 %63
%65 = load i32, i32* %64
%66 = add nsw i32 %65, 1
store i32 %66, i32* %64
br label %67
67: ; preds = %56, %55
%68 = load i32, i32* %15
%69 = add nsw i32 %68, 1
store i32 %69, i32* %15
br label %39
70: ; preds = %39
store i32 0, i32* %15
br label %71
71: ; preds = %92, %70
%72 = load i32, i32* %15
%73 = icmp slt i32 %72, 4096
br i1 %73, label %74, label %95
74: ; preds = %71
%75 = load i32*, i32** %8
%76 = load i32, i32* %10
%77 = sitofp i32 %76 to double
%78 = load i32, i32* %18
%79 = load i32, i32* %15
%80 = mul nsw i32 %78, %79
%81 = sitofp i32 %80 to double
%82 = fdiv double %81, 4.096000e+03
%83 = fadd double %77, %82
%84 = fptosi double %83 to i32
%85 = load i32, i32* %15
%86 = sext i32 %85 to i64
%87 = getelementptr inbounds [4096 x i32], [4096 x i32]* %16, i64 0, i64 %86
%88 = load i32, i32* %87
%89 = sitofp i32 %88 to double
%90 = fdiv double %89, 1.310720e+05
%91 = call i32 @fprintf(i32* %75, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %84, double %90)
br label %92
92: ; preds = %74
%93 = load i32, i32* %15
%94 = add nsw i32 %93, 1
store i32 %94, i32* %15
br label %71
95: ; preds = %71
ret void
}

LLVM IR (-O2):
@.str = [13 x i8] c"%.12f %.12f\0A\00"
define void @count_freq(i32* nocapture %0, i32 (double*, i32*, i32)* nocapture %1, i32 %2, i32 %3, double* %4, i32* %5, i32 %6) {
%8 = alloca [4096 x i32]
%9 = bitcast [4096 x i32]* %8 to i8*
%10 = sub nsw i32 %3, %2
%11 = icmp sgt i32 %10, 0
%12 = zext i1 %11 to i32
%13 = tail call i32 @assert(i32 %12)
%14 = tail call i32 @time(i32* null)
%15 = tail call i32 @srand(i32 %14)
br label %18
16: ; preds = %32
%17 = sitofp i32 %2 to double
br label %35
18: ; preds = %7, %32
%19 = phi i32 [ %33, %32 ], [ 0, %7 ]
%20 = tail call i32 %1(double* %4, i32* %5, i32 %6)
%21 = icmp slt i32 %20, %2
%22 = icmp sgt i32 %20, %3
%23 = or i1 %21, %22
br i1 %23, label %32, label %24
24: ; preds = %18
%25 = sub nsw i32 %20, %2
%26 = shl nsw i32 %25, 12
%27 = sdiv i32 %26, %10
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [4096 x i32], [4096 x i32]* %8, i64 0, i64 %28
%30 = load i32, i32* %29
%31 = add nsw i32 %30, 1
store i32 %31, i32* %29
br label %32
32: ; preds = %18, %24
%33 = add nuw nsw i32 %19, 1
%34 = icmp eq i32 %33, 131072
br i1 %34, label %16, label %18
35: ; preds = %16, %35
%36 = phi i64 [ 0, %16 ], [ %48, %35 ]
%37 = trunc i64 %36 to i32
%38 = mul nsw i32 %10, %37
%39 = sitofp i32 %38 to double
%40 = fmul double %39, 0x3F30000000000000
%41 = fadd double %40, %17
%42 = fptosi double %41 to i32
%43 = getelementptr inbounds [4096 x i32], [4096 x i32]* %8, i64 0, i64 %36
%44 = load i32, i32* %43
%45 = sitofp i32 %44 to double
%46 = fmul double %45, 0x3EE0000000000000
%47 = tail call i32 @fprintf(i32* %0, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %42, double %46)
%48 = add nuw nsw i64 %36, 1
%49 = icmp eq i64 %48, 4096
br i1 %49, label %50, label %35
50: ; preds = %35
ret void
}