#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 acos(double);
int atan(int);
double invmodDymola(double, int);
double cos_inverse(double x, double y, const char *ys) {
  double pi;
  double n;
  ;
  pi = 4 * atan(1);
  n = invmodDymola(y, 2 * pi);
  return (((y - n * 2 * pi) > pi) ? 2 * pi - acos(x) : acos(x)) + n * 2 * pi;
}


x86 assembly (clang, -O0):
<cos_inverse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
mov    %rdi,-0x18(%rbp)
mov    $0x1,%edi
call   1040 <atan@plt>
shl    $0x2,%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  0xe97(%rip),%xmm1
mulsd  -0x20(%rbp),%xmm1
cvttsd2si %xmm1,%edi
call   1050 <invmodDymola@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x10(%rbp),%xmm1
movsd  0xe77(%rip),%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm2
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
ucomisd -0x20(%rbp),%xmm0
jbe    1203 <cos_inverse+0xd3>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x8(%rbp),%xmm0
call   1030 <acos@plt>
movsd  -0x38(%rbp),%xmm0
cvtsi2sd %eax,%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
addsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
jmp    1216 <cos_inverse+0xe6>
movsd  -0x8(%rbp),%xmm0
call   1030 <acos@plt>
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm1
movsd  0xddd(%rip),%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cos_inverse>:
sub    $0x48,%rsp
movsd  %xmm1,0x8(%rsp)
movsd  %xmm0,0x18(%rsp)
mov    $0x1,%edi
call   1040 <atan@plt>
shl    $0x2,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movapd %xmm0,0x20(%rsp)
addsd  %xmm0,%xmm0
movapd %xmm0,0x30(%rsp)
cvttsd2si %xmm0,%edi
movsd  0x8(%rsp),%xmm0
call   1050 <invmodDymola@plt>
movapd %xmm0,%xmm1
addsd  %xmm0,%xmm1
mulsd  0x20(%rsp),%xmm1
movsd  %xmm1,0x10(%rsp)
movsd  0x8(%rsp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0x18(%rsp),%xmm0
call   1030 <acos@plt>
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
movapd 0x30(%rsp),%xmm2
subsd  %xmm1,%xmm2
movapd 0x20(%rsp),%xmm0
cmpltsd 0x8(%rsp),%xmm0
andpd  %xmm0,%xmm2
andnpd %xmm1,%xmm0
orpd   %xmm2,%xmm0
addsd  0x10(%rsp),%xmm0
add    $0x48,%rsp
ret

LLVM IR (-O0):
define double @cos_inverse(double %0, double %1, i8* %2) {
%4 = alloca double
%5 = alloca double
%6 = alloca i8*
%7 = alloca double
%8 = alloca double
store double %0, double* %4
store double %1, double* %5
store i8* %2, i8** %6
%9 = call i32 @atan(i32 1)
%10 = mul nsw i32 4, %9
%11 = sitofp i32 %10 to double
store double %11, double* %7
%12 = load double, double* %5
%13 = load double, double* %7
%14 = fmul double 2.000000e+00, %13
%15 = fptosi double %14 to i32
%16 = call double @invmodDymola(double %12, i32 %15)
store double %16, double* %8
%17 = load double, double* %5
%18 = load double, double* %8
%19 = fmul double %18, 2.000000e+00
%20 = load double, double* %7
%21 = fneg double %19
%22 = call double @llvm.fmuladd.f64(double %21, double %20, double %17)
%23 = load double, double* %7
%24 = fcmp ogt double %22, %23
br i1 %24, label %25, label %32
25: ; preds = %3
%26 = load double, double* %7
%27 = load double, double* %4
%28 = call i32 @acos(double %27)
%29 = sitofp i32 %28 to double
%30 = fneg double %29
%31 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %26, double %30)
br label %36
32: ; preds = %3
%33 = load double, double* %4
%34 = call i32 @acos(double %33)
%35 = sitofp i32 %34 to double
br label %36
36: ; preds = %32, %25
%37 = phi double [ %31, %25 ], [ %35, %32 ]
%38 = load double, double* %8
%39 = fmul double %38, 2.000000e+00
%40 = load double, double* %7
%41 = call double @llvm.fmuladd.f64(double %39, double %40, double %37)
ret double %41
}

LLVM IR (-O2):
define double @cos_inverse(double %0, double %1, i8* nocapture readnone %2) {
%4 = tail call i32 @atan(i32 1)
%5 = shl nsw i32 %4, 2
%6 = sitofp i32 %5 to double
%7 = fmul double %6, 2.000000e+00
%8 = fptosi double %7 to i32
%9 = tail call double @invmodDymola(double %1, i32 %8)
%10 = fmul double %9, 2.000000e+00
%11 = fneg double %10
%12 = tail call double @llvm.fmuladd.f64(double %11, double %6, double %1)
%13 = fcmp ogt double %12, %6
%14 = tail call i32 @acos(double %0)
%15 = sitofp i32 %14 to double
%16 = fneg double %15
%17 = tail call double @llvm.fmuladd.f64(double %6, double 2.000000e+00, double %16)
%18 = select i1 %13, double %17, double %15
%19 = tail call double @llvm.fmuladd.f64(double %10, double %6, double %18)
ret double %19
}