#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 */
scalar_t__ EOF;
int /*<<< orphan*/ find_primes(int, int *, int *);
int /*<<< orphan*/ printf(char *, int);
int run_josephus_cousin(int, int *);
scalar_t__ scanf(char *, int *);
int main() {
  int primes[4096], num_primes;
  int num, result;
  find_primes(1 << 15, primes, &num_primes);
  while (scanf("%d\n", &num) != EOF && num != 0) {
    result = run_josephus_cousin(num, primes);
    printf("%d\n", result);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4020,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x4010(%rbp),%rsi
mov    $0x8000,%edi
lea    -0x4014(%rbp),%rdx
call   1030 <find_primes@plt>
lea    0xe8f(%rip),%rdi
lea    -0x4018(%rbp),%rsi
call   1060 <scanf@plt>
mov    %rax,%rcx
xor    %eax,%eax
mov    0x2e5f(%rip),%rdx
cmp    (%rdx),%rcx
mov    %al,-0x401d(%rbp)
je     11a8 <main+0x68>
cmpl   $0x0,-0x4018(%rbp)
setne  %al
mov    %al,-0x401d(%rbp)
mov    -0x401d(%rbp),%al
test   $0x1,%al
jne    11bb <main+0x7b>
jmp    11ea <main+0xaa>
mov    -0x4018(%rbp),%edi
lea    -0x4010(%rbp),%rsi
call   1050 <run_josephus_cousin@plt>
mov    %eax,-0x401c(%rbp)
mov    -0x401c(%rbp),%esi
lea    0xe20(%rip),%rdi
call   1040 <printf@plt>
jmp    116a <main+0x2a>
xor    %eax,%eax
add    $0x4020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x4018,%rsp
lea    0x10(%rsp),%rsi
lea    0xc(%rsp),%rdx
mov    $0x8000,%edi
call   1030 <find_primes@plt>
lea    0xe97(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1060 <scanf@plt>
mov    0x2e6e(%rip),%r12
cmp    (%r12),%rax
je     11cb <main+0x8b>
mov    0x8(%rsp),%edi
test   %edi,%edi
je     11cb <main+0x8b>
lea    0x10(%rsp),%r14
lea    0xe6c(%rip),%rbx
lea    0x8(%rsp),%r15
nopl   0x0(%rax)
mov    %r14,%rsi
call   1050 <run_josephus_cousin@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1060 <scanf@plt>
cmp    (%r12),%rax
je     11cb <main+0x8b>
mov    0x8(%rsp),%edi
test   %edi,%edi
jne    11a0 <main+0x60>
xor    %eax,%eax
add    $0x4018,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%d\0A\00"
@EOF = global i64 0
define i32 @main() {
%1 = alloca i32
%2 = alloca [4096 x i32]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
%6 = getelementptr inbounds [4096 x i32], [4096 x i32]* %2, i64 0, i64 0
%7 = call i32 @find_primes(i32 32768, i32* %6, i32* %3)
br label %8
8: ; preds = %17, %0
%9 = call i64 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %4)
%10 = load i64, i64* @EOF
%11 = icmp ne i64 %9, %10
br i1 %11, label %12, label %15
12: ; preds = %8
%13 = load i32, i32* %4
%14 = icmp ne i32 %13, 0
br label %15
15: ; preds = %12, %8
%16 = phi i1 [ false, %8 ], [ %14, %12 ]
br i1 %16, label %17, label %23
17: ; preds = %15
%18 = load i32, i32* %4
%19 = getelementptr inbounds [4096 x i32], [4096 x i32]* %2, i64 0, i64 0
%20 = call i32 @run_josephus_cousin(i32 %18, i32* %19)
store i32 %20, i32* %5
%21 = load i32, i32* %5
%22 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %21)
br label %8
23: ; preds = %15
ret i32 0
}

LLVM IR (-O2):
@.str = [4 x i8] c"%d\0A\00"
@EOF = global i64 0
define i32 @main() {
%1 = alloca [4096 x i32]
%2 = alloca i32
%3 = alloca i32
%4 = bitcast [4096 x i32]* %1 to i8*
%5 = bitcast i32* %2 to i8*
%6 = bitcast i32* %3 to i8*
%7 = getelementptr inbounds [4096 x i32], [4096 x i32]* %1, i64 0, i64 0
%8 = call i32 @find_primes(i32 32768, i32* %7, i32* %2)
%9 = call i64 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %3)
%10 = load i64, i64* @EOF
%11 = icmp ne i64 %9, %10
%12 = load i32, i32* %3
%13 = icmp ne i32 %12, 0
%14 = select i1 %11, i1 %13, i1 false
br i1 %14, label %15, label %25
15: ; preds = %0, %15
%16 = phi i32 [ %22, %15 ], [ %12, %0 ]
%17 = call i32 @run_josephus_cousin(i32 %16, i32* %7)
%18 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %17)
%19 = call i64 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %3)
%20 = load i64, i64* @EOF
%21 = icmp ne i64 %19, %20
%22 = load i32, i32* %3
%23 = icmp ne i32 %22, 0
%24 = select i1 %21, i1 %23, i1 false
br i1 %24, label %15, label %25
25: ; preds = %15, %0
ret i32 0
}