#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_FAILURE;
scalar_t__ calloc(int, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, int);
int /*<<< orphan*/ stderr;
double **dmatrix(int n, int m) {
  double **A;
  int i;
  A = (double **)calloc(n, sizeof(double *));
  A[0] = (double *)calloc(n * m, sizeof(double));
  if (A[0] == NULL) {
    fprintf(stderr, "couldn't reserve memory for an %i x %i matrix\n", n, m);
    exit(EXIT_FAILURE);
  }
  for (i = 1; i < n; i++) {
    A[i] = A[i - 1] + m;
  }
  return A;
}


x86 assembly (clang, -O0):
<dmatrix>:
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)
mov    -0x4(%rbp),%edi
imul   -0x8(%rbp),%edi
mov    $0x8,%esi
call   1030 <calloc@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
jne    11a1 <dmatrix+0x71>
mov    0x2e61(%rip),%rax
mov    (%rax),%edi
mov    -0x4(%rbp),%edx
mov    -0x8(%rbp),%ecx
lea    0xe72(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2e3e(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11ea <dmatrix+0xba>
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    11a8 <dmatrix+0x78>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dmatrix>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%r14d
mov    %edi,%ebp
mov    $0x8,%esi
call   1030 <calloc@plt>
mov    %rax,%rbx
mov    %r14d,%edi
imul   %ebp,%edi
mov    $0x8,%esi
call   1030 <calloc@plt>
mov    %rax,(%rbx)
test   %rax,%rax
je     1238 <dmatrix+0x108>
cmp    $0x2,%ebp
jl     1230 <dmatrix+0x100>
movslq %r14d,%r9
mov    %ebp,%ecx
lea    -0x1(%rcx),%rdi
add    $0xfffffffffffffffe,%rcx
mov    %edi,%edx
and    $0x7,%edx
cmp    $0x7,%rcx
jae    1192 <dmatrix+0x62>
mov    $0x1,%esi
test   %rdx,%rdx
jne    120b <dmatrix+0xdb>
jmp    1230 <dmatrix+0x100>
and    $0xfffffffffffffff8,%rdi
mov    %r9,%r8
shl    $0x6,%r8
lea    0x0(,%r9,8),%rbp
xor    %esi,%esi
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    11b0 <dmatrix+0x80>
add    %r8,%rcx
add    $0x1,%rsi
mov    %rcx,%rax
test   %rdx,%rdx
je     1230 <dmatrix+0x100>
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    1220 <dmatrix+0xf0>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2da1(%rip),%rax
mov    (%rax),%edi
lea    0xdb8(%rip),%rsi
mov    %ebp,%edx
mov    %r14d,%ecx
call   1040 <fprintf@plt>
mov    0x2d7f(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [47 x i8] c"couldn't reserve memory for an %i x %i matrix\0A\00"
@EXIT_FAILURE = global i32 0
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 = call i64 @calloc(i32 %7, i32 8)
%9 = inttoptr i64 %8 to double**
store double** %9, double*** %5
%10 = load i32, i32* %3
%11 = load i32, i32* %4
%12 = mul nsw i32 %10, %11
%13 = call i64 @calloc(i32 %12, i32 8)
%14 = inttoptr i64 %13 to double*
%15 = load double**, double*** %5
%16 = getelementptr inbounds double*, double** %15, i64 0
store double* %14, double** %16
%17 = load double**, double*** %5
%18 = getelementptr inbounds double*, double** %17, i64 0
%19 = load double*, double** %18
%20 = icmp eq double* %19, null
br i1 %20, label %21, label %28
21: ; preds = %2
%22 = load i32, i32* @stderr
%23 = load i32, i32* %3
%24 = load i32, i32* %4
%25 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0), i32 %23, i32 %24)
%26 = load i32, i32* @EXIT_FAILURE
%27 = call i32 @exit(i32 %26)
unreachable
28: ; preds = %2
store i32 1, i32* %6
br label %29
29: ; preds = %47, %28
%30 = load i32, i32* %6
%31 = load i32, i32* %3
%32 = icmp slt i32 %30, %31
br i1 %32, label %33, label %50
33: ; preds = %29
%34 = load double**, double*** %5
%35 = load i32, i32* %6
%36 = sub nsw i32 %35, 1
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds double*, double** %34, i64 %37
%39 = load double*, double** %38
%40 = load i32, i32* %4
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds double, double* %39, i64 %41
%43 = load double**, double*** %5
%44 = load i32, i32* %6
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds double*, double** %43, i64 %45
store double* %42, double** %46
br label %47
47: ; preds = %33
%48 = load i32, i32* %6
%49 = add nsw i32 %48, 1
store i32 %49, i32* %6
br label %29
50: ; preds = %29
%51 = load double**, double*** %5
ret double** %51
}

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