#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 get_population(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
main() {
  int capacity;
  int population = 0;
  printf("Oh no! A tribble has snuck on board!\n");
  printf("How many tribbles can your ship fit?\n> ");
  scanf("%d", &capacity);
  int generation = 1;
  while (population < capacity) {
    population = get_population(generation);
    generation = generation + 1;
  }
  printf("Your ship is overrun after %d generations! Abandon ship!\n",
         generation);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
lea    0xeb3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xecb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xee5(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
movl   $0x1,-0x10(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    119e <main+0x6e>
mov    -0x10(%rbp),%edi
call   1050 <get_population@plt>
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1179 <main+0x49>
mov    -0x10(%rbp),%esi
lea    0xea9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0xf19(%rip),%rdi
call   1030 <puts@plt>
lea    0xea8(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xec2(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1050 <scanf@plt>
cmpl   $0x0,0xc(%rsp)
jle    1192 <main+0x52>
mov    $0x1,%ebx
nopl   0x0(%rax)
mov    %ebx,%edi
call   1060 <get_population@plt>
add    $0x1,%ebx
cmp    0xc(%rsp),%eax
jl     1180 <main+0x40>
jmp    1197 <main+0x57>
mov    $0x1,%ebx
lea    0xe8d(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [38 x i8] c"Oh no! A tribble has snuck on board!\0A\00"
@.str.1 = [40 x i8] c"How many tribbles can your ship fit?\0A> \00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [58 x i8] c"Your ship is overrun after %d generations! Abandon ship!\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %3
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
store i32 1, i32* %4
br label %8
8: ; preds = %12, %0
%9 = load i32, i32* %3
%10 = load i32, i32* %2
%11 = icmp slt i32 %9, %10
br i1 %11, label %12, label %17
12: ; preds = %8
%13 = load i32, i32* %4
%14 = call i32 @get_population(i32 %13)
store i32 %14, i32* %3
%15 = load i32, i32* %4
%16 = add nsw i32 %15, 1
store i32 %16, i32* %4
br label %8
17: ; preds = %8
%18 = load i32, i32* %4
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.3, i64 0, i64 0), i32 %18)
%20 = load i32, i32* %1
ret i32 %20
}

LLVM IR (-O2):
@.str.1 = [40 x i8] c"How many tribbles can your ship fit?\0A> \00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [58 x i8] c"Your ship is overrun after %d generations! Abandon ship!\0A\00"
@str = [37 x i8] c"Oh no! A tribble has snuck on board!\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str, i64 0, i64 0))
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0))
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%6 = load i32, i32* %1
%7 = icmp sgt i32 %6, 0
br i1 %7, label %8, label %14
8: ; preds = %0, %8
%9 = phi i32 [ %11, %8 ], [ 1, %0 ]
%10 = call i32 @get_population(i32 %9)
%11 = add nuw nsw i32 %9, 1
%12 = load i32, i32* %1
%13 = icmp slt i32 %10, %12
br i1 %13, label %8, label %14
14: ; preds = %8, %0
%15 = phi i32 [ 1, %0 ], [ %11, %8 ]
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([58 x i8], [58 x i8]* @.str.3, i64 0, i64 0), i32 %15)
ret i32 0
}