#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 */
float fabsf(float);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, int);
int /*<<< orphan*/ sscanf(char *, char *, float *);
CalcDevBins(char *basename, int readback, float mean, float stdev,
            int devbins[]) {
  FILE *fp;
  char filename[256];
  char theline[256];
  float theval;
  float delta;
  int x;
  for (x = 0; x < 5; x++)
    devbins[x] = 0;
  sprintf(filename, "%s/%d/values", basename, readback);
  fp = fopen(filename, "r");
  while (fgets(&(theline[0]), 256, fp) != NULL) {
    sscanf(theline, "%*d %f", &theval);
    delta = fabsf(mean - theval);
    if (delta <= (stdev * 1.0))
      devbins[0]++;
    else if (delta <= (stdev * 2.0))
      devbins[1]++;
    else if (delta <= (stdev * 3.0))
      devbins[2]++;
    else if (delta <= (stdev * 4.0))
      devbins[3]++;
    else if (delta > (stdev * 4.0))
      devbins[4]++;
  }
}


x86 assembly (clang, -O0):
<CalcDevBins>:
push   %rbp
mov    %rsp,%rbp
sub    $0x240,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movss  %xmm0,-0x18(%rbp)
movss  %xmm1,-0x1c(%rbp)
mov    %rdx,-0x28(%rbp)
movl   $0x0,-0x23c(%rbp)
cmpl   $0x5,-0x23c(%rbp)
jge    119d <CalcDevBins+0x5d>
mov    -0x28(%rbp),%rax
movslq -0x23c(%rbp),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x23c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x23c(%rbp)
jmp    116a <CalcDevBins+0x2a>
lea    -0x130(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x14(%rbp),%ecx
lea    0xe7e(%rip),%rsi
call   1060 <sprintf@plt>
lea    -0x130(%rbp),%rdi
lea    0xe78(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x30(%rbp)
lea    -0x230(%rbp),%rdi
mov    -0x30(%rbp),%rdx
mov    $0x100,%esi
call   1030 <fgets@plt>
cmp    $0x0,%rax
je     136a <CalcDevBins+0x22a>
lea    -0x230(%rbp),%rdi
lea    0xe44(%rip),%rsi
lea    -0x234(%rbp),%rdx
call   1040 <sscanf@plt>
movss  -0x18(%rbp),%xmm0
subss  -0x234(%rbp),%xmm0
ff
movaps 0xe05(%rip),%xmm1
pand   %xmm1,%xmm0
movss  %xmm0,-0x238(%rbp)
ff
movss  -0x238(%rbp),%xmm0
ff
cvtss2sd %xmm0,%xmm1
movss  -0x1c(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xdbc(%rip),%xmm2
mulsd  %xmm2,%xmm0
ucomisd %xmm1,%xmm0
jb     1262 <CalcDevBins+0x122>
mov    -0x28(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
jmp    1365 <CalcDevBins+0x225>
movss  -0x238(%rbp),%xmm0
ff
cvtss2sd %xmm0,%xmm1
movss  -0x1c(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xd89(%rip),%xmm2
mulsd  %xmm2,%xmm0
ucomisd %xmm1,%xmm0
jb     129f <CalcDevBins+0x15f>
mov    -0x28(%rbp),%rax
mov    0x4(%rax),%ecx
add    $0x1,%ecx
mov    %ecx,0x4(%rax)
jmp    1360 <CalcDevBins+0x220>
movss  -0x238(%rbp),%xmm0
ff
cvtss2sd %xmm0,%xmm1
movss  -0x1c(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xd54(%rip),%xmm2
mulsd  %xmm2,%xmm0
ucomisd %xmm1,%xmm0
jb     12dc <CalcDevBins+0x19c>
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%ecx
add    $0x1,%ecx
mov    %ecx,0x8(%rax)
jmp    135b <CalcDevBins+0x21b>
movss  -0x238(%rbp),%xmm0
ff
cvtss2sd %xmm0,%xmm1
movss  -0x1c(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xd1f(%rip),%xmm2
mulsd  %xmm2,%xmm0
ucomisd %xmm1,%xmm0
jb     1319 <CalcDevBins+0x1d9>
mov    -0x28(%rbp),%rax
mov    0xc(%rax),%ecx
add    $0x1,%ecx
mov    %ecx,0xc(%rax)
jmp    1356 <CalcDevBins+0x216>
movss  -0x238(%rbp),%xmm0
ff
cvtss2sd %xmm0,%xmm0
movss  -0x1c(%rbp),%xmm1
cvtss2sd %xmm1,%xmm1
movsd  0xce2(%rip),%xmm2
mulsd  %xmm2,%xmm1
ucomisd %xmm1,%xmm0
jbe    1351 <CalcDevBins+0x211>
mov    -0x28(%rbp),%rax
mov    0x10(%rax),%ecx
add    $0x1,%ecx
mov    %ecx,0x10(%rax)
jmp    1356 <CalcDevBins+0x216>
jmp    135b <CalcDevBins+0x21b>
jmp    1360 <CalcDevBins+0x220>
jmp    1365 <CalcDevBins+0x225>
jmp    11ce <CalcDevBins+0x8e>
mov    -0x4(%rbp),%eax
add    $0x240,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CalcDevBins>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x248,%rsp
mov    %rdx,%r14
movss  %xmm1,0x4(%rsp)
movss  %xmm0,0x8(%rsp)
mov    %esi,%ecx
mov    %rdi,%rdx
xorpd  %xmm0,%xmm0
movupd %xmm0,(%r14)
movl   $0x0,0x10(%r14)
lea    0xea3(%rip),%rsi
lea    0x140(%rsp),%rbx
mov    %rbx,%rdi
call   1060 <sprintf@plt>
lea    0xe99(%rip),%rsi
mov    %rbx,%rdi
call   1050 <fopen@plt>
mov    %rax,%r12
lea    0x40(%rsp),%rdi
mov    $0x100,%esi
mov    %rax,%rdx
call   1030 <fgets@plt>
test   %rax,%rax
je     12cc <CalcDevBins+0x18c>
movss  0x4(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
movaps %xmm0,%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x38(%rsp)
lea    0x4(%r14),%rbp
movsd  0xe23(%rip),%xmm1
mulsd  %xmm0,%xmm1
movsd  %xmm1,0x30(%rsp)
lea    0x8(%r14),%rax
mov    %rax,0x28(%rsp)
mulsd  0xe10(%rip),%xmm0
movsd  %xmm0,0x10(%rsp)
lea    0xc(%r14),%rax
mov    %rax,0x20(%rsp)
lea    0x10(%r14),%rax
mov    %rax,0x18(%rsp)
lea    0xe18(%rip),%r15
lea    0x40(%rsp),%rbx
lea    0xc(%rsp),%r13
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r13,%rdx
call   1040 <sscanf@plt>
movss  0x8(%rsp),%xmm0
subss  0xc(%rsp),%xmm0
andps  0xdbf(%rip),%xmm0
movss  0x4(%rsp),%xmm1
ucomiss %xmm0,%xmm1
mov    %r14,%rax
jae    12b0 <CalcDevBins+0x170>
cvtss2sd %xmm0,%xmm0
movsd  0x38(%rsp),%xmm1
ucomisd %xmm0,%xmm1
mov    %rbp,%rax
jae    12b0 <CalcDevBins+0x170>
movsd  0x30(%rsp),%xmm1
ucomisd %xmm0,%xmm1
mov    0x28(%rsp),%rax
jae    12b0 <CalcDevBins+0x170>
movsd  0x10(%rsp),%xmm1
ucomisd %xmm0,%xmm1
mov    0x20(%rsp),%rax
jae    12b0 <CalcDevBins+0x170>
ucomisd 0x10(%rsp),%xmm0
mov    0x18(%rsp),%rax
jbe    12b3 <CalcDevBins+0x173>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
addl   $0x1,(%rax)
mov    %rbx,%rdi
mov    $0x100,%esi
mov    %r12,%rdx
call   1030 <fgets@plt>
test   %rax,%rax
jne    1230 <CalcDevBins+0xf0>
add    $0x248,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"%s/%d/values\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [7 x i8] c"%*d %f\00"
define i32 @CalcDevBins(i8* %0, i32 %1, float %2, float %3, i32* %4) {
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca float
%10 = alloca float
%11 = alloca i32*
%12 = alloca i32*
%13 = alloca [256 x i8]
%14 = alloca [256 x i8]
%15 = alloca float
%16 = alloca float
%17 = alloca i32
store i8* %0, i8** %7
store i32 %1, i32* %8
store float %2, float* %9
store float %3, float* %10
store i32* %4, i32** %11
store i32 0, i32* %17
br label %18
18: ; preds = %26, %5
%19 = load i32, i32* %17
%20 = icmp slt i32 %19, 5
br i1 %20, label %21, label %29
21: ; preds = %18
%22 = load i32*, i32** %11
%23 = load i32, i32* %17
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i32, i32* %22, i64 %24
store i32 0, i32* %25
br label %26
26: ; preds = %21
%27 = load i32, i32* %17
%28 = add nsw i32 %27, 1
store i32 %28, i32* %17
br label %18
29: ; preds = %18
%30 = getelementptr inbounds [256 x i8], [256 x i8]* %13, i64 0, i64 0
%31 = load i8*, i8** %7
%32 = load i32, i32* %8
%33 = call i32 @sprintf(i8* %30, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %31, i32 %32)
%34 = getelementptr inbounds [256 x i8], [256 x i8]* %13, i64 0, i64 0
%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** %12
br label %36
36: ; preds = %111, %29
%37 = getelementptr inbounds [256 x i8], [256 x i8]* %14, i64 0, i64 0
%38 = load i32*, i32** %12
%39 = call i32* @fgets(i8* %37, i32 256, i32* %38)
%40 = icmp ne i32* %39, null
br i1 %40, label %41, label %112
41: ; preds = %36
%42 = getelementptr inbounds [256 x i8], [256 x i8]* %14, i64 0, i64 0
%43 = call i32 @sscanf(i8* %42, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), float* %15)
%44 = load float, float* %9
%45 = load float, float* %15
%46 = fsub float %44, %45
%47 = call float @llvm.fabs.f32(float %46)
store float %47, float* %16
%48 = load float, float* %16
%49 = fpext float %48 to double
%50 = load float, float* %10
%51 = fpext float %50 to double
%52 = fmul double %51, 1.000000e+00
%53 = fcmp ole double %49, %52
br i1 %53, label %54, label %59
54: ; preds = %41
%55 = load i32*, i32** %11
%56 = getelementptr inbounds i32, i32* %55, i64 0
%57 = load i32, i32* %56
%58 = add nsw i32 %57, 1
store i32 %58, i32* %56
br label %111
59: ; preds = %41
%60 = load float, float* %16
%61 = fpext float %60 to double
%62 = load float, float* %10
%63 = fpext float %62 to double
%64 = fmul double %63, 2.000000e+00
%65 = fcmp ole double %61, %64
br i1 %65, label %66, label %71
66: ; preds = %59
%67 = load i32*, i32** %11
%68 = getelementptr inbounds i32, i32* %67, i64 1
%69 = load i32, i32* %68
%70 = add nsw i32 %69, 1
store i32 %70, i32* %68
br label %110
71: ; preds = %59
%72 = load float, float* %16
%73 = fpext float %72 to double
%74 = load float, float* %10
%75 = fpext float %74 to double
%76 = fmul double %75, 3.000000e+00
%77 = fcmp ole double %73, %76
br i1 %77, label %78, label %83
78: ; preds = %71
%79 = load i32*, i32** %11
%80 = getelementptr inbounds i32, i32* %79, i64 2
%81 = load i32, i32* %80
%82 = add nsw i32 %81, 1
store i32 %82, i32* %80
br label %109
83: ; preds = %71
%84 = load float, float* %16
%85 = fpext float %84 to double
%86 = load float, float* %10
%87 = fpext float %86 to double
%88 = fmul double %87, 4.000000e+00
%89 = fcmp ole double %85, %88
br i1 %89, label %90, label %95
90: ; preds = %83
%91 = load i32*, i32** %11
%92 = getelementptr inbounds i32, i32* %91, i64 3
%93 = load i32, i32* %92
%94 = add nsw i32 %93, 1
store i32 %94, i32* %92
br label %108
95: ; preds = %83
%96 = load float, float* %16
%97 = fpext float %96 to double
%98 = load float, float* %10
%99 = fpext float %98 to double
%100 = fmul double %99, 4.000000e+00
%101 = fcmp ogt double %97, %100
br i1 %101, label %102, label %107
102: ; preds = %95
%103 = load i32*, i32** %11
%104 = getelementptr inbounds i32, i32* %103, i64 4
%105 = load i32, i32* %104
%106 = add nsw i32 %105, 1
store i32 %106, i32* %104
br label %107
107: ; preds = %102, %95
br label %108
108: ; preds = %107, %90
br label %109
109: ; preds = %108, %78
br label %110
110: ; preds = %109, %66
br label %111
111: ; preds = %110, %54
br label %36
112: ; preds = %36
%113 = load i32, i32* %6
ret i32 %113
}

LLVM IR (-O2):
@.str = [13 x i8] c"%s/%d/values\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [7 x i8] c"%*d %f\00"
define i32 @CalcDevBins(i8* %0, i32 %1, float %2, float %3, i32* nocapture %4) {
%6 = bitcast i32* %4 to i8*
%7 = alloca [256 x i8]
%8 = alloca [256 x i8]
%9 = alloca float
%10 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%11 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%12 = bitcast float* %9 to i8*
%13 = call i32 @sprintf(i8* %10, i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %1)
%14 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%15 = call i32* @fgets(i8* %11, i32 256, i32* %14)
%16 = icmp eq i32* %15, null
br i1 %16, label %48, label %17
17: ; preds = %5
%18 = fpext float %3 to double
%19 = fmul double %18, 2.000000e+00
%20 = getelementptr inbounds i32, i32* %4, i64 1
%21 = fmul double %18, 3.000000e+00
%22 = getelementptr inbounds i32, i32* %4, i64 2
%23 = fmul double %18, 4.000000e+00
%24 = getelementptr inbounds i32, i32* %4, i64 3
%25 = getelementptr inbounds i32, i32* %4, i64 4
br label %26
26: ; preds = %17, %45
%27 = call i32 @sscanf(i8* %11, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), float* %9)
%28 = load float, float* %9
%29 = fsub float %2, %28
%30 = call float @llvm.fabs.f32(float %29)
%31 = fpext float %30 to double
%32 = fcmp ugt float %30, %3
br i1 %32, label %33, label %41
33: ; preds = %26
%34 = fcmp ult double %19, %31
br i1 %34, label %35, label %41
35: ; preds = %33
%36 = fcmp ult double %21, %31
br i1 %36, label %37, label %41
37: ; preds = %35
%38 = fcmp ult double %23, %31
br i1 %38, label %39, label %41
39: ; preds = %37
%40 = fcmp olt double %23, %31
br i1 %40, label %41, label %45
41: ; preds = %39, %37, %35, %33, %26
%42 = phi i32* [ %4, %26 ], [ %20, %33 ], [ %22, %35 ], [ %24, %37 ], [ %25, %39 ]
%43 = load i32, i32* %42
%44 = add nsw i32 %43, 1
store i32 %44, i32* %42
br label %45
45: ; preds = %41, %39
%46 = call i32* @fgets(i8* %11, i32 256, i32* %14)
%47 = icmp eq i32* %46, null
br i1 %47, label %48, label %26
48: ; preds = %45, %5
ret i32 undef
}