#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__ calloc(int, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ stderr;
float **get_2d_mem_float(int dim1, int dim2) {
  float **array_2d;
  int i;
  if (!(array_2d = (float **)calloc(dim1, sizeof(float *)))) {
    fprintf(stderr, "unable to allocate memory in get_2d_mem_float\n");
    fprintf(stderr, "dimension1= %d\n", dim1);
    exit(1);
  }
  for (i = 0; i < dim1; i++) {
    if (!(array_2d[i] = (float *)calloc(dim2, sizeof(float)))) {
      fprintf(stderr, "unable to allocate memory in get_2d_mem_float\n");
      fprintf(stderr, "dimension1= %d, dimension2=%d\n", dim1, dim2);
      exit(1);
    }
  }
  return array_2d;
}


x86 assembly (clang, -O0):
<get_2d_mem_float>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%edi
mov    $0x8,%esi
call   1030 <calloc@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    1194 <get_2d_mem_float+0x64>
mov    0x2e80(%rip),%rax
mov    (%rax),%edi
lea    0xe97(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2e69(%rip),%rax
mov    (%rax),%edi
mov    -0x4(%rbp),%edx
lea    0xeac(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    121b <get_2d_mem_float+0xeb>
mov    -0x8(%rbp),%edi
mov    $0x4,%esi
call   1030 <calloc@plt>
mov    -0x10(%rbp),%rcx
movslq -0x14(%rbp),%rdx
mov    %rax,(%rcx,%rdx,8)
cmp    $0x0,%rax
jne    1208 <get_2d_mem_float+0xd8>
mov    0x2e0f(%rip),%rax
mov    (%rax),%edi
lea    0xe26(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2df8(%rip),%rax
mov    (%rax),%edi
mov    -0x4(%rbp),%edx
mov    -0x8(%rbp),%ecx
lea    0xe48(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
jmp    120d <get_2d_mem_float+0xdd>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    119b <get_2d_mem_float+0x6b>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_2d_mem_float>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%r15d
mov    %edi,%r14d
mov    $0x8,%esi
call   1030 <calloc@plt>
test   %rax,%rax
je     11c2 <get_2d_mem_float+0x92>
mov    %rax,%r12
test   %r14d,%r14d
jle    117f <get_2d_mem_float+0x4f>
mov    %r14d,%ebp
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    %r15d,%edi
mov    $0x4,%esi
call   1030 <calloc@plt>
mov    %rax,(%r12,%rbx,8)
test   %rax,%rax
je     118b <get_2d_mem_float+0x5b>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1160 <get_2d_mem_float+0x30>
mov    %r12,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2e4e(%rip),%rbx
mov    (%rbx),%edi
lea    0xe65(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    (%rbx),%edi
lea    0xe94(%rip),%rsi
mov    %r14d,%edx
mov    %r15d,%ecx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    0x2e17(%rip),%rbx
mov    (%rbx),%edi
lea    0xe2e(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    (%rbx),%edi
lea    0xe4d(%rip),%rsi
mov    %r14d,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [47 x i8] c"unable to allocate memory in get_2d_mem_float\0A\00"
@.str.1 = [16 x i8] c"dimension1= %d\0A\00"
@.str.2 = [31 x i8] c"dimension1= %d, dimension2=%d\0A\00"
define float** @get_2d_mem_float(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca float**
%6 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%7 = load i32, i32* %3
%8 = call i64 @calloc(i32 %7, i32 8)
%9 = inttoptr i64 %8 to float**
store float** %9, float*** %5
%10 = icmp ne float** %9, null
br i1 %10, label %18, label %11
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0))
%14 = load i32, i32* @stderr
%15 = load i32, i32* %3
%16 = call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %15)
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %2
store i32 0, i32* %6
br label %19
19: ; preds = %41, %18
%20 = load i32, i32* %6
%21 = load i32, i32* %3
%22 = icmp slt i32 %20, %21
br i1 %22, label %23, label %44
23: ; preds = %19
%24 = load i32, i32* %4
%25 = call i64 @calloc(i32 %24, i32 4)
%26 = inttoptr i64 %25 to float*
%27 = load float**, float*** %5
%28 = load i32, i32* %6
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds float*, float** %27, i64 %29
store float* %26, float** %30
%31 = icmp ne float* %26, null
br i1 %31, label %40, label %32
32: ; preds = %23
%33 = load i32, i32* @stderr
%34 = call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0))
%35 = load i32, i32* @stderr
%36 = load i32, i32* %3
%37 = load i32, i32* %4
%38 = call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i32 %36, i32 %37)
%39 = call i32 @exit(i32 1)
unreachable
40: ; preds = %23
br label %41
41: ; preds = %40
%42 = load i32, i32* %6
%43 = add nsw i32 %42, 1
store i32 %43, i32* %6
br label %19
44: ; preds = %19
%45 = load float**, float*** %5
ret float** %45
}

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