#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*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
char **malloc(int);
int /*<<< orphan*/ perror(char *);
char *strdup(char const *);
char **argCopy(const char **aArgs) {
  char **result = NULL;
  int i;
  result = malloc(sizeof(char *) * 64);
  if (!result) {
    perror("malloc");
    exit(EXIT_FAILURE);
  }
  result[64 - 1] = NULL;
  for (i = 0; i < 64 - 1; i++) {
    if (aArgs[i] == NULL) {
      result[i] = NULL;
      break;
    }
    result[i] = strdup(aArgs[i]);
    if (!result[i]) {
      perror("strdup");
      exit(EXIT_FAILURE);
    }
  }
  return result;
}


x86 assembly (clang, -O0):
<argCopy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
mov    $0x200,%edi
call   1030 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1187 <argCopy+0x47>
lea    0xe8c(%rip),%rdi
call   1040 <perror@plt>
mov    0x2e60(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
mov    -0x10(%rbp),%rax
movq   $0x0,0x1f8(%rax)
movl   $0x0,-0x14(%rbp)
cmpl   $0x3f,-0x14(%rbp)
jge    122f <argCopy+0xef>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
jne    11cf <argCopy+0x8f>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
jmp    122f <argCopy+0xef>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1060 <strdup@plt>
mov    %rax,%rdx
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
jne    121c <argCopy+0xdc>
lea    0xdfe(%rip),%rdi
call   1040 <perror@plt>
mov    0x2dcb(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
jmp    1221 <argCopy+0xe1>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    119d <argCopy+0x5d>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<argCopy>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
mov    $0x200,%edi
call   1030 <malloc@plt>
test   %rax,%rax
je     11be <argCopy+0x7e>
mov    %rax,%r15
movq   $0x0,0x1f8(%rax)
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    (%r14,%rbx,8),%rdi
test   %rdi,%rdi
je     1193 <argCopy+0x53>
call   1060 <strdup@plt>
mov    %rax,(%r15,%rbx,8)
test   %rax,%rax
je     11a4 <argCopy+0x64>
add    $0x1,%rbx
cmp    $0x3f,%rbx
jne    1170 <argCopy+0x30>
jmp    119b <argCopy+0x5b>
movq   $0x0,(%r15,%rbx,8)
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe5c(%rip),%rdi
call   1040 <perror@plt>
mov    0x2e29(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
lea    0xe3b(%rip),%rdi
jmp    11ab <argCopy+0x6b>

LLVM IR (-O0):
@.str = [7 x i8] c"malloc\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [7 x i8] c"strdup\00"
define i8** @argCopy(i8** %0) {
%2 = alloca i8**
%3 = alloca i8**
%4 = alloca i32
store i8** %0, i8*** %2
store i8** null, i8*** %3
%5 = call i8** @malloc(i32 512)
store i8** %5, i8*** %3
%6 = load i8**, i8*** %3
%7 = icmp ne i8** %6, null
br i1 %7, label %12, label %8
8: ; preds = %1
%9 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%10 = load i32, i32* @EXIT_FAILURE
%11 = call i32 @exit(i32 %10)
unreachable
12: ; preds = %1
%13 = load i8**, i8*** %3
%14 = getelementptr inbounds i8*, i8** %13, i64 63
store i8* null, i8** %14
store i32 0, i32* %4
br label %15
15: ; preds = %52, %12
%16 = load i32, i32* %4
%17 = icmp slt i32 %16, 63
br i1 %17, label %18, label %55
18: ; preds = %15
%19 = load i8**, i8*** %2
%20 = load i32, i32* %4
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8*, i8** %19, i64 %21
%23 = load i8*, i8** %22
%24 = icmp eq i8* %23, null
br i1 %24, label %25, label %30
25: ; preds = %18
%26 = load i8**, i8*** %3
%27 = load i32, i32* %4
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8*, i8** %26, i64 %28
store i8* null, i8** %29
br label %55
30: ; preds = %18
%31 = load i8**, i8*** %2
%32 = load i32, i32* %4
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8*, i8** %31, i64 %33
%35 = load i8*, i8** %34
%36 = call i8* @strdup(i8* %35)
%37 = load i8**, i8*** %3
%38 = load i32, i32* %4
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8*, i8** %37, i64 %39
store i8* %36, i8** %40
%41 = load i8**, i8*** %3
%42 = load i32, i32* %4
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i8*, i8** %41, i64 %43
%45 = load i8*, i8** %44
%46 = icmp ne i8* %45, null
br i1 %46, label %51, label %47
47: ; preds = %30
%48 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%49 = load i32, i32* @EXIT_FAILURE
%50 = call i32 @exit(i32 %49)
unreachable
51: ; preds = %30
br label %52
52: ; preds = %51
%53 = load i32, i32* %4
%54 = add nsw i32 %53, 1
store i32 %54, i32* %4
br label %15
55: ; preds = %25, %15
%56 = load i8**, i8*** %3
ret i8** %56
}

LLVM IR (-O2):
@.str = [7 x i8] c"malloc\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [7 x i8] c"strdup\00"
define noalias i8** @argCopy(i8** nocapture %0) {
%2 = tail call i8** @malloc(i32 512)
%3 = icmp eq i8** %2, null
br i1 %3, label %4, label %8
4: ; preds = %1
%5 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%6 = load i32, i32* @EXIT_FAILURE
%7 = tail call i32 @exit(i32 %6)
unreachable
8: ; preds = %1
%9 = getelementptr inbounds i8*, i8** %2, i64 63
store i8* null, i8** %9
br label %10
10: ; preds = %8, %26
%11 = phi i64 [ 0, %8 ], [ %27, %26 ]
%12 = getelementptr inbounds i8*, i8** %0, i64 %11
%13 = load i8*, i8** %12
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %18
15: ; preds = %10
%16 = and i64 %11, 4294967295
%17 = getelementptr inbounds i8*, i8** %2, i64 %16
store i8* null, i8** %17
br label %29
18: ; preds = %10
%19 = tail call i8* @strdup(i8* %13)
%20 = getelementptr inbounds i8*, i8** %2, i64 %11
store i8* %19, i8** %20
%21 = icmp eq i8* %19, null
br i1 %21, label %22, label %26
22: ; preds = %18
%23 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%24 = load i32, i32* @EXIT_FAILURE
%25 = tail call i32 @exit(i32 %24)
unreachable
26: ; preds = %18
%27 = add nuw nsw i64 %11, 1
%28 = icmp eq i64 %27, 63
br i1 %28, label %29, label %10
29: ; preds = %26, %15
ret i8** %2
}