#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 */
void *safe_raw_allocate(size_t, size_t);
void **safe_allocate_2d_array(size_t first_size, size_t second_size,
                              size_t element_size) {
  void **result = safe_raw_allocate(first_size, sizeof(void *));
  for (size_t i = 0; i < first_size; i++) {
    result[i] = safe_raw_allocate(second_size, element_size);
  }
  return result;
}


x86 assembly (clang, -O0):
<safe_allocate_2d_array>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x8,%esi
call   1030 <safe_raw_allocate@plt>
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x8(%rbp),%rax
jae    1179 <safe_allocate_2d_array+0x69>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <safe_raw_allocate@plt>
mov    %rax,%rdx
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    113e <safe_allocate_2d_array+0x2e>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<safe_allocate_2d_array>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
mov    $0x8,%esi
call   1030 <safe_raw_allocate@plt>
mov    %rax,%r13
test   %r12,%r12
je     1159 <safe_allocate_2d_array+0x49>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %r14,%rsi
call   1030 <safe_raw_allocate@plt>
mov    %rax,0x0(%r13,%rbx,8)
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1140 <safe_allocate_2d_array+0x30>
mov    %r13,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8** @safe_allocate_2d_array(i64 %0, i64 %1, i64 %2) {
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
%7 = alloca i8**
%8 = alloca i64
store i64 %0, i64* %4
store i64 %1, i64* %5
store i64 %2, i64* %6
%9 = load i64, i64* %4
%10 = call i8* @safe_raw_allocate(i64 %9, i64 8)
%11 = bitcast i8* %10 to i8**
store i8** %11, i8*** %7
store i64 0, i64* %8
br label %12
12: ; preds = %23, %3
%13 = load i64, i64* %8
%14 = load i64, i64* %4
%15 = icmp ult i64 %13, %14
br i1 %15, label %16, label %26
16: ; preds = %12
%17 = load i64, i64* %5
%18 = load i64, i64* %6
%19 = call i8* @safe_raw_allocate(i64 %17, i64 %18)
%20 = load i8**, i8*** %7
%21 = load i64, i64* %8
%22 = getelementptr inbounds i8*, i8** %20, i64 %21
store i8* %19, i8** %22
br label %23
23: ; preds = %16
%24 = load i64, i64* %8
%25 = add i64 %24, 1
store i64 %25, i64* %8
br label %12
26: ; preds = %12
%27 = load i8**, i8*** %7
ret i8** %27
}

LLVM IR (-O2):
define i8** @safe_allocate_2d_array(i64 %0, i64 %1, i64 %2) {
%4 = tail call i8* @safe_raw_allocate(i64 %0, i64 8)
%5 = bitcast i8* %4 to i8**
%6 = icmp eq i64 %0, 0
br i1 %6, label %7, label %8
7: ; preds = %8, %3
ret i8** %5
8: ; preds = %3, %8
%9 = phi i64 [ %12, %8 ], [ 0, %3 ]
%10 = tail call i8* @safe_raw_allocate(i64 %1, i64 %2)
%11 = getelementptr inbounds i8*, i8** %5, i64 %9
store i8* %10, i8** %11
%12 = add nuw i64 %9, 1
%13 = icmp eq i64 %12, %0
br i1 %13, label %7, label %8
}