#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 */
struct atrf_dsc {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ atben_cleanup(struct atrf_dsc *);
unsigned int atben_sample(struct atrf_dsc *);
int /*<<< orphan*/ atben_setup(struct atrf_dsc *, int, int);
int /*<<< orphan*/ atrf_close(struct atrf_dsc *);
double eval(unsigned int *, int);
int /*<<< orphan*/ exit(int);
double fabs(double);
unsigned int *malloc(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ putchar(char);
void do_atben(struct atrf_dsc *dsc, int size, int trim, int rep, int dump_raw,
              double base, double ppm) {
  unsigned *res;
  double avg, rel;
  int i;
  res = malloc(rep * sizeof(*res));
  if (!res) {
    perror("malloc");
    exit(1);
  }
  atben_setup(dsc, size, trim);
  for (i = 0; i != rep; i++)
    res[i] = atben_sample(dsc);
  atben_cleanup(dsc);
  atrf_close(dsc);
  if (dump_raw) {
    for (i = 0; i != rep; i++)
      printf("%u\n", res[i]);
    exit(0);
  }
  avg = eval(res, rep);
  if (!base)
    printf("%f\n", avg);
  else {
    rel = (avg / base - 1) * 1000000;
    printf("%+f ppm", rel);
    if (ppm && fabs(rel) > ppm) {
      printf(" (outside bounds)\n");
      exit(1);
    }
    putchar('\n');
  }
}


x86 assembly (clang, -O0):
<do_atben>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8d,-0x18(%rbp)
movsd  %xmm0,-0x20(%rbp)
movsd  %xmm1,-0x28(%rbp)
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11f7 <do_atben+0x57>
lea    0xe38(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1090 <atben_setup@plt>
movl   $0x0,-0x44(%rbp)
mov    -0x44(%rbp),%eax
cmp    -0x14(%rbp),%eax
je     123d <do_atben+0x9d>
mov    -0x8(%rbp),%rdi
call   1070 <atben_sample@plt>
mov    %eax,%edx
mov    -0x30(%rbp),%rax
movslq -0x44(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    120d <do_atben+0x6d>
mov    -0x8(%rbp),%rdi
call   1030 <atben_cleanup@plt>
mov    -0x8(%rbp),%rdi
call   1060 <atrf_close@plt>
cmpl   $0x0,-0x18(%rbp)
je     129a <do_atben+0xfa>
movl   $0x0,-0x44(%rbp)
mov    -0x44(%rbp),%eax
cmp    -0x14(%rbp),%eax
je     1293 <do_atben+0xf3>
mov    -0x30(%rbp),%rax
movslq -0x44(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xda9(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    1260 <do_atben+0xc0>
xor    %edi,%edi
call   10c0 <exit@plt>
mov    -0x30(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   10b0 <eval@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x20(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    12db <do_atben+0x13b>
jp     12db <do_atben+0x13b>
movsd  -0x38(%rbp),%xmm0
lea    0xd5c(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
jmp    136f <do_atben+0x1cf>
movsd  -0x38(%rbp),%xmm0
divsd  -0x20(%rbp),%xmm0
movsd  0xd1b(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  0xd07(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x40(%rbp),%xmm0
lea    0xd21(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
movsd  -0x28(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1332 <do_atben+0x192>
jp     1332 <do_atben+0x192>
jmp    1365 <do_atben+0x1c5>
movsd  -0x40(%rbp),%xmm0
movaps 0xcd2(%rip),%xmm1
pand   %xmm1,%xmm0
ucomisd -0x28(%rbp),%xmm0
jbe    1365 <do_atben+0x1c5>
lea    0xce3(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_atben>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
movsd  %xmm1,0x18(%rsp)
movsd  %xmm0,0x20(%rsp)
mov    %r8d,(%rsp)
mov    %ecx,%r14d
mov    %edx,%ebx
mov    %esi,%r13d
mov    %rdi,%r12
lea    0x0(,%r14,4),%edi
call   1090 <malloc@plt>
test   %rax,%rax
je     12e0 <do_atben+0x130>
mov    %rax,%r15
mov    %r12,%rdi
mov    %r13d,%esi
mov    %ebx,%edx
call   10a0 <atben_setup@plt>
test   %r14d,%r14d
je     1225 <do_atben+0x75>
mov    %r14d,%ebx
xor    %ebp,%ebp
nopl   0x0(%rax)
mov    %r12,%rdi
call   1080 <atben_sample@plt>
mov    %eax,(%r15,%rbp,4)
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    1210 <do_atben+0x60>
mov    %r12,%rdi
call   1030 <atben_cleanup@plt>
mov    %r12,%rdi
call   1070 <atrf_close@plt>
cmpl   $0x0,(%rsp)
jne    12f6 <do_atben+0x146>
mov    %r15,%rdi
mov    %r14d,%esi
call   10c0 <eval@plt>
xorpd  %xmm2,%xmm2
movsd  0x20(%rsp),%xmm1
ucomisd %xmm2,%xmm1
jne    125c <do_atben+0xac>
jnp    12c4 <do_atben+0x114>
divsd  %xmm1,%xmm0
addsd  0xd98(%rip),%xmm0
mulsd  0xd98(%rip),%xmm0
lea    0xdc8(%rip),%rdi
movapd %xmm0,(%rsp)
mov    $0x1,%al
call   1060 <printf@plt>
movsd  0x18(%rsp),%xmm0
ucomisd 0xd7f(%rip),%xmm0
jne    1295 <do_atben+0xe5>
jnp    12ac <do_atben+0xfc>
movapd (%rsp),%xmm1
andpd  0xd7e(%rip),%xmm1
ucomisd %xmm0,%xmm1
ja     132e <do_atben+0x17e>
mov    $0xa,%edi
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <putchar@plt>
lea    0xd70(%rip),%rdi
mov    $0x1,%al
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <printf@plt>
lea    0xd49(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
test   %r14d,%r14d
je     1327 <do_atben+0x177>
mov    %r14d,%ebp
lea    0xd32(%rip),%r14
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    (%r15,%rbx,4),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1310 <do_atben+0x160>
xor    %edi,%edi
call   10d0 <exit@plt>
lea    0xd12(%rip),%rdi
call   1050 <puts@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
%struct.atrf_dsc = type { i32 }
@.str = [7 x i8] c"malloc\00"
@.str.1 = [4 x i8] c"%u\0A\00"
@.str.2 = [4 x i8] c"%f\0A\00"
@.str.3 = [8 x i8] c"%+f ppm\00"
@.str.4 = [19 x i8] c" (outside bounds)\0A\00"
define void @do_atben(%struct.atrf_dsc* %0, i32 %1, i32 %2, i32 %3, i32 %4, double %5, double %6) {
%8 = alloca %struct.atrf_dsc*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca double
%14 = alloca double
%15 = alloca i32*
%16 = alloca double
%17 = alloca double
%18 = alloca i32
store %struct.atrf_dsc* %0, %struct.atrf_dsc** %8
store i32 %1, i32* %9
store i32 %2, i32* %10
store i32 %3, i32* %11
store i32 %4, i32* %12
store double %5, double* %13
store double %6, double* %14
%19 = load i32, i32* %11
%20 = sext i32 %19 to i64
%21 = mul i64 %20, 4
%22 = trunc i64 %21 to i32
%23 = call i32* @malloc(i32 %22)
store i32* %23, i32** %15
%24 = load i32*, i32** %15
%25 = icmp ne i32* %24, null
br i1 %25, label %29, label %26
26: ; preds = %7
%27 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%28 = call i32 @exit(i32 1)
unreachable
29: ; preds = %7
%30 = load %struct.atrf_dsc*, %struct.atrf_dsc** %8
%31 = load i32, i32* %9
%32 = load i32, i32* %10
%33 = call i32 @atben_setup(%struct.atrf_dsc* %30, i32 %31, i32 %32)
store i32 0, i32* %18
br label %34
34: ; preds = %45, %29
%35 = load i32, i32* %18
%36 = load i32, i32* %11
%37 = icmp ne i32 %35, %36
br i1 %37, label %38, label %48
38: ; preds = %34
%39 = load %struct.atrf_dsc*, %struct.atrf_dsc** %8
%40 = call i32 @atben_sample(%struct.atrf_dsc* %39)
%41 = load i32*, i32** %15
%42 = load i32, i32* %18
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i32, i32* %41, i64 %43
store i32 %40, i32* %44
br label %45
45: ; preds = %38
%46 = load i32, i32* %18
%47 = add nsw i32 %46, 1
store i32 %47, i32* %18
br label %34
48: ; preds = %34
%49 = load %struct.atrf_dsc*, %struct.atrf_dsc** %8
%50 = call i32 @atben_cleanup(%struct.atrf_dsc* %49)
%51 = load %struct.atrf_dsc*, %struct.atrf_dsc** %8
%52 = call i32 @atrf_close(%struct.atrf_dsc* %51)
%53 = load i32, i32* %12
%54 = icmp ne i32 %53, 0
br i1 %54, label %55, label %72
55: ; preds = %48
store i32 0, i32* %18
br label %56
56: ; preds = %67, %55
%57 = load i32, i32* %18
%58 = load i32, i32* %11
%59 = icmp ne i32 %57, %58
br i1 %59, label %60, label %70
60: ; preds = %56
%61 = load i32*, i32** %15
%62 = load i32, i32* %18
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds i32, i32* %61, i64 %63
%65 = load i32, i32* %64
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %65)
br label %67
67: ; preds = %60
%68 = load i32, i32* %18
%69 = add nsw i32 %68, 1
store i32 %69, i32* %18
br label %56
70: ; preds = %56
%71 = call i32 @exit(i32 0)
unreachable
72: ; preds = %48
%73 = load i32*, i32** %15
%74 = load i32, i32* %11
%75 = call double @eval(i32* %73, i32 %74)
store double %75, double* %16
%76 = load double, double* %13
%77 = fcmp une double %76, 0.000000e+00
br i1 %77, label %81, label %78
78: ; preds = %72
%79 = load double, double* %16
%80 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double %79)
br label %101
81: ; preds = %72
%82 = load double, double* %16
%83 = load double, double* %13
%84 = fdiv double %82, %83
%85 = fsub double %84, 1.000000e+00
%86 = fmul double %85, 1.000000e+06
store double %86, double* %17
%87 = load double, double* %17
%88 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), double %87)
%89 = load double, double* %14
%90 = fcmp une double %89, 0.000000e+00
br i1 %90, label %91, label %99
91: ; preds = %81
%92 = load double, double* %17
%93 = call double @llvm.fabs.f64(double %92)
%94 = load double, double* %14
%95 = fcmp ogt double %93, %94
br i1 %95, label %96, label %99
96: ; preds = %91
%97 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
%98 = call i32 @exit(i32 1)
unreachable
99: ; preds = %91, %81
%100 = call i32 @putchar(i8 signext 10)
br label %101
101: ; preds = %99, %78
ret void
}

LLVM IR (-O2):
%struct.atrf_dsc = type { i32 }
@.str = [7 x i8] c"malloc\00"
@.str.1 = [4 x i8] c"%u\0A\00"
@.str.2 = [4 x i8] c"%f\0A\00"
@.str.3 = [8 x i8] c"%+f ppm\00"
@str = [18 x i8] c" (outside bounds)\00"
define void @do_atben(%struct.atrf_dsc* %0, i32 %1, i32 %2, i32 %3, i32 %4, double %5, double %6) {
%8 = shl i32 %3, 2
%9 = tail call i32* @malloc(i32 %8)
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %14
11: ; preds = %7
%12 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%13 = tail call i32 @exit(i32 1)
unreachable
14: ; preds = %7
%15 = tail call i32 @atben_setup(%struct.atrf_dsc* %0, i32 %1, i32 %2)
%16 = icmp eq i32 %3, 0
br i1 %16, label %25, label %17
17: ; preds = %14
%18 = zext i32 %3 to i64
br label %19
19: ; preds = %17, %19
%20 = phi i64 [ 0, %17 ], [ %23, %19 ]
%21 = tail call i32 @atben_sample(%struct.atrf_dsc* %0)
%22 = getelementptr inbounds i32, i32* %9, i64 %20
store i32 %21, i32* %22
%23 = add nuw nsw i64 %20, 1
%24 = icmp eq i64 %23, %18
br i1 %24, label %25, label %19
25: ; preds = %19, %14
%26 = tail call i32 @atben_cleanup(%struct.atrf_dsc* %0)
%27 = tail call i32 @atrf_close(%struct.atrf_dsc* %0)
%28 = icmp eq i32 %4, 0
br i1 %28, label %41, label %29
29: ; preds = %25
br i1 %16, label %39, label %30
30: ; preds = %29
%31 = zext i32 %3 to i64
br label %32
32: ; preds = %30, %32
%33 = phi i64 [ 0, %30 ], [ %37, %32 ]
%34 = getelementptr inbounds i32, i32* %9, i64 %33
%35 = load i32, i32* %34
%36 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %35)
%37 = add nuw nsw i64 %33, 1
%38 = icmp eq i64 %37, %31
br i1 %38, label %39, label %32
39: ; preds = %32, %29
%40 = tail call i32 @exit(i32 0)
unreachable
41: ; preds = %25
%42 = tail call double @eval(i32* %9, i32 %3)
%43 = fcmp une double %5, 0.000000e+00
br i1 %43, label %46, label %44
44: ; preds = %41
%45 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double %42)
br label %60
46: ; preds = %41
%47 = fdiv double %42, %5
%48 = fadd double %47, -1.000000e+00
%49 = fmul double %48, 1.000000e+06
%50 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), double %49)
%51 = fcmp une double %6, 0.000000e+00
%52 = tail call double @llvm.fabs.f64(double %49)
%53 = fcmp ogt double %52, %6
%54 = select i1 %51, i1 %53, i1 false
br i1 %54, label %55, label %58
55: ; preds = %46
%56 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
%57 = tail call i32 @exit(i32 1)
unreachable
58: ; preds = %46
%59 = tail call i32 @putchar(i8 signext 10)
br label %60
60: ; preds = %58, %44
ret void
}