#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 */
char *calloc(int, int);
char **malloc(int);
void alloc_image_data(char ***dst, int y, int x) {
  *dst = malloc(sizeof(char *) * y);
  while (y--)
    (*dst)[y] = calloc(sizeof(char), x);
}


x86 assembly (clang, -O0):
<alloc_image_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
movslq -0xc(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0xc(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0xc(%rbp)
cmp    $0x0,%eax
je     1183 <alloc_image_data+0x63>
mov    -0x10(%rbp),%esi
mov    $0x1,%edi
call   1030 <calloc@plt>
mov    %rax,%rdx
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
movslq -0xc(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
jmp    114b <alloc_image_data+0x2b>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<alloc_image_data>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r12d
mov    %esi,%r15d
mov    %rdi,%r13
lea    0x0(,%r15,8),%edi
call   1040 <malloc@plt>
mov    %rax,0x0(%r13)
test   %r15d,%r15d
je     118e <alloc_image_data+0x6e>
mov    %rax,%r14
movslq %r15d,%rbp
lea    -0x1(%rbp),%rbx
mov    $0x1,%edi
mov    %r12d,%esi
call   1030 <calloc@plt>
mov    %rax,-0x8(%r14,%rbp,8)
test   %ebx,%ebx
je     118e <alloc_image_data+0x6e>
add    $0xfffffffffffffffe,%rbp
xchg   %ax,%ax
mov    0x0(%r13),%r14
mov    $0x1,%edi
mov    %r12d,%esi
call   1030 <calloc@plt>
mov    %rax,(%r14,%rbp,8)
add    $0xffffffffffffffff,%rbp
add    $0xffffffff,%ebx
jne    1170 <alloc_image_data+0x50>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @alloc_image_data(i8*** %0, i32 %1, i32 %2) {
%4 = alloca i8***
%5 = alloca i32
%6 = alloca i32
store i8*** %0, i8**** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%7 = load i32, i32* %5
%8 = sext i32 %7 to i64
%9 = mul i64 8, %8
%10 = trunc i64 %9 to i32
%11 = call i8** @malloc(i32 %10)
%12 = load i8***, i8**** %4
store i8** %11, i8*** %12
br label %13
13: ; preds = %17, %3
%14 = load i32, i32* %5
%15 = add nsw i32 %14, -1
store i32 %15, i32* %5
%16 = icmp ne i32 %14, 0
br i1 %16, label %17, label %25
17: ; preds = %13
%18 = load i32, i32* %6
%19 = call i8* @calloc(i32 1, i32 %18)
%20 = load i8***, i8**** %4
%21 = load i8**, i8*** %20
%22 = load i32, i32* %5
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8*, i8** %21, i64 %23
store i8* %19, i8** %24
br label %13
25: ; preds = %13
ret void
}

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