#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 */
struct stat {
  scalar_t__ st_size;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fileno(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ fread(char *, size_t, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fstat(int /*<<< orphan*/, struct stat *);
char *malloc(size_t);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sortStrings(char **, int);
int /*<<< orphan*/ stdout;
size_t strlen(char *);
int main(int argc, char *argv[]) {
  FILE *fp = NULL;
  char *arr = NULL, *lines[100];
  struct stat statbuf;
  size_t size = 0;
  int i = 0, j = 0;
  if (argc < 2) {
    printf("\n input filename\n");
    return -1;
  }
  fp = fopen(argv[1], "r");
  if (NULL == fp)
    return -1;
  fstat(fileno(fp), &statbuf);
  size = (size_t)statbuf.st_size;
  printf("\n size:%lu\n", size);
  arr = malloc(size);
  if (NULL == arr)
    return -1;
  fread(arr, size, 1, fp);
  fputs(arr, stdout);
  lines[j] = &arr[i];
  arr[strlen(arr)] = '\0';
  while ('\0' != arr[i]) {
    if (arr[i] == '\n') {
      j++;
      arr[i] = '\0';
      lines[j] = &arr[i + 1];
    }
    i++;
  }
  sortStrings(lines, j);
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x360,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x350(%rbp)
movl   $0x0,-0x354(%rbp)
movl   $0x0,-0x358(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    120c <main+0x6c>
lea    0xe07(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13ae <main+0x20e>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdf7(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x18(%rbp)
xor    %eax,%eax
cmp    -0x18(%rbp),%rax
jne    123c <main+0x9c>
movl   $0xffffffff,-0x4(%rbp)
jmp    13ae <main+0x20e>
mov    -0x18(%rbp),%rdi
call   1090 <fileno@plt>
mov    %eax,%edi
lea    -0x348(%rbp),%rsi
call   10c0 <fstat@plt>
mov    -0x348(%rbp),%rax
mov    %rax,-0x350(%rbp)
mov    -0x350(%rbp),%rsi
lea    0xda5(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x350(%rbp),%rdi
call   10a0 <malloc@plt>
mov    %rax,-0x20(%rbp)
xor    %eax,%eax
cmp    -0x20(%rbp),%rax
jne    129e <main+0xfe>
movl   $0xffffffff,-0x4(%rbp)
jmp    13ae <main+0x20e>
mov    -0x20(%rbp),%rdi
mov    -0x350(%rbp),%rsi
mov    -0x18(%rbp),%rcx
mov    $0x1,%edx
call   1030 <fread@plt>
mov    -0x20(%rbp),%rdi
mov    0x2d1e(%rip),%rax
mov    (%rax),%esi
call   1080 <fputs@plt>
mov    -0x20(%rbp),%rcx
movslq -0x354(%rbp),%rax
add    %rax,%rcx
movslq -0x358(%rbp),%rax
mov    %rcx,-0x340(%rbp,%rax,8)
ff
mov    -0x20(%rbp),%rax
mov    %rax,-0x360(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,%rcx
mov    -0x360(%rbp),%rax
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
movslq -0x354(%rbp),%rcx
movsbl (%rax,%rcx,1),%ecx
xor    %eax,%eax
cmp    %ecx,%eax
je     138c <main+0x1ec>
mov    -0x20(%rbp),%rax
movslq -0x354(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    1378 <main+0x1d8>
mov    -0x358(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x358(%rbp)
mov    -0x20(%rbp),%rax
movslq -0x354(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rcx
mov    -0x354(%rbp),%eax
add    $0x1,%eax
cltq
add    %rax,%rcx
movslq -0x358(%rbp),%rax
mov    %rcx,-0x340(%rbp,%rax,8)
ff
mov    -0x354(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x354(%rbp)
jmp    1308 <main+0x168>
lea    -0x340(%rbp),%rdi
mov    -0x358(%rbp),%esi
call   1070 <sortStrings@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x360,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x330,%rsp
cmp    $0x1,%edi
jg     11da <main+0x2a>
lea    0xe43(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%ebp
jmp    12c0 <main+0x110>
mov    0x8(%rsi),%rdi
lea    0xe1b(%rip),%rsi
call   10c0 <fopen@plt>
mov    $0xffffffff,%ebp
test   %rax,%rax
je     12c0 <main+0x110>
mov    %rax,%r15
mov    %rax,%rdi
call   10a0 <fileno@plt>
lea    0x8(%rsp),%rsi
mov    %eax,%edi
call   10d0 <fstat@plt>
mov    0x8(%rsp),%r12
lea    0xde7(%rip),%rdi
xor    %r14d,%r14d
mov    %r12,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r12,%rdi
call   10b0 <malloc@plt>
test   %rax,%rax
je     12c0 <main+0x110>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r12,%rsi
mov    $0x1,%edx
mov    %r15,%rcx
call   1040 <fread@plt>
mov    0x2d8a(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1090 <fputs@plt>
mov    %rbx,0x10(%rsp)
mov    %rbx,%rdi
call   1060 <strlen@plt>
movb   $0x0,(%rbx,%rax,1)
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%rax
movzbl -0x1(%rbx,%rax,1),%ecx
test   %cl,%cl
je     12a9 <main+0xf9>
cmp    $0xa,%cl
jne    1280 <main+0xd0>
lea    (%rbx,%rax,1),%rcx
movb   $0x0,-0x1(%rbx,%rax,1)
mov    %r14d,%edx
add    $0x1,%r14d
mov    %rcx,0x18(%rsp,%rdx,8)
jmp    1280 <main+0xd0>
lea    0x10(%rsp),%rdi
mov    %r14d,%esi
call   1080 <sortStrings@plt>
mov    %r15,%rdi
call   1050 <fclose@plt>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x330,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i64 }
@.str = [18 x i8] c"\0A input filename\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [12 x i8] c"\0A size:%lu\0A\00"
@stdout = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca [100 x i8*]
%9 = alloca %struct.stat
%10 = alloca i64
%11 = alloca i32
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32* null, i32** %6
store i8* null, i8** %7
store i64 0, i64* %10
store i32 0, i32* %11
store i32 0, i32* %12
%13 = load i32, i32* %4
%14 = icmp slt i32 %13, 2
br i1 %14, label %15, label %17
15: ; preds = %2
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %97
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i32* @fopen(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %21, i32** %6
%22 = load i32*, i32** %6
%23 = icmp eq i32* null, %22
br i1 %23, label %24, label %25
24: ; preds = %17
store i32 -1, i32* %3
br label %97
25: ; preds = %17
%26 = load i32*, i32** %6
%27 = call i32 @fileno(i32* %26)
%28 = call i32 @fstat(i32 %27, %struct.stat* %9)
%29 = getelementptr inbounds %struct.stat, %struct.stat* %9, i32 0, i32 0
%30 = load i64, i64* %29
store i64 %30, i64* %10
%31 = load i64, i64* %10
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i64 %31)
%33 = load i64, i64* %10
%34 = call i8* @malloc(i64 %33)
store i8* %34, i8** %7
%35 = load i8*, i8** %7
%36 = icmp eq i8* null, %35
br i1 %36, label %37, label %38
37: ; preds = %25
store i32 -1, i32* %3
br label %97
38: ; preds = %25
%39 = load i8*, i8** %7
%40 = load i64, i64* %10
%41 = load i32*, i32** %6
%42 = call i32 @fread(i8* %39, i64 %40, i32 1, i32* %41)
%43 = load i8*, i8** %7
%44 = load i32, i32* @stdout
%45 = call i32 @fputs(i8* %43, i32 %44)
%46 = load i8*, i8** %7
%47 = load i32, i32* %11
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i8, i8* %46, i64 %48
%50 = load i32, i32* %12
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds [100 x i8*], [100 x i8*]* %8, i64 0, i64 %51
store i8* %49, i8** %52
%53 = load i8*, i8** %7
%54 = load i8*, i8** %7
%55 = call i64 @strlen(i8* %54)
%56 = getelementptr inbounds i8, i8* %53, i64 %55
store i8 0, i8* %56
br label %57
57: ; preds = %88, %38
%58 = load i8*, i8** %7
%59 = load i32, i32* %11
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds i8, i8* %58, i64 %60
%62 = load i8, i8* %61
%63 = sext i8 %62 to i32
%64 = icmp ne i32 0, %63
br i1 %64, label %65, label %91
65: ; preds = %57
%66 = load i8*, i8** %7
%67 = load i32, i32* %11
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds i8, i8* %66, i64 %68
%70 = load i8, i8* %69
%71 = sext i8 %70 to i32
%72 = icmp eq i32 %71, 10
br i1 %72, label %73, label %88
73: ; preds = %65
%74 = load i32, i32* %12
%75 = add nsw i32 %74, 1
store i32 %75, i32* %12
%76 = load i8*, i8** %7
%77 = load i32, i32* %11
%78 = sext i32 %77 to i64
%79 = getelementptr inbounds i8, i8* %76, i64 %78
store i8 0, i8* %79
%80 = load i8*, i8** %7
%81 = load i32, i32* %11
%82 = add nsw i32 %81, 1
%83 = sext i32 %82 to i64
%84 = getelementptr inbounds i8, i8* %80, i64 %83
%85 = load i32, i32* %12
%86 = sext i32 %85 to i64
%87 = getelementptr inbounds [100 x i8*], [100 x i8*]* %8, i64 0, i64 %86
store i8* %84, i8** %87
br label %88
88: ; preds = %73, %65
%89 = load i32, i32* %11
%90 = add nsw i32 %89, 1
store i32 %90, i32* %11
br label %57
91: ; preds = %57
%92 = getelementptr inbounds [100 x i8*], [100 x i8*]* %8, i64 0, i64 0
%93 = load i32, i32* %12
%94 = call i32 @sortStrings(i8** %92, i32 %93)
%95 = load i32*, i32** %6
%96 = call i32 @fclose(i32* %95)
store i32 0, i32* %3
br label %97
97: ; preds = %91, %37, %24, %15
%98 = load i32, i32* %3
ret i32 %98
}

LLVM IR (-O2):
%struct.stat = type { i64 }
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [12 x i8] c"\0A size:%lu\0A\00"
@stdout = global i32 0
@str = [17 x i8] c"\0A input filename\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [100 x i8*]
%4 = alloca %struct.stat
%5 = bitcast [100 x i8*]* %3 to i8*
%6 = bitcast %struct.stat* %4 to i8*
%7 = icmp slt i32 %0, 2
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
br label %49
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp eq i32* %13, null
br i1 %14, label %49, label %15
15: ; preds = %10
%16 = tail call i32 @fileno(i32* %13)
%17 = call i32 @fstat(i32 %16, %struct.stat* %4)
%18 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
%19 = load i64, i64* %18
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i64 %19)
%21 = tail call i8* @malloc(i64 %19)
%22 = icmp eq i8* %21, null
br i1 %22, label %49, label %23
23: ; preds = %15
%24 = tail call i32 @fread(i8* %21, i64 %19, i32 1, i32* %13)
%25 = load i32, i32* @stdout
%26 = tail call i32 @fputs(i8* %21, i32 %25)
%27 = getelementptr inbounds [100 x i8*], [100 x i8*]* %3, i64 0, i64 0
store i8* %21, i8** %27
%28 = tail call i64 @strlen(i8* %21)
%29 = getelementptr inbounds i8, i8* %21, i64 %28
store i8 0, i8* %29
br label %30
30: ; preds = %39, %23
%31 = phi i64 [ %42, %39 ], [ 0, %23 ]
%32 = phi i32 [ %41, %39 ], [ 0, %23 ]
br label %33
33: ; preds = %30, %37
%34 = phi i64 [ %38, %37 ], [ %31, %30 ]
%35 = getelementptr inbounds i8, i8* %21, i64 %34
%36 = load i8, i8* %35
switch i8 %36, label %37 [
i8 0, label %46
i8 10, label %39
]
37: ; preds = %33
%38 = add nuw i64 %34, 1
br label %33
39: ; preds = %33
%40 = getelementptr inbounds i8, i8* %21, i64 %34
%41 = add nuw nsw i32 %32, 1
store i8 0, i8* %40
%42 = add nuw i64 %34, 1
%43 = getelementptr inbounds i8, i8* %21, i64 %42
%44 = zext i32 %41 to i64
%45 = getelementptr inbounds [100 x i8*], [100 x i8*]* %3, i64 0, i64 %44
store i8* %43, i8** %45
br label %30
46: ; preds = %33
%47 = call i32 @sortStrings(i8** %27, i32 %32)
%48 = call i32 @fclose(i32* %13)
br label %49
49: ; preds = %15, %10, %46, %8
%50 = phi i32 [ -1, %8 ], [ 0, %46 ], [ -1, %10 ], [ -1, %15 ]
ret i32 %50
}