#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 /*<<< orphan*/ printf(char *);
int read_lines(char **, char *);
int /*<<< orphan*/ string_sort(char **, int /*<<< orphan*/, int);
int /*<<< orphan*/ write_lines(char **, int);
int main(void) {
  int lines_count;
  char *line_pointer_array[5000];
  char lines_buffer[5000 * 1000];
  if ((lines_count = read_lines(line_pointer_array, lines_buffer)) >= 0) {
    string_sort(line_pointer_array, 0, lines_count - 1);
    write_lines(line_pointer_array, lines_count);
    return 0;
  } else {
    printf("error: input too big to sort\n");
    return 1;
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4ce790,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x9c50(%rbp),%rdi
lea    -0x4ce790(%rbp),%rsi
call   1060 <read_lines@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jl     11a0 <main+0x60>
lea    -0x9c50(%rbp),%rdi
mov    -0x8(%rbp),%edx
sub    $0x1,%edx
xor    %esi,%esi
call   1040 <string_sort@plt>
lea    -0x9c50(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1030 <write_lines@plt>
movl   $0x0,-0x4(%rbp)
jmp    11b3 <main+0x73>
lea    0xe59(%rip),%rdi
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x4ce790,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x4ce780,%rsp
mov    %rsp,%rdi
lea    0x9c40(%rsp),%rsi
call   1060 <read_lines@plt>
test   %eax,%eax
js     1181 <main+0x41>
mov    %eax,%ebx
mov    %eax,%edx
add    $0xffffffff,%edx
mov    %rsp,%r14
xor    %ebp,%ebp
mov    %r14,%rdi
xor    %esi,%esi
call   1050 <string_sort@plt>
mov    %r14,%rdi
mov    %ebx,%esi
call   1030 <write_lines@plt>
jmp    1192 <main+0x52>
lea    0xe78(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x4ce780,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [30 x i8] c"error: input too big to sort\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [5000 x i8*]
%4 = alloca [5000000 x i8]
store i32 0, i32* %1
%5 = getelementptr inbounds [5000 x i8*], [5000 x i8*]* %3, i64 0, i64 0
%6 = getelementptr inbounds [5000000 x i8], [5000000 x i8]* %4, i64 0, i64 0
%7 = call i32 @read_lines(i8** %5, i8* %6)
store i32 %7, i32* %2
%8 = icmp sge i32 %7, 0
br i1 %8, label %9, label %17
9: ; preds = %0
%10 = getelementptr inbounds [5000 x i8*], [5000 x i8*]* %3, i64 0, i64 0
%11 = load i32, i32* %2
%12 = sub nsw i32 %11, 1
%13 = call i32 @string_sort(i8** %10, i32 0, i32 %12)
%14 = getelementptr inbounds [5000 x i8*], [5000 x i8*]* %3, i64 0, i64 0
%15 = load i32, i32* %2
%16 = call i32 @write_lines(i8** %14, i32 %15)
store i32 0, i32* %1
br label %19
17: ; preds = %0
%18 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %1
br label %19
19: ; preds = %17, %9
%20 = load i32, i32* %1
ret i32 %20
}

LLVM IR (-O2):
@str = [29 x i8] c"error: input too big to sort\00"
define i32 @main() {
%1 = alloca [5000 x i8*]
%2 = alloca [5000000 x i8]
%3 = bitcast [5000 x i8*]* %1 to i8*
%4 = getelementptr inbounds [5000000 x i8], [5000000 x i8]* %2, i64 0, i64 0
%5 = getelementptr inbounds [5000 x i8*], [5000 x i8*]* %1, i64 0, i64 0
%6 = call i32 @read_lines(i8** %5, i8* %4)
%7 = icmp sgt i32 %6, -1
br i1 %7, label %8, label %12
8: ; preds = %0
%9 = add nsw i32 %6, -1
%10 = call i32 @string_sort(i8** %5, i32 0, i32 %9)
%11 = call i32 @write_lines(i8** %5, i32 %6)
br label %14
12: ; preds = %0
%13 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str, i64 0, i64 0))
br label %14
14: ; preds = %12, %8
%15 = phi i32 [ 0, %8 ], [ 1, %12 ]
ret i32 %15
}