#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 */

/* Variables and functions */
int /*<<< orphan*/ cleanup();
int /*<<< orphan*/ do_histogram(int, int /*<<< orphan*/, int, int *, int *,
                                int *, float *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ msg(scalar_t__, char *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int detect_sides(int drive) {
  int res = 1;
  int histogram[128];
  int total_cycles, total_samples;
  float peak;
  if (!do_histogram(drive, 0, 1, histogram, &total_cycles, &total_samples,
                    &peak)) {
    fprintf(stderr,
            "cw2dmk: No index hole; can't detect if side 1 is formatted\n");
    cleanup();
    exit(1);
  }
  if (peak > 0.0) {
    float dclock = 7080.5 / peak;
    if (dclock > 225.0 && dclock < 575.0) {
      res = 2;
    }
  }
  msg(0 + 1, "Detected side 1 %sformatted\n", res == 1 ? "not " : "");
  fflush(stdout);
  return res;
}


x86 assembly (clang, -O0):
<detect_sides>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x1,-0x8(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x210(%rbp),%rcx
xor    %esi,%esi
mov    $0x1,%edx
lea    -0x214(%rbp),%r8
lea    -0x218(%rbp),%r9
lea    -0x21c(%rbp),%rax
mov    %rax,(%rsp)
call   1070 <do_histogram@plt>
cmp    $0x0,%eax
jne    11d3 <detect_sides+0x73>
mov    0x2e2c(%rip),%rax
mov    (%rax),%edi
lea    0xe5b(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x0,%al
call   1050 <cleanup@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
movss  -0x21c(%rbp),%xmm0
ff
cvtss2sd %xmm0,%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    1258 <detect_sides+0xf8>
movss  -0x21c(%rbp),%xmm0
ff
cvtss2sd %xmm0,%xmm1
movsd  0xe08(%rip),%xmm0
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x220(%rbp)
ff
movss  -0x220(%rbp),%xmm0
ff
cvtss2sd %xmm0,%xmm0
movsd  0xddc(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1253 <detect_sides+0xf3>
movss  -0x220(%rbp),%xmm0
ff
cvtss2sd %xmm0,%xmm1
movsd  0xdce(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    1253 <detect_sides+0xf3>
movl   $0x2,-0x8(%rbp)
jmp    1258 <detect_sides+0xf8>
mov    -0x8(%rbp),%ecx
lea    0xdf1(%rip),%rdx
lea    0xe08(%rip),%rax
cmp    $0x1,%ecx
cmove  %rax,%rdx
mov    $0x1,%edi
lea    0xdd8(%rip),%rsi
call   1080 <msg@plt>
mov    0x2d50(%rip),%rax
mov    (%rax),%edi
call   1040 <fflush@plt>
mov    -0x8(%rbp),%eax
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<detect_sides>:
push   %rbx
sub    $0x220,%rsp
lea    0x14(%rsp),%rax
mov    %rax,(%rsp)
lea    0x20(%rsp),%rcx
lea    0x1c(%rsp),%r8
lea    0x18(%rsp),%r9
xor    %esi,%esi
mov    $0x1,%edx
call   1070 <do_histogram@plt>
test   %eax,%eax
je     1204 <detect_sides+0xa4>
movss  0x14(%rsp),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jbe    11ce <detect_sides+0x6e>
movss  0xe5a(%rip),%xmm1
divss  %xmm0,%xmm1
ucomiss 0xe53(%rip),%xmm1
jbe    11ce <detect_sides+0x6e>
movss  0xe4d(%rip),%xmm0
ucomiss %xmm1,%xmm0
jbe    11ce <detect_sides+0x6e>
lea    0xe80(%rip),%rdx
mov    $0x2,%ebx
jmp    11da <detect_sides+0x7a>
lea    0xe90(%rip),%rdx
mov    $0x1,%ebx
lea    0xe67(%rip),%rsi
mov    $0x1,%edi
call   1080 <msg@plt>
mov    0x2de6(%rip),%rax
mov    (%rax),%edi
call   1040 <fflush@plt>
mov    %ebx,%eax
add    $0x220,%rsp
pop    %rbx
ret
mov    0x2dd5(%rip),%rax
mov    (%rax),%edi
lea    0xdf8(%rip),%rsi
call   1030 <fprintf@plt>
xor    %eax,%eax
call   1050 <cleanup@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [60 x i8] c"cw2dmk: No index hole; can't detect if side 1 is formatted\0A\00"
@.str.1 = [29 x i8] c"Detected side 1 %sformatted\0A\00"
@.str.2 = [5 x i8] c"not \00"
@.str.3 = [1 x i8] zeroinitializer
@stdout = global i32 0
define i32 @detect_sides(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [128 x i32]
%5 = alloca i32
%6 = alloca i32
%7 = alloca float
%8 = alloca float
store i32 %0, i32* %2
store i32 1, i32* %3
%9 = load i32, i32* %2
%10 = getelementptr inbounds [128 x i32], [128 x i32]* %4, i64 0, i64 0
%11 = call i32 @do_histogram(i32 %9, i32 0, i32 1, i32* %10, i32* %5, i32* %6, float* %7)
%12 = icmp ne i32 %11, 0
br i1 %12, label %18, label %13
13: ; preds = %1
%14 = load i32, i32* @stderr
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str, i64 0, i64 0))
%16 = call i32 (...) @cleanup()
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %1
%19 = load float, float* %7
%20 = fpext float %19 to double
%21 = fcmp ogt double %20, 0.000000e+00
br i1 %21, label %22, label %36
22: ; preds = %18
%23 = load float, float* %7
%24 = fpext float %23 to double
%25 = fdiv double 7.080500e+03, %24
%26 = fptrunc double %25 to float
store float %26, float* %8
%27 = load float, float* %8
%28 = fpext float %27 to double
%29 = fcmp ogt double %28, 2.250000e+02
br i1 %29, label %30, label %35
30: ; preds = %22
%31 = load float, float* %8
%32 = fpext float %31 to double
%33 = fcmp olt double %32, 5.750000e+02
br i1 %33, label %34, label %35
34: ; preds = %30
store i32 2, i32* %3
br label %35
35: ; preds = %34, %30, %22
br label %36
36: ; preds = %35, %18
%37 = load i32, i32* %3
%38 = icmp eq i32 %37, 1
%39 = zext i1 %38 to i64
%40 = select i1 %38, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0)
%41 = call i32 @msg(i64 1, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %40)
%42 = load i32, i32* @stdout
%43 = call i32 @fflush(i32 %42)
%44 = load i32, i32* %3
ret i32 %44
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [60 x i8] c"cw2dmk: No index hole; can't detect if side 1 is formatted\0A\00"
@.str.1 = [29 x i8] c"Detected side 1 %sformatted\0A\00"
@.str.2 = [5 x i8] c"not \00"
@.str.3 = [1 x i8] zeroinitializer
@stdout = global i32 0
define i32 @detect_sides(i32 %0) {
%2 = alloca [128 x i32]
%3 = alloca i32
%4 = alloca i32
%5 = alloca float
%6 = bitcast [128 x i32]* %2 to i8*
%7 = bitcast i32* %3 to i8*
%8 = bitcast i32* %4 to i8*
%9 = bitcast float* %5 to i8*
%10 = getelementptr inbounds [128 x i32], [128 x i32]* %2, i64 0, i64 0
%11 = call i32 @do_histogram(i32 %0, i32 0, i32 1, i32* %10, i32* %3, i32* %4, float* %5)
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %18
13: ; preds = %1
%14 = load i32, i32* @stderr
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str, i64 0, i64 0))
%16 = call i32 (...) @cleanup()
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %1
%19 = load float, float* %5
%20 = fcmp ogt float %19, 0.000000e+00
br i1 %20, label %21, label %26
21: ; preds = %18
%22 = fdiv float 7.080500e+03, %19
%23 = fcmp ogt float %22, 2.250000e+02
%24 = fcmp olt float %22, 5.750000e+02
%25 = and i1 %23, %24
br i1 %25, label %27, label %26
26: ; preds = %21, %18
br label %27
27: ; preds = %21, %26
%28 = phi i32 [ 1, %26 ], [ 2, %21 ]
%29 = phi i8* [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), %26 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0), %21 ]
%30 = call i32 @msg(i64 1, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %29)
%31 = load i32, i32* @stdout
%32 = call i32 @fflush(i32 %31)
ret i32 %28
}