#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 */
typedef void *uint32_t;

/* Variables and functions */
void *atoi(char *);
int buildSuffixArraysForAllFiles(char *, int);
int mergeSuffixArraysIntoSA_LCP(char *, int, void *, void *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int main(int argc, char *argv[]) {
  char inputFileNamePrefix[500];
  uint32_t availmemoryInputBuffersBytes;
  uint32_t maxOutputBufferElements;
  int result;
  int totalInputFiles;
  if (argc < 5) {
    printf("./buildandmerge <inputfilenamefullpathprefix> <total_files> "
           "<memory_bytes_for_inputbuffers>  <max_elements_output_buffer>\n");
    return 1;
  }
  sprintf(inputFileNamePrefix, "%s", argv[1]);
  totalInputFiles = atoi(argv[2]);
  availmemoryInputBuffersBytes = atoi(argv[3]);
  maxOutputBufferElements = atoi(argv[4]);
  result = buildSuffixArraysForAllFiles(inputFileNamePrefix, totalInputFiles);
  if (result != 0)
    return 1;
  return mergeSuffixArraysIntoSA_LCP(inputFileNamePrefix, totalInputFiles,
                                     availmemoryInputBuffersBytes,
                                     maxOutputBufferElements);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x5,-0x8(%rbp)
jge    118b <main+0x3b>
lea    0xe86(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1235 <main+0xe5>
lea    -0x210(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xeda(%rip),%rsi
call   1070 <sprintf@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x228(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1060 <atoi@plt>
mov    %rax,-0x218(%rbp)
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdi
call   1060 <atoi@plt>
mov    %rax,-0x220(%rbp)
lea    -0x210(%rbp),%rdi
mov    -0x228(%rbp),%esi
call   1040 <buildSuffixArraysForAllFiles@plt>
mov    %eax,-0x224(%rbp)
cmpl   $0x0,-0x224(%rbp)
je     1212 <main+0xc2>
movl   $0x1,-0x4(%rbp)
jmp    1235 <main+0xe5>
lea    -0x210(%rbp),%rdi
mov    -0x228(%rbp),%esi
mov    -0x218(%rbp),%rdx
mov    -0x220(%rbp),%rcx
call   1050 <mergeSuffixArraysIntoSA_LCP@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x1f8,%rsp
cmp    $0x4,%edi
jg     1176 <main+0x26>
lea    0xe96(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%eax
jmp    11d3 <main+0x83>
mov    %rsi,%rbx
mov    0x8(%rsi),%rsi
mov    %rsp,%r12
mov    %r12,%rdi
call   1030 <strcpy@plt>
mov    0x10(%rbx),%rdi
call   1070 <atoi@plt>
mov    %rax,%r14
mov    0x18(%rbx),%rdi
call   1070 <atoi@plt>
mov    %rax,%r15
mov    0x20(%rbx),%rdi
call   1070 <atoi@plt>
mov    %rax,%rbx
mov    %r12,%rdi
mov    %r14d,%esi
call   1050 <buildSuffixArraysForAllFiles@plt>
mov    %eax,%ecx
mov    $0x1,%eax
test   %ecx,%ecx
jne    11d3 <main+0x83>
mov    %rsp,%rdi
mov    %r14d,%esi
mov    %r15,%rdx
mov    %rbx,%rcx
call   1060 <mergeSuffixArraysIntoSA_LCP@plt>
add    $0x1f8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [123 x i8] c"./buildandmerge <inputfilenamefullpathprefix> <total_files> <memory_bytes_for_inputbuffers> <max_elements_output_buffer>\0A\00"
@.str.1 = [3 x i8] c"%s\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [500 x i8]
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 5
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = call i32 @printf(i8* getelementptr inbounds ([123 x i8], [123 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %46
15: ; preds = %2
%16 = getelementptr inbounds [500 x i8], [500 x i8]* %6, i64 0, i64 0
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i32 @sprintf(i8* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %19)
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 2
%23 = load i8*, i8** %22
%24 = call i8* @atoi(i8* %23)
%25 = ptrtoint i8* %24 to i32
store i32 %25, i32* %10
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 3
%28 = load i8*, i8** %27
%29 = call i8* @atoi(i8* %28)
store i8* %29, i8** %7
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 4
%32 = load i8*, i8** %31
%33 = call i8* @atoi(i8* %32)
store i8* %33, i8** %8
%34 = getelementptr inbounds [500 x i8], [500 x i8]* %6, i64 0, i64 0
%35 = load i32, i32* %10
%36 = call i32 @buildSuffixArraysForAllFiles(i8* %34, i32 %35)
store i32 %36, i32* %9
%37 = load i32, i32* %9
%38 = icmp ne i32 %37, 0
br i1 %38, label %39, label %40
39: ; preds = %15
store i32 1, i32* %3
br label %46
40: ; preds = %15
%41 = getelementptr inbounds [500 x i8], [500 x i8]* %6, i64 0, i64 0
%42 = load i32, i32* %10
%43 = load i8*, i8** %7
%44 = load i8*, i8** %8
%45 = call i32 @mergeSuffixArraysIntoSA_LCP(i8* %41, i32 %42, i8* %43, i8* %44)
store i32 %45, i32* %3
br label %46
46: ; preds = %40, %39, %13
%47 = load i32, i32* %3
ret i32 %47
}

LLVM IR (-O2):
@str = [122 x i8] c"./buildandmerge <inputfilenamefullpathprefix> <total_files> <memory_bytes_for_inputbuffers> <max_elements_output_buffer>\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [500 x i8]
%4 = getelementptr inbounds [500 x i8], [500 x i8]* %3, i64 0, i64 0
%5 = icmp slt i32 %0, 5
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([122 x i8], [122 x i8]* @str, i64 0, i64 0))
br label %27
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = call i8* @strcpy(i8* %4, i8* dereferenceable(1) %10)
%12 = getelementptr inbounds i8*, i8** %1, i64 2
%13 = load i8*, i8** %12
%14 = call i8* @atoi(i8* %13)
%15 = ptrtoint i8* %14 to i64
%16 = trunc i64 %15 to i32
%17 = getelementptr inbounds i8*, i8** %1, i64 3
%18 = load i8*, i8** %17
%19 = call i8* @atoi(i8* %18)
%20 = getelementptr inbounds i8*, i8** %1, i64 4
%21 = load i8*, i8** %20
%22 = call i8* @atoi(i8* %21)
%23 = call i32 @buildSuffixArraysForAllFiles(i8* %4, i32 %16)
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %8
%26 = call i32 @mergeSuffixArraysIntoSA_LCP(i8* %4, i32 %16, i8* %19, i8* %22)
br label %27
27: ; preds = %8, %25, %6
%28 = phi i32 [ 1, %6 ], [ %26, %25 ], [ 1, %8 ]
ret i32 %28
}