double acos(x)
double x;
{
  double t, copysign(), atan2(), sqrt(), one = 1.0;
  if (x != x)
    return (x);
  if (x != -1.0)
    t = atan2(sqrt((one - x) / (one + x)), one);
  else
    t = atan2(one, 0.0);
  return (t + t);
}


x86 assembly (clang, -O0):
<acos>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  0xecb(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm0
ucomisd -0x10(%rbp),%xmm0
jne    1155 <acos+0x35>
jp     1155 <acos+0x35>
jmp    1164 <acos+0x44>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11d8 <acos+0xb8>
movsd  -0x10(%rbp),%xmm0
movsd  0xe97(%rip),%xmm1
ucomisd %xmm1,%xmm0
jne    1186 <acos+0x66>
jp     1186 <acos+0x66>
jmp    11b7 <acos+0x97>
movsd  -0x20(%rbp),%xmm0
subsd  -0x10(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
addsd  -0x10(%rbp),%xmm1
divsd  %xmm1,%xmm0
call   1040 <sqrt@plt>
movsd  -0x20(%rbp),%xmm1
call   1030 <atan2@plt>
movsd  %xmm0,-0x18(%rbp)
jmp    11c9 <acos+0xa9>
movsd  -0x20(%rbp),%xmm0
xorps  %xmm1,%xmm1
call   1030 <atan2@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<acos>:
ucomisd %xmm0,%xmm0
jp     1196 <acos+0x76>
push   %rax
ucomisd 0xed1(%rip),%xmm0
jne    1133 <acos+0x13>
jnp    115e <acos+0x3e>
movsd  0xecd(%rip),%xmm2
movapd %xmm2,%xmm1
subsd  %xmm0,%xmm1
addsd  %xmm2,%xmm0
divsd  %xmm0,%xmm1
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm1
jb     1178 <acos+0x58>
xorps  %xmm0,%xmm0
sqrtsd %xmm1,%xmm0
jmp    1181 <acos+0x61>
movsd  0xea2(%rip),%xmm0
xorps  %xmm1,%xmm1
call   1030 <atan2@plt>
movsd  0xe9a(%rip),%xmm0
jmp    118e <acos+0x6e>
movapd %xmm1,%xmm0
call   1040 <sqrt@plt>
movsd  0xe7f(%rip),%xmm1
call   1030 <atan2@plt>
addsd  %xmm0,%xmm0
add    $0x8,%rsp
ret

LLVM IR (-O0):
define double @acos(double %0) {
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = alloca double
store double %0, double* %3
store double 1.000000e+00, double* %5
%6 = load double, double* %3
%7 = load double, double* %3
%8 = fcmp une double %6, %7
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = load double, double* %3
store double %10, double* %2
br label %32
11: ; preds = %1
%12 = load double, double* %3
%13 = fcmp une double %12, -1.000000e+00
br i1 %13, label %14, label %25
14: ; preds = %11
%15 = load double, double* %5
%16 = load double, double* %3
%17 = fsub double %15, %16
%18 = load double, double* %5
%19 = load double, double* %3
%20 = fadd double %18, %19
%21 = fdiv double %17, %20
%22 = call double @sqrt(double %21)
%23 = load double, double* %5
%24 = call double @atan2(double %22, double %23)
store double %24, double* %4
br label %28
25: ; preds = %11
%26 = load double, double* %5
%27 = call double @atan2(double %26, double 0.000000e+00)
store double %27, double* %4
br label %28
28: ; preds = %25, %14
%29 = load double, double* %4
%30 = load double, double* %4
%31 = fadd double %29, %30
store double %31, double* %2
br label %32
32: ; preds = %28, %9
%33 = load double, double* %2
ret double %33
}

LLVM IR (-O2):
define double @acos(double %0) {
%2 = fcmp uno double %0, 0.000000e+00
br i1 %2, label %16, label %3
3: ; preds = %1
%4 = fcmp une double %0, -1.000000e+00
br i1 %4, label %5, label %11
5: ; preds = %3
%6 = fsub double 1.000000e+00, %0
%7 = fadd double %0, 1.000000e+00
%8 = fdiv double %6, %7
%9 = tail call double @sqrt(double %8)
%10 = tail call double @atan2(double %9, double 1.000000e+00)
br label %13
11: ; preds = %3
%12 = tail call double @atan2(double 1.000000e+00, double 0.000000e+00)
br label %13
13: ; preds = %11, %5
%14 = phi double [ %10, %5 ], [ 0x3FF921FB54442D18, %11 ]
%15 = fadd double %14, %14
br label %16
16: ; preds = %1, %13
%17 = phi double [ %15, %13 ], [ %0, %1 ]
ret double %17
}