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


x86 assembly (clang, -O0):
<psdmatrix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movslq -0x4(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    116f <psdmatrix+0x3f>
lea    0xea0(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    -0x4(%rbp),%eax
imul   -0x4(%rbp),%eax
cltq
shl    $0x3,%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    11b1 <psdmatrix+0x81>
lea    0xe80(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
movl   $0x1,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11fa <psdmatrix+0xca>
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdx
movslq -0x4(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdx
mov    -0x10(%rbp),%rax
movslq -0x8(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11b8 <psdmatrix+0x88>
mov    -0x10(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<psdmatrix>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%r14d
lea    0x0(,%r14,8),%ebp
mov    %ebp,%edi
call   1040 <malloc@plt>
test   %rax,%rax
je     1248 <psdmatrix+0x118>
mov    %rax,%rbx
imul   %r14d,%ebp
mov    %ebp,%edi
call   1040 <malloc@plt>
mov    %rax,(%rbx)
test   %rax,%rax
je     1251 <psdmatrix+0x121>
cmp    $0x2,%r14d
jl     1240 <psdmatrix+0x110>
movslq %r14d,%r9
mov    %r14d,%ecx
lea    -0x1(%rcx),%rdi
add    $0xfffffffffffffffe,%rcx
mov    %edi,%edx
and    $0x7,%edx
cmp    $0x7,%rcx
jae    119f <psdmatrix+0x6f>
mov    $0x1,%esi
test   %rdx,%rdx
jne    121b <psdmatrix+0xeb>
jmp    1240 <psdmatrix+0x110>
and    $0xfffffffffffffff8,%rdi
mov    %r9,%r8
shl    $0x6,%r8
lea    0x0(,%r9,8),%rbp
xor    %esi,%esi
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
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 <psdmatrix+0x90>
add    %r8,%rcx
add    $0x1,%rsi
mov    %rcx,%rax
test   %rdx,%rdx
je     1240 <psdmatrix+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 <psdmatrix+0x100>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xdb1(%rip),%rdi
jmp    1258 <psdmatrix+0x128>
lea    0xdc9(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

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

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