#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 */
float acosf(float);
float atan2f(float, float);
int sqrtf(float);
int kinematicsInverse(float x, float y, float L1, float L2, float *S,
                      float *E) {
  if (L1 <= 0 || L2 <= 0)
    return 0;
  *E = acosf((x * x + y * y - L1 * L1 - L2 * L2) / (2. * L1 * L2));
  *S = atan2f(y, x) - acosf((x * x + y * y + L1 * L1 - L2 * L2) /
                            (2 * L1 * sqrtf(x * x + y * y)));
  return 1;
}


x86 assembly (clang, -O0):
<kinematicsInverse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movss  %xmm0,-0x8(%rbp)
movss  %xmm1,-0xc(%rbp)
movss  %xmm2,-0x10(%rbp)
movss  %xmm3,-0x14(%rbp)
mov    %rdi,-0x20(%rbp)
mov    %rsi,-0x28(%rbp)
xorps  %xmm0,%xmm0
ucomiss -0x10(%rbp),%xmm0
jae    116e <kinematicsInverse+0x3e>
xorps  %xmm0,%xmm0
ucomiss -0x14(%rbp),%xmm0
jb     117a <kinematicsInverse+0x4a>
movl   $0x0,-0x4(%rbp)
jmp    12de <kinematicsInverse+0x1ae>
movss  -0x8(%rbp),%xmm0
movss  -0x8(%rbp),%xmm2
movss  -0xc(%rbp),%xmm1
mulss  -0xc(%rbp),%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  -0x10(%rbp),%xmm1
movss  -0x10(%rbp),%xmm2
movd   %xmm1,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm1
mulss  %xmm2,%xmm1
addss  %xmm0,%xmm1
movss  -0x14(%rbp),%xmm0
movss  -0x14(%rbp),%xmm2
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
movss  -0x10(%rbp),%xmm1
cvtss2sd %xmm1,%xmm2
movsd  0xe1f(%rip),%xmm1
mulsd  %xmm2,%xmm1
movss  -0x14(%rbp),%xmm2
cvtss2sd %xmm2,%xmm2
mulsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
call   1030 <acosf@plt>
mov    -0x28(%rbp),%rax
movss  %xmm0,(%rax)
movss  -0xc(%rbp),%xmm0
movss  -0x8(%rbp),%xmm1
call   1050 <atan2f@plt>
movss  %xmm0,-0x2c(%rbp)
movss  -0x8(%rbp),%xmm0
movss  -0x8(%rbp),%xmm2
movss  -0xc(%rbp),%xmm1
mulss  -0xc(%rbp),%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  -0x10(%rbp),%xmm1
movss  -0x10(%rbp),%xmm2
mulss  %xmm2,%xmm1
addss  %xmm0,%xmm1
movss  -0x14(%rbp),%xmm0
movss  -0x14(%rbp),%xmm2
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x30(%rbp)
movss  0xd83(%rip),%xmm0
mulss  -0x10(%rbp),%xmm0
movss  %xmm0,-0x34(%rbp)
movss  -0x8(%rbp),%xmm0
movss  -0x8(%rbp),%xmm2
movss  -0xc(%rbp),%xmm1
mulss  -0xc(%rbp),%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
call   1040 <sqrtf@plt>
movss  -0x34(%rbp),%xmm1
movss  -0x30(%rbp),%xmm0
cvtsi2ss %eax,%xmm2
mulss  %xmm2,%xmm1
divss  %xmm1,%xmm0
call   1030 <acosf@plt>
movaps %xmm0,%xmm1
movss  -0x2c(%rbp),%xmm0
subss  %xmm1,%xmm0
mov    -0x20(%rbp),%rax
movss  %xmm0,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<kinematicsInverse>:
xor    %eax,%eax
xorps  %xmm4,%xmm4
ucomiss %xmm2,%xmm4
jae    1256 <kinematicsInverse+0x126>
ucomiss %xmm3,%xmm4
jae    1256 <kinematicsInverse+0x126>
push   %r14
push   %rbx
sub    $0x38,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
movaps %xmm1,%xmm4
mulss  %xmm1,%xmm4
movaps %xmm0,%xmm5
mulss  %xmm0,%xmm5
addss  %xmm4,%xmm5
movss  %xmm5,0x1c(%rsp)
movaps %xmm2,%xmm6
mulss  %xmm2,%xmm6
movss  %xmm6,0x10(%rsp)
movaps %xmm5,%xmm4
subss  %xmm6,%xmm4
movaps 0xe79(%rip),%xmm5
xorps  %xmm3,%xmm5
mulss  %xmm3,%xmm5
movaps %xmm5,0x20(%rsp)
addss  %xmm5,%xmm4
movss  %xmm1,0x18(%rsp)
cvtss2sd %xmm4,%xmm4
movss  %xmm0,0xc(%rsp)
xorps  %xmm1,%xmm1
cvtss2sd %xmm2,%xmm1
addsd  %xmm1,%xmm1
movss  %xmm2,0x14(%rsp)
xorps  %xmm2,%xmm2
cvtss2sd %xmm3,%xmm2
mulsd  %xmm1,%xmm2
divsd  %xmm2,%xmm4
xorps  %xmm0,%xmm0
cvtsd2ss %xmm4,%xmm0
call   1030 <acosf@plt>
movss  %xmm0,(%rbx)
movss  0x18(%rsp),%xmm0
movss  0xc(%rsp),%xmm1
call   1050 <atan2f@plt>
movss  %xmm0,0xc(%rsp)
movss  0x10(%rsp),%xmm1
movss  0x1c(%rsp),%xmm0
addss  %xmm0,%xmm1
addss  0x20(%rsp),%xmm1
movss  %xmm1,0x10(%rsp)
movss  0x14(%rsp),%xmm1
addss  %xmm1,%xmm1
movss  %xmm1,0x14(%rsp)
call   1040 <sqrtf@plt>
xorps  %xmm1,%xmm1
cvtsi2ss %eax,%xmm1
mulss  0x14(%rsp),%xmm1
movss  0x10(%rsp),%xmm0
divss  %xmm1,%xmm0
call   1030 <acosf@plt>
movss  0xc(%rsp),%xmm1
subss  %xmm0,%xmm1
movss  %xmm1,(%r14)
mov    $0x1,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @kinematicsInverse(float %0, float %1, float %2, float %3, float* %4, float* %5) {
%7 = alloca i32
%8 = alloca float
%9 = alloca float
%10 = alloca float
%11 = alloca float
%12 = alloca float*
%13 = alloca float*
store float %0, float* %8
store float %1, float* %9
store float %2, float* %10
store float %3, float* %11
store float* %4, float** %12
store float* %5, float** %13
%14 = load float, float* %10
%15 = fcmp ole float %14, 0.000000e+00
br i1 %15, label %19, label %16
16: ; preds = %6
%17 = load float, float* %11
%18 = fcmp ole float %17, 0.000000e+00
br i1 %18, label %19, label %20
19: ; preds = %16, %6
store i32 0, i32* %7
br label %77
20: ; preds = %16
%21 = load float, float* %8
%22 = load float, float* %8
%23 = load float, float* %9
%24 = load float, float* %9
%25 = fmul float %23, %24
%26 = call float @llvm.fmuladd.f32(float %21, float %22, float %25)
%27 = load float, float* %10
%28 = load float, float* %10
%29 = fneg float %27
%30 = call float @llvm.fmuladd.f32(float %29, float %28, float %26)
%31 = load float, float* %11
%32 = load float, float* %11
%33 = fneg float %31
%34 = call float @llvm.fmuladd.f32(float %33, float %32, float %30)
%35 = fpext float %34 to double
%36 = load float, float* %10
%37 = fpext float %36 to double
%38 = fmul double 2.000000e+00, %37
%39 = load float, float* %11
%40 = fpext float %39 to double
%41 = fmul double %38, %40
%42 = fdiv double %35, %41
%43 = fptrunc double %42 to float
%44 = call float @acosf(float %43)
%45 = load float*, float** %13
store float %44, float* %45
%46 = load float, float* %9
%47 = load float, float* %8
%48 = call float @atan2f(float %46, float %47)
%49 = load float, float* %8
%50 = load float, float* %8
%51 = load float, float* %9
%52 = load float, float* %9
%53 = fmul float %51, %52
%54 = call float @llvm.fmuladd.f32(float %49, float %50, float %53)
%55 = load float, float* %10
%56 = load float, float* %10
%57 = call float @llvm.fmuladd.f32(float %55, float %56, float %54)
%58 = load float, float* %11
%59 = load float, float* %11
%60 = fneg float %58
%61 = call float @llvm.fmuladd.f32(float %60, float %59, float %57)
%62 = load float, float* %10
%63 = fmul float 2.000000e+00, %62
%64 = load float, float* %8
%65 = load float, float* %8
%66 = load float, float* %9
%67 = load float, float* %9
%68 = fmul float %66, %67
%69 = call float @llvm.fmuladd.f32(float %64, float %65, float %68)
%70 = call i32 @sqrtf(float %69)
%71 = sitofp i32 %70 to float
%72 = fmul float %63, %71
%73 = fdiv float %61, %72
%74 = call float @acosf(float %73)
%75 = fsub float %48, %74
%76 = load float*, float** %12
store float %75, float* %76
store i32 1, i32* %7
br label %77
77: ; preds = %20, %19
%78 = load i32, i32* %7
ret i32 %78
}

