#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);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *);
double **pdmatrix(int rows, int cols) {
  int i;
  double **m;
  m = (double **)malloc(rows * sizeof(double *));
  if (!m) {
    printf("allocation error in pdmatrix 1.\n");
    exit(1);
  }
  m[0] = (double *)malloc(rows * cols * sizeof(double));
  if (!m[0]) {
    printf("allocation error in pdmatrix 2.\n");
    exit(1);
  }
  for (i = 1; i < rows; i++) {
    m[i] = m[i - 1] + cols;
  }
  return m;
}


x86 assembly (clang, -O0):
<pdmatrix>:
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    1172 <pdmatrix+0x42>
lea    0xe9d(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    -0x4(%rbp),%eax
imul   -0x8(%rbp),%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
cmpq   $0x0,(%rax)
jne    11b4 <pdmatrix+0x84>
lea    0xe7c(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
movl   $0x1,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11fd <pdmatrix+0xcd>
mov    -0x18(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdx
movslq -0x8(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdx
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11bb <pdmatrix+0x8b>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pdmatrix>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %edi,%r15d
lea    0x0(,%r15,8),%ebp
mov    %ebp,%edi
call   1040 <malloc@plt>
test   %rax,%rax
je     124e <pdmatrix+0x11e>
mov    %rax,%rbx
imul   %r14d,%ebp
mov    %ebp,%edi
call   1040 <malloc@plt>
mov    %rax,(%rbx)
test   %rax,%rax
je     1257 <pdmatrix+0x127>
cmp    $0x2,%r15d
jl     1240 <pdmatrix+0x110>
movslq %r14d,%r9
mov    %r15d,%ecx
lea    -0x1(%rcx),%rdi
add    $0xfffffffffffffffe,%rcx
mov    %edi,%edx
and    $0x7,%edx
cmp    $0x7,%rcx
jae    11a1 <pdmatrix+0x71>
mov    $0x1,%esi
test   %rdx,%rdx
jne    121b <pdmatrix+0xeb>
jmp    1240 <pdmatrix+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 <pdmatrix+0x90>
add    %r8,%rcx
add    $0x1,%rsi
mov    %rcx,%rax
test   %rdx,%rdx
je     1240 <pdmatrix+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 <pdmatrix+0x100>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdab(%rip),%rdi
jmp    125e <pdmatrix+0x12e>
lea    0xdc2(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

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

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