#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*/ death_star_wins();
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ free(int *);
int getint();
int /*<<< orphan*/ printf(char *);
void face_deathstar(int *starships[], int starships_num) {
  int choice;
  int i;
  printf("Please select the starship id to attack deathstar, 0 to use all your "
         "fleet!\n");
  choice = getint();
  if (choice == 0) {
    for (i = 0; i < starships_num; i++) {
      free(starships[i]);
      starships[i] = 0;
    }
    death_star_wins();
    exit(0);
  } else if (choice < starships_num && choice > 0) {
    free(starships[choice]);
    starships[i] = 0;
    death_star_wins();
  } else {
    printf("Bad choice!\n");
  }
}


x86 assembly (clang, -O0):
<face_deathstar>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    0xe9a(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1050 <getint@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jne    11cf <face_deathstar+0x7f>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11c1 <face_deathstar+0x71>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1030 <free@plt>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1186 <face_deathstar+0x36>
mov    $0x0,%al
call   1060 <death_star_wins@plt>
xor    %edi,%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1212 <face_deathstar+0xc2>
cmpl   $0x0,-0x10(%rbp)
jle    1212 <face_deathstar+0xc2>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1030 <free@plt>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    $0x0,%al
call   1060 <death_star_wins@plt>
jmp    121e <face_deathstar+0xce>
lea    0xe34(%rip),%rdi
call   1040 <printf@plt>
jmp    1223 <face_deathstar+0xd3>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<face_deathstar>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebp
mov    %rdi,%rbx
lea    0xea0(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   1050 <getint@plt>
test   %eax,%eax
je     11a5 <face_deathstar+0x55>
cmp    %ebp,%eax
jge    1195 <face_deathstar+0x45>
test   %eax,%eax
jle    1195 <face_deathstar+0x45>
mov    %eax,%eax
mov    (%rbx,%rax,8),%rdi
call   1030 <free@plt>
movq   $0x0,(%rbx)
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
jmp    1060 <death_star_wins@plt>
lea    0xeb0(%rip),%rdi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <puts@plt>
test   %ebp,%ebp
jle    11ca <face_deathstar+0x7a>
mov    %ebp,%r14d
xor    %ebp,%ebp
xchg   %ax,%ax
mov    (%rbx,%rbp,8),%rdi
call   1030 <free@plt>
movq   $0x0,(%rbx,%rbp,8)
add    $0x1,%rbp
cmp    %rbp,%r14
jne    11b0 <face_deathstar+0x60>
xor    %eax,%eax
call   1060 <death_star_wins@plt>
xor    %edi,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [77 x i8] c"Please select the starship id to attack deathstar, 0 to use all your fleet!\0A\00"
@.str.1 = [13 x i8] c"Bad choice!\0A\00"
define void @face_deathstar(i32** %0, i32 %1) {
%3 = alloca i32**
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32** %0, i32*** %3
store i32 %1, i32* %4
%7 = call i32 @printf(i8* getelementptr inbounds ([77 x i8], [77 x i8]* @.str, i64 0, i64 0))
%8 = call i32 (...) @getint()
store i32 %8, i32* %5
%9 = load i32, i32* %5
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %33
11: ; preds = %2
store i32 0, i32* %6
br label %12
12: ; preds = %27, %11
%13 = load i32, i32* %6
%14 = load i32, i32* %4
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %30
16: ; preds = %12
%17 = load i32**, i32*** %3
%18 = load i32, i32* %6
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i32*, i32** %17, i64 %19
%21 = load i32*, i32** %20
%22 = call i32 @free(i32* %21)
%23 = load i32**, i32*** %3
%24 = load i32, i32* %6
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i32*, i32** %23, i64 %25
store i32* null, i32** %26
br label %27
27: ; preds = %16
%28 = load i32, i32* %6
%29 = add nsw i32 %28, 1
store i32 %29, i32* %6
br label %12
30: ; preds = %12
%31 = call i32 (...) @death_star_wins()
%32 = call i32 @exit(i32 0)
unreachable
33: ; preds = %2
%34 = load i32, i32* %5
%35 = load i32, i32* %4
%36 = icmp slt i32 %34, %35
br i1 %36, label %37, label %52
37: ; preds = %33
%38 = load i32, i32* %5
%39 = icmp sgt i32 %38, 0
br i1 %39, label %40, label %52
40: ; preds = %37
%41 = load i32**, i32*** %3
%42 = load i32, i32* %5
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i32*, i32** %41, i64 %43
%45 = load i32*, i32** %44
%46 = call i32 @free(i32* %45)
%47 = load i32**, i32*** %3
%48 = load i32, i32* %6
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i32*, i32** %47, i64 %49
store i32* null, i32** %50
%51 = call i32 (...) @death_star_wins()
br label %54
52: ; preds = %37, %33
%53 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %54
54: ; preds = %52, %40
br label %55
55: ; preds = %54
ret void
}

LLVM IR (-O2):
@str = [76 x i8] c"Please select the starship id to attack deathstar, 0 to use all your fleet!\00"
@str.2 = [12 x i8] c"Bad choice!\00"
define void @face_deathstar(i32** nocapture %0, i32 %1) {
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([76 x i8], [76 x i8]* @str, i64 0, i64 0))
%4 = tail call i32 (...) @getint()
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %20
6: ; preds = %2
%7 = icmp sgt i32 %1, 0
br i1 %7, label %8, label %17
8: ; preds = %6
%9 = zext i32 %1 to i64
br label %10
10: ; preds = %8, %10
%11 = phi i64 [ 0, %8 ], [ %15, %10 ]
%12 = getelementptr inbounds i32*, i32** %0, i64 %11
%13 = load i32*, i32** %12
%14 = tail call i32 @free(i32* %13)
store i32* null, i32** %12
%15 = add nuw nsw i64 %11, 1
%16 = icmp eq i64 %15, %9
br i1 %16, label %17, label %10
17: ; preds = %10, %6
%18 = tail call i32 (...) @death_star_wins()
%19 = tail call i32 @exit(i32 0)
unreachable
20: ; preds = %2
%21 = icmp slt i32 %4, %1
%22 = icmp sgt i32 %4, 0
%23 = and i1 %21, %22
br i1 %23, label %24, label %30
24: ; preds = %20
%25 = zext i32 %4 to i64
%26 = getelementptr inbounds i32*, i32** %0, i64 %25
%27 = load i32*, i32** %26
%28 = tail call i32 @free(i32* %27)
store i32* null, i32** %0
%29 = tail call i32 (...) @death_star_wins()
br label %32
30: ; preds = %20
%31 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.2, i64 0, i64 0))
br label %32
32: ; preds = %24, %30
ret void
}