#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 */
double atan2(double, double);
double sqrt(double);
void trans_rect2polar(double **toTrans) {
  for (int i = 0; i < 3; i++) {
    double a = toTrans[i][0];
    double b = toTrans[i][1];
    toTrans[i][0] = sqrt(a * a + b * b);
    toTrans[i][1] = atan2(b, a);
  }
}


x86 assembly (clang, -O0):
<trans_rect2polar>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x3,-0xc(%rbp)
jge    11c7 <trans_rect2polar+0xa7>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movsd  0x8(%rax),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm2
movsd  -0x20(%rbp),%xmm1
mulsd  -0x20(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1040 <sqrt@plt>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movsd  %xmm0,(%rax)
movsd  -0x20(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
call   1030 <atan2@plt>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movsd  %xmm0,0x8(%rax)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1133 <trans_rect2polar+0x13>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<trans_rect2polar>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
mov    (%rdi),%rax
movsd  (%rax),%xmm1
movsd  0x8(%rax),%xmm3
movapd %xmm3,%xmm2
mulsd  %xmm3,%xmm2
movapd %xmm1,%xmm0
mulsd  %xmm1,%xmm0
addsd  %xmm2,%xmm0
xorpd  %xmm2,%xmm2
ucomisd %xmm2,%xmm0
jb     1158 <trans_rect2polar+0x38>
sqrtsd %xmm0,%xmm0
jmp    1173 <trans_rect2polar+0x53>
movsd  %xmm1,0x8(%rsp)
movsd  %xmm3,(%rsp)
call   1040 <sqrt@plt>
movsd  (%rsp),%xmm3
movsd  0x8(%rsp),%xmm1
mov    (%rbx),%rax
movsd  %xmm0,(%rax)
movapd %xmm3,%xmm0
call   1030 <atan2@plt>
mov    (%rbx),%rax
movsd  %xmm0,0x8(%rax)
mov    0x8(%rbx),%rax
movsd  (%rax),%xmm1
movsd  0x8(%rax),%xmm3
movapd %xmm3,%xmm2
mulsd  %xmm3,%xmm2
movapd %xmm1,%xmm0
mulsd  %xmm1,%xmm0
addsd  %xmm2,%xmm0
ucomisd 0xe4c(%rip),%xmm0
jb     11bc <trans_rect2polar+0x9c>
sqrtsd %xmm0,%xmm0
jmp    11d7 <trans_rect2polar+0xb7>
movsd  %xmm1,0x8(%rsp)
movsd  %xmm3,(%rsp)
call   1040 <sqrt@plt>
movsd  (%rsp),%xmm3
movsd  0x8(%rsp),%xmm1
mov    0x8(%rbx),%rax
movsd  %xmm0,(%rax)
movapd %xmm3,%xmm0
call   1030 <atan2@plt>
mov    0x8(%rbx),%rax
movsd  %xmm0,0x8(%rax)
mov    0x10(%rbx),%rax
movsd  (%rax),%xmm1
movsd  0x8(%rax),%xmm3
movapd %xmm3,%xmm2
mulsd  %xmm3,%xmm2
movapd %xmm1,%xmm0
mulsd  %xmm1,%xmm0
addsd  %xmm2,%xmm0
xorpd  %xmm2,%xmm2
ucomisd %xmm2,%xmm0
jb     1222 <trans_rect2polar+0x102>
sqrtsd %xmm0,%xmm0
jmp    123d <trans_rect2polar+0x11d>
movsd  %xmm1,0x8(%rsp)
movsd  %xmm3,(%rsp)
call   1040 <sqrt@plt>
movsd  (%rsp),%xmm3
movsd  0x8(%rsp),%xmm1
mov    0x10(%rbx),%rax
movsd  %xmm0,(%rax)
movapd %xmm3,%xmm0
call   1030 <atan2@plt>
mov    0x10(%rbx),%rax
movsd  %xmm0,0x8(%rax)
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define void @trans_rect2polar(double** %0) {
%2 = alloca double**
%3 = alloca i32
%4 = alloca double
%5 = alloca double
store double** %0, double*** %2
store i32 0, i32* %3
br label %6
6: ; preds = %46, %1
%7 = load i32, i32* %3
%8 = icmp slt i32 %7, 3
br i1 %8, label %9, label %49
9: ; preds = %6
%10 = load double**, double*** %2
%11 = load i32, i32* %3
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds double*, double** %10, i64 %12
%14 = load double*, double** %13
%15 = getelementptr inbounds double, double* %14, i64 0
%16 = load double, double* %15
store double %16, double* %4
%17 = load double**, double*** %2
%18 = load i32, i32* %3
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds double*, double** %17, i64 %19
%21 = load double*, double** %20
%22 = getelementptr inbounds double, double* %21, i64 1
%23 = load double, double* %22
store double %23, double* %5
%24 = load double, double* %4
%25 = load double, double* %4
%26 = load double, double* %5
%27 = load double, double* %5
%28 = fmul double %26, %27
%29 = call double @llvm.fmuladd.f64(double %24, double %25, double %28)
%30 = call double @sqrt(double %29)
%31 = load double**, double*** %2
%32 = load i32, i32* %3
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds double*, double** %31, i64 %33
%35 = load double*, double** %34
%36 = getelementptr inbounds double, double* %35, i64 0
store double %30, double* %36
%37 = load double, double* %5
%38 = load double, double* %4
%39 = call double @atan2(double %37, double %38)
%40 = load double**, double*** %2
%41 = load i32, i32* %3
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds double*, double** %40, i64 %42
%44 = load double*, double** %43
%45 = getelementptr inbounds double, double* %44, i64 1
store double %39, double* %45
br label %46
46: ; preds = %9
%47 = load i32, i32* %3
%48 = add nsw i32 %47, 1
store i32 %48, i32* %3
br label %6
49: ; preds = %6
ret void
}

LLVM IR (-O2):
define void @trans_rect2polar(double** nocapture %0) {
%2 = load double*, double** %0
%3 = load double, double* %2
%4 = getelementptr inbounds double, double* %2, i64 1
%5 = load double, double* %4
%6 = fmul double %5, %5
%7 = tail call double @llvm.fmuladd.f64(double %3, double %3, double %6)
%8 = tail call double @sqrt(double %7)
%9 = load double*, double** %0
store double %8, double* %9
%10 = tail call double @atan2(double %5, double %3)
%11 = load double*, double** %0
%12 = getelementptr inbounds double, double* %11, i64 1
store double %10, double* %12
%13 = getelementptr inbounds double*, double** %0, i64 1
%14 = load double*, double** %13
%15 = load double, double* %14
%16 = getelementptr inbounds double, double* %14, i64 1
%17 = load double, double* %16
%18 = fmul double %17, %17
%19 = tail call double @llvm.fmuladd.f64(double %15, double %15, double %18)
%20 = tail call double @sqrt(double %19)
%21 = load double*, double** %13
store double %20, double* %21
%22 = tail call double @atan2(double %17, double %15)
%23 = load double*, double** %13
%24 = getelementptr inbounds double, double* %23, i64 1
store double %22, double* %24
%25 = getelementptr inbounds double*, double** %0, i64 2
%26 = load double*, double** %25
%27 = load double, double* %26
%28 = getelementptr inbounds double, double* %26, i64 1
%29 = load double, double* %28
%30 = fmul double %29, %29
%31 = tail call double @llvm.fmuladd.f64(double %27, double %27, double %30)
%32 = tail call double @sqrt(double %31)
%33 = load double*, double** %25
store double %32, double* %33
%34 = tail call double @atan2(double %29, double %27)
%35 = load double*, double** %25
%36 = getelementptr inbounds double, double* %35, i64 1
store double %34, double* %36
ret void
}