#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 */
typedef scalar_t__ *original_dimx;
typedef size_t j;
typedef scalar_t__ i;

/* Variables and functions */
int const atan2(double, double);
scalar_t__ calloc(int const, int);
unsigned short p3dBicubicInterpolation_p2c_16(unsigned short *, int const,
                                              int const, double, double);
double sqrt(double);
void p3dPolar2cartesian_16(unsigned short *in_im, unsigned short **out_im,
                           const int polarX, const double centerX,
                           const double centerY, const int original_dimx,
                           const int original_dimy) {
  double r, phi;
  int i, j;
  double x, y;
  (*out_im) = (unsigned short *)calloc(original_dimx * original_dimy,
                                       sizeof(unsigned short));
#pragma omp parallel for private(i, r, phi, x, y)
  for (j = 0; j < original_dimy; j++)
    for (i = 0; i < original_dimx; i++) {
      x = (double)(i)-centerX;
      y = (double)(j)-centerY;
      r = sqrt(x * x + y * y);
      phi = (atan2(y, x) * polarX) / (3.1415926535897932384626433 * 2);
      if (phi < 0)
        phi += polarX;
      (*out_im)[((j) * (original_dimx) + (i))] =
          p3dBicubicInterpolation_p2c_16(in_im, polarX, polarX, r, phi);
    }
}


