#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 addIfNew(char **, int, char *);
scalar_t__ calloc(int, int);
char *copyUntilTab(char *);
int /*<<< orphan*/ free(char *);
char **uniqueFiles(char **fileClassPairs, int nfiles, int *nUniqueFiles) {
  int k = 0;
  int i;
  char *filename;
  char **uniqueFilenames = (char **)calloc(nfiles, sizeof(char *));
  for (i = 0; i < nfiles; i++) {
    filename = copyUntilTab(fileClassPairs[i]);
    k = addIfNew(uniqueFilenames, k, filename);
    free(filename);
  }
  *nUniqueFiles = k;
  return uniqueFilenames;
}


x86 assembly (clang, -O0):
<uniqueFiles>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0xc(%rbp),%edi
mov    $0x8,%esi
call   1060 <calloc@plt>
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11bd <uniqueFiles+0x7d>
mov    -0x8(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1040 <copyUntilTab@plt>
mov    %rax,-0x28(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x28(%rbp),%rdx
call   1050 <addIfNew@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1172 <uniqueFiles+0x32>
mov    -0x1c(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x30(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<uniqueFiles>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,(%rsp)
mov    %esi,%ebp
mov    %rdi,%r15
mov    %esi,%edi
mov    $0x8,%esi
call   1060 <calloc@plt>
mov    %rax,%r12
test   %ebp,%ebp
jle    119e <uniqueFiles+0x5e>
mov    %ebp,%r13d
xor    %r14d,%r14d
xor    %ebp,%ebp
nop
mov    (%r15,%r14,8),%rdi
call   1040 <copyUntilTab@plt>
mov    %rax,%rbx
mov    %r12,%rdi
mov    %ebp,%esi
mov    %rax,%rdx
call   1050 <addIfNew@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <free@plt>
add    $0x1,%r14
cmp    %r14,%r13
jne    1170 <uniqueFiles+0x30>
jmp    11a0 <uniqueFiles+0x60>
xor    %ebp,%ebp
mov    (%rsp),%rax
mov    %ebp,(%rax)
mov    %r12,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8** @uniqueFiles(i8** %0, i32 %1, i32* %2) {
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i8**
store i8** %0, i8*** %4
store i32 %1, i32* %5
store i32* %2, i32** %6
store i32 0, i32* %7
%11 = load i32, i32* %5
%12 = call i64 @calloc(i32 %11, i32 8)
%13 = inttoptr i64 %12 to i8**
store i8** %13, i8*** %10
store i32 0, i32* %8
br label %14
14: ; preds = %31, %3
%15 = load i32, i32* %8
%16 = load i32, i32* %5
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %34
18: ; preds = %14
%19 = load i8**, i8*** %4
%20 = load i32, i32* %8
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8*, i8** %19, i64 %21
%23 = load i8*, i8** %22
%24 = call i8* @copyUntilTab(i8* %23)
store i8* %24, i8** %9
%25 = load i8**, i8*** %10
%26 = load i32, i32* %7
%27 = load i8*, i8** %9
%28 = call i32 @addIfNew(i8** %25, i32 %26, i8* %27)
store i32 %28, i32* %7
%29 = load i8*, i8** %9
%30 = call i32 @free(i8* %29)
br label %31
31: ; preds = %18
%32 = load i32, i32* %8
%33 = add nsw i32 %32, 1
store i32 %33, i32* %8
br label %14
34: ; preds = %14
%35 = load i32, i32* %7
%36 = load i32*, i32** %6
store i32 %35, i32* %36
%37 = load i8**, i8*** %10
ret i8** %37
}

LLVM IR (-O2):
define i8** @uniqueFiles(i8** nocapture %0, i32 %1, i32* nocapture writeonly %2) {
%4 = tail call i64 @calloc(i32 %1, i32 8)
%5 = inttoptr i64 %4 to i8**
%6 = icmp sgt i32 %1, 0
br i1 %6, label %7, label %19
7: ; preds = %3
%8 = zext i32 %1 to i64
br label %9
9: ; preds = %7, %9
%10 = phi i64 [ 0, %7 ], [ %17, %9 ]
%11 = phi i32 [ 0, %7 ], [ %15, %9 ]
%12 = getelementptr inbounds i8*, i8** %0, i64 %10
%13 = load i8*, i8** %12
%14 = tail call i8* @copyUntilTab(i8* %13)
%15 = tail call i32 @addIfNew(i8** %5, i32 %11, i8* %14)
%16 = tail call i32 @free(i8* %14)
%17 = add nuw nsw i64 %10, 1
%18 = icmp eq i64 %17, %8
br i1 %18, label %19, label %9
19: ; preds = %9, %3
%20 = phi i32 [ 0, %3 ], [ %15, %9 ]
store i32 %20, i32* %2
ret i8** %5
}