#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.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)
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    1235 <cartesianToPolar+0x115>
movss  -0x4(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1210 <cartesianToPolar+0xf0>
jp     1210 <cartesianToPolar+0xf0>
movss  -0x8(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11c3 <cartesianToPolar+0xa3>
jp     11c3 <cartesianToPolar+0xa3>
xorps  %xmm0,%xmm0
movss  %xmm0,-0x1c(%rbp)
jmp    120b <cartesianToPolar+0xeb>
movss  -0x8(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jbe    11e9 <cartesianToPolar+0xc9>
mov    0x2e0d(%rip),%rax
movss  (%rax),%xmm0
movss  %xmm0,-0x1c(%rbp)
jmp    1206 <cartesianToPolar+0xe6>
mov    0x2df8(%rip),%rax
movss  (%rax),%xmm0
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
movss  %xmm0,-0x1c(%rbp)
jmp    120b <cartesianToPolar+0xeb>
jmp    1224 <cartesianToPolar+0x104>
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 %53
25: ; preds = %21
%26 = load float, float* %5
%27 = fpext float %26 to double
%28 = fcmp oeq double %27, 0.000000e+00
br i1 %28, label %29, label %44
29: ; preds = %25
%30 = load float, float* %6
%31 = fpext float %30 to double
%32 = fcmp oeq double %31, 0.000000e+00
br i1 %32, label %33, label %34
33: ; preds = %29
store float 0.000000e+00, float* %9
br label %43
34: ; preds = %29
%35 = load float, float* %6
%36 = fcmp ogt float %35, 0.000000e+00
br i1 %36, label %37, label %39
37: ; preds = %34
%38 = load float, float* @M_PI_2
store float %38, float* %9
br label %42
39: ; preds = %34
%40 = load float, float* @M_PI_2
%41 = fneg float %40
store float %41, float* %9
br label %42
42: ; preds = %39, %37
br label %43
43: ; preds = %42, %33
br label %49
44: ; preds = %25
%45 = load float, float* %6
%46 = load float, float* %5
%47 = fdiv float %45, %46
%48 = call float @atan(float %47)
store float %48, float* %9
br label %49
49: ; preds = %44, %43
%50 = load float, float* %9
%51 = fpext float %50 to double
%52 = load double*, double** %8
store double %51, double* %52
br label %53
53: ; preds = %49, %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
}