#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 /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ malloc(unsigned int);
int /*<<< orphan*/ stderr;
float **matrix(int nrl, int nrh, int ncl, int nch) {
  int i;
  float **m;
  m = (float **)malloc((nrh - nrl + 1) * sizeof(float *));
  if (!m) {
    fprintf(stderr, "allocation failure 1 in matrix()\n");
    exit(0);
  }
  m -= nrl;
  for (i = nrl; i <= nrh; i++) {
    m[i] = (float *)malloc((unsigned)(nch - ncl + 1) * sizeof(float));
    if (!m[i]) {
      fprintf(stderr, "allocation failure 2 in matrix()\n");
      exit(0);
    }
    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
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1185 <matrix+0x55>
mov    0x2e70(%rip),%rax
mov    (%rax),%edi
lea    0xe87(%rip),%rsi
call   1030 <fprintf@plt>
xor    %edi,%edi
call   1050 <exit@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     1235 <matrix+0x105>
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    1205 <matrix+0xd5>
mov    0x2df0(%rip),%rax
mov    (%rax),%edi
lea    0xe29(%rip),%rsi
call   1030 <fprintf@plt>
xor    %edi,%edi
call   1050 <exit@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    11a5 <matrix+0x75>
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,%ebx
mov    %edx,%r12d
mov    %esi,%r15d
mov    %edi,%r14d
mov    %esi,%eax
sub    %edi,%eax
lea    0x8(,%rax,8),%edi
call   1040 <malloc@plt>
test   %rax,%rax
je     11dc <matrix+0xac>
mov    %rax,%rbp
sub    %r14d,%r15d
jl     11a4 <matrix+0x74>
sub    %r12d,%ebx
lea    0x4(,%rbx,4),%r13d
movslq %r12d,%r12
neg    %r12
add    $0x1,%r15d
xor    %ebx,%ebx
xchg   %ax,%ax
mov    %r13d,%edi
call   1040 <malloc@plt>
mov    %rax,0x0(%rbp,%rbx,8)
test   %rax,%rax
je     11c0 <matrix+0x90>
lea    (%rax,%r12,4),%rax
mov    %rax,0x0(%rbp,%rbx,8)
add    $0x1,%rbx
cmp    %ebx,%r15d
jne    1180 <matrix+0x50>
movslq %r14d,%rax
shl    $0x3,%rax
sub    %rax,%rbp
mov    %rbp,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2e19(%rip),%rax
mov    (%rax),%edi
lea    0xe52(%rip),%rsi
call   1030 <fprintf@plt>
xor    %edi,%edi
call   1050 <exit@plt>
mov    0x2dfd(%rip),%rax
mov    (%rax),%edi
lea    0xe14(%rip),%rsi
jmp    11d0 <matrix+0xa0>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [34 x i8] c"allocation failure 1 in matrix()\0A\00"
@.str.1 = [34 x i8] c"allocation failure 2 in matrix()\0A\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 = sext 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 %26, label %22
22: ; preds = %4
%23 = load i32, i32* @stderr
%24 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
%25 = call i32 @exit(i32 0)
unreachable
26: ; preds = %4
%27 = load i32, i32* %5
%28 = load float**, float*** %10
%29 = sext i32 %27 to i64
%30 = sub i64 0, %29
%31 = getelementptr inbounds float*, float** %28, i64 %30
store float** %31, float*** %10
%32 = load i32, i32* %5
store i32 %32, i32* %9
br label %33
33: ; preds = %71, %26
%34 = load i32, i32* %9
%35 = load i32, i32* %6
%36 = icmp sle i32 %34, %35
br i1 %36, label %37, label %74
37: ; preds = %33
%38 = load i32, i32* %8
%39 = load i32, i32* %7
%40 = sub nsw i32 %38, %39
%41 = add nsw i32 %40, 1
%42 = zext i32 %41 to i64
%43 = mul i64 %42, 4
%44 = trunc i64 %43 to i32
%45 = call i64 @malloc(i32 %44)
%46 = inttoptr i64 %45 to float*
%47 = load float**, float*** %10
%48 = load i32, i32* %9
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds float*, float** %47, i64 %49
store float* %46, float** %50
%51 = load float**, float*** %10
%52 = load i32, i32* %9
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds float*, float** %51, i64 %53
%55 = load float*, float** %54
%56 = icmp ne float* %55, null
br i1 %56, label %61, label %57
57: ; preds = %37
%58 = load i32, i32* @stderr
%59 = call i32 @fprintf(i32 %58, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
%60 = call i32 @exit(i32 0)
unreachable
61: ; preds = %37
%62 = load i32, i32* %7
%63 = load float**, float*** %10
%64 = load i32, i32* %9
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds float*, float** %63, i64 %65
%67 = load float*, float** %66
%68 = sext i32 %62 to i64
%69 = sub i64 0, %68
%70 = getelementptr inbounds float, float* %67, i64 %69
store float* %70, float** %66
br label %71
71: ; preds = %61
%72 = load i32, i32* %9
%73 = add nsw i32 %72, 1
store i32 %73, i32* %9
br label %33
74: ; preds = %33
%75 = load float**, float*** %10
ret float** %75
}

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