#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*/ ft_free_two(char **);
int ft_ptrlen(char **);
char **ft_ptrnew(int);
char *ft_strdup(char *);
int ft_twod_realloc(char ***map, char *line) {
  int len;
  char **new;
  int index;
  len = ft_ptrlen(*map);
  new = ft_ptrnew(len);
  index = -1;
  while (++index < len)
    new[index] = ft_strdup((*map)[index]);
  ft_free_two(*map);
  *map = ft_ptrnew(len + 1);
  index = -1;
  while (++index < len)
    (*map)[index] = ft_strdup(new[index]);
  (*map)[index] = ft_strdup(line);
  ft_free_two(new);
  return (1);
}


x86 assembly (clang, -O0):
<ft_twod_realloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1040 <ft_ptrlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1030 <ft_ptrnew@plt>
mov    %rax,-0x20(%rbp)
movl   $0xffffffff,-0x24(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
cmp    -0x14(%rbp),%eax
jge    11ac <ft_twod_realloc+0x6c>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1050 <ft_strdup@plt>
mov    %rax,%rdx
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
jmp    1172 <ft_twod_realloc+0x32>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1060 <ft_free_two@plt>
mov    -0x14(%rbp),%edi
add    $0x1,%edi
call   1030 <ft_ptrnew@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
movl   $0xffffffff,-0x24(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
cmp    -0x14(%rbp),%eax
jge    120e <ft_twod_realloc+0xce>
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1050 <ft_strdup@plt>
mov    %rax,%rdx
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
movslq -0x24(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
jmp    11d4 <ft_twod_realloc+0x94>
mov    -0x10(%rbp),%rdi
call   1050 <ft_strdup@plt>
mov    %rax,%rdx
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
movslq -0x24(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x20(%rbp),%rdi
call   1060 <ft_free_two@plt>
mov    $0x1,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ft_twod_realloc>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r13
mov    (%rdi),%rdi
call   1040 <ft_ptrlen@plt>
mov    %eax,%r12d
mov    %eax,%edi
call   1030 <ft_ptrnew@plt>
mov    %rax,%r15
test   %r12d,%r12d
jle    11cf <ft_twod_realloc+0x8f>
mov    %r12d,%ebx
xor    %ebp,%ebp
mov    0x0(%r13),%rax
mov    (%rax,%rbp,8),%rdi
call   1050 <ft_strdup@plt>
mov    %rax,(%r15,%rbp,8)
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    1170 <ft_twod_realloc+0x30>
mov    0x0(%r13),%rdi
call   1060 <ft_free_two@plt>
lea    0x1(%r12),%edi
call   1030 <ft_ptrnew@plt>
mov    %rax,0x0(%r13)
test   %r12d,%r12d
jle    11e8 <ft_twod_realloc+0xa8>
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
mov    (%r15,%rbp,8),%rdi
call   1050 <ft_strdup@plt>
mov    0x0(%r13),%rcx
mov    %rax,(%rcx,%rbp,8)
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    11b0 <ft_twod_realloc+0x70>
movslq %r12d,%rbx
jmp    11ea <ft_twod_realloc+0xaa>
mov    0x0(%r13),%rdi
call   1060 <ft_free_two@plt>
add    $0x1,%r12d
mov    %r12d,%edi
call   1030 <ft_ptrnew@plt>
mov    %rax,0x0(%r13)
xor    %ebx,%ebx
mov    %r14,%rdi
call   1050 <ft_strdup@plt>
mov    0x0(%r13),%rcx
mov    %rax,(%rcx,%rbx,8)
mov    %r15,%rdi
call   1060 <ft_free_two@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @ft_twod_realloc(i8*** %0, i8* %1) {
%3 = alloca i8***
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i32
store i8*** %0, i8**** %3
store i8* %1, i8** %4
%8 = load i8***, i8**** %3
%9 = load i8**, i8*** %8
%10 = call i32 @ft_ptrlen(i8** %9)
store i32 %10, i32* %5
%11 = load i32, i32* %5
%12 = call i8** @ft_ptrnew(i32 %11)
store i8** %12, i8*** %6
store i32 -1, i32* %7
br label %13
13: ; preds = %18, %2
%14 = load i32, i32* %7
%15 = add nsw i32 %14, 1
store i32 %15, i32* %7
%16 = load i32, i32* %5
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %30
18: ; preds = %13
%19 = load i8***, i8**** %3
%20 = load i8**, i8*** %19
%21 = load i32, i32* %7
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8*, i8** %20, i64 %22
%24 = load i8*, i8** %23
%25 = call i8* @ft_strdup(i8* %24)
%26 = load i8**, i8*** %6
%27 = load i32, i32* %7
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8*, i8** %26, i64 %28
store i8* %25, i8** %29
br label %13
30: ; preds = %13
%31 = load i8***, i8**** %3
%32 = load i8**, i8*** %31
%33 = call i32 @ft_free_two(i8** %32)
%34 = load i32, i32* %5
%35 = add nsw i32 %34, 1
%36 = call i8** @ft_ptrnew(i32 %35)
%37 = load i8***, i8**** %3
store i8** %36, i8*** %37
store i32 -1, i32* %7
br label %38
38: ; preds = %43, %30
%39 = load i32, i32* %7
%40 = add nsw i32 %39, 1
store i32 %40, i32* %7
%41 = load i32, i32* %5
%42 = icmp slt i32 %40, %41
br i1 %42, label %43, label %55
43: ; preds = %38
%44 = load i8**, i8*** %6
%45 = load i32, i32* %7
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i8*, i8** %44, i64 %46
%48 = load i8*, i8** %47
%49 = call i8* @ft_strdup(i8* %48)
%50 = load i8***, i8**** %3
%51 = load i8**, i8*** %50
%52 = load i32, i32* %7
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i8*, i8** %51, i64 %53
store i8* %49, i8** %54
br label %38
55: ; preds = %38
%56 = load i8*, i8** %4
%57 = call i8* @ft_strdup(i8* %56)
%58 = load i8***, i8**** %3
%59 = load i8**, i8*** %58
%60 = load i32, i32* %7
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds i8*, i8** %59, i64 %61
store i8* %57, i8** %62
%63 = load i8**, i8*** %6
%64 = call i32 @ft_free_two(i8** %63)
ret i32 1
}

LLVM IR (-O2):
define i32 @ft_twod_realloc(i8*** nocapture %0, i8* %1) {
%3 = load i8**, i8*** %0
%4 = tail call i32 @ft_ptrlen(i8** %3)
%5 = tail call i8** @ft_ptrnew(i32 %4)
%6 = icmp sgt i32 %4, 0
br i1 %6, label %7, label %36
7: ; preds = %2
%8 = zext i32 %4 to i64
br label %9
9: ; preds = %7, %9
%10 = phi i64 [ 0, %7 ], [ %16, %9 ]
%11 = load i8**, i8*** %0
%12 = getelementptr inbounds i8*, i8** %11, i64 %10
%13 = load i8*, i8** %12
%14 = tail call i8* @ft_strdup(i8* %13)
%15 = getelementptr inbounds i8*, i8** %5, i64 %10
store i8* %14, i8** %15
%16 = add nuw nsw i64 %10, 1
%17 = icmp eq i64 %16, %8
br i1 %17, label %18, label %9
18: ; preds = %9
%19 = load i8**, i8*** %0
%20 = tail call i32 @ft_free_two(i8** %19)
%21 = add nsw i32 %4, 1
%22 = tail call i8** @ft_ptrnew(i32 %21)
store i8** %22, i8*** %0
br i1 %6, label %23, label %41
23: ; preds = %18
%24 = zext i32 %4 to i64
br label %25
25: ; preds = %23, %25
%26 = phi i64 [ 0, %23 ], [ %32, %25 ]
%27 = getelementptr inbounds i8*, i8** %5, i64 %26
%28 = load i8*, i8** %27
%29 = tail call i8* @ft_strdup(i8* %28)
%30 = load i8**, i8*** %0
%31 = getelementptr inbounds i8*, i8** %30, i64 %26
store i8* %29, i8** %31
%32 = add nuw nsw i64 %26, 1
%33 = icmp eq i64 %32, %24
br i1 %33, label %34, label %25
34: ; preds = %25
%35 = sext i32 %4 to i64
br label %41
36: ; preds = %2
%37 = load i8**, i8*** %0
%38 = tail call i32 @ft_free_two(i8** %37)
%39 = add nsw i32 %4, 1
%40 = tail call i8** @ft_ptrnew(i32 %39)
store i8** %40, i8*** %0
br label %41
41: ; preds = %36, %34, %18
%42 = phi i64 [ 0, %18 ], [ %35, %34 ], [ 0, %36 ]
%43 = tail call i8* @ft_strdup(i8* %1)
%44 = load i8**, i8*** %0
%45 = getelementptr inbounds i8*, i8** %44, i64 %42
store i8* %43, i8** %45
%46 = tail call i32 @ft_free_two(i8** %5)
ret i32 1
}