#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 array_length(char **);
char **concat_array(char **, char **);
int /*<<< orphan*/ copy_array(char **, char **);
char **malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  char **list = malloc(sizeof(char *) * 3);
  list[0] = "Hello, world";
  list[1] = "cat is very cute";
  list[2] = NULL;
  char **list2 = malloc(sizeof(char *) * 3);
  copy_array(list2, list);
  printf("%s\n%s\n%s\n", list[0], list[1], list[2]);
  printf("%s\n%s\n%s\n", list2[0], list2[1], list2[2]);
  char **list3 = concat_array(list, list2);
  char **iter = list3;
  while (*iter != NULL) {
    printf("%s\n", *iter);
    iter++;
  }
  printf("%d\n", array_length(list));
  printf("%d\n", array_length(list2));
  printf("%d\n", array_length(list3));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x18,%edi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
lea    0xe88(%rip),%rcx
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
lea    0xe87(%rip),%rcx
mov    %rcx,0x8(%rax)
mov    -0x10(%rbp),%rax
movq   $0x0,0x10(%rax)
mov    $0x18,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1070 <copy_array@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rcx
lea    0xe4f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%rsi
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rdx
mov    -0x18(%rbp),%rax
mov    0x10(%rax),%rcx
lea    0xe2a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <concat_array@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmpq   $0x0,(%rax)
je     1248 <main+0xf8>
mov    -0x28(%rbp),%rax
mov    (%rax),%rsi
lea    0xdf4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x28(%rbp)
jmp    1214 <main+0xc4>
mov    -0x10(%rbp),%rdi
call   1050 <array_length@plt>
mov    %eax,%esi
lea    0xdce(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1050 <array_length@plt>
mov    %eax,%esi
lea    0xdb5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1050 <array_length@plt>
mov    %eax,%esi
lea    0xd9c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    $0x18,%edi
call   1070 <malloc@plt>
mov    %rax,%r12
lea    0xe84(%rip),%rax
mov    %rax,(%r12)
lea    0xe86(%rip),%rax
mov    %rax,0x8(%r12)
movq   $0x0,0x10(%r12)
mov    $0x18,%edi
call   1070 <malloc@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    %r12,%rsi
call   1080 <copy_array@plt>
mov    (%r12),%rsi
mov    0x8(%r12),%rdx
mov    0x10(%r12),%rcx
lea    0xe5c(%rip),%r15
mov    %r15,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%r14),%rsi
mov    0x8(%r14),%rdx
mov    0x10(%r14),%rcx
mov    %r15,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r12,%rdi
mov    %r14,%rsi
call   1030 <concat_array@plt>
mov    %rax,%r15
mov    (%rax),%rdi
test   %rdi,%rdi
je     1211 <main+0xb1>
mov    %r15,%rbx
add    $0x8,%rbx
xchg   %ax,%ax
call   1040 <puts@plt>
mov    (%rbx),%rdi
add    $0x8,%rbx
test   %rdi,%rdi
jne    1200 <main+0xa0>
mov    %r12,%rdi
call   1060 <array_length@plt>
lea    0xe08(%rip),%rbx
mov    %rbx,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14,%rdi
call   1060 <array_length@plt>
mov    %rbx,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15,%rdi
call   1060 <array_length@plt>
mov    %rbx,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [13 x i8] c"Hello, world\00"
@.str.1 = [17 x i8] c"cat is very cute\00"
@.str.2 = [10 x i8] c"%s\0A%s\0A%s\0A\00"
@.str.3 = [4 x i8] c"%s\0A\00"
@.str.4 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8**
%3 = alloca i8**
%4 = alloca i8**
%5 = alloca i8**
store i32 0, i32* %1
%6 = call i8** @malloc(i32 24)
store i8** %6, i8*** %2
%7 = load i8**, i8*** %2
%8 = getelementptr inbounds i8*, i8** %7, i64 0
store i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8** %8
%9 = load i8**, i8*** %2
%10 = getelementptr inbounds i8*, i8** %9, i64 1
store i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8** %10
%11 = load i8**, i8*** %2
%12 = getelementptr inbounds i8*, i8** %11, i64 2
store i8* null, i8** %12
%13 = call i8** @malloc(i32 24)
store i8** %13, i8*** %3
%14 = load i8**, i8*** %3
%15 = load i8**, i8*** %2
%16 = call i32 @copy_array(i8** %14, i8** %15)
%17 = load i8**, i8*** %2
%18 = getelementptr inbounds i8*, i8** %17, i64 0
%19 = load i8*, i8** %18
%20 = load i8**, i8*** %2
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = load i8**, i8*** %2
%24 = getelementptr inbounds i8*, i8** %23, i64 2
%25 = load i8*, i8** %24
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %19, i8* %22, i8* %25)
%27 = load i8**, i8*** %3
%28 = getelementptr inbounds i8*, i8** %27, i64 0
%29 = load i8*, i8** %28
%30 = load i8**, i8*** %3
%31 = getelementptr inbounds i8*, i8** %30, i64 1
%32 = load i8*, i8** %31
%33 = load i8**, i8*** %3
%34 = getelementptr inbounds i8*, i8** %33, i64 2
%35 = load i8*, i8** %34
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %29, i8* %32, i8* %35)
%37 = load i8**, i8*** %2
%38 = load i8**, i8*** %3
%39 = call i8** @concat_array(i8** %37, i8** %38)
store i8** %39, i8*** %4
%40 = load i8**, i8*** %4
store i8** %40, i8*** %5
br label %41
41: ; preds = %45, %0
%42 = load i8**, i8*** %5
%43 = load i8*, i8** %42
%44 = icmp ne i8* %43, null
br i1 %44, label %45, label %51
45: ; preds = %41
%46 = load i8**, i8*** %5
%47 = load i8*, i8** %46
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %47)
%49 = load i8**, i8*** %5
%50 = getelementptr inbounds i8*, i8** %49, i32 1
store i8** %50, i8*** %5
br label %41
51: ; preds = %41
%52 = load i8**, i8*** %2
%53 = call i32 @array_length(i8** %52)
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %53)
%55 = load i8**, i8*** %3
%56 = call i32 @array_length(i8** %55)
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %56)
%58 = load i8**, i8*** %4
%59 = call i32 @array_length(i8** %58)
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %59)
ret i32 0
}

