#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 */
void *malloc(int);
int /*<<< orphan*/ strncpy(char *, char *, int);
char **cleanTokenList(char **tokenList) {
  char **tl;
  int len, i;
  len = 0;
  while (tokenList[len++])
    ;
  len--;
  len = (len + 1) / 2;
  tl = malloc((len + 1) * sizeof(char *));
  for (i = 0; i < len; i++) {
    tl[i] = malloc(1024 * sizeof(char));
    strncpy(tl[i], tokenList[i * 2], 1023);
    tl[i][1023] = 0;
  }
  tl[len] = NULL;
  return tl;
}


x86 assembly (clang, -O0):
<cleanTokenList>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x14(%rbp)
movslq %ecx,%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     1155 <cleanTokenList+0x35>
jmp    1133 <cleanTokenList+0x13>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11fa <cleanTokenList+0xda>
mov    $0x400,%edi
call   1040 <malloc@plt>
mov    %rax,%rdx
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%ecx
shl    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rsi
mov    $0x3ff,%edx
call   1030 <strncpy@plt>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movb   $0x0,0x3ff(%rax)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    118d <cleanTokenList+0x6d>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cleanTokenList>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r15
xor    %ebx,%ebx
cmpq   $0x0,(%r15,%rbx,8)
lea    0x1(%rbx),%rbx
jne    1130 <cleanTokenList+0x10>
mov    %ebx,%r12d
shr    %r12d
lea    0x8(,%r12,8),%edi
call   1040 <malloc@plt>
mov    %rax,%r14
cmp    $0x1,%ebx
je     11a2 <cleanTokenList+0x82>
shr    %ebx
cmp    $0x2,%ebx
mov    $0x1,%r13d
cmovae %ebx,%r13d
shl    $0x3,%r13
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
mov    $0x400,%edi
call   1040 <malloc@plt>
mov    %rax,%rbx
mov    %rax,(%r14,%rbp,1)
mov    (%r15,%rbp,2),%rsi
mov    %rax,%rdi
mov    $0x3ff,%edx
call   1030 <strncpy@plt>
movb   $0x0,0x3ff(%rbx)
add    $0x8,%rbp
cmp    %rbp,%r13
jne    1170 <cleanTokenList+0x50>
mov    %r12d,%eax
movq   $0x0,(%r14,%rax,8)
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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