int main(int argc, char **argv) {
  int ii;
  int num_shells = 0;
  char **shell_name = 0;
  char **shell_cmds = 0;
  num_shells = read_shells("/etc/shsel", &shell_name, &shell_cmds);
  if (num_shells == 0) {
    printf("no shells for you -- go away\n");
    exit(1);
  }
  printf("available shells:\n");
  for (ii = 0; ii < num_shells; ii++) {
    printf("  %2d - %s\n", ii, shell_name[ii]);
  }
  printf("select shell [%d]: ", 0);
  int shell_choice = read_choice(num_shells);
  system(shell_cmds[shell_choice]);
  for (ii = 0; ii < num_shells; ii++) {
    free(shell_name[ii]);
    free(shell_cmds[ii]);
  }
  free(shell_name);
  free(shell_cmds);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
lea    0xe6c(%rip),%rdi
lea    -0x20(%rbp),%rsi
lea    -0x28(%rbp),%rdx
mov    $0x0,%al
call   1070 <read_shells@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jne    11c8 <main+0x68>
lea    0xe54(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
lea    0xe5a(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1214 <main+0xb4>
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xe3d(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11dd <main+0x7d>
lea    0xe2d(%rip),%rdi
xor    %esi,%esi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x18(%rbp),%edi
mov    $0x0,%al
call   1040 <read_choice@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    $0x0,%al
call   1050 <system@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1287 <main+0x127>
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1030 <free@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    124b <main+0xeb>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
movq   $0x0,0x8(%rsp)
movq   $0x0,(%rsp)
lea    0xe6f(%rip),%rdi
lea    0x8(%rsp),%rsi
mov    %rsp,%rdx
xor    %eax,%eax
call   1080 <read_shells@plt>
test   %eax,%eax
je     1290 <main+0x120>
mov    %eax,%r15d
lea    0xe79(%rip),%rdi
call   1040 <puts@plt>
test   %r15d,%r15d
jle    1246 <main+0xd6>
lea    0xe44(%rip),%r14
xor    %ebx,%ebx
nopl   0x0(%rax)
mov    0x8(%rsp),%rax
mov    (%rax,%rbx,8),%rdx
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1070 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r15
jne    11d0 <main+0x60>
lea    0xe22(%rip),%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r15d,%edi
xor    %eax,%eax
call   1050 <read_choice@plt>
mov    (%rsp),%rcx
cltq
mov    (%rcx,%rax,8),%rdi
xor    %eax,%eax
call   1060 <system@plt>
test   %r15d,%r15d
jle    1271 <main+0x101>
xor    %ebx,%ebx
mov    0x8(%rsp),%rax
mov    (%rax,%rbx,8),%rdi
call   1030 <free@plt>
mov    (%rsp),%rax
mov    (%rax,%rbx,8),%rdi
call   1030 <free@plt>
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1220 <main+0xb0>
jmp    1271 <main+0x101>
lea    0xdca(%rip),%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r15d,%edi
xor    %eax,%eax
call   1050 <read_choice@plt>
mov    (%rsp),%rcx
cltq
mov    (%rcx,%rax,8),%rdi
xor    %eax,%eax
call   1060 <system@plt>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
mov    (%rsp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xda6(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [11 x i8] c"/etc/shsel\00"
@.str.1 = [30 x i8] c"no shells for you -- go away\0A\00"
@.str.2 = [19 x i8] c"available shells:\0A\00"
@.str.3 = [12 x i8] c" %2d - %s\0A\00"
@.str.4 = [20 x i8] c"select shell [%d]: \00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8**
%9 = alloca i8**
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
store i8** null, i8*** %8
store i8** null, i8*** %9
%11 = call i32 (i8*, i8***, i8***, ...) bitcast (i32 (...)* @read_shells to i32 (i8*, i8***, i8***, ...)*)(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8*** %8, i8*** %9)
store i32 %11, i32* %7
%12 = load i32, i32* %7
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
unreachable
16: ; preds = %2
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %6
br label %18
18: ; preds = %30, %16
%19 = load i32, i32* %6
%20 = load i32, i32* %7
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %33
22: ; preds = %18
%23 = load i32, i32* %6
%24 = load i8**, i8*** %8
%25 = load i32, i32* %6
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8*, i8** %24, i64 %26
%28 = load i8*, i8** %27
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 %23, i8* %28)
br label %30
30: ; preds = %22
%31 = load i32, i32* %6
%32 = add nsw i32 %31, 1
store i32 %32, i32* %6
br label %18
33: ; preds = %18
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i32 0)
%35 = load i32, i32* %7
%36 = call i32 (i32, ...) bitcast (i32 (...)* @read_choice to i32 (i32, ...)*)(i32 %35)
store i32 %36, i32* %10
%37 = load i8**, i8*** %9
%38 = load i32, i32* %10
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8*, i8** %37, i64 %39
%41 = load i8*, i8** %40
%42 = call i32 (i8*, ...) bitcast (i32 (...)* @system to i32 (i8*, ...)*)(i8* %41)
store i32 0, i32* %6
br label %43
43: ; preds = %58, %33
%44 = load i32, i32* %6
%45 = load i32, i32* %7
%46 = icmp slt i32 %44, %45
br i1 %46, label %47, label %61
47: ; preds = %43
%48 = load i8**, i8*** %8
%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*** %9
%54 = load i32, i32* %6
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds i8*, i8** %53, i64 %55
%57 = load i8*, i8** %56
br label %58
58: ; preds = %47
%59 = load i32, i32* %6
%60 = add nsw i32 %59, 1
store i32 %60, i32* %6
br label %43
61: ; preds = %43
%62 = load i8**, i8*** %8
%63 = bitcast i8** %62 to i8*
%64 = load i8**, i8*** %9
%65 = bitcast i8** %64 to i8*
ret i32 0
}

LLVM IR (-O2):
@.str = [11 x i8] c"/etc/shsel\00"
@.str.3 = [12 x i8] c" %2d - %s\0A\00"
@.str.4 = [20 x i8] c"select shell [%d]: \00"
@str = [18 x i8] c"available shells:\00"
@str.5 = [29 x i8] c"no shells for you -- go away\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i8**
%4 = alloca i8**
%5 = bitcast i8*** %3 to i8*
store i8** null, i8*** %3
%6 = bitcast i8*** %4 to i8*
store i8** null, i8*** %4
%7 = call i32 (i8*, i8***, i8***, ...) bitcast (i32 (...)* @read_shells to i32 (i8*, i8***, i8***, ...)*)(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8*** %3, i8*** %4)
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str.5, i64 0, i64 0))
unreachable
11: ; preds = %2
%12 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
%13 = icmp sgt i32 %7, 0
br i1 %13, label %14, label %45
14: ; preds = %11
%15 = zext i32 %7 to i64
br label %16
16: ; preds = %14, %16
%17 = phi i64 [ 0, %14 ], [ %23, %16 ]
%18 = load i8**, i8*** %3
%19 = getelementptr inbounds i8*, i8** %18, i64 %17
%20 = load i8*, i8** %19
%21 = trunc i64 %17 to i32
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 %21, i8* %20)
%23 = add nuw nsw i64 %17, 1
%24 = icmp eq i64 %23, %15
br i1 %24, label %25, label %16
25: ; preds = %16
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i32 0)
%27 = call i32 (i32, ...) bitcast (i32 (...)* @read_choice to i32 (i32, ...)*)(i32 %7)
%28 = load i8**, i8*** %4
%29 = sext i32 %27 to i64
%30 = getelementptr inbounds i8*, i8** %28, i64 %29
%31 = load i8*, i8** %30
%32 = call i32 (i8*, ...) bitcast (i32 (...)* @system to i32 (i8*, ...)*)(i8* %31)
br i1 %13, label %33, label %53
33: ; preds = %25
%34 = zext i32 %7 to i64
br label %35
35: ; preds = %33, %35
%36 = phi i64 [ 0, %33 ], [ %43, %35 ]
%37 = load i8**, i8*** %3
%38 = getelementptr inbounds i8*, i8** %37, i64 %36
%39 = load i8*, i8** %38
%40 = load i8**, i8*** %4
%41 = getelementptr inbounds i8*, i8** %40, i64 %36
%42 = load i8*, i8** %41
%43 = add nuw nsw i64 %36, 1
%44 = icmp eq i64 %43, %34
br i1 %44, label %53, label %35
45: ; preds = %11
%46 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i32 0)
%47 = call i32 (i32, ...) bitcast (i32 (...)* @read_choice to i32 (i32, ...)*)(i32 %7)
%48 = load i8**, i8*** %4
%49 = sext i32 %47 to i64
%50 = getelementptr inbounds i8*, i8** %48, i64 %49
%51 = load i8*, i8** %50
%52 = call i32 (i8*, ...) bitcast (i32 (...)* @system to i32 (i8*, ...)*)(i8* %51)
br label %53
53: ; preds = %35, %45, %25
%54 = bitcast i8*** %3 to i8**
%55 = load i8*, i8** %54
%56 = bitcast i8*** %4 to i8**
%57 = load i8*, i8** %56
ret i32 0
}