#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*/ M_PI;
int /*<<< orphan*/ atan2k(int /*<<< orphan*/, int /*<<< orphan*/);
double mulsign(int /*<<< orphan*/, double);
int /*<<< orphan*/ sqrt(int);
int /*<<< orphan*/ xfabs(double);
double xacos(double d) {
  return mulsign(atan2k(sqrt((1 + d) * (1 - d)), xfabs(d)), d) +
         (d < 0 ? M_PI : 0);
}


x86 assembly (clang, -O0):
<xacos>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  0xeab(%rip),%xmm0
addsd  -0x8(%rbp),%xmm0
movsd  0xe9e(%rip),%xmm1
subsd  -0x8(%rbp),%xmm1
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1060 <sqrt@plt>
mov    %eax,-0x14(%rbp)
movsd  -0x8(%rbp),%xmm0
call   1050 <xfabs@plt>
mov    -0x14(%rbp),%edi
mov    %eax,%esi
call   1040 <atan2k@plt>
mov    %eax,%edi
movsd  -0x8(%rbp),%xmm0
call   1030 <mulsign@plt>
movsd  %xmm0,-0x10(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x8(%rbp),%xmm0
jbe    11bb <xacos+0x7b>
mov    0x2e37(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
jmp    11c5 <xacos+0x85>
xor    %eax,%eax
mov    %eax,-0x18(%rbp)
jmp    11c5 <xacos+0x85>
movsd  -0x10(%rbp),%xmm0
mov    -0x18(%rbp),%eax
cvtsi2sd %eax,%xmm1
addsd  %xmm1,%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xacos>:
push   %rbx
sub    $0x10,%rsp
movapd %xmm0,(%rsp)
movsd  0xeae(%rip),%xmm2
movapd %xmm0,%xmm1
addsd  %xmm2,%xmm1
subsd  %xmm0,%xmm2
mulsd  %xmm1,%xmm2
cvttsd2si %xmm2,%edi
call   1060 <sqrt@plt>
mov    %eax,%ebx
movaps (%rsp),%xmm0
call   1050 <xfabs@plt>
mov    %ebx,%edi
mov    %eax,%esi
call   1040 <atan2k@plt>
mov    %eax,%edi
movapd (%rsp),%xmm0
call   1030 <mulsign@plt>
mov    0x2e56(%rip),%rax
xorps  %xmm1,%xmm1
cvtsi2sdl (%rax),%xmm1
xorpd  %xmm2,%xmm2
movapd (%rsp),%xmm3
cmpltsd %xmm2,%xmm3
andpd  %xmm1,%xmm3
addsd  %xmm3,%xmm0
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@M_PI = global i32 0
define double @xacos(double %0) {
%2 = alloca double
store double %0, double* %2
%3 = load double, double* %2
%4 = fadd double 1.000000e+00, %3
%5 = load double, double* %2
%6 = fsub double 1.000000e+00, %5
%7 = fmul double %4, %6
%8 = fptosi double %7 to i32
%9 = call i32 @sqrt(i32 %8)
%10 = load double, double* %2
%11 = call i32 @xfabs(double %10)
%12 = call i32 @atan2k(i32 %9, i32 %11)
%13 = load double, double* %2
%14 = call double @mulsign(i32 %12, double %13)
%15 = load double, double* %2
%16 = fcmp olt double %15, 0.000000e+00
br i1 %16, label %17, label %19
17: ; preds = %1
%18 = load i32, i32* @M_PI
br label %20
19: ; preds = %1
br label %20
20: ; preds = %19, %17
%21 = phi i32 [ %18, %17 ], [ 0, %19 ]
%22 = sitofp i32 %21 to double
%23 = fadd double %14, %22
ret double %23
}

LLVM IR (-O2):
@M_PI = global i32 0
define double @xacos(double %0) {
%2 = fadd double %0, 1.000000e+00
%3 = fsub double 1.000000e+00, %0
%4 = fmul double %2, %3
%5 = fptosi double %4 to i32
%6 = tail call i32 @sqrt(i32 %5)
%7 = tail call i32 @xfabs(double %0)
%8 = tail call i32 @atan2k(i32 %6, i32 %7)
%9 = tail call double @mulsign(i32 %8, double %0)
%10 = fcmp olt double %0, 0.000000e+00
%11 = load i32, i32* @M_PI
%12 = sitofp i32 %11 to double
%13 = select i1 %10, double %12, double 0.000000e+00
%14 = fadd double %9, %13
ret double %14
}