#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*/ stderr;
double **dmatrix(int nx, int ny) {
  double **m;
  int i;
  m = (double **)malloc(sizeof(double *) * nx);
  if (m == (double **)NULL) {
    fprintf(stderr, "Error: Could not allocate memory\n");
    exit(1);
  }
  m[0] = (double *)malloc(sizeof(double) * nx * ny);
  if (m[0] == (double *)NULL) {
    fprintf(stderr, "Error: Could not allocate memory\n");
    exit(1);
  }
  for (i = 1; i < nx; i++)
    m[i] = m[i - 1] + ny;
  return (m);
}


x86 assembly (clang, -O0):
<dmatrix>:
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,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    117b <dmatrix+0x4b>
mov    0x2e7d(%rip),%rax
mov    (%rax),%edi
lea    0xe94(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
movslq -0x4(%rbp),%rax
shl    $0x3,%rax
movslq -0x8(%rbp),%rcx
imul   %rcx,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
jne    11c9 <dmatrix+0x99>
mov    0x2e2f(%rip),%rax
mov    (%rax),%edi
lea    0xe46(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1212 <dmatrix+0xe2>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdx
movslq -0x8(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdx
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11d0 <dmatrix+0xa0>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dmatrix>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r15d
mov    %edi,%r14d
lea    0x0(,%r14,8),%ebp
mov    %ebp,%edi
call   1040 <malloc@plt>
test   %rax,%rax
je     124e <dmatrix+0x11e>
mov    %rax,%rbx
imul   %r15d,%ebp
mov    %ebp,%edi
call   1040 <malloc@plt>
mov    %rax,(%rbx)
test   %rax,%rax
je     124e <dmatrix+0x11e>
cmp    $0x2,%r14d
jl     1240 <dmatrix+0x110>
movslq %r15d,%r9
mov    %r14d,%ecx
lea    -0x1(%rcx),%rdi
add    $0xfffffffffffffffe,%rcx
mov    %edi,%edx
and    $0x7,%edx
cmp    $0x7,%rcx
jae    11a1 <dmatrix+0x71>
mov    $0x1,%esi
test   %rdx,%rdx
jne    121b <dmatrix+0xeb>
jmp    1240 <dmatrix+0x110>
and    $0xfffffffffffffff8,%rdi
mov    %r9,%r8
shl    $0x6,%r8
lea    0x0(,%r9,8),%rbp
xor    %esi,%esi
cs nopw 0x0(%rax,%rax,1)
mov    %rax,%rcx
add    %rbp,%rax
mov    %rax,0x8(%rbx,%rsi,8)
add    %rbp,%rax
mov    %rax,0x10(%rbx,%rsi,8)
add    %rbp,%rax
mov    %rax,0x18(%rbx,%rsi,8)
add    %rbp,%rax
mov    %rax,0x20(%rbx,%rsi,8)
add    %rbp,%rax
mov    %rax,0x28(%rbx,%rsi,8)
add    %rbp,%rax
mov    %rax,0x30(%rbx,%rsi,8)
add    %rbp,%rax
mov    %rax,0x38(%rbx,%rsi,8)
add    %rbp,%rax
mov    %rax,0x40(%rbx,%rsi,8)
add    $0x8,%rsi
cmp    %rsi,%rdi
jne    11c0 <dmatrix+0x90>
add    %r8,%rcx
add    $0x1,%rsi
mov    %rcx,%rax
test   %rdx,%rdx
je     1240 <dmatrix+0x110>
lea    (%rax,%r9,8),%rax
shl    $0x3,%r9
lea    (%rbx,%rsi,8),%rcx
xor    %esi,%esi
nopl   0x0(%rax)
mov    %rax,(%rcx,%rsi,8)
add    $0x1,%rsi
add    %r9,%rax
cmp    %rsi,%rdx
jne    1230 <dmatrix+0x100>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d8b(%rip),%rax
mov    (%rax),%edi
lea    0xda2(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

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

LLVM IR (-O2):
@stderr = global i32 0
@.str = [34 x i8] c"Error: Could not allocate memory\0A\00"
define double** @dmatrix(i32 %0, i32 %1) {
%3 = shl i32 %0, 3
%4 = tail call i64 @malloc(i32 %3)
%5 = inttoptr i64 %4 to double**
%6 = icmp eq i64 %4, 0
br i1 %6, label %7, label %11
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %2
%12 = sext i32 %1 to i64
%13 = mul i32 %3, %1
%14 = tail call i64 @malloc(i32 %13)
%15 = inttoptr i64 %14 to double*
store double* %15, double** %5
%16 = icmp eq i64 %14, 0
br i1 %16, label %27, label %17
17: ; preds = %11
%18 = icmp sgt i32 %0, 1
br i1 %18, label %19, label %74
19: ; preds = %17
%20 = zext i32 %0 to i64
%21 = add nsw i64 %20, -1
%22 = add nsw i64 %20, -2
%23 = and i64 %21, 7
%24 = icmp ult i64 %22, 7
br i1 %24, label %61, label %25
25: ; preds = %19
%26 = and i64 %21, -8
br label %31
27: ; preds = %11
%28 = load i32, i32* @stderr
%29 = tail call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
%30 = tail call i32 @exit(i32 1)
unreachable
31: ; preds = %31, %25
%32 = phi double* [ %15, %25 ], [ %56, %31 ]
%33 = phi i64 [ 1, %25 ], [ %58, %31 ]
%34 = phi i64 [ 0, %25 ], [ %59, %31 ]
%35 = getelementptr inbounds double, double* %32, i64 %12
%36 = getelementptr inbounds double*, double** %5, i64 %33
store double* %35, double** %36
%37 = add nuw nsw i64 %33, 1
%38 = getelementptr inbounds double, double* %35, i64 %12
%39 = getelementptr inbounds double*, double** %5, i64 %37
store double* %38, double** %39
%40 = add nuw nsw i64 %33, 2
%41 = getelementptr inbounds double, double* %38, i64 %12
%42 = getelementptr inbounds double*, double** %5, i64 %40
store double* %41, double** %42
%43 = add nuw nsw i64 %33, 3
%44 = getelementptr inbounds double, double* %41, i64 %12
%45 = getelementptr inbounds double*, double** %5, i64 %43
store double* %44, double** %45
%46 = add nuw nsw i64 %33, 4
%47 = getelementptr inbounds double, double* %44, i64 %12
%48 = getelementptr inbounds double*, double** %5, i64 %46
store double* %47, double** %48
%49 = add nuw nsw i64 %33, 5
%50 = getelementptr inbounds double, double* %47, i64 %12
%51 = getelementptr inbounds double*, double** %5, i64 %49
store double* %50, double** %51
%52 = add nuw nsw i64 %33, 6
%53 = getelementptr inbounds double, double* %50, i64 %12
%54 = getelementptr inbounds double*, double** %5, i64 %52
store double* %53, double** %54
%55 = add nuw nsw i64 %33, 7
%56 = getelementptr inbounds double, double* %53, i64 %12
%57 = getelementptr inbounds double*, double** %5, i64 %55
store double* %56, double** %57
%58 = add nuw nsw i64 %33, 8
%59 = add i64 %34, 8
%60 = icmp eq i64 %59, %26
br i1 %60, label %61, label %31
61: ; preds = %31, %19
%62 = phi double* [ %15, %19 ], [ %56, %31 ]
%63 = phi i64 [ 1, %19 ], [ %58, %31 ]
%64 = icmp eq i64 %23, 0
br i1 %64, label %74, label %65
65: ; preds = %61, %65
%66 = phi double* [ %69, %65 ], [ %62, %61 ]
%67 = phi i64 [ %71, %65 ], [ %63, %61 ]
%68 = phi i64 [ %72, %65 ], [ 0, %61 ]
%69 = getelementptr inbounds double, double* %66, i64 %12
%70 = getelementptr inbounds double*, double** %5, i64 %67
store double* %69, double** %70
%71 = add nuw nsw i64 %67, 1
%72 = add i64 %68, 1
%73 = icmp eq i64 %72, %23
br i1 %73, label %74, label %65
74: ; preds = %61, %65, %17
ret double** %5
}