int main() {
  printf("How many students do you have? ");
  int n = read_int();
  if (n < 0 || 0x20000000 <= n)
    abort();
  char **names = malloc(n * sizeof(char **));
  if (names == 0)
    abort();
  for (int i = 0;; i++) {
    if (i == n) {
      break;
    }
    printf("Please enter the name of student number %d: ", i + 1);
    char *name = read_line();
    printf("Adding '%s'...\n", name);
    names[i] = name;
  }
  for (;;) {
    printf("Please enter a student number: ");
    int k = read_int();
    if (k < 1 || n < k) {
      printf("Student number out of range. Terminating...\n");
      break;
    } else {
      char *name = names[k - 1];
      printf("Student number %d is called %s.\n", k, name);
    }
  }
  for (int i = 0;; i++) {
    if (i == n) {
      break;
    }
    free(names[i]);
  }
  free(names);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe8a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1070 <read_int@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jl     119f <main+0x3f>
mov    $0x20000000,%eax
cmp    -0x8(%rbp),%eax
jg     11a4 <main+0x44>
call   1040 <abort@plt>
movslq -0x8(%rbp),%rdi
shl    $0x3,%rdi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11c5 <main+0x65>
call   1040 <abort@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jne    11dd <main+0x7d>
jmp    122e <main+0xce>
mov    -0x14(%rbp),%esi
add    $0x1,%esi
lea    0xe36(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1080 <read_line@plt>
cltq
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rsi
lea    0xe44(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x20(%rbp),%rdx
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11cc <main+0x6c>
jmp    1233 <main+0xd3>
lea    0xe23(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1070 <read_int@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x1,-0x24(%rbp)
jl     1261 <main+0x101>
mov    -0x8(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    1274 <main+0x114>
lea    0xe15(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    12a3 <main+0x143>
mov    -0x10(%rbp),%rax
mov    -0x24(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x30(%rbp)
mov    -0x24(%rbp),%esi
mov    -0x30(%rbp),%rdx
lea    0xe13(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1233 <main+0xd3>
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x8(%rbp),%eax
jne    12bb <main+0x15b>
jmp    12da <main+0x17a>
mov    -0x10(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1030 <free@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    12aa <main+0x14a>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xe7e(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
call   1080 <read_int@plt>
cmp    $0x20000000,%eax
jae    12ac <main+0x13c>
mov    %eax,%ebx
mov    %eax,%r12d
lea    0x0(,%r12,8),%rdi
call   1070 <malloc@plt>
test   %rax,%rax
je     12ac <main+0x13c>
mov    %rax,%r13
mov    %ebx,0x4(%rsp)
test   %ebx,%ebx
je     1209 <main+0x99>
lea    0xe85(%rip),%r15
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
lea    0x1(%rbp),%r14
lea    0xe45(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
call   1090 <read_line@plt>
movslq %eax,%rbx
mov    %r15,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,0x0(%r13,%rbp,8)
mov    %r14,%rbp
cmp    %r14,%r12
jne    11d0 <main+0x60>
lea    0xe4d(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
call   1080 <read_int@plt>
test   %eax,%eax
mov    0x4(%rsp),%ebx
jle    126d <main+0xfd>
cmp    %eax,%ebx
jl     126d <main+0xfd>
lea    0xe4c(%rip),%r14
lea    0xe25(%rip),%r15
nopl   0x0(%rax,%rax,1)
lea    -0x1(%rax),%ecx
mov    0x0(%r13,%rcx,8),%rdx
mov    %r14,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r15,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
call   1080 <read_int@plt>
test   %eax,%eax
jle    126d <main+0xfd>
cmp    %eax,%ebx
jge    1240 <main+0xd0>
lea    0xe2a(%rip),%rdi
call   1050 <puts@plt>
test   %ebx,%ebx
je     1293 <main+0x123>
xor    %ebx,%ebx
nop
mov    0x0(%r13,%rbx,8),%rdi
call   1030 <free@plt>
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1280 <main+0x110>
mov    %r13,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
call   1040 <abort@plt>

LLVM IR (-O0):
@.str = [32 x i8] c"How many students do you have? \00"
@.str.1 = [45 x i8] c"Please enter the name of student number %d: \00"
@.str.2 = [16 x i8] c"Adding '%s'...\0A\00"
@.str.3 = [32 x i8] c"Please enter a student number: \00"
@.str.4 = [45 x i8] c"Student number out of range. Terminating...\0A\00"
@.str.5 = [33 x i8] c"Student number %d is called %s.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8**
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
store i32 0, i32* %1
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%10 = call i32 (...) @read_int()
store i32 %10, i32* %2
%11 = load i32, i32* %2
%12 = icmp slt i32 %11, 0
br i1 %12, label %16, label %13
13: ; preds = %0
%14 = load i32, i32* %2
%15 = icmp sle i32 536870912, %14
br i1 %15, label %16, label %17
16: ; preds = %13, %0
unreachable
17: ; preds = %13
%18 = load i32, i32* %2
%19 = sext i32 %18 to i64
%20 = mul i64 %19, 8
%21 = call i8* @malloc(i64 %20)
%22 = bitcast i8* %21 to i8**
store i8** %22, i8*** %3
%23 = load i8**, i8*** %3
%24 = icmp eq i8** %23, null
br i1 %24, label %25, label %26
25: ; preds = %17
unreachable
26: ; preds = %17
store i32 0, i32* %4
br label %27
27: ; preds = %46, %26
%28 = load i32, i32* %4
%29 = load i32, i32* %2
%30 = icmp eq i32 %28, %29
br i1 %30, label %31, label %32
31: ; preds = %27
br label %49
32: ; preds = %27
%33 = load i32, i32* %4
%34 = add nsw i32 %33, 1
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0), i32 %34)
%36 = call i32 (...) @read_line()
%37 = sext i32 %36 to i64
%38 = inttoptr i64 %37 to i8*
store i8* %38, i8** %5
%39 = load i8*, i8** %5
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* %39)
%41 = load i8*, i8** %5
%42 = load i8**, i8*** %3
%43 = load i32, i32* %4
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8*, i8** %42, i64 %44
store i8* %41, i8** %45
br label %46
46: ; preds = %32
%47 = load i32, i32* %4
%48 = add nsw i32 %47, 1
store i32 %48, i32* %4
br label %27
49: ; preds = %31
br label %50
50: ; preds = %71, %49
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0))
%52 = call i32 (...) @read_int()
store i32 %52, i32* %6
%53 = load i32, i32* %6
%54 = icmp slt i32 %53, 1
br i1 %54, label %59, label %55
55: ; preds = %50
%56 = load i32, i32* %2
%57 = load i32, i32* %6
%58 = icmp slt i32 %56, %57
br i1 %58, label %59, label %61
59: ; preds = %55, %50
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.4, i64 0, i64 0))
br label %72
61: ; preds = %55
%62 = load i8**, i8*** %3
%63 = load i32, i32* %6
%64 = sub nsw i32 %63, 1
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds i8*, i8** %62, i64 %65
%67 = load i8*, i8** %66
store i8* %67, i8** %7
%68 = load i32, i32* %6
%69 = load i8*, i8** %7
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.5, i64 0, i64 0), i32 %68, i8* %69)
br label %71
71: ; preds = %61
br label %50
72: ; preds = %59
store i32 0, i32* %8
br label %73
73: ; preds = %84, %72
%74 = load i32, i32* %8
%75 = load i32, i32* %2
%76 = icmp eq i32 %74, %75
br i1 %76, label %77, label %78
77: ; preds = %73
br label %87
78: ; preds = %73
%79 = load i8**, i8*** %3
%80 = load i32, i32* %8
%81 = sext i32 %80 to i64
%82 = getelementptr inbounds i8*, i8** %79, i64 %81
%83 = load i8*, i8** %82
br label %84
84: ; preds = %78
%85 = load i32, i32* %8
%86 = add nsw i32 %85, 1
store i32 %86, i32* %8
br label %73
87: ; preds = %77
%88 = load i8**, i8*** %3
%89 = bitcast i8** %88 to i8*
ret i32 0
}

LLVM IR (-O2):
@.str = [32 x i8] c"How many students do you have? \00"
@.str.1 = [45 x i8] c"Please enter the name of student number %d: \00"
@.str.2 = [16 x i8] c"Adding '%s'...\0A\00"
@.str.3 = [32 x i8] c"Please enter a student number: \00"
@.str.5 = [33 x i8] c"Student number %d is called %s.\0A\00"
@str = [44 x i8] c"Student number out of range. Terminating...\00"
define i32 @main() {
%1 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%2 = tail call i32 (...) @read_int()
%3 = icmp ugt i32 %2, 536870911
br i1 %3, label %4, label %5
4: ; preds = %0
tail call void @abort()
unreachable
5: ; preds = %0
%6 = zext i32 %2 to i64
%7 = shl nuw nsw i64 %6, 3
%8 = tail call i8* @malloc(i64 %7)
%9 = bitcast i8* %8 to i8**
%10 = icmp eq i8* %8, null
br i1 %10, label %13, label %11
11: ; preds = %5
%12 = icmp eq i32 %2, 0
br i1 %12, label %14, label %20
13: ; preds = %5
tail call void @abort()
unreachable
14: ; preds = %20, %11
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0))
%16 = tail call i32 (...) @read_int()
%17 = icmp slt i32 %16, 1
%18 = icmp slt i32 %2, %16
%19 = select i1 %17, i1 true, i1 %18
br i1 %19, label %43, label %31
20: ; preds = %11, %20
%21 = phi i64 [ %22, %20 ], [ 0, %11 ]
%22 = add nuw nsw i64 %21, 1
%23 = trunc i64 %22 to i32
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0), i32 %23)
%25 = tail call i32 (...) @read_line()
%26 = sext i32 %25 to i64
%27 = inttoptr i64 %26 to i8*
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* %27)
%29 = getelementptr inbounds i8*, i8** %9, i64 %21
store i8* %27, i8** %29
%30 = icmp eq i64 %22, %6
br i1 %30, label %14, label %20
31: ; preds = %14, %31
%32 = phi i32 [ %39, %31 ], [ %16, %14 ]
%33 = add nsw i32 %32, -1
%34 = zext i32 %33 to i64
%35 = getelementptr inbounds i8*, i8** %9, i64 %34
%36 = load i8*, i8** %35
%37 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.5, i64 0, i64 0), i32 %32, i8* %36)
%38 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0))
%39 = tail call i32 (...) @read_int()
%40 = icmp slt i32 %39, 1
%41 = icmp slt i32 %2, %39
%42 = select i1 %40, i1 true, i1 %41
br i1 %42, label %43, label %31
43: ; preds = %31, %14
%44 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @str, i64 0, i64 0))
br i1 %12, label %45, label %46
45: ; preds = %46, %43
tail call void @free(i8* %8)
ret i32 0
46: ; preds = %43, %46
%47 = phi i64 [ %50, %46 ], [ 0, %43 ]
%48 = getelementptr inbounds i8*, i8** %9, i64 %47
%49 = load i8*, i8** %48
tail call void @free(i8* %49)
%50 = add nuw nsw i64 %47, 1
%51 = icmp eq i64 %50, %6
br i1 %51, label %45, label %46
}