#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__ allocate_matrix(double ***, int, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
int allocate_memory(double ***P, double ***U, double ***V, int nx, int ny) {
  if (allocate_matrix(P, nx + 2, ny + 2) != 0) {
    fprintf(stderr, "allocate_memory: Could not allocate memory for P\n");
    return 1;
  }
  if (allocate_matrix(U, nx + 2, ny + 2) != 0) {
    fprintf(stderr, "allocate_memory: Could not allocate memory for U\n");
    return 1;
  }
  if (allocate_matrix(V, nx + 2, ny + 2) != 0) {
    fprintf(stderr, "allocate_memory: Could not allocate memory for V\n");
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<allocate_memory>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    %r8d,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x24(%rbp),%esi
add    $0x2,%esi
mov    -0x28(%rbp),%edx
add    $0x2,%edx
call   1040 <allocate_matrix@plt>
cmp    $0x0,%rax
je     117b <allocate_memory+0x5b>
mov    0x2e7f(%rip),%rax
mov    (%rax),%edi
lea    0xe96(%rip),%rsi
call   1030 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1202 <allocate_memory+0xe2>
mov    -0x18(%rbp),%rdi
mov    -0x24(%rbp),%esi
add    $0x2,%esi
mov    -0x28(%rbp),%edx
add    $0x2,%edx
call   1040 <allocate_matrix@plt>
cmp    $0x0,%rax
je     11bb <allocate_memory+0x9b>
mov    0x2e3f(%rip),%rax
mov    (%rax),%edi
lea    0xe88(%rip),%rsi
call   1030 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1202 <allocate_memory+0xe2>
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%esi
add    $0x2,%esi
mov    -0x28(%rbp),%edx
add    $0x2,%edx
call   1040 <allocate_matrix@plt>
cmp    $0x0,%rax
je     11fb <allocate_memory+0xdb>
mov    0x2dff(%rip),%rax
mov    (%rax),%edi
lea    0xe7a(%rip),%rsi
call   1030 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1202 <allocate_memory+0xe2>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<allocate_memory>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %r8d,%ebx
mov    %ecx,%ebp
mov    %rdx,%r14
mov    %rsi,%r15
add    $0x2,%ebp
add    $0x2,%ebx
mov    %ebp,%esi
mov    %ebx,%edx
call   1040 <allocate_matrix@plt>
test   %rax,%rax
je     114f <allocate_memory+0x2f>
lea    0xeb3(%rip),%rsi
jmp    1181 <allocate_memory+0x61>
mov    %r15,%rdi
mov    %ebp,%esi
mov    %ebx,%edx
call   1040 <allocate_matrix@plt>
test   %rax,%rax
je     1169 <allocate_memory+0x49>
lea    0xecb(%rip),%rsi
jmp    1181 <allocate_memory+0x61>
mov    %r14,%rdi
mov    %ebp,%esi
mov    %ebx,%edx
call   1040 <allocate_matrix@plt>
test   %rax,%rax
je     119f <allocate_memory+0x7f>
lea    0xee3(%rip),%rsi
mov    0x2e58(%rip),%rax
mov    (%rax),%edi
call   1030 <fprintf@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %eax,%eax
jmp    1194 <allocate_memory+0x74>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [50 x i8] c"allocate_memory: Could not allocate memory for P\0A\00"
@.str.1 = [50 x i8] c"allocate_memory: Could not allocate memory for U\0A\00"
@.str.2 = [50 x i8] c"allocate_memory: Could not allocate memory for V\0A\00"
define i32 @allocate_memory(double*** %0, double*** %1, double*** %2, i32 %3, i32 %4) {
%6 = alloca i32
%7 = alloca double***
%8 = alloca double***
%9 = alloca double***
%10 = alloca i32
%11 = alloca i32
store double*** %0, double**** %7
store double*** %1, double**** %8
store double*** %2, double**** %9
store i32 %3, i32* %10
store i32 %4, i32* %11
%12 = load double***, double**** %7
%13 = load i32, i32* %10
%14 = add nsw i32 %13, 2
%15 = load i32, i32* %11
%16 = add nsw i32 %15, 2
%17 = call i64 @allocate_matrix(double*** %12, i32 %14, i32 %16)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %5
%20 = load i32, i32* @stderr
%21 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %6
br label %45
22: ; preds = %5
%23 = load double***, double**** %8
%24 = load i32, i32* %10
%25 = add nsw i32 %24, 2
%26 = load i32, i32* %11
%27 = add nsw i32 %26, 2
%28 = call i64 @allocate_matrix(double*** %23, i32 %25, i32 %27)
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %22
%31 = load i32, i32* @stderr
%32 = call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %6
br label %45
33: ; preds = %22
%34 = load double***, double**** %9
%35 = load i32, i32* %10
%36 = add nsw i32 %35, 2
%37 = load i32, i32* %11
%38 = add nsw i32 %37, 2
%39 = call i64 @allocate_matrix(double*** %34, i32 %36, i32 %38)
%40 = icmp ne i64 %39, 0
br i1 %40, label %41, label %44
41: ; preds = %33
%42 = load i32, i32* @stderr
%43 = call i32 @fprintf(i32 %42, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %6
br label %45
44: ; preds = %33
store i32 0, i32* %6
br label %45
45: ; preds = %44, %41, %30, %19
%46 = load i32, i32* %6
ret i32 %46
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [50 x i8] c"allocate_memory: Could not allocate memory for P\0A\00"
@.str.1 = [50 x i8] c"allocate_memory: Could not allocate memory for U\0A\00"
@.str.2 = [50 x i8] c"allocate_memory: Could not allocate memory for V\0A\00"
define i32 @allocate_memory(double*** %0, double*** %1, double*** %2, i32 %3, i32 %4) {
%6 = add nsw i32 %3, 2
%7 = add nsw i32 %4, 2
%8 = tail call i64 @allocate_matrix(double*** %0, i32 %6, i32 %7)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %16
10: ; preds = %5
%11 = tail call i64 @allocate_matrix(double*** %1, i32 %6, i32 %7)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %10
%14 = tail call i64 @allocate_matrix(double*** %2, i32 %6, i32 %7)
%15 = icmp eq i64 %14, 0
br i1 %15, label %20, label %16
16: ; preds = %13, %10, %5
%17 = phi i8* [ getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0), %5 ], [ getelementptr inbounds ([50 x i8], [50 x i8]* @.str.1, i64 0, i64 0), %10 ], [ getelementptr inbounds ([50 x i8], [50 x i8]* @.str.2, i64 0, i64 0), %13 ]
%18 = load i32, i32* @stderr
%19 = tail call i32 @fprintf(i32 %18, i8* %17)
br label %20
20: ; preds = %16, %13
%21 = phi i32 [ 0, %13 ], [ 1, %16 ]
ret i32 %21
}