#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 */
char *cloneString(char *);
char **needMem(int);
char **cloneCmdVector(char **cmd) {
  int i, cmdLen = 0;
  for (i = 0; cmd[i] != NULL; i++)
    cmdLen++;
  char **cmd2 = needMem((cmdLen + 1) * sizeof(char *));
  for (i = 0; i < cmdLen; i++)
    cmd2[i] = cloneString(cmd[i]);
  cmd2[cmdLen] = NULL;
  return cmd2;
}


x86 assembly (clang, -O0):
<cloneCmdVector>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     1164 <cloneCmdVector+0x44>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    113a <cloneCmdVector+0x1a>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1040 <needMem@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    11bc <cloneCmdVector+0x9c>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1030 <cloneString@plt>
mov    %rax,%rdx
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1182 <cloneCmdVector+0x62>
mov    -0x18(%rbp),%rax
movslq -0x10(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cloneCmdVector>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r12
cmpq   $0x0,(%rdi)
je     114e <cloneCmdVector+0x2e>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
cmpq   $0x0,0x8(%r12,%rbx,8)
lea    0x1(%rbx),%rbx
jne    1140 <cloneCmdVector+0x20>
jmp    1150 <cloneCmdVector+0x30>
xor    %ebx,%ebx
lea    0x8(,%rbx,8),%edi
call   1040 <needMem@plt>
mov    %rax,%r14
test   %ebx,%ebx
je     1188 <cloneCmdVector+0x68>
mov    %ebx,%r15d
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
mov    (%r12,%rbx,8),%rdi
call   1030 <cloneString@plt>
mov    %rax,(%r14,%rbx,8)
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1170 <cloneCmdVector+0x50>
jmp    118b <cloneCmdVector+0x6b>
xor    %r15d,%r15d
movq   $0x0,(%r14,%r15,8)
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i8** @cloneCmdVector(i8** nocapture %0) {
%2 = load i8*, i8** %0
%3 = icmp eq i8* %2, null
br i1 %3, label %12, label %4
4: ; preds = %1, %4
%5 = phi i64 [ %6, %4 ], [ 0, %1 ]
%6 = add nuw nsw i64 %5, 1
%7 = getelementptr inbounds i8*, i8** %0, i64 %6
%8 = load i8*, i8** %7
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %4
10: ; preds = %4
%11 = trunc i64 %6 to i32
br label %12
12: ; preds = %10, %1
%13 = phi i32 [ 0, %1 ], [ %11, %10 ]
%14 = shl i32 %13, 3
%15 = add i32 %14, 8
%16 = tail call i8** @needMem(i32 %15)
%17 = icmp eq i32 %13, 0
br i1 %17, label %28, label %18
18: ; preds = %12
%19 = zext i32 %13 to i64
br label %20
20: ; preds = %18, %20
%21 = phi i64 [ 0, %18 ], [ %26, %20 ]
%22 = getelementptr inbounds i8*, i8** %0, i64 %21
%23 = load i8*, i8** %22
%24 = tail call i8* @cloneString(i8* %23)
%25 = getelementptr inbounds i8*, i8** %16, i64 %21
store i8* %24, i8** %25
%26 = add nuw nsw i64 %21, 1
%27 = icmp eq i64 %26, %19
br i1 %27, label %28, label %20
28: ; preds = %20, %12
%29 = phi i64 [ 0, %12 ], [ %19, %20 ]
%30 = getelementptr inbounds i8*, i8** %16, i64 %29
store i8* null, i8** %30
ret i8** %16
}