#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 *double_vector(int);
scalar_t__ malloc(int);
double **rfprof_alloc(int N, int chan) {
  int i;
  double **obj = NULL;
  obj = (double **)malloc((N + 1) * sizeof(double *));
  obj[0] = (double *)malloc(sizeof(double));
  *(int *)(obj[0]) = N;
  for (i = 1; i <= N; i++) {
    obj[i] = double_vector(chan + 1);
  }
  return obj;
}


x86 assembly (clang, -O0):
<rfprof_alloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    $0x8,%edi
call   1040 <malloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x4(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %ecx,(%rax)
movl   $0x1,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x4(%rbp),%eax
jg     11a8 <rfprof_alloc+0x88>
mov    -0x8(%rbp),%edi
add    $0x1,%edi
call   1030 <double_vector@plt>
mov    %rax,%rdx
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1174 <rfprof_alloc+0x54>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rfprof_alloc>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %edi,%r15d
lea    0x8(,%r15,8),%edi
call   1040 <malloc@plt>
mov    %rax,%rbp
mov    $0x8,%edi
call   1040 <malloc@plt>
mov    %rax,0x0(%rbp)
mov    %r15d,(%rax)
test   %r15d,%r15d
jle    1176 <rfprof_alloc+0x56>
add    $0x1,%r14d
add    $0x1,%r15d
mov    $0x1,%ebx
mov    %r14d,%edi
call   1030 <double_vector@plt>
mov    %rax,0x0(%rbp,%rbx,8)
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1160 <rfprof_alloc+0x40>
mov    %rbp,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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