#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 devcards_handle(int, int, int);
int /*<<< orphan*/ devcards_refresh(int, int);
int io_getkey();
int devcards_routine(int player, int hascarded) {
  int pos = 0;
  while (1) {
    devcards_refresh(player, pos);
    switch (io_getkey()) {
    case 0:
      if (--pos < 0)
        pos = 5;
      break;
    case 1:
      pos = (pos + 1) % 6;
      break;
    case 4:
      return devcards_handle(player, pos, hascarded);
      break;
    case 'c':
      return 0;
      break;
    default:
      break;
    }
  }
}


x86 assembly (clang, -O0):
<devcards_routine>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%esi
call   1040 <devcards_refresh@plt>
xor    %eax,%eax
call   1050 <io_getkey@plt>
mov    %eax,%ecx
mov    %ecx,-0x14(%rbp)
test   %eax,%eax
je     119c <devcards_routine+0x6c>
jmp    1169 <devcards_routine+0x39>
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
je     11ba <devcards_routine+0x8a>
jmp    117a <devcards_routine+0x4a>
mov    -0x14(%rbp),%eax
sub    $0x4,%eax
je     11d0 <devcards_routine+0xa0>
jmp    118b <devcards_routine+0x5b>
mov    -0x14(%rbp),%eax
sub    $0x63,%eax
je     11e6 <devcards_routine+0xb6>
jmp    11f2 <devcards_routine+0xc2>
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
cmp    $0x0,%eax
jge    11b5 <devcards_routine+0x85>
movl   $0x5,-0x10(%rbp)
jmp    11f7 <devcards_routine+0xc7>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    $0x6,%ecx
cltd
idiv   %ecx
mov    %edx,-0x10(%rbp)
jmp    11f7 <devcards_routine+0xc7>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1030 <devcards_handle@plt>
mov    %eax,-0x4(%rbp)
jmp    11fc <devcards_routine+0xcc>
movl   $0x0,-0x4(%rbp)
jmp    11fc <devcards_routine+0xcc>
jmp    11f7 <devcards_routine+0xc7>
jmp    1145 <devcards_routine+0x15>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<devcards_routine>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %edi,%ebp
mov    $0x5,%r15d
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %ebp,%edi
mov    %ebx,%esi
call   1040 <devcards_refresh@plt>
xor    %eax,%eax
call   1050 <io_getkey@plt>
cmp    $0x3,%eax
jg     11a0 <devcards_routine+0x70>
test   %eax,%eax
je     11ac <devcards_routine+0x7c>
cmp    $0x1,%eax
jne    1150 <devcards_routine+0x20>
add    $0x1,%ebx
movslq %ebx,%rbx
imul   $0x2aaaaaab,%rbx,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
shr    $0x20,%rax
add    %ecx,%eax
add    %eax,%eax
lea    (%rax,%rax,2),%eax
sub    %eax,%ebx
jmp    1150 <devcards_routine+0x20>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
cmp    $0x4,%eax
je     11b9 <devcards_routine+0x89>
cmp    $0x63,%eax
jne    1150 <devcards_routine+0x20>
jmp    11cf <devcards_routine+0x9f>
test   %ebx,%ebx
lea    -0x1(%rbx),%eax
cmovle %r15d,%eax
mov    %eax,%ebx
jmp    1150 <devcards_routine+0x20>
mov    %ebp,%edi
mov    %ebx,%esi
mov    %r14d,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <devcards_handle@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @devcards_routine(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 0, i32* %6
br label %7
7: ; preds = %2, %29
%8 = load i32, i32* %4
%9 = load i32, i32* %6
%10 = call i32 @devcards_refresh(i32 %8, i32 %9)
%11 = call i32 (...) @io_getkey()
switch i32 %11, label %28 [
i32 0, label %12
i32 1, label %18
i32 4, label %22
i32 99, label %27
]
12: ; preds = %7
%13 = load i32, i32* %6
%14 = add nsw i32 %13, -1
store i32 %14, i32* %6
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %12
store i32 5, i32* %6
br label %17
17: ; preds = %16, %12
br label %29
18: ; preds = %7
%19 = load i32, i32* %6
%20 = add nsw i32 %19, 1
%21 = srem i32 %20, 6
store i32 %21, i32* %6
br label %29
22: ; preds = %7
%23 = load i32, i32* %4
%24 = load i32, i32* %6
%25 = load i32, i32* %5
%26 = call i32 @devcards_handle(i32 %23, i32 %24, i32 %25)
store i32 %26, i32* %3
br label %30
27: ; preds = %7
store i32 0, i32* %3
br label %30
28: ; preds = %7
br label %29
29: ; preds = %28, %18, %17
br label %7
30: ; preds = %27, %22
%31 = load i32, i32* %3
ret i32 %31
}

LLVM IR (-O2):
define i32 @devcards_routine(i32 %0, i32 %1) {
br label %3
3: ; preds = %15, %2
%4 = phi i32 [ 0, %2 ], [ %16, %15 ]
br label %5
5: ; preds = %3, %5
%6 = tail call i32 @devcards_refresh(i32 %0, i32 %4)
%7 = tail call i32 (...) @io_getkey()
switch i32 %7, label %5 [
i32 0, label %8
i32 1, label %12
i32 4, label %17
i32 99, label %19
]
8: ; preds = %5
%9 = add nsw i32 %4, -1
%10 = icmp slt i32 %4, 1
%11 = select i1 %10, i32 5, i32 %9
br label %15
12: ; preds = %5
%13 = add nsw i32 %4, 1
%14 = srem i32 %13, 6
br label %15
15: ; preds = %12, %8
%16 = phi i32 [ %11, %8 ], [ %14, %12 ]
br label %3
17: ; preds = %5
%18 = tail call i32 @devcards_handle(i32 %0, i32 %4, i32 %1)
br label %19
19: ; preds = %5, %17
%20 = phi i32 [ %18, %17 ], [ 0, %5 ]
ret i32 %20
}