#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 getint();
int /*<<< orphan*/ modstats(int *);
int /*<<< orphan*/ printf(char *);
void arm_fleet(int *starships[], int starships_num) {
  int selection = 0;
  printf("Please select starship index:\n");
  selection = getint();
  if (selection >= 0 && selection < starships_num) {
    modstats(starships[selection]);
  } else {
    printf("Bad index!\n");
  }
}


x86 assembly (clang, -O0):
<arm_fleet>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
lea    0xeb3(%rip),%rdi
call   1030 <printf@plt>
mov    $0x0,%al
call   1040 <getint@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jl     1188 <arm_fleet+0x58>
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1188 <arm_fleet+0x58>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1050 <modstats@plt>
jmp    1194 <arm_fleet+0x64>
lea    0xe90(%rip),%rdi
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<arm_fleet>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
lea    0xec1(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1040 <getint@plt>
test   %eax,%eax
js     1164 <arm_fleet+0x34>
cmp    %ebp,%eax
jge    1164 <arm_fleet+0x34>
mov    %eax,%eax
mov    (%rbx,%rax,8),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1050 <modstats@plt>
lea    0xeb3(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <puts@plt>

LLVM IR (-O0):
@.str = [31 x i8] c"Please select starship index:\0A\00"
@.str.1 = [12 x i8] c"Bad index!\0A\00"
define void @arm_fleet(i32** %0, i32 %1) {
%3 = alloca i32**
%4 = alloca i32
%5 = alloca i32
store i32** %0, i32*** %3
store i32 %1, i32* %4
store i32 0, i32* %5
%6 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%7 = call i32 (...) @getint()
store i32 %7, i32* %5
%8 = load i32, i32* %5
%9 = icmp sge i32 %8, 0
br i1 %9, label %10, label %21
10: ; preds = %2
%11 = load i32, i32* %5
%12 = load i32, i32* %4
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %21
14: ; preds = %10
%15 = load i32**, i32*** %3
%16 = load i32, i32* %5
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i32*, i32** %15, i64 %17
%19 = load i32*, i32** %18
%20 = call i32 @modstats(i32* %19)
br label %23
21: ; preds = %10, %2
%22 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
br label %23
23: ; preds = %21, %14
ret void
}

LLVM IR (-O2):
@str = [30 x i8] c"Please select starship index:\00"
@str.2 = [11 x i8] c"Bad index!\00"
define void @arm_fleet(i32** nocapture %0, i32 %1) {
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str, i64 0, i64 0))
%4 = tail call i32 (...) @getint()
%5 = icmp sgt i32 %4, -1
%6 = icmp slt i32 %4, %1
%7 = and i1 %5, %6
br i1 %7, label %8, label %13
8: ; preds = %2
%9 = zext i32 %4 to i64
%10 = getelementptr inbounds i32*, i32** %0, i64 %9
%11 = load i32*, i32** %10
%12 = tail call i32 @modstats(i32* %11)
br label %15
13: ; preds = %2
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str.2, i64 0, i64 0))
br label %15
15: ; preds = %13, %8
ret void
}