#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 */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ memcpy(float *, float *, int);
int /*<<< orphan*/ stderr;
float **copyFloatDim2Array(float **src, int rows, int cols) {
  float **ret;
  int r;
  {
    if ((ret = (float **)malloc(rows * sizeof(float *))) == NULL) {
      {
        fprintf(stderr, "error: malloc()\n");
        exit(1);
      };
    }
  };
  for (r = 0; r < rows; r++) {
    {
      if ((ret[r] = (float *)malloc(cols * sizeof(float))) == NULL) {
        {
          fprintf(stderr, "error: malloc()\n");
          exit(1);
        };
      }
    };
    memcpy(ret[r], src[r], sizeof(float) * cols);
  }
  return ret;
}


x86 assembly (clang, -O0):
<copyFloatDim2Array>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
movslq -0xc(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    118e <copyFloatDim2Array+0x4e>
mov    0x2e6a(%rip),%rax
mov    (%rax),%edi
lea    0xe81(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    121a <copyFloatDim2Array+0xda>
movslq -0x10(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    -0x18(%rbp),%rcx
movslq -0x1c(%rbp),%rdx
mov    %rax,(%rcx,%rdx,8)
cmp    $0x0,%rax
jne    11e5 <copyFloatDim2Array+0xa5>
mov    0x2e13(%rip),%rax
mov    (%rax),%edi
lea    0xe2a(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
movslq -0x10(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edx
call   1040 <memcpy@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1195 <copyFloatDim2Array+0x55>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<copyFloatDim2Array>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%ebp
mov    %esi,%r12d
mov    %rdi,%r14
lea    0x0(,%r12,8),%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     11b3 <copyFloatDim2Array+0x73>
mov    %rax,%r15
test   %r12d,%r12d
jle    11a7 <copyFloatDim2Array+0x67>
shl    $0x2,%ebp
mov    %r12d,%r12d
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %ebp,%edi
call   1050 <malloc@plt>
mov    %rax,(%r15,%rbx,8)
test   %rax,%rax
je     11b3 <copyFloatDim2Array+0x73>
mov    (%r14,%rbx,8),%rsi
mov    %rax,%rdi
mov    %ebp,%edx
call   1040 <memcpy@plt>
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1180 <copyFloatDim2Array+0x40>
mov    %r15,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2e26(%rip),%rax
mov    (%rax),%edi
lea    0xe3d(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [17 x i8] c"error: malloc()\0A\00"
define float** @copyFloatDim2Array(float** %0, i32 %1, i32 %2) {
%4 = alloca float**
%5 = alloca i32
%6 = alloca i32
%7 = alloca float**
%8 = alloca i32
store float** %0, float*** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%9 = load i32, i32* %5
%10 = sext i32 %9 to i64
%11 = mul i64 %10, 8
%12 = trunc i64 %11 to i32
%13 = call i64 @malloc(i32 %12)
%14 = inttoptr i64 %13 to float**
store float** %14, float*** %7
%15 = icmp eq float** %14, null
br i1 %15, label %16, label %20
16: ; preds = %3
%17 = load i32, i32* @stderr
%18 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %3
store i32 0, i32* %8
br label %21
21: ; preds = %57, %20
%22 = load i32, i32* %8
%23 = load i32, i32* %5
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %60
25: ; preds = %21
%26 = load i32, i32* %6
%27 = sext i32 %26 to i64
%28 = mul i64 %27, 4
%29 = trunc i64 %28 to i32
%30 = call i64 @malloc(i32 %29)
%31 = inttoptr i64 %30 to float*
%32 = load float**, float*** %7
%33 = load i32, i32* %8
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds float*, float** %32, i64 %34
store float* %31, float** %35
%36 = icmp eq float* %31, null
br i1 %36, label %37, label %41
37: ; preds = %25
%38 = load i32, i32* @stderr
%39 = call i32 @fprintf(i32 %38, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%40 = call i32 @exit(i32 1)
unreachable
41: ; preds = %25
%42 = load float**, float*** %7
%43 = load i32, i32* %8
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds float*, float** %42, i64 %44
%46 = load float*, float** %45
%47 = load float**, float*** %4
%48 = load i32, i32* %8
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds float*, float** %47, i64 %49
%51 = load float*, float** %50
%52 = load i32, i32* %6
%53 = sext i32 %52 to i64
%54 = mul i64 4, %53
%55 = trunc i64 %54 to i32
%56 = call i32 @memcpy(float* %46, float* %51, i32 %55)
br label %57
57: ; preds = %41
%58 = load i32, i32* %8
%59 = add nsw i32 %58, 1
store i32 %59, i32* %8
br label %21
60: ; preds = %21
%61 = load float**, float*** %7
ret float** %61
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [17 x i8] c"error: malloc()\0A\00"
define float** @copyFloatDim2Array(float** nocapture %0, i32 %1, i32 %2) {
%4 = shl i32 %1, 3
%5 = tail call i64 @malloc(i32 %4)
%6 = inttoptr i64 %5 to float**
%7 = icmp eq i64 %5, 0
br i1 %7, label %13, label %8
8: ; preds = %3
%9 = icmp sgt i32 %1, 0
br i1 %9, label %10, label %33
10: ; preds = %8
%11 = shl i32 %2, 2
%12 = zext i32 %1 to i64
br label %17
13: ; preds = %3
%14 = load i32, i32* @stderr
%15 = tail call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%16 = tail call i32 @exit(i32 1)
unreachable
17: ; preds = %10, %27
%18 = phi i64 [ 0, %10 ], [ %31, %27 ]
%19 = tail call i64 @malloc(i32 %11)
%20 = inttoptr i64 %19 to float*
%21 = getelementptr inbounds float*, float** %6, i64 %18
store float* %20, float** %21
%22 = icmp eq i64 %19, 0
br i1 %22, label %23, label %27
23: ; preds = %17
%24 = load i32, i32* @stderr
%25 = tail call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%26 = tail call i32 @exit(i32 1)
unreachable
27: ; preds = %17
%28 = getelementptr inbounds float*, float** %0, i64 %18
%29 = load float*, float** %28
%30 = tail call i32 @memcpy(float* %20, float* %29, i32 %11)
%31 = add nuw nsw i64 %18, 1
%32 = icmp eq i64 %31, %12
br i1 %32, label %33, label %17
33: ; preds = %27, %8
ret float** %6
}