#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 */
scalar_t__ malloc(int);
scalar_t__ realloc(double **, int);
double **rad2d(double **A, int X, int Y) {
  int i;
  **A = 0;
  for (i = 0; i < X; i++) {
    A = (double **)realloc(A, (i + 1) * sizeof(double *));
    A[i] = (double *)malloc(Y * sizeof(double));
  }
  return A;
}


x86 assembly (clang, -O0):
<rad2d>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    119a <rad2d+0x7a>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%esi
call   1040 <realloc@plt>
mov    %rax,-0x8(%rbp)
movslq -0x10(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1030 <malloc@plt>
mov    %rax,%rdx
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1147 <rad2d+0x27>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rad2d>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%r12
mov    (%rdi),%rax
movq   $0x0,(%rax)
test   %esi,%esi
jle    1175 <rad2d+0x55>
mov    %edx,%r14d
shl    $0x3,%r14d
mov    %esi,%r15d
shl    $0x3,%r15
xor    %ebp,%ebp
nopl   0x0(%rax)
lea    0x8(%rbp),%rbx
mov    %r12,%rdi
mov    %ebx,%esi
call   1040 <realloc@plt>
mov    %rax,%r12
mov    %r14d,%edi
call   1030 <malloc@plt>
mov    %rax,(%r12,%rbp,1)
mov    %rbx,%rbp
cmp    %rbx,%r15
jne    1150 <rad2d+0x30>
mov    %r12,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define double** @rad2d(double** %0, i32 %1, i32 %2) {
%4 = alloca double**
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store double** %0, double*** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%8 = load double**, double*** %4
%9 = load double*, double** %8
store double 0.000000e+00, double* %9
store i32 0, i32* %7
br label %10
10: ; preds = %33, %3
%11 = load i32, i32* %7
%12 = load i32, i32* %5
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %36
14: ; preds = %10
%15 = load double**, double*** %4
%16 = load i32, i32* %7
%17 = add nsw i32 %16, 1
%18 = sext i32 %17 to i64
%19 = mul i64 %18, 8
%20 = trunc i64 %19 to i32
%21 = call i64 @realloc(double** %15, i32 %20)
%22 = inttoptr i64 %21 to double**
store double** %22, double*** %4
%23 = load i32, i32* %6
%24 = sext i32 %23 to i64
%25 = mul i64 %24, 8
%26 = trunc i64 %25 to i32
%27 = call i64 @malloc(i32 %26)
%28 = inttoptr i64 %27 to double*
%29 = load double**, double*** %4
%30 = load i32, i32* %7
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds double*, double** %29, i64 %31
store double* %28, double** %32
br label %33
33: ; preds = %14
%34 = load i32, i32* %7
%35 = add nsw i32 %34, 1
store i32 %35, i32* %7
br label %10
36: ; preds = %10
%37 = load double**, double*** %4
ret double** %37
}

LLVM IR (-O2):
define double** @rad2d(double** %0, i32 %1, i32 %2) {
%4 = load double*, double** %0
store double 0.000000e+00, double* %4
%5 = icmp sgt i32 %1, 0
br i1 %5, label %6, label %23
6: ; preds = %3
%7 = shl i32 %2, 3
%8 = zext i32 %1 to i64
br label %9
9: ; preds = %6, %9
%10 = phi i64 [ 0, %6 ], [ %12, %9 ]
%11 = phi double** [ %0, %6 ], [ %16, %9 ]
%12 = add nuw nsw i64 %10, 1
%13 = trunc i64 %12 to i32
%14 = shl i32 %13, 3
%15 = tail call i64 @realloc(double** %11, i32 %14)
%16 = inttoptr i64 %15 to double**
%17 = tail call i64 @malloc(i32 %7)
%18 = inttoptr i64 %17 to double*
%19 = getelementptr inbounds double*, double** %16, i64 %10
store double* %18, double** %19
%20 = icmp eq i64 %12, %8
br i1 %20, label %21, label %9
21: ; preds = %9
%22 = inttoptr i64 %15 to double**
br label %23
23: ; preds = %21, %3
%24 = phi double** [ %0, %3 ], [ %22, %21 ]
ret double** %24
}