#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*/ EXIT_FAILURE;
int EXIT_SUCCESS;
void *calloc(size_t, int);
int /*<<< orphan*/ check_intInput(int *);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ free_array(char **, int);
int /*<<< orphan*/ insert_selection_sort(char **, int);
char *line_reading(int);
int /*<<< orphan*/ print_array(char **, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcpy(char *, char *);
char *strerror(int /*<<< orphan*/);
size_t strlen(char *);
int main() {
  printf("Enter number of city: ");
  int n;
  check_intInput(&n);
  char *line = NULL;
  char **cities = calloc(n, sizeof(char *));
  if (!cities) {
    fprintf(stderr, "%s", strerror(errno));
    exit(EXIT_FAILURE);
  }
  size_t lineLenght = 0;
  int i;
  for (i = 0; i < n; i++) {
    line = line_reading(20);
    lineLenght = strlen(line);
    cities[i] = calloc(lineLenght + 1, sizeof(char));
    if (!cities) {
      fprintf(stderr, "%s", strerror(errno));
      exit(EXIT_FAILURE);
    }
    strcpy(cities[i], line);
    free(line);
  }
  insert_selection_sort(cities, n);
  print_array(cities, n);
  free_array(cities, n);
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe1a(%rip),%rdi
call   1080 <printf@plt>
lea    -0x8(%rbp),%rdi
call   1040 <check_intInput@plt>
movq   $0x0,-0x10(%rbp)
movslq -0x8(%rbp),%rdi
mov    $0x8,%esi
call   10a0 <calloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1253 <main+0x83>
mov    0x2dc0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    0x2dac(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
mov    -0x28(%rbp),%edi
mov    %rax,%rdx
lea    0xdd7(%rip),%rsi
call   10b0 <fprintf@plt>
mov    0x2d84(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
movq   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    131b <main+0x14b>
mov    $0x14,%edi
call   10d0 <line_reading@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
add    $0x1,%rdi
mov    $0x1,%esi
call   10a0 <calloc@plt>
mov    %rax,%rdx
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
cmpq   $0x0,-0x18(%rbp)
jne    12ef <main+0x11f>
mov    0x2d24(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    0x2d10(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
mov    -0x2c(%rbp),%edi
mov    %rax,%rdx
lea    0xd3b(%rip),%rsi
call   10b0 <fprintf@plt>
mov    0x2ce8(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <strcpy@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1262 <main+0x92>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   10c0 <insert_selection_sort@plt>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1060 <print_array@plt>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1090 <free_array@plt>
mov    0x2c82(%rip),%rax
mov    (%rax),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xe20(%rip),%rdi
call   1080 <printf@plt>
lea    0xc(%rsp),%rdi
call   1040 <check_intInput@plt>
movslq 0xc(%rsp),%rdi
mov    $0x8,%esi
call   10a0 <calloc@plt>
test   %rax,%rax
je     129b <main+0xcb>
mov    %rax,%r14
mov    0xc(%rsp),%esi
test   %esi,%esi
jle    1268 <main+0x98>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    $0x14,%edi
call   10d0 <line_reading@plt>
mov    %rax,%r15
mov    %rax,%rdi
call   1070 <strlen@plt>
lea    0x1(%rax),%rdi
mov    $0x1,%esi
call   10a0 <calloc@plt>
mov    %rax,(%r14,%rbx,8)
mov    %rax,%rdi
mov    %r15,%rsi
call   1050 <strcpy@plt>
mov    %r15,%rdi
call   1030 <free@plt>
add    $0x1,%rbx
movslq 0xc(%rsp),%rsi
cmp    %rsi,%rbx
jl     1220 <main+0x50>
mov    %r14,%rdi
call   10c0 <insert_selection_sort@plt>
mov    0xc(%rsp),%esi
mov    %r14,%rdi
call   1060 <print_array@plt>
mov    0xc(%rsp),%esi
mov    %r14,%rdi
call   1090 <free_array@plt>
mov    0x2d39(%rip),%rax
mov    (%rax),%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2d3e(%rip),%rax
mov    (%rax),%ebx
mov    0x2d2d(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
lea    0xd5e(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   10b0 <fprintf@plt>
mov    0x2d06(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>

LLVM IR (-O0):
@.str = [23 x i8] c"Enter number of city: \00"
@stderr = global i32 0
@.str.1 = [3 x i8] c"%s\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8**
%5 = alloca i64
%6 = alloca i32
store i32 0, i32* %1
%7 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @check_intInput(i32* %2)
store i8* null, i8** %3
%9 = load i32, i32* %2
%10 = sext i32 %9 to i64
%11 = call i8* @calloc(i64 %10, i32 8)
%12 = bitcast i8* %11 to i8**
store i8** %12, i8*** %4
%13 = load i8**, i8*** %4
%14 = icmp ne i8** %13, null
br i1 %14, label %22, label %15
15: ; preds = %0
%16 = load i32, i32* @stderr
%17 = load i32, i32* @errno
%18 = call i8* @strerror(i32 %17)
%19 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %18)
%20 = load i32, i32* @EXIT_FAILURE
%21 = call i32 @exit(i32 %20)
unreachable
22: ; preds = %0
store i64 0, i64* %5
store i32 0, i32* %6
br label %23
23: ; preds = %57, %22
%24 = load i32, i32* %6
%25 = load i32, i32* %2
%26 = icmp slt i32 %24, %25
br i1 %26, label %27, label %60
27: ; preds = %23
%28 = call i8* @line_reading(i32 20)
store i8* %28, i8** %3
%29 = load i8*, i8** %3
%30 = call i64 @strlen(i8* %29)
store i64 %30, i64* %5
%31 = load i64, i64* %5
%32 = add i64 %31, 1
%33 = call i8* @calloc(i64 %32, i32 1)
%34 = load i8**, i8*** %4
%35 = load i32, i32* %6
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8*, i8** %34, i64 %36
store i8* %33, i8** %37
%38 = load i8**, i8*** %4
%39 = icmp ne i8** %38, null
br i1 %39, label %47, label %40
40: ; preds = %27
%41 = load i32, i32* @stderr
%42 = load i32, i32* @errno
%43 = call i8* @strerror(i32 %42)
%44 = call i32 @fprintf(i32 %41, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %43)
%45 = load i32, i32* @EXIT_FAILURE
%46 = call i32 @exit(i32 %45)
unreachable
47: ; preds = %27
%48 = load i8**, i8*** %4
%49 = load i32, i32* %6
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i8*, i8** %48, i64 %50
%52 = load i8*, i8** %51
%53 = load i8*, i8** %3
%54 = call i32 @strcpy(i8* %52, i8* %53)
%55 = load i8*, i8** %3
%56 = call i32 @free(i8* %55)
br label %57
57: ; preds = %47
%58 = load i32, i32* %6
%59 = add nsw i32 %58, 1
store i32 %59, i32* %6
br label %23
60: ; preds = %23
%61 = load i8**, i8*** %4
%62 = load i32, i32* %2
%63 = call i32 @insert_selection_sort(i8** %61, i32 %62)
%64 = load i8**, i8*** %4
%65 = load i32, i32* %2
%66 = call i32 @print_array(i8** %64, i32 %65)
%67 = load i8**, i8*** %4
%68 = load i32, i32* %2
%69 = call i32 @free_array(i8** %67, i32 %68)
%70 = load i32, i32* @EXIT_SUCCESS
ret i32 %70
}

LLVM IR (-O2):
@.str = [23 x i8] c"Enter number of city: \00"
@stderr = global i32 0
@.str.1 = [3 x i8] c"%s\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%3 = bitcast i32* %1 to i8*
%4 = call i32 @check_intInput(i32* %1)
%5 = load i32, i32* %1
%6 = sext i32 %5 to i64
%7 = call i8* @calloc(i64 %6, i32 8)
%8 = bitcast i8* %7 to i8**
%9 = icmp eq i8* %7, null
br i1 %9, label %13, label %10
10: ; preds = %0
%11 = load i32, i32* %1
%12 = icmp sgt i32 %11, 0
br i1 %12, label %20, label %33
13: ; preds = %0
%14 = load i32, i32* @stderr
%15 = load i32, i32* @errno
%16 = call i8* @strerror(i32 %15)
%17 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %16)
%18 = load i32, i32* @EXIT_FAILURE
%19 = call i32 @exit(i32 %18)
unreachable
20: ; preds = %10, %20
%21 = phi i64 [ %29, %20 ], [ 0, %10 ]
%22 = call i8* @line_reading(i32 20)
%23 = call i64 @strlen(i8* dereferenceable(1) %22)
%24 = add i64 %23, 1
%25 = call i8* @calloc(i64 %24, i32 1)
%26 = getelementptr inbounds i8*, i8** %8, i64 %21
store i8* %25, i8** %26
%27 = call i32 @strcpy(i8* %25, i8* %22)
%28 = call i32 @free(i8* %22)
%29 = add nuw nsw i64 %21, 1
%30 = load i32, i32* %1
%31 = sext i32 %30 to i64
%32 = icmp slt i64 %29, %31
br i1 %32, label %20, label %33
33: ; preds = %20, %10
%34 = phi i32 [ %11, %10 ], [ %30, %20 ]
%35 = call i32 @insert_selection_sort(i8** %8, i32 %34)
%36 = load i32, i32* %1
%37 = call i32 @print_array(i8** %8, i32 %36)
%38 = load i32, i32* %1
%39 = call i32 @free_array(i8** %8, i32 %38)
%40 = load i32, i32* @EXIT_SUCCESS
ret i32 %40
}