#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*/ addch(int);
int /*<<< orphan*/ clear_question();
int getch();
int /*<<< orphan*/ printw(char *);
int which_hex(void) {
  clear_question();
  printw("Which hexagram do you want to visit (1 - 64)? ");
  int ans = getch();
  addch(ans);
  ans = ans - '0';
  int digit2 = getch();
  if (digit2 != '\n')
    ans = ans * 10 + (digit2 - '0');
  clear_question();
  return (ans - 1) & 63;
}


x86 assembly (clang, -O0):
<which_hex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1060 <clear_question@plt>
lea    0xeaa(%rip),%rdi
call   1030 <printw@plt>
mov    $0x0,%al
call   1050 <getch@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%edi
call   1040 <addch@plt>
mov    -0x4(%rbp),%eax
sub    $0x30,%eax
mov    %eax,-0x4(%rbp)
mov    $0x0,%al
call   1050 <getch@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xa,-0x8(%rbp)
je     1199 <which_hex+0x59>
imul   $0xa,-0x4(%rbp),%eax
mov    -0x8(%rbp),%ecx
sub    $0x30,%ecx
add    %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    $0x0,%al
call   1060 <clear_question@plt>
mov    -0x4(%rbp),%eax
sub    $0x1,%eax
and    $0x3f,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<which_hex>:
push   %rbp
push   %rbx
push   %rax
xor    %eax,%eax
call   1060 <clear_question@plt>
lea    0xeaf(%rip),%rdi
call   1030 <printw@plt>
xor    %eax,%eax
call   1050 <getch@plt>
mov    %eax,%ebx
mov    %eax,%edi
call   1040 <addch@plt>
add    $0xffffffd0,%ebx
xor    %eax,%eax
call   1050 <getch@plt>
cmp    $0xa,%eax
lea    (%rbx,%rbx,4),%ecx
lea    0x10(%rax,%rcx,2),%ebp
cmove  %ebx,%ebp
xor    %eax,%eax
call   1060 <clear_question@plt>
add    $0xffffffff,%ebp
and    $0x3f,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [47 x i8] c"Which hexagram do you want to visit (1 - 64)? \00"
define i32 @which_hex() {
%1 = alloca i32
%2 = alloca i32
%3 = call i32 (...) @clear_question()
%4 = call i32 @printw(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0))
%5 = call i32 (...) @getch()
store i32 %5, i32* %1
%6 = load i32, i32* %1
%7 = call i32 @addch(i32 %6)
%8 = load i32, i32* %1
%9 = sub nsw i32 %8, 48
store i32 %9, i32* %1
%10 = call i32 (...) @getch()
store i32 %10, i32* %2
%11 = load i32, i32* %2
%12 = icmp ne i32 %11, 10
br i1 %12, label %13, label %19
13: ; preds = %0
%14 = load i32, i32* %1
%15 = mul nsw i32 %14, 10
%16 = load i32, i32* %2
%17 = sub nsw i32 %16, 48
%18 = add nsw i32 %15, %17
store i32 %18, i32* %1
br label %19
19: ; preds = %13, %0
%20 = call i32 (...) @clear_question()
%21 = load i32, i32* %1
%22 = sub nsw i32 %21, 1
%23 = and i32 %22, 63
ret i32 %23
}

LLVM IR (-O2):
@.str = [47 x i8] c"Which hexagram do you want to visit (1 - 64)? \00"
define i32 @which_hex() {
%1 = tail call i32 (...) @clear_question()
%2 = tail call i32 @printw(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0))
%3 = tail call i32 (...) @getch()
%4 = tail call i32 @addch(i32 %3)
%5 = add nsw i32 %3, -48
%6 = tail call i32 (...) @getch()
%7 = icmp eq i32 %6, 10
%8 = mul nsw i32 %5, 10
%9 = add i32 %6, 16
%10 = add i32 %9, %8
%11 = select i1 %7, i32 %5, i32 %10
%12 = tail call i32 (...) @clear_question()
%13 = add i32 %11, 63
%14 = and i32 %13, 63
ret i32 %14
}