#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 M_PI_2;
float atan(float);
double sqrt(float);
void cartesianToPolar(float x, float y, double *rPtr, double *thetaPtr) {
  *rPtr = sqrt(x * x + y * y);
  float theta;
  if (x == 0) {
    if (y == 0.0) {
      theta = 0.0;
    } else if (y > 0) {
      theta = M_PI_2;
    } else {
      theta = -M_PI_2;
    }
  } else {
    theta = atan(y / x);
  }
  *thetaPtr = theta;
}


x86 assembly (clang, -O0):
<cartesianToPolar>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movss  %xmm0,-0x4(%rbp)
movss  %xmm1,-0x8(%rbp)
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movss  -0x4(%rbp),%xmm0
movss  -0x4(%rbp),%xmm2
movss  -0x8(%rbp),%xmm1
mulss  -0x8(%rbp),%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
call   1040 <sqrt@plt>
mov    -0x10(%rbp),%rax
movsd  %xmm0,(%rax)
movss  -0x4(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jne    11f0 <cartesianToPolar+0xd0>
jp     11f0 <cartesianToPolar+0xd0>
movss  -0x8(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11a3 <cartesianToPolar+0x83>
jp     11a3 <cartesianToPolar+0x83>
xorps  %xmm0,%xmm0
movss  %xmm0,-0x1c(%rbp)
jmp    11eb <cartesianToPolar+0xcb>
movss  -0x8(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jbe    11c9 <cartesianToPolar+0xa9>
mov    0x2e2d(%rip),%rax
movss  (%rax),%xmm0
movss  %xmm0,-0x1c(%rbp)
jmp    11e6 <cartesianToPolar+0xc6>
mov    0x2e18(%rip),%rax
movss  (%rax),%xmm0
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
movss  %xmm0,-0x1c(%rbp)
jmp    11eb <cartesianToPolar+0xcb>
jmp    1204 <cartesianToPolar+0xe4>
movss  -0x8(%rbp),%xmm0
divss  -0x4(%rbp),%xmm0
call   1030 <atan@plt>
movss  %xmm0,-0x1c(%rbp)
movss  -0x1c(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cartesianToPolar>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
movss  %xmm0,0x4(%rsp)
movss  %xmm1,(%rsp)
mulss  %xmm1,%xmm1
mulss  %xmm0,%xmm0
addss  %xmm1,%xmm0
call   1040 <sqrt@plt>
movss  0x4(%rsp),%xmm1
movsd  %xmm0,(%rbx)
xorps  %xmm0,%xmm0
ucomiss %xmm0,%xmm1
jne    1182 <cartesianToPolar+0x62>
jp     1182 <cartesianToPolar+0x62>
movss  (%rsp),%xmm1
ucomiss %xmm0,%xmm1
jne    1166 <cartesianToPolar+0x46>
jnp    1190 <cartesianToPolar+0x70>
xorps  %xmm0,%xmm0
ucomiss %xmm0,%xmm1
mov    0x2e75(%rip),%rax
movss  (%rax),%xmm0
ja     1190 <cartesianToPolar+0x70>
xorps  0xe80(%rip),%xmm0
jmp    1190 <cartesianToPolar+0x70>
movss  (%rsp),%xmm0
divss  %xmm1,%xmm0
call   1030 <atan@plt>
cvtss2sd %xmm0,%xmm0
movsd  %xmm0,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@M_PI_2 = global float 0.000000e+00
define void @cartesianToPolar(float %0, float %1, double* %2, double* %3) {
%5 = alloca float
%6 = alloca float
%7 = alloca double*
%8 = alloca double*
%9 = alloca float
store float %0, float* %5
store float %1, float* %6
store double* %2, double** %7
store double* %3, double** %8
%10 = load float, float* %5
%11 = load float, float* %5
%12 = load float, float* %6
%13 = load float, float* %6
%14 = fmul float %12, %13
%15 = call float @llvm.fmuladd.f32(float %10, float %11, float %14)
%16 = call double @sqrt(float %15)
%17 = load double*, double** %7
store double %16, double* %17
%18 = load float, float* %5
%19 = fcmp oeq float %18, 0.000000e+00
br i1 %19, label %20, label %35
20: ; preds = %4
%21 = load float, float* %6
%22 = fpext float %21 to double
%23 = fcmp oeq double %22, 0.000000e+00
br i1 %23, label %24, label %25
24: ; preds = %20
store float 0.000000e+00, float* %9
br label %34
25: ; preds = %20
%26 = load float, float* %6
%27 = fcmp ogt float %26, 0.000000e+00
br i1 %27, label %28, label %30
28: ; preds = %25
%29 = load float, float* @M_PI_2
store float %29, float* %9
br label %33
30: ; preds = %25
%31 = load float, float* @M_PI_2
%32 = fneg float %31
store float %32, float* %9
br label %33
33: ; preds = %30, %28
br label %34
34: ; preds = %33, %24
br label %40
35: ; preds = %4
%36 = load float, float* %6
%37 = load float, float* %5
%38 = fdiv float %36, %37
%39 = call float @atan(float %38)
store float %39, float* %9
br label %40
40: ; preds = %35, %34
%41 = load float, float* %9
%42 = fpext float %41 to double
%43 = load double*, double** %8
store double %42, double* %43
ret void
}

LLVM IR (-O2):
@M_PI_2 = global float 0.000000e+00
define void @cartesianToPolar(float %0, float %1, double* nocapture writeonly %2, double* nocapture writeonly %3) {
%5 = fmul float %1, %1
%6 = tail call float @llvm.fmuladd.f32(float %0, float %0, float %5)
%7 = tail call double @sqrt(float %6)
store double %7, double* %2
%8 = fcmp oeq float %0, 0.000000e+00
br i1 %8, label %9, label %16
9: ; preds = %4
%10 = fcmp oeq float %1, 0.000000e+00
br i1 %10, label %19, label %11
11: ; preds = %9
%12 = fcmp ogt float %1, 0.000000e+00
%13 = load float, float* @M_PI_2
br i1 %12, label %19, label %14
14: ; preds = %11
%15 = fneg float %13
br label %19
16: ; preds = %4
%17 = fdiv float %1, %0
%18 = tail call float @atan(float %17)
br label %19
19: ; preds = %11, %9, %14, %16
%20 = phi float [ %15, %14 ], [ %18, %16 ], [ 0.000000e+00, %9 ], [ %13, %11 ]
%21 = fpext float %20 to double
store double %21, double* %3
ret void
}