#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 */
struct node {
  int dummy;
};

/* Variables and functions */
struct node *circularDoublyLinkedList_Make(int);
int /*<<< orphan*/ printf(char *, int);
scalar_t__ scanf(char *, int *, int *);
int solver(struct node *, int, int);
int main() {
  struct node *queue;
  int n, k;
  while (scanf("%d %d", &n, &k) && (n > 0) && (k > 0)) {
    queue = circularDoublyLinkedList_Make(n);
    printf("%d\n", solver(queue, n, k));
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
lea    -0x14(%rbp),%rsi
lea    -0x18(%rbp),%rdx
call   1060 <scanf@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x19(%rbp)
je     118e <main+0x4e>
xor    %eax,%eax
cmpl   $0x0,-0x14(%rbp)
mov    %al,-0x19(%rbp)
jle    118e <main+0x4e>
cmpl   $0x0,-0x18(%rbp)
setg   %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    119e <main+0x5e>
jmp    11cc <main+0x8c>
mov    -0x14(%rbp),%edi
call   1040 <circularDoublyLinkedList_Make@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1050 <solver@plt>
mov    %eax,%esi
lea    0xe44(%rip),%rdi
call   1030 <printf@plt>
jmp    114f <main+0xf>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
lea    0xeb1(%rip),%rdi
lea    0x4(%rsp),%rsi
mov    %rsp,%rdx
call   1060 <scanf@plt>
test   %rax,%rax
je     11cf <main+0x8f>
mov    0x4(%rsp),%edi
test   %edi,%edi
jle    11cf <main+0x8f>
cmpl   $0x0,(%rsp)
jle    11cf <main+0x8f>
lea    0xe90(%rip),%r14
lea    0xe83(%rip),%r15
lea    0x4(%rsp),%r12
mov    %rsp,%rbx
cs nopw 0x0(%rax,%rax,1)
nop
call   1040 <circularDoublyLinkedList_Make@plt>
mov    0x4(%rsp),%esi
mov    (%rsp),%edx
mov    %rax,%rdi
call   1050 <solver@plt>
mov    %r14,%rdi
mov    %eax,%esi
call   1030 <printf@plt>
mov    %r15,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1060 <scanf@plt>
test   %rax,%rax
je     11cf <main+0x8f>
mov    0x4(%rsp),%edi
test   %edi,%edi
jle    11cf <main+0x8f>
cmpl   $0x0,(%rsp)
jg     1190 <main+0x50>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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