#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 int /*<<< orphan*/ FILE;

/* Variables and functions */
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, int *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
int main(int argc, const char *argv[]) {
  FILE *file = fopen(argv[1], "r");
  char line[1024];
  char string_array[40][1024];
  int n = 0, keep = 0;
  fscanf(file, "%d\n", &keep);
  while (fgets(line, 1024, file)) {
    n++;
    for (int i = 0; i < n; i++) {
      if (strlen(string_array[i]) < strlen(line)) {
        for (int j = n; j >= i; j--) {
          strcpy(string_array[j], string_array[j - 1]);
        }
        strcpy(string_array[i], line);
        break;
      }
    }
  }
  for (int i = 0; i < keep; i++) {
    printf("%s", string_array[i]);
  }
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa440,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe78(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0xa424(%rbp)
movl   $0x0,-0xa428(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe52(%rip),%rsi
lea    -0xa428(%rbp),%rdx
call   1060 <fscanf@plt>
lea    -0x420(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x400,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
je     12ef <main+0x18f>
mov    -0xa424(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xa424(%rbp)
movl   $0x0,-0xa42c(%rbp)
mov    -0xa42c(%rbp),%eax
cmp    -0xa424(%rbp),%eax
jge    12ea <main+0x18a>
movslq -0xa42c(%rbp),%rax
lea    -0xa420(%rbp),%rdi
shl    $0xa,%rax
add    %rax,%rdi
call   1040 <strlen@plt>
mov    %rax,-0xa440(%rbp)
lea    -0x420(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0xa440(%rbp),%rax
cmp    %rcx,%rax
jge    12d1 <main+0x171>
mov    -0xa424(%rbp),%eax
mov    %eax,-0xa430(%rbp)
mov    -0xa430(%rbp),%eax
cmp    -0xa42c(%rbp),%eax
jl     12ab <main+0x14b>
movslq -0xa430(%rbp),%rax
lea    -0xa420(%rbp),%rdi
shl    $0xa,%rax
add    %rax,%rdi
mov    -0xa430(%rbp),%eax
sub    $0x1,%eax
cltq
lea    -0xa420(%rbp),%rsi
shl    $0xa,%rax
add    %rax,%rsi
call   1030 <strcpy@plt>
mov    -0xa430(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xa430(%rbp)
jmp    1252 <main+0xf2>
movslq -0xa42c(%rbp),%rax
lea    -0xa420(%rbp),%rdi
shl    $0xa,%rax
add    %rax,%rdi
lea    -0x420(%rbp),%rsi
call   1030 <strcpy@plt>
jmp    12ea <main+0x18a>
jmp    12d6 <main+0x176>
mov    -0xa42c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xa42c(%rbp)
jmp    11f4 <main+0x94>
jmp    11bc <main+0x5c>
movl   $0x0,-0xa434(%rbp)
mov    -0xa434(%rbp),%eax
cmp    -0xa428(%rbp),%eax
jge    1340 <main+0x1e0>
movslq -0xa434(%rbp),%rax
lea    -0xa420(%rbp),%rsi
shl    $0xa,%rax
add    %rax,%rsi
lea    0xcdf(%rip),%rdi
call   1050 <printf@plt>
mov    -0xa434(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xa434(%rbp)
jmp    12f9 <main+0x199>
xor    %eax,%eax
add    $0xa440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xa428,%rsp
mov    0x8(%rsi),%rdi
lea    0xe84(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%rbx
movl   $0x0,0x4(%rsp)
lea    0xe6f(%rip),%rsi
lea    0x4(%rsp),%rdx
mov    %rax,%rdi
call   1060 <fscanf@plt>
lea    0x20(%rsp),%rdi
mov    $0x400,%esi
mov    %rbx,0x18(%rsp)
mov    %rbx,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     12d4 <main+0x174>
xor    %eax,%eax
mov    %rax,0x8(%rsp)
mov    $0x1,%ecx
lea    0x20(%rsp),%rbx
jmp    1216 <main+0xb6>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
lea    0x20(%rsp),%rsi
call   1030 <strcpy@plt>
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x400,%esi
mov    0x18(%rsp),%rdx
call   1070 <fgets@plt>
mov    0x10(%rsp),%rcx
add    $0x1,%rcx
test   %rax,%rax
je     12d4 <main+0x174>
mov    %rcx,0x10(%rsp)
movslq %ecx,%rax
lea    0x1(%rax),%rbp
shl    $0xa,%rax
lea    (%rsp,%rax,1),%r12
add    $0x420,%r12
mov    0x8(%rsp),%rax
add    $0x1,%eax
mov    %rax,0x8(%rsp)
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %rax,%r13
lea    0x420(%rsp),%rbx
xor    %r15d,%r15d
xor    %r14d,%r14d
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1040 <strlen@plt>
cmp    %r13,%rax
jl     12a0 <main+0x140>
add    $0x1,%r14
movabs $0x100000000,%rax
add    %rax,%r15
add    $0x400,%rbx
cmp    %r14,0x10(%rsp)
jne    1260 <main+0x100>
jmp    11ed <main+0x8d>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
cmp    %r14d,0x8(%rsp)
jb     11e0 <main+0x80>
sar    $0x20,%r15
nop
lea    -0x400(%r12),%r13
ff
mov    %r12,%rdi
mov    %r13,%rsi
call   1030 <strcpy@plt>
add    $0xffffffffffffffff,%rbp
mov    %r13,%r12
cmp    %r15,%rbp
jg     12b0 <main+0x150>
jmp    11e0 <main+0x80>
cmpl   $0x0,0x4(%rsp)
jle    1310 <main+0x1b0>
lea    0x420(%rsp),%rbx
xor    %ebp,%ebp
lea    0xd1a(%rip),%r14
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
add    $0x1,%rbp
movslq 0x4(%rsp),%rax
add    $0x400,%rbx
cmp    %rax,%rbp
jl     12f0 <main+0x190>
xor    %eax,%eax
add    $0xa428,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [4 x i8] c"%d\0A\00"
@.str.2 = [3 x i8] c"%s\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca [1024 x i8]
%8 = alloca [40 x [1024 x i8]]
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = call i32* @fopen(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %17, i32** %6
store i32 0, i32* %9
store i32 0, i32* %10
%18 = load i32*, i32** %6
%19 = call i32 @fscanf(i32* %18, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32* %10)
br label %20
20: ; preds = %72, %2
%21 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%22 = load i32*, i32** %6
%23 = call i64 @fgets(i8* %21, i32 1024, i32* %22)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %73
25: ; preds = %20
%26 = load i32, i32* %9
%27 = add nsw i32 %26, 1
store i32 %27, i32* %9
store i32 0, i32* %11
br label %28
28: ; preds = %69, %25
%29 = load i32, i32* %11
%30 = load i32, i32* %9
%31 = icmp slt i32 %29, %30
br i1 %31, label %32, label %72
32: ; preds = %28
%33 = load i32, i32* %11
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds [40 x [1024 x i8]], [40 x [1024 x i8]]* %8, i64 0, i64 %34
%36 = getelementptr inbounds [1024 x i8], [1024 x i8]* %35, i64 0, i64 0
%37 = call i64 @strlen(i8* %36)
%38 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%39 = call i64 @strlen(i8* %38)
%40 = icmp slt i64 %37, %39
br i1 %40, label %41, label %68
41: ; preds = %32
%42 = load i32, i32* %9
store i32 %42, i32* %12
br label %43
43: ; preds = %58, %41
%44 = load i32, i32* %12
%45 = load i32, i32* %11
%46 = icmp sge i32 %44, %45
br i1 %46, label %47, label %61
47: ; preds = %43
%48 = load i32, i32* %12
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds [40 x [1024 x i8]], [40 x [1024 x i8]]* %8, i64 0, i64 %49
%51 = getelementptr inbounds [1024 x i8], [1024 x i8]* %50, i64 0, i64 0
%52 = load i32, i32* %12
%53 = sub nsw i32 %52, 1
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds [40 x [1024 x i8]], [40 x [1024 x i8]]* %8, i64 0, i64 %54
%56 = getelementptr inbounds [1024 x i8], [1024 x i8]* %55, i64 0, i64 0
%57 = call i32 @strcpy(i8* %51, i8* %56)
br label %58
58: ; preds = %47
%59 = load i32, i32* %12
%60 = add nsw i32 %59, -1
store i32 %60, i32* %12
br label %43
61: ; preds = %43
%62 = load i32, i32* %11
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds [40 x [1024 x i8]], [40 x [1024 x i8]]* %8, i64 0, i64 %63
%65 = getelementptr inbounds [1024 x i8], [1024 x i8]* %64, i64 0, i64 0
%66 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%67 = call i32 @strcpy(i8* %65, i8* %66)
br label %72
68: ; preds = %32
br label %69
69: ; preds = %68
%70 = load i32, i32* %11
%71 = add nsw i32 %70, 1
store i32 %71, i32* %11
br label %28
72: ; preds = %61, %28
br label %20
73: ; preds = %20
store i32 0, i32* %13
br label %74
74: ; preds = %84, %73
%75 = load i32, i32* %13
%76 = load i32, i32* %10
%77 = icmp slt i32 %75, %76
br i1 %77, label %78, label %87
78: ; preds = %74
%79 = load i32, i32* %13
%80 = sext i32 %79 to i64
%81 = getelementptr inbounds [40 x [1024 x i8]], [40 x [1024 x i8]]* %8, i64 0, i64 %80
%82 = getelementptr inbounds [1024 x i8], [1024 x i8]* %81, i64 0, i64 0
%83 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %82)
br label %84
84: ; preds = %78
%85 = load i32, i32* %13
%86 = add nsw i32 %85, 1
store i32 %86, i32* %13
br label %74
87: ; preds = %74
ret i32 0
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [4 x i8] c"%d\0A\00"
@.str.2 = [3 x i8] c"%s\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = alloca [40 x [1024 x i8]]
%5 = alloca i32
%6 = getelementptr inbounds i8*, i8** %1, i64 1
%7 = load i8*, i8** %6
%8 = tail call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%10 = getelementptr inbounds [40 x [1024 x i8]], [40 x [1024 x i8]]* %4, i64 0, i64 0, i64 0
%11 = bitcast i32* %5 to i8*
store i32 0, i32* %5
%12 = call i32 @fscanf(i32* %8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32* %5)
%13 = call i64 @fgets(i8* %9, i32 1024, i32* %8)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %48, %2
%16 = load i32, i32* %5
%17 = icmp sgt i32 %16, 0
br i1 %17, label %53, label %52
18: ; preds = %2, %48
%19 = phi i32 [ %51, %48 ], [ 1, %2 ]
%20 = phi i32 [ %22, %48 ], [ 0, %2 ]
%21 = sext i32 %19 to i64
%22 = add nuw nsw i32 %20, 1
%23 = call i64 @strlen(i8* %9)
%24 = zext i32 %19 to i64
br label %25
25: ; preds = %18, %45
%26 = phi i64 [ 0, %18 ], [ %46, %45 ]
%27 = getelementptr inbounds [40 x [1024 x i8]], [40 x [1024 x i8]]* %4, i64 0, i64 %26, i64 0
%28 = call i64 @strlen(i8* %27)
%29 = icmp slt i64 %28, %23
br i1 %29, label %30, label %45
30: ; preds = %25
%31 = trunc i64 %26 to i32
%32 = icmp ult i32 %22, %31
br i1 %32, label %36, label %33
33: ; preds = %30
%34 = shl i64 %26, 32
%35 = ashr exact i64 %34, 32
br label %38
36: ; preds = %38, %30
%37 = call i32 @strcpy(i8* %27, i8* %9)
br label %48
38: ; preds = %33, %38
%39 = phi i64 [ %21, %33 ], [ %41, %38 ]
%40 = getelementptr inbounds [40 x [1024 x i8]], [40 x [1024 x i8]]* %4, i64 0, i64 %39, i64 0
%41 = add nsw i64 %39, -1
%42 = getelementptr inbounds [40 x [1024 x i8]], [40 x [1024 x i8]]* %4, i64 0, i64 %41, i64 0
%43 = call i32 @strcpy(i8* %40, i8* %42)
%44 = icmp sgt i64 %39, %35
br i1 %44, label %38, label %36
45: ; preds = %25
%46 = add nuw nsw i64 %26, 1
%47 = icmp eq i64 %46, %24
br i1 %47, label %48, label %25
48: ; preds = %45, %36
%49 = call i64 @fgets(i8* %9, i32 1024, i32* %8)
%50 = icmp eq i64 %49, 0
%51 = add nuw i32 %19, 1
br i1 %50, label %15, label %18
52: ; preds = %53, %15
ret i32 0
53: ; preds = %15, %53
%54 = phi i64 [ %57, %53 ], [ 0, %15 ]
%55 = getelementptr inbounds [40 x [1024 x i8]], [40 x [1024 x i8]]* %4, i64 0, i64 %54, i64 0
%56 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %55)
%57 = add nuw nsw i64 %54, 1
%58 = load i32, i32* %5
%59 = sext i32 %58 to i64
%60 = icmp slt i64 %57, %59
br i1 %60, label %53, label %52
}