#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);
void allocate_row(int row, char **output) {
  for (int i = 0; i < 3; i++) {
    if (output[row - i] == NULL) {
      output[row - i] = calloc(40 * 4 + 1, sizeof(char));
    }
  }
}


x86 assembly (clang, -O0):
<allocate_row>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x3,-0x14(%rbp)
jge    117e <allocate_row+0x6e>
mov    -0x10(%rbp),%rax
mov    -0x4(%rbp),%ecx
sub    -0x14(%rbp),%ecx
movslq %ecx,%rcx
cmpq   $0x0,(%rax,%rcx,8)
jne    116b <allocate_row+0x5b>
mov    $0xa1,%edi
mov    $0x1,%esi
call   1030 <calloc@plt>
mov    %rax,%rdx
mov    -0x10(%rbp),%rax
mov    -0x4(%rbp),%ecx
sub    -0x14(%rbp),%ecx
movslq %ecx,%rcx
mov    %rdx,(%rax,%rcx,8)
jmp    1170 <allocate_row+0x60>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1126 <allocate_row+0x16>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<allocate_row>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
movslq %edi,%rbx
cmpq   $0x0,(%rsi,%rbx,8)
je     1139 <allocate_row+0x29>
cmpq   $0x0,-0x8(%r14,%rbx,8)
je     1154 <allocate_row+0x44>
cmpq   $0x0,-0x10(%r14,%rbx,8)
je     1170 <allocate_row+0x60>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    $0xa1,%edi
mov    $0x1,%esi
call   1030 <calloc@plt>
mov    %rax,(%r14,%rbx,8)
cmpq   $0x0,-0x8(%r14,%rbx,8)
jne    1129 <allocate_row+0x19>
mov    $0xa1,%edi
mov    $0x1,%esi
call   1030 <calloc@plt>
mov    %rax,-0x8(%r14,%rbx,8)
cmpq   $0x0,-0x10(%r14,%rbx,8)
jne    1131 <allocate_row+0x21>
mov    $0xa1,%edi
mov    $0x1,%esi
call   1030 <calloc@plt>
mov    %rax,-0x10(%r14,%rbx,8)
jmp    1131 <allocate_row+0x21>

LLVM IR (-O0):
define void @allocate_row(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32
store i32 %0, i32* %3
store i8** %1, i8*** %4
store i32 0, i32* %5
br label %6
6: ; preds = %27, %2
%7 = load i32, i32* %5
%8 = icmp slt i32 %7, 3
br i1 %8, label %9, label %30
9: ; preds = %6
%10 = load i8**, i8*** %4
%11 = load i32, i32* %3
%12 = load i32, i32* %5
%13 = sub nsw i32 %11, %12
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8*, i8** %10, i64 %14
%16 = load i8*, i8** %15
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %26
18: ; preds = %9
%19 = call i8* @calloc(i32 161, i32 1)
%20 = load i8**, i8*** %4
%21 = load i32, i32* %3
%22 = load i32, i32* %5
%23 = sub nsw i32 %21, %22
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8*, i8** %20, i64 %24
store i8* %19, i8** %25
br label %26
26: ; preds = %18, %9
br label %27
27: ; preds = %26
%28 = load i32, i32* %5
%29 = add nsw i32 %28, 1
store i32 %29, i32* %5
br label %6
30: ; preds = %6
ret void
}

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