#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 abs(int);
int /*<<< orphan*/ freeVoice(int);
int getFrequency(int, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ setFrequency(int, int, int);
int voiceFactory(int, int, int, int);
int testFrequency() {
  int result = 0;
  int hvox = voiceFactory(60, 64, 128, 44100);
  float freq;
  int hz;
  int voxFreq;
  for (freq = 60; freq < 3200; freq *= 1.1) {
    hz = (int)freq;
    setFrequency(hvox, hz, 44100);
    voxFreq = getFrequency(hvox, 44100);
    if (abs(hz - voxFreq) > 20)
      result = 1;
    printf("Test frequency: %i", hz);
    printf("\tVoice Frequency: %i", voxFreq);
    printf("\n");
  }
  freeVoice(hvox);
  return result;
}


x86 assembly (clang, -O0):
<testFrequency>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x3c,%edi
mov    $0x40,%esi
mov    $0x80,%edx
mov    $0xac44,%ecx
call   1030 <voiceFactory@plt>
mov    %eax,-0x8(%rbp)
movss  0xe6d(%rip),%xmm0
movss  %xmm0,-0xc(%rbp)
movss  0xe64(%rip),%xmm0
ucomiss -0xc(%rbp),%xmm0
jbe    1240 <testFrequency+0xe0>
cvttss2si -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%esi
mov    $0xac44,%edx
call   1050 <setFrequency@plt>
mov    -0x8(%rbp),%edi
mov    $0xac44,%esi
call   1080 <getFrequency@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%edi
sub    -0x14(%rbp),%edi
call   1040 <abs@plt>
cmp    $0x14,%eax
jle    11ed <testFrequency+0x8d>
movl   $0x1,-0x4(%rbp)
mov    -0x10(%rbp),%esi
lea    0xe19(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x14(%rbp),%esi
lea    0xe1b(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    0xe22(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xdda(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0xc(%rbp)
jmp    1198 <testFrequency+0x38>
mov    -0x8(%rbp),%edi
call   1060 <freeVoice@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<testFrequency>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0x3c,%edi
mov    $0x40,%esi
mov    $0x80,%edx
mov    $0xac44,%ecx
call   1040 <voiceFactory@plt>
mov    %eax,%r12d
movss  0xe71(%rip),%xmm0
lea    0xe7a(%rip),%r14
lea    0xe86(%rip),%r15
xor    %ebp,%ebp
nop
movss  %xmm0,0x4(%rsp)
cvttss2si %xmm0,%ebx
mov    %r12d,%edi
mov    %ebx,%esi
mov    $0xac44,%edx
call   1050 <setFrequency@plt>
mov    %r12d,%edi
mov    $0xac44,%esi
call   1080 <getFrequency@plt>
mov    %eax,%r13d
mov    %ebx,%eax
sub    %r13d,%eax
mov    %eax,%ecx
neg    %ecx
cmovs  %eax,%ecx
cmp    $0x15,%ecx
mov    $0x1,%eax
cmovae %eax,%ebp
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r15,%rdi
mov    %r13d,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
movss  0x4(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
mulsd  0xdf3(%rip),%xmm0
cvtsd2ss %xmm0,%xmm0
movss  0xde3(%rip),%xmm1
ucomiss %xmm0,%xmm1
ja     11a0 <testFrequency+0x40>
mov    %r12d,%edi
call   1060 <freeVoice@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [19 x i8] c"Test frequency: %i\00"
@.str.1 = [21 x i8] c"\09Voice Frequency: %i\00"
@.str.2 = [2 x i8] c"\0A\00"
define i32 @testFrequency() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca float
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
%6 = call i32 @voiceFactory(i32 60, i32 64, i32 128, i32 44100)
store i32 %6, i32* %2
store float 6.000000e+01, float* %3
br label %7
7: ; preds = %30, %0
%8 = load float, float* %3
%9 = fcmp olt float %8, 3.200000e+03
br i1 %9, label %10, label %35
10: ; preds = %7
%11 = load float, float* %3
%12 = fptosi float %11 to i32
store i32 %12, i32* %4
%13 = load i32, i32* %2
%14 = load i32, i32* %4
%15 = call i32 @setFrequency(i32 %13, i32 %14, i32 44100)
%16 = load i32, i32* %2
%17 = call i32 @getFrequency(i32 %16, i32 44100)
store i32 %17, i32* %5
%18 = load i32, i32* %4
%19 = load i32, i32* %5
%20 = sub nsw i32 %18, %19
%21 = call i32 @abs(i32 %20)
%22 = icmp sgt i32 %21, 20
br i1 %22, label %23, label %24
23: ; preds = %10
store i32 1, i32* %1
br label %24
24: ; preds = %23, %10
%25 = load i32, i32* %4
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %25)
%27 = load i32, i32* %5
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 %27)
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %30
30: ; preds = %24
%31 = load float, float* %3
%32 = fpext float %31 to double
%33 = fmul double %32, 1.100000e+00
%34 = fptrunc double %33 to float
store float %34, float* %3
br label %7
35: ; preds = %7
%36 = load i32, i32* %2
%37 = call i32 @freeVoice(i32 %36)
%38 = load i32, i32* %1
ret i32 %38
}

LLVM IR (-O2):
@.str = [19 x i8] c"Test frequency: %i\00"
@.str.1 = [21 x i8] c"\09Voice Frequency: %i\00"
define i32 @testFrequency() {
%1 = tail call i32 @voiceFactory(i32 60, i32 64, i32 128, i32 44100)
br label %2
2: ; preds = %0, %2
%3 = phi i32 [ 0, %0 ], [ %11, %2 ]
%4 = phi float [ 6.000000e+01, %0 ], [ %17, %2 ]
%5 = fptosi float %4 to i32
%6 = tail call i32 @setFrequency(i32 %1, i32 %5, i32 44100)
%7 = tail call i32 @getFrequency(i32 %1, i32 44100)
%8 = sub nsw i32 %5, %7
%9 = tail call i32 @llvm.abs.i32(i32 %8, i1 true)
%10 = icmp ugt i32 %9, 20
%11 = select i1 %10, i32 1, i32 %3
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %5)
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 %7)
%14 = tail call i32 @putchar(i32 10)
%15 = fpext float %4 to double
%16 = fmul double %15, 1.100000e+00
%17 = fptrunc double %16 to float
%18 = fcmp olt float %17, 3.200000e+03
br i1 %18, label %2, label %19
19: ; preds = %2
%20 = tail call i32 @freeVoice(i32 %1)
ret i32 %11
}