#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*/ puts(char *);
int /*<<< orphan*/ *s_gets(char *, int);
int /*<<< orphan*/ sort(char **, int);
int main(void) {
  char input[20][81];
  char *ptstr[20];
  int count = 0;
  int k;
  printf("Input up to %d lines, then sort.\n", 20);
  printf("To stop, press the Enter key at a line's start.\n");
  while (count < 20 && s_gets(input[count], 81) != NULL &&
         input[count][0] != '\0') {
    ptstr[count] = input[count];
    count++;
  }
  sort(ptstr, count);
  puts("\nHere's the sorted list:\n");
  for (k = 0; k < count; k++)
    puts(ptstr[k]);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x710,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x704(%rbp)
lea    0xe9d(%rip),%rdi
mov    $0x14,%esi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xeac(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %eax,%eax
cmpl   $0x14,-0x704(%rbp)
mov    %al,-0x709(%rbp)
jge    11ea <main+0xaa>
movslq -0x704(%rbp),%rax
lea    -0x660(%rbp),%rdi
imul   $0x51,%rax,%rax
add    %rax,%rdi
mov    $0x51,%esi
call   1040 <s_gets@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x709(%rbp)
je     11ea <main+0xaa>
movslq -0x704(%rbp),%rcx
lea    -0x660(%rbp),%rax
imul   $0x51,%rcx,%rcx
add    %rcx,%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x709(%rbp)
mov    -0x709(%rbp),%al
test   $0x1,%al
jne    11fd <main+0xbd>
jmp    1235 <main+0xf5>
movslq -0x704(%rbp),%rax
lea    -0x660(%rbp),%rcx
imul   $0x51,%rax,%rax
add    %rax,%rcx
movslq -0x704(%rbp),%rax
mov    %rcx,-0x700(%rbp,%rax,8)
ff
mov    -0x704(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x704(%rbp)
jmp    117d <main+0x3d>
lea    -0x700(%rbp),%rdi
mov    -0x704(%rbp),%esi
call   1060 <sort@plt>
lea    0xe05(%rip),%rdi
call   1030 <puts@plt>
movl   $0x0,-0x708(%rbp)
mov    -0x708(%rbp),%eax
cmp    -0x704(%rbp),%eax
jge    1297 <main+0x157>
movslq -0x708(%rbp),%rax
mov    -0x700(%rbp,%rax,8),%rdi
ff
call   1030 <puts@plt>
mov    -0x708(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x708(%rbp)
jmp    125d <main+0x11d>
xor    %eax,%eax
add    $0x710,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x6f8,%rsp
lea    0xeaf(%rip),%rdi
xor    %r14d,%r14d
mov    $0x14,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xed5(%rip),%rdi
call   1030 <puts@plt>
lea    0xa0(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rdi
mov    $0x51,%esi
call   1040 <s_gets@plt>
test   %rax,%rax
je     11af <main+0x6f>
cmpb   $0x0,(%rbx)
je     11af <main+0x6f>
mov    %rbx,(%rsp,%r14,8)
add    $0x1,%r14
add    $0x51,%rbx
cmp    $0x14,%r14
jne    1180 <main+0x40>
mov    $0x14,%r14d
mov    %rsp,%rdi
mov    %r14d,%esi
call   1060 <sort@plt>
lea    0xe61(%rip),%rdi
call   1030 <puts@plt>
test   %r14d,%r14d
je     11e2 <main+0xa2>
mov    %r14d,%r14d
xor    %ebx,%ebx
mov    (%rsp,%rbx,8),%rdi
call   1030 <puts@plt>
add    $0x1,%rbx
cmp    %rbx,%r14
jne    11d0 <main+0x90>
xor    %eax,%eax
add    $0x6f8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [34 x i8] c"Input up to %d lines, then sort.\0A\00"
@.str.1 = [49 x i8] c"To stop, press the Enter key at a line's start.\0A\00"
@.str.2 = [26 x i8] c"\0AHere's the sorted list:\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [20 x [81 x i8]]
%3 = alloca [20 x i8*]
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %4
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 20)
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.1, i64 0, i64 0))
br label %8
8: ; preds = %28, %0
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 20
br i1 %10, label %11, label %26
11: ; preds = %8
%12 = load i32, i32* %4
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds [20 x [81 x i8]], [20 x [81 x i8]]* %2, i64 0, i64 %13
%15 = getelementptr inbounds [81 x i8], [81 x i8]* %14, i64 0, i64 0
%16 = call i32* @s_gets(i8* %15, i32 81)
%17 = icmp ne i32* %16, null
br i1 %17, label %18, label %26
18: ; preds = %11
%19 = load i32, i32* %4
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [20 x [81 x i8]], [20 x [81 x i8]]* %2, i64 0, i64 %20
%22 = getelementptr inbounds [81 x i8], [81 x i8]* %21, i64 0, i64 0
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp ne i32 %24, 0
br label %26
26: ; preds = %18, %11, %8
%27 = phi i1 [ false, %11 ], [ false, %8 ], [ %25, %18 ]
br i1 %27, label %28, label %38
28: ; preds = %26
%29 = load i32, i32* %4
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [20 x [81 x i8]], [20 x [81 x i8]]* %2, i64 0, i64 %30
%32 = getelementptr inbounds [81 x i8], [81 x i8]* %31, i64 0, i64 0
%33 = load i32, i32* %4
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds [20 x i8*], [20 x i8*]* %3, i64 0, i64 %34
store i8* %32, i8** %35
%36 = load i32, i32* %4
%37 = add nsw i32 %36, 1
store i32 %37, i32* %4
br label %8
38: ; preds = %26
%39 = getelementptr inbounds [20 x i8*], [20 x i8*]* %3, i64 0, i64 0
%40 = load i32, i32* %4
%41 = call i32 @sort(i8** %39, i32 %40)
%42 = call i32 @puts(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %5
br label %43
43: ; preds = %53, %38
%44 = load i32, i32* %5
%45 = load i32, i32* %4
%46 = icmp slt i32 %44, %45
br i1 %46, label %47, label %56
47: ; preds = %43
%48 = load i32, i32* %5
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds [20 x i8*], [20 x i8*]* %3, i64 0, i64 %49
%51 = load i8*, i8** %50
%52 = call i32 @puts(i8* %51)
br label %53
53: ; preds = %47
%54 = load i32, i32* %5
%55 = add nsw i32 %54, 1
store i32 %55, i32* %5
br label %43
56: ; preds = %43
ret i32 0
}

LLVM IR (-O2):
@.str = [34 x i8] c"Input up to %d lines, then sort.\0A\00"
@.str.2 = [26 x i8] c"\0AHere's the sorted list:\0A\00"
@str = [48 x i8] c"To stop, press the Enter key at a line's start.\00"
define i32 @main() {
%1 = alloca [20 x [81 x i8]]
%2 = alloca [20 x i8*]
%3 = getelementptr inbounds [20 x [81 x i8]], [20 x [81 x i8]]* %1, i64 0, i64 0, i64 0
%4 = bitcast [20 x i8*]* %2 to i8*
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 20)
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @str, i64 0, i64 0))
br label %7
7: ; preds = %0, %15
%8 = phi i64 [ 0, %0 ], [ %17, %15 ]
%9 = getelementptr inbounds [20 x [81 x i8]], [20 x [81 x i8]]* %1, i64 0, i64 %8, i64 0
%10 = call i32* @s_gets(i8* %9, i32 81)
%11 = icmp eq i32* %10, null
br i1 %11, label %19, label %12
12: ; preds = %7
%13 = load i8, i8* %9
%14 = icmp eq i8 %13, 0
br i1 %14, label %21, label %15
15: ; preds = %12
%16 = getelementptr inbounds [20 x i8*], [20 x i8*]* %2, i64 0, i64 %8
store i8* %9, i8** %16
%17 = add nuw nsw i64 %8, 1
%18 = icmp eq i64 %17, 20
br i1 %18, label %23, label %7
19: ; preds = %7
%20 = trunc i64 %8 to i32
br label %23
21: ; preds = %12
%22 = trunc i64 %8 to i32
br label %23
23: ; preds = %15, %21, %19
%24 = phi i32 [ %20, %19 ], [ %22, %21 ], [ 20, %15 ]
%25 = getelementptr inbounds [20 x i8*], [20 x i8*]* %2, i64 0, i64 0
%26 = call i32 @sort(i8** %25, i32 %24)
%27 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
%28 = icmp eq i32 %24, 0
br i1 %28, label %38, label %29
29: ; preds = %23
%30 = zext i32 %24 to i64
br label %31
31: ; preds = %29, %31
%32 = phi i64 [ 0, %29 ], [ %36, %31 ]
%33 = getelementptr inbounds [20 x i8*], [20 x i8*]* %2, i64 0, i64 %32
%34 = load i8*, i8** %33
%35 = call i32 @puts(i8* dereferenceable(1) %34)
%36 = add nuw nsw i64 %32, 1
%37 = icmp eq i64 %36, %30
br i1 %37, label %38, label %31
38: ; preds = %31, %23
ret i32 0
}