LLVM IR (-O2):
@.str = [13 x i8] c"Hello, world\00"
@.str.1 = [17 x i8] c"cat is very cute\00"
@.str.2 = [10 x i8] c"%s\0A%s\0A%s\0A\00"
@.str.4 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = tail call i8** @malloc(i32 24)
store i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8** %1
%2 = getelementptr inbounds i8*, i8** %1, i64 1
store i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8** %2
%3 = getelementptr inbounds i8*, i8** %1, i64 2
store i8* null, i8** %3
%4 = tail call i8** @malloc(i32 24)
%5 = tail call i32 @copy_array(i8** %4, i8** %1)
%6 = load i8*, i8** %1
%7 = load i8*, i8** %2
%8 = load i8*, i8** %3
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %6, i8* %7, i8* %8)
%10 = load i8*, i8** %4
%11 = getelementptr inbounds i8*, i8** %4, i64 1
%12 = load i8*, i8** %11
%13 = getelementptr inbounds i8*, i8** %4, i64 2
%14 = load i8*, i8** %13
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %10, i8* %12, i8* %14)
%16 = tail call i8** @concat_array(i8** %1, i8** %4)
%17 = load i8*, i8** %16
%18 = icmp eq i8* %17, null
br i1 %18, label %26, label %19
19: ; preds = %0, %19
%20 = phi i8* [ %24, %19 ], [ %17, %0 ]
%21 = phi i8** [ %23, %19 ], [ %16, %0 ]
%22 = tail call i32 @puts(i8* %20)
%23 = getelementptr inbounds i8*, i8** %21, i64 1
%24 = load i8*, i8** %23
%25 = icmp eq i8* %24, null
br i1 %25, label %26, label %19
26: ; preds = %19, %0
%27 = tail call i32 @array_length(i8** %1)
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %27)
%29 = tail call i32 @array_length(i8** %4)
%30 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %29)
%31 = tail call i32 @array_length(i8** %16)
%32 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %31)
ret i32 0
}