#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) {
  if (rPtr) {
    *rPtr = sqrt(x * x + y * y);
  }
  if (!thetaPtr) {
    return;
  }
  float theta;
  if (x == 0) {
    if (y == 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)
cmpq   $0x0,-0x10(%rbp)
je     116e <cartesianToPolar+0x4e>
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)
cmpq   $0x0,-0x18(%rbp)
jne    117e <cartesianToPolar+0x5e>
jmp    122b <cartesianToPolar+0x10b>
movss  -0x4(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jne    1206 <cartesianToPolar+0xe6>
jp     1206 <cartesianToPolar+0xe6>
movss  -0x8(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jne    11b9 <cartesianToPolar+0x99>
jp     11b9 <cartesianToPolar+0x99>
xorps  %xmm0,%xmm0
movss  %xmm0,-0x1c(%rbp)
jmp    1201 <cartesianToPolar+0xe1>
movss  -0x8(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jbe    11df <cartesianToPolar+0xbf>
mov    0x2e17(%rip),%rax
movss  (%rax),%xmm0
movss  %xmm0,-0x1c(%rbp)
jmp    11fc <cartesianToPolar+0xdc>
mov    0x2e02(%rip),%rax
movss  (%rax),%xmm0
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
movss  %xmm0,-0x1c(%rbp)
jmp    1201 <cartesianToPolar+0xe1>
jmp    121a <cartesianToPolar+0xfa>
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
movaps %xmm0,%xmm2
test   %rdi,%rdi
je     1165 <cartesianToPolar+0x45>
mov    %rdi,%rbx
movss  %xmm1,(%rsp)
movss  (%rsp),%xmm1
mulss  %xmm1,%xmm1
movaps %xmm2,%xmm0
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm2,0x4(%rsp)
call   1040 <sqrt@plt>
movss  0x4(%rsp),%xmm2
movss  (%rsp),%xmm1
movsd  %xmm0,(%rbx)
test   %r14,%r14
je     11ac <cartesianToPolar+0x8c>
xorps  %xmm0,%xmm0
ucomiss %xmm0,%xmm2
jne    1197 <cartesianToPolar+0x77>
jp     1197 <cartesianToPolar+0x77>
ucomiss %xmm0,%xmm1
jne    117b <cartesianToPolar+0x5b>
jnp    11a3 <cartesianToPolar+0x83>
xorps  %xmm0,%xmm0
ucomiss %xmm0,%xmm1
mov    0x2e60(%rip),%rax
movss  (%rax),%xmm0
ja     11a3 <cartesianToPolar+0x83>
xorps  0xe6b(%rip),%xmm0
jmp    11a3 <cartesianToPolar+0x83>
divss  %xmm2,%xmm1
movaps %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 double*, double** %7
%11 = icmp ne double* %10, null
br i1 %11, label %12, label %21
12: ; preds = %4
%13 = load float, float* %5
%14 = load float, float* %5
%15 = load float, float* %6
%16 = load float, float* %6
%17 = fmul float %15, %16
%18 = call float @llvm.fmuladd.f32(float %13, float %14, float %17)
%19 = call double @sqrt(float %18)
%20 = load double*, double** %7
store double %19, double* %20
br label %21
21: ; preds = %12, %4
%22 = load double*, double** %8
%23 = icmp ne double* %22, null
br i1 %23, label %25, label %24
24: ; preds = %21
br label %51
25: ; preds = %21
%26 = load float, float* %5
%27 = fcmp oeq float %26, 0.000000e+00
br i1 %27, label %28, label %42
28: ; preds = %25
%29 = load float, float* %6
%30 = fcmp oeq float %29, 0.000000e+00
br i1 %30, label %31, label %32
31: ; preds = %28
store float 0.000000e+00, float* %9
br label %41
32: ; preds = %28
%33 = load float, float* %6
%34 = fcmp ogt float %33, 0.000000e+00
br i1 %34, label %35, label %37
35: ; preds = %32
%36 = load float, float* @M_PI_2
store float %36, float* %9
br label %40
37: ; preds = %32
%38 = load float, float* @M_PI_2
%39 = fneg float %38
store float %39, float* %9
br label %40
40: ; preds = %37, %35
br label %41
41: ; preds = %40, %31
br label %47
42: ; preds = %25
%43 = load float, float* %6
%44 = load float, float* %5
%45 = fdiv float %43, %44
%46 = call float @atan(float %45)
store float %46, float* %9
br label %47
47: ; preds = %42, %41
%48 = load float, float* %9
%49 = fpext float %48 to double
%50 = load double*, double** %8
store double %49, double* %50
br label %51
51: ; preds = %47, %24
ret void
}

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