#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(long);
int /*<<< orphan*/ printf(char *);
void alloc_matrix(float ***matrix, long nx, long ny) {
  long i;
  *matrix = (float **)malloc(nx * sizeof(float *));
  if (*matrix == NULL) {
    printf("alloc_matrix: not enough storage available\n");
    exit(1);
  }
  for (i = 0; i < nx; i++) {
    (*matrix)[i] = (float *)malloc(ny * sizeof(float));
    if ((*matrix)[i] == NULL) {
      printf("alloc_matrix: not enough storage available\n");
      exit(1);
    }
  }
  return;
}


x86 assembly (clang, -O0):
<alloc_matrix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
shl    $0x3,%rdi
call   1040 <malloc@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
cmpq   $0x0,(%rax)
jne    117f <alloc_matrix+0x4f>
lea    0xe90(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
jge    11f6 <alloc_matrix+0xc6>
mov    -0x18(%rbp),%rdi
shl    $0x2,%rdi
call   1040 <malloc@plt>
mov    %rax,%rdx
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    -0x20(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    -0x20(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
jne    11e0 <alloc_matrix+0xb0>
lea    0xe2f(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
jmp    11e5 <alloc_matrix+0xb5>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1187 <alloc_matrix+0x57>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<alloc_matrix>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
lea    0x0(,%rsi,8),%rdi
call   1040 <malloc@plt>
mov    %rax,(%r12)
test   %rax,%rax
je     11a0 <alloc_matrix+0x70>
test   %r15,%r15
jle    1194 <alloc_matrix+0x64>
shl    $0x2,%r14
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14,%rdi
call   1040 <malloc@plt>
mov    (%r12),%rcx
mov    %rax,(%rcx,%rbx,8)
mov    (%r12),%rax
cmpq   $0x0,(%rax,%rbx,8)
je     11a0 <alloc_matrix+0x70>
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1170 <alloc_matrix+0x40>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xe59(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

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

LLVM IR (-O2):
@str.1 = [43 x i8] c"alloc_matrix: not enough storage available\00"
define void @alloc_matrix(float*** nocapture %0, i64 %1, i64 %2) {
%4 = shl i64 %1, 3
%5 = tail call i64 @malloc(i64 %4)
%6 = inttoptr i64 %5 to float**
store float** %6, float*** %0
%7 = icmp eq i64 %5, 0
br i1 %7, label %12, label %8
8: ; preds = %3
%9 = icmp sgt i64 %1, 0
br i1 %9, label %10, label %31
10: ; preds = %8
%11 = shl i64 %2, 2
br label %17
12: ; preds = %3
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @str.1, i64 0, i64 0))
%14 = tail call i32 @exit(i32 1)
unreachable
15: ; preds = %17
%16 = icmp eq i64 %27, %1
br i1 %16, label %31, label %17
17: ; preds = %10, %15
%18 = phi i64 [ 0, %10 ], [ %27, %15 ]
%19 = tail call i64 @malloc(i64 %11)
%20 = inttoptr i64 %19 to float*
%21 = load float**, float*** %0
%22 = getelementptr inbounds float*, float** %21, i64 %18
store float* %20, float** %22
%23 = load float**, float*** %0
%24 = getelementptr inbounds float*, float** %23, i64 %18
%25 = load float*, float** %24
%26 = icmp eq float* %25, null
%27 = add nuw nsw i64 %18, 1
br i1 %26, label %28, label %15
28: ; preds = %17
%29 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @str.1, i64 0, i64 0))
%30 = tail call i32 @exit(i32 1)
unreachable
31: ; preds = %15, %8
ret void
}