#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 M_PI;
double acos(double);
double acos2(double num, double denom, double disambiguator) {
  double val;
  double cosine = num / denom;
  if (cosine > -1. && cosine < 1.) {
    val = acos(cosine);
    if (disambiguator < 0.) {
      val = -val;
    }
  } else {
    val = (cosine <= -1.) ? M_PI : 0.;
  }
  return val;
}


x86 assembly (clang, -O0):
<acos2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  %xmm2,-0x18(%rbp)
movsd  -0x8(%rbp),%xmm0
divsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  0xebd(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11a3 <acos2+0x93>
movsd  0xeb3(%rip),%xmm0
ucomisd -0x28(%rbp),%xmm0
jbe    11a3 <acos2+0x93>
movsd  -0x28(%rbp),%xmm0
call   1030 <acos@plt>
movsd  %xmm0,-0x20(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    119e <acos2+0x8e>
movsd  -0x20(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    11e2 <acos2+0xd2>
movsd  0xe55(%rip),%xmm0
ucomisd -0x28(%rbp),%xmm0
jb     11cb <acos2+0xbb>
mov    0x2e2b(%rip),%rax
cvtsi2sdl (%rax),%xmm0
movsd  %xmm0,-0x30(%rbp)
jmp    11d8 <acos2+0xc8>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
jmp    11d8 <acos2+0xc8>
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<acos2>:
push   %rax
divsd  %xmm1,%xmm0
ucomisd 0xee3(%rip),%xmm0
jbe    114c <acos2+0x3c>
movsd  0xee1(%rip),%xmm1
ucomisd %xmm0,%xmm1
jbe    114c <acos2+0x3c>
movsd  %xmm2,(%rsp)
call   1030 <acos@plt>
xorpd  %xmm1,%xmm1
ucomisd (%rsp),%xmm1
jbe    1167 <acos2+0x57>
xorpd  0xec6(%rip),%xmm0
pop    %rax
ret
mov    0x2e95(%rip),%rax
xorps  %xmm1,%xmm1
cvtsi2sdl (%rax),%xmm1
cmplesd 0xe9d(%rip),%xmm0
andpd  %xmm1,%xmm0
pop    %rax
ret

LLVM IR (-O0):
@M_PI = global i32 0
define double @acos2(double %0, double %1, double %2) {
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
store double %0, double* %4
store double %1, double* %5
store double %2, double* %6
%9 = load double, double* %4
%10 = load double, double* %5
%11 = fdiv double %9, %10
store double %11, double* %8
%12 = load double, double* %8
%13 = fcmp ogt double %12, -1.000000e+00
br i1 %13, label %14, label %26
14: ; preds = %3
%15 = load double, double* %8
%16 = fcmp olt double %15, 1.000000e+00
br i1 %16, label %17, label %26
17: ; preds = %14
%18 = load double, double* %8
%19 = call double @acos(double %18)
store double %19, double* %7
%20 = load double, double* %6
%21 = fcmp olt double %20, 0.000000e+00
br i1 %21, label %22, label %25
22: ; preds = %17
%23 = load double, double* %7
%24 = fneg double %23
store double %24, double* %7
br label %25
25: ; preds = %22, %17
br label %35
26: ; preds = %14, %3
%27 = load double, double* %8
%28 = fcmp ole double %27, -1.000000e+00
br i1 %28, label %29, label %32
29: ; preds = %26
%30 = load i32, i32* @M_PI
%31 = sitofp i32 %30 to double
br label %33
32: ; preds = %26
br label %33
33: ; preds = %32, %29
%34 = phi double [ %31, %29 ], [ 0.000000e+00, %32 ]
store double %34, double* %7
br label %35
35: ; preds = %33, %25
%36 = load double, double* %7
ret double %36
}

LLVM IR (-O2):
@M_PI = global i32 0
define double @acos2(double %0, double %1, double %2) {
%4 = fdiv double %0, %1
%5 = fcmp ogt double %4, -1.000000e+00
%6 = fcmp olt double %4, 1.000000e+00
%7 = and i1 %5, %6
br i1 %7, label %8, label %13
8: ; preds = %3
%9 = tail call double @acos(double %4)
%10 = fcmp olt double %2, 0.000000e+00
br i1 %10, label %11, label %18
11: ; preds = %8
%12 = fneg double %9
br label %18
13: ; preds = %3
%14 = fcmp ole double %4, -1.000000e+00
%15 = load i32, i32* @M_PI
%16 = sitofp i32 %15 to double
%17 = select i1 %14, double %16, double 0.000000e+00
br label %18
18: ; preds = %8, %11, %13
%19 = phi double [ %12, %11 ], [ %9, %8 ], [ %17, %13 ]
ret double %19
}