short **allocate_image_array(length, width)
long length, width;
{
  int i;
  short **the_array;
  the_array = malloc(length * sizeof(short *));
  for (i = 0; i < length; i++) {
    the_array[i] = malloc(width * sizeof(short));
    if (the_array[i] == '\0') {
      printf("\n\tmalloc of the_image[%d] failed", i);
    }
  }
  return (the_array);
}


x86 assembly (clang, -O0):
<allocate_image_array>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
shl    $0x3,%rdi
call   1040 <malloc@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x14(%rbp)
movslq -0x14(%rbp),%rax
cmp    -0x8(%rbp),%rax
jge    11a9 <allocate_image_array+0x89>
mov    -0x10(%rbp),%rdi
shl    $0x1,%rdi
call   1040 <malloc@plt>
mov    %rax,%rdx
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
jne    1196 <allocate_image_array+0x76>
mov    -0x14(%rbp),%esi
lea    0xe71(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    119b <allocate_image_array+0x7b>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1148 <allocate_image_array+0x28>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<allocate_image_array>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
lea    0x0(,%rdi,8),%rdi
call   1040 <malloc@plt>
mov    %rax,%r13
test   %r15,%r15
jle    1189 <allocate_image_array+0x69>
add    %r14,%r14
lea    0xeb2(%rip),%r12
xor    %ebx,%ebx
jmp    1169 <allocate_image_array+0x49>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0x1,%rbx
cmp    %rbx,%r15
je     1189 <allocate_image_array+0x69>
mov    %r14,%rdi
call   1040 <malloc@plt>
mov    %rax,0x0(%r13,%rbx,8)
test   %rax,%rax
jne    1160 <allocate_image_array+0x40>
mov    %r12,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1030 <printf@plt>
jmp    1160 <allocate_image_array+0x40>
mov    %r13,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [33 x i8] c"\0A\09malloc of the_image[%d] failed\00"
define i16** @allocate_image_array(i64 %0, i64 %1) {
%3 = alloca i64
%4 = alloca i64
%5 = alloca i32
%6 = alloca i16**
store i64 %0, i64* %3
store i64 %1, i64* %4
%7 = load i64, i64* %3
%8 = mul i64 %7, 8
%9 = call i8* @malloc(i64 %8)
%10 = bitcast i8* %9 to i16**
store i16** %10, i16*** %6
store i32 0, i32* %5
br label %11
11: ; preds = %35, %2
%12 = load i32, i32* %5
%13 = sext i32 %12 to i64
%14 = load i64, i64* %3
%15 = icmp slt i64 %13, %14
br i1 %15, label %16, label %38
16: ; preds = %11
%17 = load i64, i64* %4
%18 = mul i64 %17, 2
%19 = call i8* @malloc(i64 %18)
%20 = bitcast i8* %19 to i16*
%21 = load i16**, i16*** %6
%22 = load i32, i32* %5
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i16*, i16** %21, i64 %23
store i16* %20, i16** %24
%25 = load i16**, i16*** %6
%26 = load i32, i32* %5
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i16*, i16** %25, i64 %27
%29 = load i16*, i16** %28
%30 = icmp eq i16* %29, null
br i1 %30, label %31, label %34
31: ; preds = %16
%32 = load i32, i32* %5
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i32 %32)
br label %34
34: ; preds = %31, %16
br label %35
35: ; preds = %34
%36 = load i32, i32* %5
%37 = add nsw i32 %36, 1
store i32 %37, i32* %5
br label %11
38: ; preds = %11
%39 = load i16**, i16*** %6
ret i16** %39
}

LLVM IR (-O2):
@.str = [33 x i8] c"\0A\09malloc of the_image[%d] failed\00"
define noalias i16** @allocate_image_array(i64 %0, i64 %1) {
%3 = shl i64 %0, 3
%4 = tail call i8* @malloc(i64 %3)
%5 = bitcast i8* %4 to i16**
%6 = icmp sgt i64 %0, 0
br i1 %6, label %7, label %21
7: ; preds = %2
%8 = shl i64 %1, 1
br label %9
9: ; preds = %7, %18
%10 = phi i64 [ 0, %7 ], [ %19, %18 ]
%11 = tail call i8* @malloc(i64 %8)
%12 = getelementptr inbounds i16*, i16** %5, i64 %10
%13 = bitcast i16** %12 to i8**
store i8* %11, i8** %13
%14 = icmp eq i8* %11, null
br i1 %14, label %15, label %18
15: ; preds = %9
%16 = trunc i64 %10 to i32
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i32 %16)
br label %18
18: ; preds = %9, %15
%19 = add nuw nsw i64 %10, 1
%20 = icmp eq i64 %19, %0
br i1 %20, label %21, label %9
21: ; preds = %18, %2
ret i16** %5
}