#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);
double **malloc(int);
int /*<<< orphan*/ printf(char *);
double **generate_double_matrix(long int n, long int m) {
  long int i;
  double **matrix;
  if ((matrix = malloc(sizeof(double) * n * m + sizeof(double *) * n)) ==
      NULL) {
    printf("Out of memory, exit.");
    exit(1);
  }
  for (i = 0; i < n; i++) {
    matrix[i] = (double *)(matrix + n) + i * m;
  }
  return matrix;
}


x86 assembly (clang, -O0):
<generate_double_matrix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
shl    $0x3,%rax
imul   -0x10(%rbp),%rax
mov    -0x8(%rbp),%rcx
shl    $0x3,%rcx
add    %rcx,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1183 <generate_double_matrix+0x53>
lea    0xe8c(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x8(%rbp),%rax
jge    11d5 <generate_double_matrix+0xa5>
mov    -0x20(%rbp),%rdx
mov    -0x8(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdx
mov    -0x18(%rbp),%rax
imul   -0x10(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdx
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    118b <generate_double_matrix+0x5b>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<generate_double_matrix>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r14
lea    0x0(,%rdi,8),%eax
imul   %r15d,%eax
lea    (%rax,%rdi,8),%edi
call   1040 <malloc@plt>
test   %rax,%rax
je     1226 <generate_double_matrix+0xf6>
test   %r14,%r14
jle    1220 <generate_double_matrix+0xf0>
lea    -0x1(%r14),%rcx
mov    %r14d,%r8d
and    $0x7,%r8d
cmp    $0x7,%rcx
jae    1175 <generate_double_matrix+0x45>
xor    %edx,%edx
jmp    11ec <generate_double_matrix+0xbc>
mov    %r14,%r9
and    $0xfffffffffffffff8,%r9
lea    0x0(,%r14,8),%rdi
mov    %r15,%rbx
shl    $0x6,%rbx
lea    0x0(,%r15,8),%rcx
xor    %edx,%edx
cs nopw 0x0(%rax,%rax,1)
nop
lea    (%rax,%rdi,1),%rsi
mov    %rsi,(%rax,%rdx,8)
add    %rcx,%rsi
mov    %rsi,0x8(%rax,%rdx,8)
add    %rcx,%rsi
mov    %rsi,0x10(%rax,%rdx,8)
add    %rcx,%rsi
mov    %rsi,0x18(%rax,%rdx,8)
add    %rcx,%rsi
mov    %rsi,0x20(%rax,%rdx,8)
add    %rcx,%rsi
mov    %rsi,0x28(%rax,%rdx,8)
add    %rcx,%rsi
mov    %rsi,0x30(%rax,%rdx,8)
add    %rcx,%rsi
mov    %rsi,0x38(%rax,%rdx,8)
add    $0x8,%rdx
add    %rbx,%rdi
cmp    %rdx,%r9
jne    11a0 <generate_double_matrix+0x70>
test   %r8,%r8
je     1220 <generate_double_matrix+0xf0>
lea    (%rax,%rdx,8),%rcx
imul   %r15,%rdx
add    %rdx,%r14
lea    (%rax,%r14,8),%rdx
shl    $0x3,%r15
xor    %esi,%esi
cs nopw 0x0(%rax,%rax,1)
mov    %rdx,(%rcx,%rsi,8)
add    $0x1,%rsi
add    %r15,%rdx
cmp    %rsi,%r8
jne    1210 <generate_double_matrix+0xe0>
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xdd3(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [21 x i8] c"Out of memory, exit.\00"
define double** @generate_double_matrix(i64 %0, i64 %1) {
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
%6 = alloca double**
store i64 %0, i64* %3
store i64 %1, i64* %4
%7 = load i64, i64* %3
%8 = mul i64 8, %7
%9 = load i64, i64* %4
%10 = mul i64 %8, %9
%11 = load i64, i64* %3
%12 = mul i64 8, %11
%13 = add i64 %10, %12
%14 = trunc i64 %13 to i32
%15 = call double** @malloc(i32 %14)
store double** %15, double*** %6
%16 = icmp eq double** %15, null
br i1 %16, label %17, label %20
17: ; preds = %2
%18 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %2
store i64 0, i64* %5
br label %21
21: ; preds = %37, %20
%22 = load i64, i64* %5
%23 = load i64, i64* %3
%24 = icmp slt i64 %22, %23
br i1 %24, label %25, label %40
25: ; preds = %21
%26 = load double**, double*** %6
%27 = load i64, i64* %3
%28 = getelementptr inbounds double*, double** %26, i64 %27
%29 = bitcast double** %28 to double*
%30 = load i64, i64* %5
%31 = load i64, i64* %4
%32 = mul nsw i64 %30, %31
%33 = getelementptr inbounds double, double* %29, i64 %32
%34 = load double**, double*** %6
%35 = load i64, i64* %5
%36 = getelementptr inbounds double*, double** %34, i64 %35
store double* %33, double** %36
br label %37
37: ; preds = %25
%38 = load i64, i64* %5
%39 = add nsw i64 %38, 1
store i64 %39, i64* %5
br label %21
40: ; preds = %21
%41 = load double**, double*** %6
ret double** %41
}

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