LLVM IR (-O2):
define i32 @kinematicsInverse(float %0, float %1, float %2, float %3, float* nocapture writeonly %4, float* nocapture writeonly %5) {
%7 = fcmp ole float %2, 0.000000e+00
%8 = fcmp ole float %3, 0.000000e+00
%9 = or i1 %7, %8
br i1 %9, label %35, label %10
10: ; preds = %6
%11 = fmul float %1, %1
%12 = tail call float @llvm.fmuladd.f32(float %0, float %0, float %11)
%13 = fneg float %2
%14 = tail call float @llvm.fmuladd.f32(float %13, float %2, float %12)
%15 = fneg float %3
%16 = tail call float @llvm.fmuladd.f32(float %15, float %3, float %14)
%17 = fpext float %16 to double
%18 = fpext float %2 to double
%19 = fmul double %18, 2.000000e+00
%20 = fpext float %3 to double
%21 = fmul double %19, %20
%22 = fdiv double %17, %21
%23 = fptrunc double %22 to float
%24 = tail call float @acosf(float %23)
store float %24, float* %5
%25 = tail call float @atan2f(float %1, float %0)
%26 = tail call float @llvm.fmuladd.f32(float %2, float %2, float %12)
%27 = tail call float @llvm.fmuladd.f32(float %15, float %3, float %26)
%28 = fmul float %2, 2.000000e+00
%29 = tail call i32 @sqrtf(float %12)
%30 = sitofp i32 %29 to float
%31 = fmul float %28, %30
%32 = fdiv float %27, %31
%33 = tail call float @acosf(float %32)
%34 = fsub float %25, %33
store float %34, float* %4
br label %35
35: ; preds = %6, %10
%36 = phi i32 [ 1, %10 ], [ 0, %6 ]
ret i32 %36
}