#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 */
int /*<<< orphan*/ free_table(char **);
int my_strlen(char *);
void *xcalloc(int, int);
char **malloc_table(char **board, char *str, int words) {
  int len;
  int count;
  len = my_strlen(str);
  board = xcalloc((words + 1), sizeof(*board));
  if (!board)
    return (NULL);
  count = 0;
  while (count < words) {
    board[count] = xcalloc((len + 1), sizeof(*board));
    if (!board[count]) {
      free_table(board);
      return (NULL);
    }
    count++;
  }
  return (board);
}


x86 assembly (clang, -O0):
<malloc_table>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <my_strlen@plt>
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%edi
add    $0x1,%edi
mov    $0x8,%esi
call   1050 <xcalloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    117b <malloc_table+0x4b>
movq   $0x0,-0x8(%rbp)
jmp    11ec <malloc_table+0xbc>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11e4 <malloc_table+0xb4>
mov    -0x20(%rbp),%edi
add    $0x1,%edi
mov    $0x8,%esi
call   1050 <xcalloc@plt>
mov    %rax,%rdx
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
jne    11d6 <malloc_table+0xa6>
mov    -0x10(%rbp),%rdi
call   1040 <free_table@plt>
movq   $0x0,-0x8(%rbp)
jmp    11ec <malloc_table+0xbc>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1182 <malloc_table+0x52>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<malloc_table>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r14d
mov    %rsi,%rdi
call   1030 <my_strlen@plt>
mov    %eax,%r15d
lea    0x1(%r14),%edi
mov    $0x8,%esi
call   1050 <xcalloc@plt>
test   %rax,%rax
je     1199 <malloc_table+0x69>
mov    %rax,%r12
test   %r14d,%r14d
jle    119c <malloc_table+0x6c>
add    $0x1,%r15d
mov    %r14d,%ebp
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    %r15d,%edi
mov    $0x8,%esi
call   1050 <xcalloc@plt>
mov    %rax,(%r12,%rbx,8)
test   %rax,%rax
je     1191 <malloc_table+0x61>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1170 <malloc_table+0x40>
jmp    119c <malloc_table+0x6c>
mov    %r12,%rdi
call   1040 <free_table@plt>
xor    %r12d,%r12d
mov    %r12,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i8** @malloc_table(i8** nocapture readnone %0, i8* %1, i32 %2) {
%4 = tail call i32 @my_strlen(i8* %1)
%5 = add nsw i32 %2, 1
%6 = tail call i8* @xcalloc(i32 %5, i32 8)
%7 = bitcast i8* %6 to i8**
%8 = icmp eq i8* %6, null
br i1 %8, label %24, label %9
9: ; preds = %3
%10 = icmp sgt i32 %2, 0
br i1 %10, label %11, label %24
11: ; preds = %9
%12 = add nsw i32 %4, 1
%13 = zext i32 %2 to i64
br label %16
14: ; preds = %16
%15 = icmp eq i64 %21, %13
br i1 %15, label %24, label %16
16: ; preds = %11, %14
%17 = phi i64 [ 0, %11 ], [ %21, %14 ]
%18 = tail call i8* @xcalloc(i32 %12, i32 8)
%19 = getelementptr inbounds i8*, i8** %7, i64 %17
store i8* %18, i8** %19
%20 = icmp eq i8* %18, null
%21 = add nuw nsw i64 %17, 1
br i1 %20, label %22, label %14
22: ; preds = %16
%23 = tail call i32 @free_table(i8** %7)
br label %24
24: ; preds = %14, %9, %3, %22
%25 = phi i8** [ null, %22 ], [ null, %3 ], [ %7, %9 ], [ %7, %14 ]
ret i8** %25
}