#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__ ft_memalloc(int);
char *ft_strdup(char *);
int ft_tabsize(void **);
char **ft_cpytab(char **tab, int lenth) {
  char **new_tab;
  int i;
  int tablen;
  i = 0;
  tablen = ft_tabsize((void **)tab);
  new_tab = (char **)ft_memalloc(sizeof(char *) * lenth + 1);
  while (i < tablen) {
    new_tab[i] = ft_strdup(tab[i]);
    i++;
  }
  return (new_tab);
}


x86 assembly (clang, -O0):
<ft_cpytab>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <ft_tabsize@plt>
mov    %eax,-0x20(%rbp)
movslq -0xc(%rbp),%rax
shl    $0x3,%rax
add    $0x1,%rax
mov    %eax,%edi
call   1050 <ft_memalloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    11a3 <ft_cpytab+0x73>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1040 <ft_strdup@plt>
mov    %rax,%rdx
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1169 <ft_cpytab+0x39>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ft_cpytab>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %rdi,%r14
call   1030 <ft_tabsize@plt>
mov    %eax,%ebp
lea    0x1(,%rbx,8),%edi
call   1050 <ft_memalloc@plt>
mov    %rax,%r15
test   %ebp,%ebp
jle    1176 <ft_cpytab+0x46>
mov    %ebp,%ebp
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    (%r14,%rbx,8),%rdi
call   1040 <ft_strdup@plt>
mov    %rax,(%r15,%rbx,8)
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1160 <ft_cpytab+0x30>
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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