#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 */
unsigned int UINT_MAX;
unsigned int canoes(size_t, unsigned int *);
int /*<<< orphan*/ printf(char *, ...);
int scanf(char *, ...);
int main(void) {
  printf("Enter the number of kids, followed by each kid's weight\n");
  printf("> ");
  size_t kids_sz;
  while (scanf("%zu", &kids_sz) == 1) {
    unsigned kids[kids_sz];
    size_t i;
    for (i = 0; i < kids_sz; i++) {
      scanf("%u", &kids[i]);
    }
    unsigned min_canoes = canoes(kids_sz, kids);
    if (min_canoes == UINT_MAX) {
      printf("Impossible\n");
    } else {
      printf("Min canoes: %u\n", min_canoes);
    }
    printf("> ");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xee5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeda(%rip),%rdi
lea    -0x10(%rbp),%rsi
mov    $0x0,%al
call   1050 <scanf@plt>
cmp    $0x1,%eax
jne    1242 <main+0x112>
mov    -0x10(%rbp),%rax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    11e2 <main+0xb2>
mov    -0x38(%rbp),%rsi
mov    -0x28(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe76(%rip),%rdi
mov    $0x0,%al
call   1050 <scanf@plt>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    11a6 <main+0x76>
mov    -0x38(%rbp),%rsi
mov    -0x10(%rbp),%rdi
call   1040 <canoes@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    0x2dec(%rip),%rcx
cmp    (%rcx),%eax
jne    1217 <main+0xe7>
lea    0xe38(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1228 <main+0xf8>
mov    -0x2c(%rbp),%esi
lea    0xe2e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe0a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
jmp    115b <main+0x2b>
xor    %eax,%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xec5(%rip),%rdi
call   1030 <puts@plt>
lea    0xe9f(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe94(%rip),%rdi
lea    -0x30(%rbp),%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
cmp    $0x1,%eax
jne    123a <main+0xfa>
lea    0xe7d(%rip),%r14
jmp    11c8 <main+0x88>
nopl   0x0(%rax)
lea    0xe73(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe59(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r12,%rsp
lea    0xe4b(%rip),%rdi
lea    -0x30(%rbp),%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
cmp    $0x1,%eax
jne    123a <main+0xfa>
mov    %rsp,%r12
mov    -0x30(%rbp),%rax
mov    %rsp,%r15
lea    0xf(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r15
mov    %r15,%rsp
cmpq   $0x0,-0x30(%rbp)
je     1210 <main+0xd0>
mov    %r15,%r13
xor    %ebx,%ebx
mov    %r14,%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
add    $0x1,%rbx
mov    -0x30(%rbp),%rdi
add    $0x4,%r13
cmp    %rdi,%rbx
jb     11f0 <main+0xb0>
jmp    1212 <main+0xd2>
xor    %edi,%edi
mov    %r15,%rsi
call   1050 <canoes@plt>
mov    0x2dc7(%rip),%rcx
cmp    (%rcx),%eax
jne    1190 <main+0x50>
lea    0xe22(%rip),%rdi
call   1030 <puts@plt>
jmp    11a0 <main+0x60>
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [57 x i8] c"Enter the number of kids, followed by each kid's weight\0A\00"
@.str.1 = [3 x i8] c"> \00"
@.str.2 = [4 x i8] c"%zu\00"
@.str.3 = [3 x i8] c"%u\00"
@UINT_MAX = global i32 0
@.str.4 = [12 x i8] c"Impossible\0A\00"
@.str.5 = [16 x i8] c"Min canoes: %u\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i64
%6 = alloca i32
store i32 0, i32* %1
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0))
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %9
9: ; preds = %38, %0
%10 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i64* %2)
%11 = icmp eq i32 %10, 1
br i1 %11, label %12, label %41
12: ; preds = %9
%13 = load i64, i64* %2
%14 = call i8* @llvm.stacksave()
store i8* %14, i8** %3
%15 = alloca i32, i64 %13
store i64 %13, i64* %4
store i64 0, i64* %5
br label %16
16: ; preds = %24, %12
%17 = load i64, i64* %5
%18 = load i64, i64* %2
%19 = icmp ult i64 %17, %18
br i1 %19, label %20, label %27
20: ; preds = %16
%21 = load i64, i64* %5
%22 = getelementptr inbounds i32, i32* %15, i64 %21
%23 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %22)
br label %24
24: ; preds = %20
%25 = load i64, i64* %5
%26 = add i64 %25, 1
store i64 %26, i64* %5
br label %16
27: ; preds = %16
%28 = load i64, i64* %2
%29 = call i32 @canoes(i64 %28, i32* %15)
store i32 %29, i32* %6
%30 = load i32, i32* %6
%31 = load i32, i32* @UINT_MAX
%32 = icmp eq i32 %30, %31
br i1 %32, label %33, label %35
33: ; preds = %27
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
br label %38
35: ; preds = %27
%36 = load i32, i32* %6
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), i32 %36)
br label %38
38: ; preds = %35, %33
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%40 = load i8*, i8** %3
br label %9
41: ; preds = %9
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"> \00"
@.str.2 = [4 x i8] c"%zu\00"
@.str.3 = [3 x i8] c"%u\00"
@UINT_MAX = global i32 0
@.str.5 = [16 x i8] c"Min canoes: %u\0A\00"
@str = [56 x i8] c"Enter the number of kids, followed by each kid's weight\00"
@str.6 = [11 x i8] c"Impossible\00"
define i32 @main() {
%1 = alloca i64
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([56 x i8], [56 x i8]* @str, i64 0, i64 0))
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%4 = bitcast i64* %1 to i8*
%5 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i64* %1)
%6 = icmp eq i32 %5, 1
br i1 %6, label %7, label %33
7: ; preds = %0, %29
%8 = load i64, i64* %1
%9 = call i8* @llvm.stacksave()
%10 = alloca i32, i64 %8
%11 = load i64, i64* %1
%12 = icmp eq i64 %11, 0
br i1 %12, label %20, label %13
13: ; preds = %7, %13
%14 = phi i64 [ %17, %13 ], [ 0, %7 ]
%15 = getelementptr inbounds i32, i32* %10, i64 %14
%16 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %15)
%17 = add nuw i64 %14, 1
%18 = load i64, i64* %1
%19 = icmp ult i64 %17, %18
br i1 %19, label %13, label %20
20: ; preds = %13, %7
%21 = phi i64 [ 0, %7 ], [ %18, %13 ]
%22 = call i32 @canoes(i64 %21, i32* %10)
%23 = load i32, i32* @UINT_MAX
%24 = icmp eq i32 %22, %23
br i1 %24, label %25, label %27
25: ; preds = %20
%26 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str.6, i64 0, i64 0))
br label %29
27: ; preds = %20
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), i32 %22)
br label %29
29: ; preds = %27, %25
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%31 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i64* %1)
%32 = icmp eq i32 %31, 1
br i1 %32, label %7, label %33
33: ; preds = %29, %0
ret i32 0
}