x86 assembly (clang, -O0):
<p3dPolar2cartesian_16>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movsd  %xmm0,-0x20(%rbp)
movsd  %xmm1,-0x28(%rbp)
mov    %ecx,-0x2c(%rbp)
mov    %r8d,-0x30(%rbp)
mov    -0x2c(%rbp),%edi
imul   -0x30(%rbp),%edi
mov    $0x2,%esi
call   1040 <calloc@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x48(%rbp)
mov    -0x48(%rbp),%eax
cmp    -0x30(%rbp),%eax
jge    1283 <p3dPolar2cartesian_16+0x143>
movl   $0x0,-0x44(%rbp)
mov    -0x44(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jge    1270 <p3dPolar2cartesian_16+0x130>
cvtsi2sdl -0x44(%rbp),%xmm0
subsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
cvtsi2sdl -0x48(%rbp),%xmm0
subsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x50(%rbp),%xmm0
movsd  -0x50(%rbp),%xmm2
movsd  -0x58(%rbp),%xmm1
mulsd  -0x58(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1050 <sqrt@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x58(%rbp),%xmm0
movsd  -0x50(%rbp),%xmm1
call   1030 <atan2@plt>
imul   -0x14(%rbp),%eax
cvtsi2sd %eax,%xmm0
movsd  0xdf8(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x40(%rbp),%xmm0
jbe    122e <p3dPolar2cartesian_16+0xee>
cvtsi2sdl -0x14(%rbp),%xmm0
addsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x14(%rbp),%edx
movsd  -0x38(%rbp),%xmm0
movsd  -0x40(%rbp),%xmm1
call   1060 <p3dBicubicInterpolation_p2c_16@plt>
mov    %ax,%dx
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    -0x48(%rbp),%ecx
imul   -0x2c(%rbp),%ecx
add    -0x44(%rbp),%ecx
movslq %ecx,%rcx
mov    %dx,(%rax,%rcx,2)
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    1199 <p3dPolar2cartesian_16+0x59>
jmp    1275 <p3dPolar2cartesian_16+0x135>
mov    -0x48(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x48(%rbp)
jmp    1186 <p3dPolar2cartesian_16+0x46>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<p3dPolar2cartesian_16>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
mov    %r8d,%r12d
movsd  %xmm1,0x18(%rsp)
movsd  %xmm0,0x38(%rsp)
mov    %edx,%ebp
mov    %rsi,%r15
mov    %rdi,%rbx
mov    %r8d,%edi
mov    %ecx,0x4(%rsp)
imul   %ecx,%edi
mov    $0x2,%esi
call   1040 <calloc@plt>
mov    %rax,(%r15)
test   %r12d,%r12d
jle    12cc <p3dPolar2cartesian_16+0x18c>
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
movapd %xmm0,0x50(%rsp)
movslq 0x4(%rsp),%rax
mov    %r12d,%ecx
mov    %rcx,0x20(%rsp)
mov    %eax,%r14d
add    %rax,%rax
mov    %rax,0x28(%rsp)
xor    %r12d,%r12d
xorpd  %xmm2,%xmm2
xor    %eax,%eax
mov    %rax,0x8(%rsp)
jmp    11e1 <p3dPolar2cartesian_16+0xa1>
nopw   0x0(%rax,%rax,1)
mov    0x8(%rsp),%rcx
add    $0x1,%rcx
add    0x28(%rsp),%r12
mov    %rcx,%rax
mov    %rcx,0x8(%rsp)
cmp    0x20(%rsp),%rcx
je     12cc <p3dPolar2cartesian_16+0x18c>
cmpl   $0x0,0x4(%rsp)
jle    11c0 <p3dPolar2cartesian_16+0x80>
xorps  %xmm0,%xmm0
cvtsi2sdl 0x8(%rsp),%xmm0
subsd  0x18(%rsp),%xmm0
movsd  %xmm0,0x48(%rsp)
mulsd  %xmm0,%xmm0
movsd  %xmm0,0x40(%rsp)
xor    %r13d,%r13d
jmp    129d <p3dPolar2cartesian_16+0x15d>
nop
movsd  %xmm1,0x30(%rsp)
call   1050 <sqrt@plt>
movsd  0x30(%rsp),%xmm1
movsd  %xmm0,0x10(%rsp)
movsd  0x48(%rsp),%xmm0
call   1030 <atan2@plt>
imul   %ebp,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
divsd  0xdbc(%rip),%xmm0
movapd %xmm0,%xmm1
xorpd  %xmm2,%xmm2
cmpltsd %xmm2,%xmm1
movapd %xmm1,%xmm2
andpd  0x50(%rsp),%xmm2
movsd  0xda5(%rip),%xmm3
andnpd %xmm3,%xmm1
orpd   %xmm2,%xmm1
addsd  %xmm0,%xmm1
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %ebp,%edx
movsd  0x10(%rsp),%xmm0
call   1060 <p3dBicubicInterpolation_p2c_16@plt>
xorpd  %xmm2,%xmm2
mov    (%r15),%rcx
add    %r12,%rcx
mov    %ax,(%rcx,%r13,2)
add    $0x1,%r13
cmp    %r13,%r14
je     11c0 <p3dPolar2cartesian_16+0x80>
xorps  %xmm1,%xmm1
cvtsi2sd %r13d,%xmm1
subsd  0x38(%rsp),%xmm1
movapd %xmm1,%xmm0
mulsd  %xmm1,%xmm0
addsd  0x40(%rsp),%xmm0
ucomisd %xmm2,%xmm0
jb     1210 <p3dPolar2cartesian_16+0xd0>
sqrtsd %xmm0,%xmm0
jmp    1221 <p3dPolar2cartesian_16+0xe1>
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @p3dPolar2cartesian_16(i16* %0, i16** %1, i32 %2, double %3, double %4, i32 %5, i32 %6) {
%8 = alloca i16*
%9 = alloca i16**
%10 = alloca i32
%11 = alloca double
%12 = alloca double
%13 = alloca i32
%14 = alloca i32
%15 = alloca double
%16 = alloca double
%17 = alloca i32
%18 = alloca i32
%19 = alloca double
%20 = alloca double
store i16* %0, i16** %8
store i16** %1, i16*** %9
store i32 %2, i32* %10
store double %3, double* %11
store double %4, double* %12
store i32 %5, i32* %13
store i32 %6, i32* %14
%21 = load i32, i32* %13
%22 = load i32, i32* %14
%23 = mul nsw i32 %21, %22
%24 = call i64 @calloc(i32 %23, i32 2)
%25 = inttoptr i64 %24 to i16*
%26 = load i16**, i16*** %9
store i16* %25, i16** %26
store i32 0, i32* %18
br label %27
27: ; preds = %86, %7
%28 = load i32, i32* %18
%29 = load i32, i32* %14
%30 = icmp slt i32 %28, %29
br i1 %30, label %31, label %89
31: ; preds = %27
store i32 0, i32* %17
br label %32
32: ; preds = %82, %31
%33 = load i32, i32* %17
%34 = load i32, i32* %13
%35 = icmp slt i32 %33, %34
br i1 %35, label %36, label %85
36: ; preds = %32
%37 = load i32, i32* %17
%38 = sitofp i32 %37 to double
%39 = load double, double* %11
%40 = fsub double %38, %39
store double %40, double* %19
%41 = load i32, i32* %18
%42 = sitofp i32 %41 to double
%43 = load double, double* %12
%44 = fsub double %42, %43
store double %44, double* %20
%45 = load double, double* %19
%46 = load double, double* %19
%47 = load double, double* %20
%48 = load double, double* %20
%49 = fmul double %47, %48
%50 = call double @llvm.fmuladd.f64(double %45, double %46, double %49)
%51 = call double @sqrt(double %50)
store double %51, double* %15
%52 = load double, double* %20
%53 = load double, double* %19
%54 = call i32 @atan2(double %52, double %53)
%55 = load i32, i32* %10
%56 = mul nsw i32 %54, %55
%57 = sitofp i32 %56 to double
%58 = fdiv double %57, 0x401921FB54442D18
store double %58, double* %16
%59 = load double, double* %16
%60 = fcmp olt double %59, 0.000000e+00
br i1 %60, label %61, label %66
61: ; preds = %36
%62 = load i32, i32* %10
%63 = sitofp i32 %62 to double
%64 = load double, double* %16
%65 = fadd double %64, %63
store double %65, double* %16
br label %66
66: ; preds = %61, %36
%67 = load i16*, i16** %8
%68 = load i32, i32* %10
%69 = load i32, i32* %10
%70 = load double, double* %15
%71 = load double, double* %16
%72 = call zeroext i16 @p3dBicubicInterpolation_p2c_16(i16* %67, i32 %68, i32 %69, double %70, double %71)
%73 = load i16**, i16*** %9
%74 = load i16*, i16** %73
%75 = load i32, i32* %18
%76 = load i32, i32* %13
%77 = mul nsw i32 %75, %76
%78 = load i32, i32* %17
%79 = add nsw i32 %77, %78
%80 = sext i32 %79 to i64
%81 = getelementptr inbounds i16, i16* %74, i64 %80
store i16 %72, i16* %81
br label %82
82: ; preds = %66
%83 = load i32, i32* %17
%84 = add nsw i32 %83, 1
store i32 %84, i32* %17
br label %32
85: ; preds = %32
br label %86
86: ; preds = %85
%87 = load i32, i32* %18
%88 = add nsw i32 %87, 1
store i32 %88, i32* %18
br label %27
89: ; preds = %27
ret void
}

LLVM IR (-O2):
define void @p3dPolar2cartesian_16(i16* %0, i16** nocapture %1, i32 %2, double %3, double %4, i32 %5, i32 %6) {
%8 = mul nsw i32 %6, %5
%9 = tail call i64 @calloc(i32 %8, i32 2)
%10 = inttoptr i64 %9 to i16*
store i16* %10, i16** %1
%11 = icmp sgt i32 %6, 0
br i1 %11, label %12, label %49
12: ; preds = %7
%13 = icmp sgt i32 %5, 0
%14 = sitofp i32 %2 to double
%15 = sext i32 %5 to i64
%16 = zext i32 %6 to i64
%17 = zext i32 %5 to i64
br label %18
18: ; preds = %12, %46
%19 = phi i64 [ 0, %12 ], [ %47, %46 ]
br i1 %13, label %20, label %46
20: ; preds = %18
%21 = trunc i64 %19 to i32
%22 = sitofp i32 %21 to double
%23 = fsub double %22, %4
%24 = fmul double %23, %23
%25 = mul nsw i64 %19, %15
br label %26
26: ; preds = %20, %26
%27 = phi i64 [ 0, %20 ], [ %44, %26 ]
%28 = trunc i64 %27 to i32
%29 = sitofp i32 %28 to double
%30 = fsub double %29, %3
%31 = tail call double @llvm.fmuladd.f64(double %30, double %30, double %24)
%32 = tail call double @sqrt(double %31)
%33 = tail call i32 @atan2(double %23, double %30)
%34 = mul nsw i32 %33, %2
%35 = sitofp i32 %34 to double
%36 = fdiv double %35, 0x401921FB54442D18
%37 = fcmp olt double %36, 0.000000e+00
%38 = select i1 %37, double %14, double -0.000000e+00
%39 = fadd double %36, %38
%40 = tail call zeroext i16 @p3dBicubicInterpolation_p2c_16(i16* %0, i32 %2, i32 %2, double %32, double %39)
%41 = load i16*, i16** %1
%42 = add nsw i64 %27, %25
%43 = getelementptr inbounds i16, i16* %41, i64 %42
store i16 %40, i16* %43
%44 = add nuw nsw i64 %27, 1
%45 = icmp eq i64 %44, %17
br i1 %45, label %46, label %26
46: ; preds = %26, %18
%47 = add nuw nsw i64 %19, 1
%48 = icmp eq i64 %47, %16
br i1 %48, label %49, label %18
49: ; preds = %46, %7
ret void
}