#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 RAND_MAX;
double corbel_zget(double);
double fabs(double const);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int, ...);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
double orbel_zget_(double *);
int rand();
int test_orbel_zget(FILE *logfile, unsigned int num_vals) {
  fputs("Testing orbel_zget() function:\n", logfile);
  double orbel_in = -100.0;
  int num_failures = 0;
  while (--num_vals > 0) {
    orbel_in = rand() > (RAND_MAX / 2) ? rand() : -rand();
    const double cresult = corbel_zget(orbel_in);
    const double fresult = orbel_zget_(&orbel_in);
    if (fabs(cresult - fresult) > 0.1) {
      fprintf(logfile,
              "FAILED: test_orbel_zget(q = %e) - expected %f, got %e\n",
              orbel_in, fresult, cresult);
      num_failures++;
    } else {
      fprintf(logfile, "SUCCESS: test_orbel_zget(q = %e) - both are %e\n",
              orbel_in, fresult);
    }
  }
  fprintf(logfile, "orbel_zget() failures: %i\n", num_failures);
  return num_failures;
}


x86 assembly (clang, -O0):
<test_orbel_zget>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xeb6(%rip),%rdi
call   1040 <fputs@plt>
movsd  0xe89(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jbe    127c <test_orbel_zget+0x12c>
mov    $0x0,%al
call   1070 <rand@plt>
mov    %eax,-0x34(%rbp)
mov    0x2e42(%rip),%rax
mov    (%rax),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x34(%rbp),%eax
cmp    %ecx,%eax
jle    11cc <test_orbel_zget+0x7c>
mov    $0x0,%al
call   1070 <rand@plt>
mov    %eax,-0x38(%rbp)
jmp    11dc <test_orbel_zget+0x8c>
mov    $0x0,%al
call   1070 <rand@plt>
mov    %eax,%ecx
xor    %eax,%eax
sub    %ecx,%eax
mov    %eax,-0x38(%rbp)
mov    -0x38(%rbp),%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1030 <corbel_zget@plt>
movsd  %xmm0,-0x28(%rbp)
lea    -0x18(%rbp),%rdi
call   1060 <orbel_zget_@plt>
movsd  %xmm0,-0x30(%rbp)
movsd  -0x28(%rbp),%xmm0
subsd  -0x30(%rbp),%xmm0
movaps 0xdfa(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  0xde6(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    125b <test_orbel_zget+0x10b>
mov    -0x8(%rbp),%rdi
cvttsd2si -0x18(%rbp),%edx
movsd  -0x30(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
lea    0xdfa(%rip),%rsi
mov    $0x2,%al
call   1050 <fprintf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1277 <test_orbel_zget+0x127>
mov    -0x8(%rbp),%rdi
cvttsd2si -0x18(%rbp),%edx
movsd  -0x30(%rbp),%xmm0
lea    0xe07(%rip),%rsi
mov    $0x1,%al
call   1050 <fprintf@plt>
jmp    1183 <test_orbel_zget+0x33>
mov    -0x8(%rbp),%rdi
mov    -0x1c(%rbp),%edx
lea    0xe1d(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x1c(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_orbel_zget>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %esi,%ebp
mov    %rdi,%r14
lea    0xeae(%rip),%rdi
mov    $0x1f,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1060 <fwrite@plt>
movabs $0xc059000000000000,%rax
mov    %rax,0x8(%rsp)
add    $0xffffffff,%ebp
je     1251 <test_orbel_zget+0x101>
lea    0x8(%rsp),%r15
xor    %ebx,%ebx
jmp    11b7 <test_orbel_zget+0x67>
nopl   (%rax)
lea    0xec8(%rip),%rsi
mov    $0x1,%al
call   1040 <fprintf@plt>
add    $0xffffffff,%ebp
je     1253 <test_orbel_zget+0x103>
xor    %eax,%eax
call   1070 <rand@plt>
mov    %eax,%r12d
mov    0x2e20(%rip),%rax
mov    (%rax),%eax
mov    %eax,%r13d
shr    $0x1f,%r13d
add    %eax,%r13d
sar    %r13d
xor    %eax,%eax
call   1070 <rand@plt>
mov    %eax,%ecx
neg    %ecx
cmp    %r13d,%r12d
cmovg  %eax,%ecx
xorps  %xmm0,%xmm0
cvtsi2sd %ecx,%xmm0
movsd  %xmm0,0x8(%rsp)
call   1030 <corbel_zget@plt>
movsd  %xmm0,0x10(%rsp)
mov    %r15,%rdi
call   1050 <orbel_zget_@plt>
movsd  0x10(%rsp),%xmm1
movapd %xmm1,%xmm2
subsd  %xmm0,%xmm2
andpd  0xde2(%rip),%xmm2
ucomisd 0xdea(%rip),%xmm2
cvttsd2si 0x8(%rsp),%edx
mov    %r14,%rdi
jbe    11a0 <test_orbel_zget+0x50>
lea    0xdfc(%rip),%rsi
mov    $0x2,%al
call   1040 <fprintf@plt>
add    $0x1,%ebx
add    $0xffffffff,%ebp
jne    11b7 <test_orbel_zget+0x67>
jmp    1253 <test_orbel_zget+0x103>
xor    %ebx,%ebx
lea    0xe45(%rip),%rsi
mov    %r14,%rdi
mov    %ebx,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [32 x i8] c"Testing orbel_zget() function:\0A\00"
@RAND_MAX = global i32 0
@.str.1 = [55 x i8] c"FAILED: test_orbel_zget(q = %e) - expected %f, got %e\0A\00"
@.str.2 = [48 x i8] c"SUCCESS: test_orbel_zget(q = %e) - both are %e\0A\00"
@.str.3 = [27 x i8] c"orbel_zget() failures: %i\0A\00"
define i32 @test_orbel_zget(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca double
%6 = alloca i32
%7 = alloca double
%8 = alloca double
store i32* %0, i32** %3
store i32 %1, i32* %4
%9 = load i32*, i32** %3
%10 = call i32 @fputs(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i32* %9)
store double -1.000000e+02, double* %5
store i32 0, i32* %6
br label %11
11: ; preds = %51, %2
%12 = load i32, i32* %4
%13 = add i32 %12, -1
store i32 %13, i32* %4
%14 = icmp ugt i32 %13, 0
br i1 %14, label %15, label %52
15: ; preds = %11
%16 = call i32 (...) @rand()
%17 = load i32, i32* @RAND_MAX
%18 = sdiv i32 %17, 2
%19 = icmp sgt i32 %16, %18
br i1 %19, label %20, label %22
20: ; preds = %15
%21 = call i32 (...) @rand()
br label %25
22: ; preds = %15
%23 = call i32 (...) @rand()
%24 = sub nsw i32 0, %23
br label %25
25: ; preds = %22, %20
%26 = phi i32 [ %21, %20 ], [ %24, %22 ]
%27 = sitofp i32 %26 to double
store double %27, double* %5
%28 = load double, double* %5
%29 = call double @corbel_zget(double %28)
store double %29, double* %7
%30 = call double @orbel_zget_(double* %5)
store double %30, double* %8
%31 = load double, double* %7
%32 = load double, double* %8
%33 = fsub double %31, %32
%34 = call double @llvm.fabs.f64(double %33)
%35 = fcmp ogt double %34, 1.000000e-01
br i1 %35, label %36, label %45
36: ; preds = %25
%37 = load i32*, i32** %3
%38 = load double, double* %5
%39 = fptosi double %38 to i32
%40 = load double, double* %8
%41 = load double, double* %7
%42 = call i32 (i32*, i8*, i32, ...) @fprintf(i32* %37, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.1, i64 0, i64 0), i32 %39, double %40, double %41)
%43 = load i32, i32* %6
%44 = add nsw i32 %43, 1
store i32 %44, i32* %6
br label %51
45: ; preds = %25
%46 = load i32*, i32** %3
%47 = load double, double* %5
%48 = fptosi double %47 to i32
%49 = load double, double* %8
%50 = call i32 (i32*, i8*, i32, ...) @fprintf(i32* %46, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.2, i64 0, i64 0), i32 %48, double %49)
br label %51
51: ; preds = %45, %36
br label %11
52: ; preds = %11
%53 = load i32*, i32** %3
%54 = load i32, i32* %6
%55 = call i32 (i32*, i8*, i32, ...) @fprintf(i32* %53, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i32 %54)
%56 = load i32, i32* %6
ret i32 %56
}

LLVM IR (-O2):
@.str = [32 x i8] c"Testing orbel_zget() function:\0A\00"
@RAND_MAX = global i32 0
@.str.1 = [55 x i8] c"FAILED: test_orbel_zget(q = %e) - expected %f, got %e\0A\00"
@.str.2 = [48 x i8] c"SUCCESS: test_orbel_zget(q = %e) - both are %e\0A\00"
@.str.3 = [27 x i8] c"orbel_zget() failures: %i\0A\00"
define i32 @test_orbel_zget(i32* nocapture %0, i32 %1) {
%3 = alloca double
%4 = tail call i64 @fwrite(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i64 31, i64 1, i32* %0)
%5 = bitcast double* %3 to i8*
store double -1.000000e+02, double* %3
%6 = add i32 %1, -1
%7 = icmp eq i32 %6, 0
br i1 %7, label %35, label %8
8: ; preds = %2, %31
%9 = phi i32 [ %33, %31 ], [ %6, %2 ]
%10 = phi i32 [ %32, %31 ], [ 0, %2 ]
%11 = call i32 (...) @rand()
%12 = load i32, i32* @RAND_MAX
%13 = sdiv i32 %12, 2
%14 = icmp sgt i32 %11, %13
%15 = call i32 (...) @rand()
%16 = sub nsw i32 0, %15
%17 = select i1 %14, i32 %15, i32 %16
%18 = sitofp i32 %17 to double
store double %18, double* %3
%19 = call double @corbel_zget(double %18)
%20 = call double @orbel_zget_(double* %3)
%21 = fsub double %19, %20
%22 = call double @llvm.fabs.f64(double %21)
%23 = fcmp ogt double %22, 1.000000e-01
%24 = load double, double* %3
%25 = fptosi double %24 to i32
br i1 %23, label %26, label %29
26: ; preds = %8
%27 = call i32 (i32*, i8*, i32, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.1, i64 0, i64 0), i32 %25, double %20, double %19)
%28 = add nsw i32 %10, 1
br label %31
29: ; preds = %8
%30 = call i32 (i32*, i8*, i32, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.2, i64 0, i64 0), i32 %25, double %20)
br label %31
31: ; preds = %29, %26
%32 = phi i32 [ %28, %26 ], [ %10, %29 ]
%33 = add i32 %9, -1
%34 = icmp eq i32 %33, 0
br i1 %34, label %35, label %8
35: ; preds = %31, %2
%36 = phi i32 [ 0, %2 ], [ %32, %31 ]
%37 = call i32 (i32*, i8*, i32, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i32 %36)
ret i32 %36
}