#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*/ fail(char *);
scalar_t__ malloc(unsigned int);
float **matrix(int nrl, int nrh, int ncl, int nch) {
  int i;
  float **m;
  m = (float **)malloc((unsigned)(nrh - nrl + 1) * sizeof(float *));
  if (!m)
    fail("allocation failure 1 in matrix()");
  m -= nrl;
  for (i = nrl; i <= nrh; i++) {
    m[i] = (float *)malloc((unsigned)(nch - ncl + 1) * sizeof(float));
    if (!m[i])
      fail("allocation failure 2 in matrix()");
    m[i] -= ncl;
  }
  return m;
}


x86 assembly (clang, -O0):
<matrix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %ecx,-0x10(%rbp)
mov    -0x8(%rbp),%eax
sub    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,%eax
shl    $0x3,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1165 <matrix+0x45>
lea    0xea0(%rip),%rdi
call   1030 <fail@plt>
mov    -0x4(%rbp),%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rdx
xor    %ecx,%ecx
sub    %rdx,%rcx
shl    $0x3,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     1205 <matrix+0xe5>
mov    -0x10(%rbp),%eax
sub    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,%eax
shl    $0x2,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,%rdx
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
jne    11d5 <matrix+0xb5>
lea    0xe51(%rip),%rdi
call   1030 <fail@plt>
mov    -0xc(%rbp),%esi
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
movslq %esi,%rdi
xor    %esi,%esi
sub    %rdi,%rsi
shl    $0x2,%rsi
add    %rsi,%rdx
mov    %rdx,(%rax,%rcx,8)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1185 <matrix+0x65>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<matrix>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%r13d
mov    %edx,%r12d
mov    %esi,%r14d
mov    %edi,%ebp
mov    %esi,%eax
sub    %edi,%eax
lea    0x8(,%rax,8),%edi
call   1040 <malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    115a <matrix+0x3a>
lea    0xeab(%rip),%rdi
call   1030 <fail@plt>
movslq %ebp,%rax
shl    $0x3,%rax
mov    %rbx,%rcx
sub    %rax,%rcx
mov    %rcx,(%rsp)
sub    %ebp,%r14d
jge    1183 <matrix+0x63>
mov    (%rsp),%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
sub    %r12d,%r13d
lea    0x4(,%r13,4),%r13d
movslq %r12d,%rbp
neg    %rbp
add    $0x1,%r14d
xor    %r15d,%r15d
lea    0xe7f(%rip),%r12
jmp    11c1 <matrix+0xa1>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    (%rax,%rbp,4),%rax
mov    %rax,(%rbx,%r15,8)
add    $0x1,%r15
cmp    %r15d,%r14d
je     1170 <matrix+0x50>
mov    %r13d,%edi
call   1040 <malloc@plt>
mov    %rax,(%rbx,%r15,8)
test   %rax,%rax
jne    11b0 <matrix+0x90>
mov    %r12,%rdi
call   1030 <fail@plt>
mov    (%rbx,%r15,8),%rax
jmp    11b0 <matrix+0x90>

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

LLVM IR (-O2):
@.str = [33 x i8] c"allocation failure 1 in matrix()\00"
@.str.1 = [33 x i8] c"allocation failure 2 in matrix()\00"
define float** @matrix(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = sub nsw i32 %1, %0
%6 = shl i32 %5, 3
%7 = add i32 %6, 8
%8 = tail call i64 @malloc(i32 %7)
%9 = inttoptr i64 %8 to float**
%10 = icmp eq i64 %8, 0
br i1 %10, label %11, label %13
11: ; preds = %4
%12 = tail call i32 @fail(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %11, %4
%14 = sext i32 %0 to i64
%15 = sub nsw i64 0, %14
%16 = getelementptr inbounds float*, float** %9, i64 %15
%17 = icmp slt i32 %1, %0
br i1 %17, label %40, label %18
18: ; preds = %13
%19 = sub nsw i32 %3, %2
%20 = shl i32 %19, 2
%21 = add i32 %20, 4
%22 = sext i32 %2 to i64
%23 = sub nsw i64 0, %22
%24 = add i32 %1, 1
br label %25
25: ; preds = %18, %34
%26 = phi i64 [ %14, %18 ], [ %37, %34 ]
%27 = tail call i64 @malloc(i32 %21)
%28 = inttoptr i64 %27 to float*
%29 = getelementptr inbounds float*, float** %16, i64 %26
store float* %28, float** %29
%30 = icmp eq i64 %27, 0
br i1 %30, label %31, label %34
31: ; preds = %25
%32 = tail call i32 @fail(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
%33 = load float*, float** %29
br label %34
34: ; preds = %31, %25
%35 = phi float* [ %33, %31 ], [ %28, %25 ]
%36 = getelementptr inbounds float, float* %35, i64 %23
store float* %36, float** %29
%37 = add nsw i64 %26, 1
%38 = trunc i64 %37 to i32
%39 = icmp eq i32 %24, %38
br i1 %39, label %40, label %25
40: ; preds = %34, %13
ret float** %16
}