#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*/ printf(char *, int);
int main() {
  int sailors = 5;
  int monkeys = 1;
  int j;
  int coconuts_tot = 0;
  int coconuts;
  while (0 == 0) {
    coconuts_tot += 1;
    coconuts = coconuts_tot;
    for (j = 0; j < sailors; j++) {
      coconuts -= monkeys;
      if (coconuts % sailors != 0) {
        break;
      }
      coconuts -= coconuts / sailors;
    }
    if (coconuts % sailors == 0) {
      break;
    }
  }
  printf("Solution: %d coconuts to begin with\n", coconuts_tot);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x5,-0x8(%rbp)
movl   $0x1,-0xc(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1195 <main+0x85>
mov    -0xc(%rbp),%ecx
mov    -0x18(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cltd
idivl  -0x8(%rbp)
cmp    $0x0,%edx
je     1176 <main+0x66>
jmp    1195 <main+0x85>
mov    -0x18(%rbp),%eax
cltd
idivl  -0x8(%rbp)
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    114a <main+0x3a>
mov    -0x18(%rbp),%eax
cltd
idivl  -0x8(%rbp)
cmp    $0x0,%edx
jne    11aa <main+0x9a>
jmp    11af <main+0x9f>
jmp    1134 <main+0x24>
mov    -0x14(%rbp),%esi
lea    0xe47(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
xor    %eax,%eax
mov    $0xcccccccd,%r8d
xor    %esi,%esi
jmp    113e <main+0x2e>
nopl   0x0(%rax)
imul   $0xcccccccd,%edx,%ecx
add    $0x19999999,%ecx
add    $0xffffffff,%eax
add    $0x1,%esi
cmp    $0x33333332,%ecx
jbe    125f <main+0x14f>
mov    %esi,%ecx
imul   %r8,%rcx
shr    $0x22,%rcx
lea    (%rcx,%rcx,4),%ecx
mov    %esi,%edx
add    %eax,%ecx
jne    1120 <main+0x10>
movslq %esi,%rcx
imul   $0xffffffff99999999,%rcx,%rdi
mov    %rdi,%rcx
shr    $0x3f,%rcx
sar    $0x21,%rdi
add    %ecx,%edi
lea    (%rsi,%rdi,1),%edx
add    $0xffffffff,%edx
imul   $0xcccccccd,%edx,%ecx
add    $0x19999999,%ecx
cmp    $0x33333332,%ecx
ja     1120 <main+0x10>
movslq %edx,%rcx
imul   $0xffffffff99999999,%rcx,%rcx
mov    %rcx,%r9
shr    $0x3f,%r9
sar    $0x21,%rcx
add    %r9d,%ecx
add    %ecx,%edx
add    $0xffffffff,%edx
add    %ecx,%edi
lea    (%rsi,%rdi,1),%r9d
add    $0xfffffffe,%r9d
imul   $0xcccccccd,%r9d,%ecx
add    $0x19999999,%ecx
cmp    $0x33333332,%ecx
ja     1120 <main+0x10>
movslq %r9d,%rcx
imul   $0xffffffff99999999,%rcx,%rcx
mov    %rcx,%r9
shr    $0x3f,%r9
sar    $0x21,%rcx
add    %r9d,%ecx
add    %ecx,%edx
add    $0xffffffff,%edx
add    %ecx,%edi
lea    (%rsi,%rdi,1),%r9d
add    $0xfffffffd,%r9d
imul   $0xcccccccd,%r9d,%ecx
add    $0x19999999,%ecx
cmp    $0x33333332,%ecx
ja     1120 <main+0x10>
movslq %r9d,%rcx
imul   $0xffffffff99999999,%rcx,%rcx
mov    %rcx,%r9
shr    $0x3f,%r9
sar    $0x21,%rcx
add    %r9d,%ecx
add    %ecx,%edx
add    $0xffffffff,%edx
add    %ecx,%edi
lea    (%rsi,%rdi,1),%ecx
add    $0xfffffffc,%ecx
imul   $0xcccccccd,%ecx,%edi
add    $0x19999999,%edi
cmp    $0x33333332,%edi
ja     1120 <main+0x10>
movslq %ecx,%rcx
imul   $0xffffffff99999999,%rcx,%rcx
mov    %rcx,%rdi
shr    $0x3f,%rdi
sar    $0x21,%rcx
add    %edi,%ecx
add    %edx,%ecx
mov    %ecx,%edx
jmp    1120 <main+0x10>
push   %rax
lea    0xd99(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [37 x i8] c"Solution: %d coconuts to begin with\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
store i32 5, i32* %2
store i32 1, i32* %3
store i32 0, i32* %5
br label %7
7: ; preds = %0, %39
%8 = load i32, i32* %5
%9 = add nsw i32 %8, 1
store i32 %9, i32* %5
%10 = load i32, i32* %5
store i32 %10, i32* %6
store i32 0, i32* %4
br label %11
11: ; preds = %30, %7
%12 = load i32, i32* %4
%13 = load i32, i32* %2
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %33
15: ; preds = %11
%16 = load i32, i32* %3
%17 = load i32, i32* %6
%18 = sub nsw i32 %17, %16
store i32 %18, i32* %6
%19 = load i32, i32* %6
%20 = load i32, i32* %2
%21 = srem i32 %19, %20
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %15
br label %33
24: ; preds = %15
%25 = load i32, i32* %6
%26 = load i32, i32* %2
%27 = sdiv i32 %25, %26
%28 = load i32, i32* %6
%29 = sub nsw i32 %28, %27
store i32 %29, i32* %6
br label %30
30: ; preds = %24
%31 = load i32, i32* %4
%32 = add nsw i32 %31, 1
store i32 %32, i32* %4
br label %11
33: ; preds = %23, %11
%34 = load i32, i32* %6
%35 = load i32, i32* %2
%36 = srem i32 %34, %35
%37 = icmp eq i32 %36, 0
br i1 %37, label %38, label %39
38: ; preds = %33
br label %40
39: ; preds = %33
br label %7
40: ; preds = %38
%41 = load i32, i32* %5
%42 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i32 %41)
ret i32 0
}

LLVM IR (-O2):
@.str = [37 x i8] c"Solution: %d coconuts to begin with\0A\00"
define i32 @main() {
br label %1
1: ; preds = %33, %0
%2 = phi i32 [ 0, %0 ], [ %3, %33 ]
%3 = add nuw nsw i32 %2, 1
%4 = urem i32 %2, 5
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %33
6: ; preds = %1
%7 = sdiv i32 %2, -5
%8 = add i32 %7, %2
%9 = add nsw i32 %8, -1
%10 = srem i32 %9, 5
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %33
12: ; preds = %6
%13 = sdiv i32 %9, -5
%14 = add i32 %13, %9
%15 = add nsw i32 %14, -1
%16 = srem i32 %15, 5
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %33
18: ; preds = %12
%19 = sdiv i32 %15, -5
%20 = add i32 %19, %15
%21 = add nsw i32 %20, -1
%22 = srem i32 %21, 5
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %33
24: ; preds = %18
%25 = sdiv i32 %21, -5
%26 = add i32 %25, %21
%27 = add nsw i32 %26, -1
%28 = srem i32 %27, 5
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %24
%31 = sdiv i32 %27, -5
%32 = add i32 %31, %27
br label %33
33: ; preds = %30, %24, %18, %12, %6, %1
%34 = phi i32 [ %2, %1 ], [ %9, %6 ], [ %15, %12 ], [ %21, %18 ], [ %27, %24 ], [ %32, %30 ]
%35 = srem i32 %34, 5
%36 = icmp eq i32 %35, 0
br i1 %36, label %37, label %1
37: ; preds = %33
%38 = tail call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i32 %3)
ret i32 0
}