#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(int);
int allocate_memory_for_profit(long max_precincts, int max_quality_layers,
                               double ***profit) {
  int i;
  *profit = NULL;
  *profit = (double **)malloc(max_precincts * (sizeof(double *)));
  if (*profit == NULL)
    return -1;
  for (i = 0; i < max_precincts; i++) {
    (*profit)[i] = (double *)malloc(max_quality_layers * (sizeof(double)));
  }
  return 1;
}


x86 assembly (clang, -O0):
<allocate_memory_for_profit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1030 <malloc@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rax
cmpq   $0x0,(%rax)
jne    1161 <allocate_memory_for_profit+0x51>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ac <allocate_memory_for_profit+0x9c>
movl   $0x0,-0x24(%rbp)
movslq -0x24(%rbp),%rax
cmp    -0x10(%rbp),%rax
jge    11a5 <allocate_memory_for_profit+0x95>
movslq -0x14(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1030 <malloc@plt>
mov    %rax,%rdx
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
movslq -0x24(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1168 <allocate_memory_for_profit+0x58>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<allocate_memory_for_profit>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%r12
mov    %esi,%r14d
mov    %rdi,%rbp
movq   $0x0,(%rdx)
lea    0x0(,%rdi,8),%edi
call   1030 <malloc@plt>
mov    %rax,(%r12)
test   %rax,%rax
je     116b <allocate_memory_for_profit+0x5b>
mov    $0x1,%r15d
test   %rbp,%rbp
jle    1171 <allocate_memory_for_profit+0x61>
shl    $0x3,%r14d
xor    %ebx,%ebx
xchg   %ax,%ax
mov    %r14d,%edi
call   1030 <malloc@plt>
mov    (%r12),%rcx
mov    %rax,(%rcx,%rbx,8)
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1150 <allocate_memory_for_profit+0x40>
jmp    1171 <allocate_memory_for_profit+0x61>
mov    $0xffffffff,%r15d
mov    %r15d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @allocate_memory_for_profit(i64 %0, i32 %1, double*** %2) {
%4 = alloca i32
%5 = alloca i64
%6 = alloca i32
%7 = alloca double***
%8 = alloca i32
store i64 %0, i64* %5
store i32 %1, i32* %6
store double*** %2, double**** %7
%9 = load double***, double**** %7
store double** null, double*** %9
%10 = load i64, i64* %5
%11 = mul i64 %10, 8
%12 = trunc i64 %11 to i32
%13 = call i64 @malloc(i32 %12)
%14 = inttoptr i64 %13 to double**
%15 = load double***, double**** %7
store double** %14, double*** %15
%16 = load double***, double**** %7
%17 = load double**, double*** %16
%18 = icmp eq double** %17, null
br i1 %18, label %19, label %20
19: ; preds = %3
store i32 -1, i32* %4
br label %42
20: ; preds = %3
store i32 0, i32* %8
br label %21
21: ; preds = %38, %20
%22 = load i32, i32* %8
%23 = sext i32 %22 to i64
%24 = load i64, i64* %5
%25 = icmp slt i64 %23, %24
br i1 %25, label %26, label %41
26: ; preds = %21
%27 = load i32, i32* %6
%28 = sext i32 %27 to i64
%29 = mul i64 %28, 8
%30 = trunc i64 %29 to i32
%31 = call i64 @malloc(i32 %30)
%32 = inttoptr i64 %31 to double*
%33 = load double***, double**** %7
%34 = load double**, double*** %33
%35 = load i32, i32* %8
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds double*, double** %34, i64 %36
store double* %32, double** %37
br label %38
38: ; preds = %26
%39 = load i32, i32* %8
%40 = add nsw i32 %39, 1
store i32 %40, i32* %8
br label %21
41: ; preds = %21
store i32 1, i32* %4
br label %42
42: ; preds = %41, %19
%43 = load i32, i32* %4
ret i32 %43
}

LLVM IR (-O2):
define i32 @allocate_memory_for_profit(i64 %0, i32 %1, double*** nocapture %2) {
store double** null, double*** %2
%4 = trunc i64 %0 to i32
%5 = shl i32 %4, 3
%6 = tail call i64 @malloc(i32 %5)
%7 = inttoptr i64 %6 to double**
store double** %7, double*** %2
%8 = icmp eq i64 %6, 0
br i1 %8, label %21, label %9
9: ; preds = %3
%10 = icmp sgt i64 %0, 0
br i1 %10, label %11, label %21
11: ; preds = %9
%12 = shl i32 %1, 3
br label %13
13: ; preds = %11, %13
%14 = phi i64 [ 0, %11 ], [ %19, %13 ]
%15 = tail call i64 @malloc(i32 %12)
%16 = inttoptr i64 %15 to double*
%17 = load double**, double*** %2
%18 = getelementptr inbounds double*, double** %17, i64 %14
store double* %16, double** %18
%19 = add nuw nsw i64 %14, 1
%20 = icmp eq i64 %19, %0
br i1 %20, label %21, label %13
21: ; preds = %13, %9, %3
%22 = phi i32 [ -1, %3 ], [ 1, %9 ], [ 1, %13 ]
ret i32 %22
}