#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 */
double atan(double);
double sqrt(int);
double acos(double x) {
  if (x < -1.0 || x > 1.0)
    return -1024;
  if (x == -1.0)
    return 3.14159265;
  if (x == 1.0)
    return 0.0;
  if (x > 0.816) {
    return 1.5707963 - atan(x / sqrt((1 + x) * (1 - x)));
  } else {
    return 1.5707963 - atan(x / sqrt(1 - x * x));
  }
}


x86 assembly (clang, -O0):
<acos>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  0xecb(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
ja     1157 <acos+0x37>
movsd  -0x10(%rbp),%xmm0
movsd  0xebb(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1169 <acos+0x49>
movsd  0xec9(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    129d <acos+0x17d>
movsd  -0x10(%rbp),%xmm0
movsd  0xe8a(%rip),%xmm1
ucomisd %xmm1,%xmm0
jne    1198 <acos+0x78>
jp     1198 <acos+0x78>
movsd  0xe92(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    129d <acos+0x17d>
movsd  -0x10(%rbp),%xmm0
movsd  0xe63(%rip),%xmm1
ucomisd %xmm1,%xmm0
jne    11c2 <acos+0xa2>
jp     11c2 <acos+0xa2>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    129d <acos+0x17d>
movsd  -0x10(%rbp),%xmm0
movsd  0xe41(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1234 <acos+0x114>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xe1d(%rip),%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  0xe10(%rip),%xmm1
subsd  -0x10(%rbp),%xmm1
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1040 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0x18(%rbp),%xmm0
divsd  %xmm1,%xmm0
call   1030 <atan@plt>
movaps %xmm0,%xmm1
movsd  0xdf2(%rip),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    129d <acos+0x17d>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm1,%xmm0
movsd  0xd9d(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1040 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0x20(%rbp),%xmm0
divsd  %xmm1,%xmm0
call   1030 <atan@plt>
movaps %xmm0,%xmm1
movsd  0xd84(%rip),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<acos>:
push   %rax
movapd %xmm0,%xmm2
movsd  0xed3(%rip),%xmm0
ucomisd %xmm2,%xmm0
movsd  0xecf(%rip),%xmm0
ja     116a <acos+0x4a>
ucomisd 0xecd(%rip),%xmm2
ja     116a <acos+0x4a>
ucomisd 0xeb3(%rip),%xmm2
jne    115b <acos+0x3b>
jp     115b <acos+0x3b>
movsd  0xebf(%rip),%xmm0
pop    %rax
ret
xorps  %xmm0,%xmm0
ucomisd 0xeaa(%rip),%xmm2
jne    116c <acos+0x4c>
jp     116c <acos+0x4c>
pop    %rax
ret
ucomisd 0xeac(%rip),%xmm2
movsd  %xmm2,(%rsp)
jbe    1195 <acos+0x75>
movsd  0xe8d(%rip),%xmm0
movapd %xmm2,%xmm1
addsd  %xmm0,%xmm1
subsd  %xmm2,%xmm0
mulsd  %xmm1,%xmm0
jmp    11a5 <acos+0x85>
mulsd  %xmm2,%xmm2
movsd  0xe6f(%rip),%xmm0
subsd  %xmm2,%xmm0
cvttsd2si %xmm0,%edi
call   1040 <sqrt@plt>
movsd  (%rsp),%xmm1
divsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
call   1030 <atan@plt>
movapd %xmm0,%xmm1
movsd  0xe5c(%rip),%xmm0
subsd  %xmm1,%xmm0
pop    %rax
ret

LLVM IR (-O0):
define double @acos(double %0) {
%2 = alloca double
%3 = alloca double
store double %0, double* %3
%4 = load double, double* %3
%5 = fcmp olt double %4, -1.000000e+00
br i1 %5, label %9, label %6
6: ; preds = %1
%7 = load double, double* %3
%8 = fcmp ogt double %7, 1.000000e+00
br i1 %8, label %9, label %10
9: ; preds = %6, %1
store double -1.024000e+03, double* %2
br label %44
10: ; preds = %6
%11 = load double, double* %3
%12 = fcmp oeq double %11, -1.000000e+00
br i1 %12, label %13, label %14
13: ; preds = %10
store double 0x400921FB53C8D4F1, double* %2
br label %44
14: ; preds = %10
%15 = load double, double* %3
%16 = fcmp oeq double %15, 1.000000e+00
br i1 %16, label %17, label %18
17: ; preds = %14
store double 0.000000e+00, double* %2
br label %44
18: ; preds = %14
%19 = load double, double* %3
%20 = fcmp ogt double %19, 8.160000e-01
br i1 %20, label %21, label %33
21: ; preds = %18
%22 = load double, double* %3
%23 = load double, double* %3
%24 = fadd double 1.000000e+00, %23
%25 = load double, double* %3
%26 = fsub double 1.000000e+00, %25
%27 = fmul double %24, %26
%28 = fptosi double %27 to i32
%29 = call double @sqrt(i32 %28)
%30 = fdiv double %22, %29
%31 = call double @atan(double %30)
%32 = fsub double 0x3FF921FB4D12D84A, %31
store double %32, double* %2
br label %44
33: ; preds = %18
%34 = load double, double* %3
%35 = load double, double* %3
%36 = load double, double* %3
%37 = fneg double %35
%38 = call double @llvm.fmuladd.f64(double %37, double %36, double 1.000000e+00)
%39 = fptosi double %38 to i32
%40 = call double @sqrt(i32 %39)
%41 = fdiv double %34, %40
%42 = call double @atan(double %41)
%43 = fsub double 0x3FF921FB4D12D84A, %42
store double %43, double* %2
br label %44
44: ; preds = %33, %21, %17, %13, %9
%45 = load double, double* %2
ret double %45
}

LLVM IR (-O2):
define double @acos(double %0) {
%2 = fcmp olt double %0, -1.000000e+00
%3 = fcmp ogt double %0, 1.000000e+00
%4 = or i1 %2, %3
br i1 %4, label %25, label %5
5: ; preds = %1
%6 = fcmp oeq double %0, -1.000000e+00
br i1 %6, label %25, label %7
7: ; preds = %5
%8 = fcmp oeq double %0, 1.000000e+00
br i1 %8, label %25, label %9
9: ; preds = %7
%10 = fcmp ogt double %0, 8.160000e-01
br i1 %10, label %11, label %15
11: ; preds = %9
%12 = fadd double %0, 1.000000e+00
%13 = fsub double 1.000000e+00, %0
%14 = fmul double %12, %13
br label %18
15: ; preds = %9
%16 = fneg double %0
%17 = tail call double @llvm.fmuladd.f64(double %16, double %0, double 1.000000e+00)
br label %18
18: ; preds = %11, %15
%19 = phi double [ %17, %15 ], [ %14, %11 ]
%20 = fptosi double %19 to i32
%21 = tail call double @sqrt(i32 %20)
%22 = fdiv double %0, %21
%23 = tail call double @atan(double %22)
%24 = fsub double 0x3FF921FB4D12D84A, %23
br label %25
25: ; preds = %18, %7, %5, %1
%26 = phi double [ -1.024000e+03, %1 ], [ 0x400921FB53C8D4F1, %5 ], [ 0.000000e+00, %7 ], [ %24, %18 ]
ret double %26
}