#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*/ error_and_exit();
void *malloc(int);
double **malloc_double_mat(int dim1, int dim2) {
  int i;
  double **mat;
  mat = malloc(sizeof(double) * dim1);
  if (mat == NULL)
    error_and_exit();
  for (i = 0; i < dim1; i++) {
    mat[i] = malloc(sizeof(double) * dim2);
    if (mat[i] == NULL)
      error_and_exit();
  }
  return mat;
}


x86 assembly (clang, -O0):
<malloc_double_mat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movslq -0x4(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1153 <malloc_double_mat+0x33>
mov    $0x0,%al
call   1030 <error_and_exit@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11b1 <malloc_double_mat+0x91>
movslq -0x8(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,%rdx
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
jne    119e <malloc_double_mat+0x7e>
mov    $0x0,%al
call   1030 <error_and_exit@plt>
jmp    11a3 <malloc_double_mat+0x83>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    115a <malloc_double_mat+0x3a>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<malloc_double_mat>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%r15d
mov    %edi,%r14d
lea    0x0(,%r14,8),%edi
call   1040 <malloc@plt>
mov    %rax,%r12
test   %rax,%rax
je     114a <malloc_double_mat+0x2a>
test   %r14d,%r14d
jg     1156 <malloc_double_mat+0x36>
jmp    1193 <malloc_double_mat+0x73>
xor    %eax,%eax
call   1030 <error_and_exit@plt>
test   %r14d,%r14d
jle    1193 <malloc_double_mat+0x73>
shl    $0x3,%r15d
mov    %r14d,%ebp
xor    %ebx,%ebx
jmp    1179 <malloc_double_mat+0x59>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%rbx
cmp    %rbx,%rbp
je     1193 <malloc_double_mat+0x73>
mov    %r15d,%edi
call   1040 <malloc@plt>
mov    %rax,(%r12,%rbx,8)
test   %rax,%rax
jne    1170 <malloc_double_mat+0x50>
xor    %eax,%eax
call   1030 <error_and_exit@plt>
jmp    1170 <malloc_double_mat+0x50>
mov    %r12,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define double** @malloc_double_mat(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
%7 = load i32, i32* %3
%8 = sext i32 %7 to i64
%9 = mul i64 8, %8
%10 = trunc i64 %9 to i32
%11 = call i8* @malloc(i32 %10)
%12 = bitcast i8* %11 to double**
store double** %12, double*** %6
%13 = load double**, double*** %6
%14 = icmp eq double** %13, null
br i1 %14, label %15, label %17
15: ; preds = %2
%16 = call i32 (...) @error_and_exit()
br label %17
17: ; preds = %15, %2
store i32 0, i32* %5
br label %18
18: ; preds = %42, %17
%19 = load i32, i32* %5
%20 = load i32, i32* %3
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %45
22: ; preds = %18
%23 = load i32, i32* %4
%24 = sext i32 %23 to i64
%25 = mul i64 8, %24
%26 = trunc i64 %25 to i32
%27 = call i8* @malloc(i32 %26)
%28 = bitcast i8* %27 to double*
%29 = load double**, double*** %6
%30 = load i32, i32* %5
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds double*, double** %29, i64 %31
store double* %28, double** %32
%33 = load double**, double*** %6
%34 = load i32, i32* %5
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds double*, double** %33, i64 %35
%37 = load double*, double** %36
%38 = icmp eq double* %37, null
br i1 %38, label %39, label %41
39: ; preds = %22
%40 = call i32 (...) @error_and_exit()
br label %41
41: ; preds = %39, %22
br label %42
42: ; preds = %41
%43 = load i32, i32* %5
%44 = add nsw i32 %43, 1
store i32 %44, i32* %5
br label %18
45: ; preds = %18
%46 = load double**, double*** %6
ret double** %46
}

LLVM IR (-O2):
define noalias double** @malloc_double_mat(i32 %0, i32 %1) {
%3 = shl i32 %0, 3
%4 = tail call i8* @malloc(i32 %3)
%5 = bitcast i8* %4 to double**
%6 = icmp eq i8* %4, null
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = tail call i32 (...) @error_and_exit()
br label %9
9: ; preds = %7, %2
%10 = icmp sgt i32 %0, 0
br i1 %10, label %11, label %25
11: ; preds = %9
%12 = shl i32 %1, 3
%13 = zext i32 %0 to i64
br label %14
14: ; preds = %11, %22
%15 = phi i64 [ 0, %11 ], [ %23, %22 ]
%16 = tail call i8* @malloc(i32 %12)
%17 = getelementptr inbounds double*, double** %5, i64 %15
%18 = bitcast double** %17 to i8**
store i8* %16, i8** %18
%19 = icmp eq i8* %16, null
br i1 %19, label %20, label %22
20: ; preds = %14
%21 = tail call i32 (...) @error_and_exit()
br label %22
22: ; preds = %14, %20
%23 = add nuw nsw i64 %15, 1
%24 = icmp eq i64 %23, %13
br i1 %24, label %25, label %14
25: ; preds = %22, %9
ret double** %5
}