#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 /*<<< orphan*/ qsort(char **, int /*<<< orphan*/, int);
int readlines(char **, char *, int);
int /*<<< orphan*/ writelines(char **, int);
int main(void) {
  int nlines;
  char buf[1000 * 5000];
  char *lineptr[5000];
  if ((nlines = readlines(lineptr, buf, 5000)) >= 0) {
    qsort(lineptr, 0, nlines - 1);
    writelines(lineptr, nlines);
    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    -0x4ce790(%rbp),%rdi
lea    -0x4c4b50(%rbp),%rsi
mov    $0x1388,%edx
call   1060 <readlines@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jl     11a5 <main+0x65>
lea    -0x4ce790(%rbp),%rdi
mov    -0x8(%rbp),%edx
sub    $0x1,%edx
xor    %esi,%esi
call   1030 <qsort@plt>
lea    -0x4ce790(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1050 <writelines@plt>
movl   $0x0,-0x4(%rbp)
jmp    11b8 <main+0x78>
lea    0xe54(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-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
mov    $0x1388,%edx
call   1060 <readlines@plt>
test   %eax,%eax
js     1186 <main+0x46>
mov    %eax,%ebx
mov    %eax,%edx
add    $0xffffffff,%edx
mov    %rsp,%r14
xor    %ebp,%ebp
mov    %r14,%rdi
xor    %esi,%esi
call   1040 <qsort@plt>
mov    %r14,%rdi
mov    %ebx,%esi
call   1050 <writelines@plt>
jmp    1197 <main+0x57>
lea    0xe73(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%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 [5000000 x i8]
%4 = alloca [5000 x i8*]
store i32 0, i32* %1
%5 = getelementptr inbounds [5000 x i8*], [5000 x i8*]* %4, i64 0, i64 0
%6 = getelementptr inbounds [5000000 x i8], [5000000 x i8]* %3, i64 0, i64 0
%7 = call i32 @readlines(i8** %5, i8* %6, i32 5000)
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*]* %4, i64 0, i64 0
%11 = load i32, i32* %2
%12 = sub nsw i32 %11, 1
%13 = call i32 @qsort(i8** %10, i32 0, i32 %12)
%14 = getelementptr inbounds [5000 x i8*], [5000 x i8*]* %4, i64 0, i64 0
%15 = load i32, i32* %2
%16 = call i32 @writelines(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 [5000000 x i8]
%2 = alloca [5000 x i8*]
%3 = getelementptr inbounds [5000000 x i8], [5000000 x i8]* %1, i64 0, i64 0
%4 = bitcast [5000 x i8*]* %2 to i8*
%5 = getelementptr inbounds [5000 x i8*], [5000 x i8*]* %2, i64 0, i64 0
%6 = call i32 @readlines(i8** %5, i8* %3, i32 5000)
%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 @qsort(i8** %5, i32 0, i32 %9)
%11 = call i32 @writelines(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
}