#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 */
scalar_t__ malloc(int);
int /*<<< orphan*/ strcpy(char *, char *);
char **copyBoard(char **board, int n) {
  int i;
  char **w;
  w = (char **)malloc(sizeof(char *) * n);
  for (i = 0; i < n; i++) {
    w[i] = (char *)malloc(sizeof(char) * (n + 1));
    strcpy(w[i], board[i]);
  }
  return w;
}


x86 assembly (clang, -O0):
<copyBoard>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movslq -0xc(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11a2 <copyBoard+0x82>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,%rdx
mov    -0x18(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x18(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1030 <strcpy@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1149 <copyBoard+0x29>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<copyBoard>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %esi,%r12d
mov    %rdi,%r14
lea    0x0(,%r12,8),%edi
call   1040 <malloc@plt>
mov    %rax,%r15
test   %r12d,%r12d
jle    1171 <copyBoard+0x51>
mov    %r12d,%r13d
add    $0x1,%r12d
xor    %ebx,%ebx
nopl   (%rax)
mov    %r12d,%edi
call   1040 <malloc@plt>
mov    %rax,(%r15,%rbx,8)
mov    (%r14,%rbx,8),%rsi
mov    %rax,%rdi
call   1030 <strcpy@plt>
add    $0x1,%rbx
cmp    %rbx,%r13
jne    1150 <copyBoard+0x30>
mov    %r15,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

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