#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 */
scalar_t__ malloc(size_t);
int /*<<< orphan*/ nrerror(char *);
double **convert_matrix(double *a, long nrl, long nrh, long ncl, long nch) {
  long i, j, nrow = nrh - nrl + 1, ncol = nch - ncl + 1;
  double **m;
  m = (double **)malloc((size_t)((nrow + 1) * sizeof(double *)));
  if (!m)
    nrerror("allocation failure in convert_matrix()");
  m += 1;
  m -= nrl;
  m[nrl] = a - ncl;
  for (i = 1, j = nrl + 1; i < nrow; i++, j++)
    m[j] = m[j - 1] + ncol;
  return m;
}


x86 assembly (clang, -O0):
<convert_matrix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0x18(%rbp),%rax
sub    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
mov    -0x28(%rbp),%rax
sub    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x48(%rbp)
mov    -0x40(%rbp),%rdi
add    $0x1,%rdi
shl    $0x3,%rdi
call   1040 <malloc@plt>
mov    %rax,-0x50(%rbp)
cmpq   $0x0,-0x50(%rbp)
jne    1188 <convert_matrix+0x68>
lea    0xe7d(%rip),%rdi
call   1030 <nrerror@plt>
mov    -0x50(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x50(%rbp)
mov    -0x10(%rbp),%rdx
mov    -0x50(%rbp),%rax
xor    %ecx,%ecx
sub    %rdx,%rcx
shl    $0x3,%rcx
add    %rcx,%rax
mov    %rax,-0x50(%rbp)
mov    -0x8(%rbp),%rdx
xor    %eax,%eax
sub    -0x20(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdx
mov    -0x50(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
movq   $0x1,-0x30(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x40(%rbp),%rax
jge    122f <convert_matrix+0x10f>
mov    -0x50(%rbp),%rax
mov    -0x38(%rbp),%rcx
sub    $0x1,%rcx
mov    (%rax,%rcx,8),%rdx
mov    -0x48(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdx
mov    -0x50(%rbp),%rax
mov    -0x38(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    11dd <convert_matrix+0xbd>
mov    -0x50(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<convert_matrix>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r8,%r12
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%rbp
mov    %rdi,%rbx
mov    %rcx,0x8(%rsp)
neg    %r14
mov    %rdx,0x10(%rsp)
sub    %rsi,%r15
lea    0x10(,%r15,8),%rdi
call   1040 <malloc@plt>
mov    %rax,%r13
test   %rax,%rax
jne    116e <convert_matrix+0x4e>
lea    0xe97(%rip),%rdi
call   1030 <nrerror@plt>
lea    0x0(,%rbp,8),%rcx
mov    %r13,%rax
sub    %rcx,%rax
lea    (%rbx,%r14,8),%rcx
mov    %rcx,0x8(%rax,%rbp,8)
add    $0x8,%rax
test   %r15,%r15
jle    12b0 <convert_matrix+0x190>
mov    %rbp,%rsi
not    %rsi
add    0x10(%rsp),%rsi
mov    %r15d,%r9d
and    $0x3,%r9d
mov    %rbp,%rdx
cmp    $0x3,%rsi
jb     125c <convert_matrix+0x13c>
mov    %rbp,%r14
and    $0xfffffffffffffffc,%r15
mov    %r12,%r11
shl    $0x5,%r11
add    $0x20,%r11
mov    0x8(%rsp),%rsi
mov    %rsi,%rdx
shl    $0x5,%rdx
mov    %r11,%r10
sub    %rdx,%r10
lea    0x0(,%rsi,8),%r8
lea    (%r8,%r8,4),%rcx
sub    %rcx,%r11
lea    0x0(,%r12,8),%rcx
lea    (%rcx,%rcx,2),%rbp
sub    %rdx,%rbp
add    $0x18,%rbp
mov    %r12,%rdi
shl    $0x4,%rdi
lea    (%r8,%r8,2),%rdx
sub    %rdx,%rdi
add    $0x10,%rdi
mov    %rsi,%rdx
shl    $0x4,%rdx
sub    %rdx,%rcx
add    $0x8,%rcx
xor    %edx,%edx
nopl   0x0(%rax)
lea    (%rbx,%rcx,1),%rsi
mov    %rsi,0x10(%r13,%rdx,8)
lea    (%rbx,%rdi,1),%rsi
mov    %rsi,0x18(%r13,%rdx,8)
lea    (%rbx,%rbp,1),%rsi
mov    %rsi,0x20(%r13,%rdx,8)
lea    (%rbx,%r11,1),%rsi
mov    %rsi,0x28(%r13,%rdx,8)
add    $0x4,%rdx
add    %r10,%rbx
cmp    %rdx,%r15
jne    1220 <convert_matrix+0x100>
sub    %r8,%rbx
mov    %r14,%rbp
add    %r14,%rdx
mov    %rbx,%rcx
test   %r9,%r9
je     12b0 <convert_matrix+0x190>
mov    %r12,%rsi
mov    0x8(%rsp),%rdi
sub    %rdi,%rsi
add    $0x1,%rsi
lea    (%rcx,%rsi,8),%rcx
shl    $0x3,%r12
shl    $0x3,%rdi
sub    %rdi,%r12
add    $0x8,%r12
sub    %rbp,%rdx
lea    0x10(,%rdx,8),%rdx
add    %r13,%rdx
xor    %esi,%esi
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rcx,(%rdx,%rsi,8)
add    $0x1,%rsi
add    %r12,%rcx
cmp    %rsi,%r9
jne    12a0 <convert_matrix+0x180>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [39 x i8] c"allocation failure in convert_matrix()\00"
define double** @convert_matrix(double* %0, i64 %1, i64 %2, i64 %3, i64 %4) {
%6 = sub i64 0, %3
%7 = sub nsw i64 %2, %1
%8 = sub i64 1, %3
%9 = add i64 %8, %4
%10 = shl i64 %7, 3
%11 = add i64 %10, 16
%12 = tail call i64 @malloc(i64 %11)
%13 = inttoptr i64 %12 to double**
%14 = icmp eq i64 %12, 0
br i1 %14, label %15, label %17
15: ; preds = %5
%16 = tail call i32 @nrerror(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
br label %17
17: ; preds = %15, %5
%18 = getelementptr inbounds double*, double** %13, i64 1
%19 = sub i64 0, %1
%20 = getelementptr inbounds double*, double** %18, i64 %19
%21 = getelementptr inbounds double, double* %0, i64 %6
%22 = getelementptr inbounds double*, double** %20, i64 %1
store double* %21, double** %22
%23 = icmp slt i64 %7, 1
br i1 %23, label %62, label %24
24: ; preds = %17
%25 = xor i64 %1, -1
%26 = add i64 %25, %2
%27 = and i64 %7, 3
%28 = icmp ult i64 %26, 3
br i1 %28, label %49, label %29
29: ; preds = %24
%30 = and i64 %7, -4
br label %31
31: ; preds = %31, %29
%32 = phi double* [ %21, %29 ], [ %45, %31 ]
%33 = phi i64 [ %1, %29 ], [ %44, %31 ]
%34 = phi i64 [ 0, %29 ], [ %47, %31 ]
%35 = add nsw i64 %33, 1
%36 = getelementptr inbounds double, double* %32, i64 %9
%37 = getelementptr inbounds double*, double** %20, i64 %35
store double* %36, double** %37
%38 = add nsw i64 %33, 2
%39 = getelementptr inbounds double, double* %36, i64 %9
%40 = getelementptr inbounds double*, double** %20, i64 %38
store double* %39, double** %40
%41 = add nsw i64 %33, 3
%42 = getelementptr inbounds double, double* %39, i64 %9
%43 = getelementptr inbounds double*, double** %20, i64 %41
store double* %42, double** %43
%44 = add nsw i64 %33, 4
%45 = getelementptr inbounds double, double* %42, i64 %9
%46 = getelementptr inbounds double*, double** %20, i64 %44
store double* %45, double** %46
%47 = add i64 %34, 4
%48 = icmp eq i64 %47, %30
br i1 %48, label %49, label %31
49: ; preds = %31, %24
%50 = phi double* [ %21, %24 ], [ %45, %31 ]
%51 = phi i64 [ %1, %24 ], [ %44, %31 ]
%52 = icmp eq i64 %27, 0
br i1 %52, label %62, label %53
53: ; preds = %49, %53
%54 = phi double* [ %58, %53 ], [ %50, %49 ]
%55 = phi i64 [ %57, %53 ], [ %51, %49 ]
%56 = phi i64 [ %60, %53 ], [ 0, %49 ]
%57 = add nsw i64 %55, 1
%58 = getelementptr inbounds double, double* %54, i64 %9
%59 = getelementptr inbounds double*, double** %20, i64 %57
store double* %58, double** %59
%60 = add i64 %56, 1
%61 = icmp eq i64 %60, %27
br i1 %61, label %62, label %53
62: ; preds = %49, %53, %17
ret double** %20
}