#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 **calloc(int, int);
char *needNextToken();
char *nextToken(int /*<<< orphan*/, int /*<<< orphan*/);
char **realloc(char **, int);
scalar_t__ strcmp(char *, char *);
char **getListOfFilenames(int *count, char *first) {
  int length = 1000;
  char **filenames = calloc(sizeof(char *), length);
  char *token;
  if (first) {
    filenames[0] = first;
    (*count)++;
  }
  for (token = needNextToken(); token != NULL && strcmp(token, ":");
       token = nextToken(0, 0)) {
    filenames[*count] = token;
    if (++(*count) == length) {
      length += 1000;
      filenames = realloc(filenames, sizeof(char *) * length);
    }
  }
  return filenames;
}


x86 assembly (clang, -O0):
<getListOfFilenames>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x3e8,-0x14(%rbp)
mov    -0x14(%rbp),%esi
mov    $0x8,%edi
call   1040 <calloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1199 <getListOfFilenames+0x49>
mov    -0x10(%rbp),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
mov    $0x0,%al
call   1060 <needNextToken@plt>
mov    %rax,-0x28(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x28(%rbp)
mov    %al,-0x29(%rbp)
je     11ce <getListOfFilenames+0x7e>
mov    -0x28(%rbp),%rdi
lea    0xe41(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    11de <getListOfFilenames+0x8e>
jmp    123e <getListOfFilenames+0xee>
mov    -0x28(%rbp),%rdx
mov    -0x20(%rbp),%rax
mov    -0x8(%rbp),%rcx
movslq (%rcx),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x8(%rbp),%rcx
mov    (%rcx),%eax
add    $0x1,%eax
mov    %eax,(%rcx)
cmp    -0x14(%rbp),%eax
jne    1227 <getListOfFilenames+0xd7>
mov    -0x14(%rbp),%eax
add    $0x3e8,%eax
mov    %eax,-0x14(%rbp)
mov    -0x20(%rbp),%rdi
movslq -0x14(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%esi
call   1070 <realloc@plt>
mov    %rax,-0x20(%rbp)
jmp    122c <getListOfFilenames+0xdc>
xor    %esi,%esi
mov    %esi,%edi
call   1030 <nextToken@plt>
mov    %rax,-0x28(%rbp)
jmp    11a4 <getListOfFilenames+0x54>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getListOfFilenames>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%rbx
mov    %rdi,%r14
mov    $0x8,%edi
mov    $0x3e8,%esi
call   1040 <calloc@plt>
mov    %rax,%r12
test   %rbx,%rbx
je     117e <getListOfFilenames+0x2e>
mov    %rbx,(%r12)
addl   $0x1,(%r14)
xor    %eax,%eax
call   1060 <needNextToken@plt>
test   %rax,%rax
je     11f4 <getListOfFilenames+0xa4>
mov    %rax,%rbx
mov    $0x3e8,%r13d
lea    0xe66(%rip),%r15
jmp    11b1 <getListOfFilenames+0x61>
nopl   0x0(%rax)
xor    %edi,%edi
xor    %esi,%esi
call   1030 <nextToken@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11f4 <getListOfFilenames+0xa4>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     11f4 <getListOfFilenames+0xa4>
movslq (%r14),%rax
mov    %rbx,(%r12,%rax,8)
add    $0x1,%eax
mov    %eax,(%r14)
cmp    %r13d,%eax
jne    11a0 <getListOfFilenames+0x50>
mov    %r13d,%ebx
add    $0x3e8,%ebx
lea    0x1f40(,%r13,8),%esi
mov    %r12,%rdi
call   1070 <realloc@plt>
mov    %rax,%r12
mov    %ebx,%r13d
jmp    11a0 <getListOfFilenames+0x50>
mov    %r12,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c":\00"
define i8** @getListOfFilenames(i32* nocapture %0, i8* %1) {
%3 = tail call i8** @calloc(i32 8, i32 1000)
%4 = icmp eq i8* %1, null
br i1 %4, label %8, label %5
5: ; preds = %2
store i8* %1, i8** %3
%6 = load i32, i32* %0
%7 = add nsw i32 %6, 1
store i32 %7, i32* %0
br label %8
8: ; preds = %5, %2
%9 = tail call i8* (...) @needNextToken()
%10 = icmp eq i8* %9, null
br i1 %10, label %32, label %11
11: ; preds = %8, %27
%12 = phi i8* [ %30, %27 ], [ %9, %8 ]
%13 = phi i8** [ %29, %27 ], [ %3, %8 ]
%14 = phi i32 [ %28, %27 ], [ 1000, %8 ]
%15 = tail call i64 @strcmp(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%16 = icmp eq i64 %15, 0
br i1 %16, label %32, label %17
17: ; preds = %11
%18 = load i32, i32* %0
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8*, i8** %13, i64 %19
store i8* %12, i8** %20
%21 = add nsw i32 %18, 1
store i32 %21, i32* %0
%22 = icmp eq i32 %21, %14
br i1 %22, label %23, label %27
23: ; preds = %17
%24 = add nsw i32 %14, 1000
%25 = shl i32 %24, 3
%26 = tail call i8** @realloc(i8** %13, i32 %25)
br label %27
27: ; preds = %17, %23
%28 = phi i32 [ %24, %23 ], [ %14, %17 ]
%29 = phi i8** [ %26, %23 ], [ %13, %17 ]
%30 = tail call i8* @nextToken(i32 0, i32 0)
%31 = icmp eq i8* %30, null
br i1 %31, label %32, label %11
32: ; preds = %11, %27, %8
%33 = phi i8** [ %3, %8 ], [ %29, %27 ], [ %13, %11 ]
ret i8** %33
}