#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*/ isalpha(char);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, char *);
char ask_user(char *history) {
  static int history_index = 0;
  char c;
  printf("Enter letter: ");
  do {
    scanf("%c", &c);
  } while (!isalpha(c));
  printf("\n");
  history[history_index++ % (16 - 1)] = c;
  return c;
}


x86 assembly (clang, -O0):
<ask_user>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xebd(%rip),%rdi
call   1030 <printf@plt>
lea    0xec0(%rip),%rdi
lea    -0x9(%rbp),%rsi
call   1050 <scanf@plt>
movsbl -0x9(%rbp),%edi
call   1040 <isalpha@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1148 <ask_user+0x18>
lea    0xe9a(%rip),%rdi
call   1030 <printf@plt>
mov    -0x9(%rbp),%al
mov    %al,-0xa(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    0x2eab(%rip),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,0x2ea0(%rip)
mov    $0xf,%ecx
cltd
idiv   %ecx
mov    -0x18(%rbp),%rax
mov    %edx,%ecx
mov    -0xa(%rbp),%dl
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
movsbl -0x9(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ask_user>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r14
lea    0xead(%rip),%rdi
call   1040 <printf@plt>
lea    0xeb0(%rip),%r15
lea    0xf(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r15,%rdi
mov    %rbx,%rsi
call   1060 <scanf@plt>
movsbl 0xf(%rsp),%edi
call   1050 <isalpha@plt>
test   %eax,%eax
je     1170 <ask_user+0x30>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0xf(%rsp),%al
movslq 0x2ea6(%rip),%rcx
lea    0x1(%rcx),%edx
mov    %edx,0x2e9d(%rip)
imul   $0xffffffff88888889,%rcx,%rdx
shr    $0x20,%rdx
add    %ecx,%edx
mov    %edx,%esi
shr    $0x1f,%esi
sar    $0x3,%edx
add    %esi,%edx
lea    (%rdx,%rdx,4),%edx
lea    (%rdx,%rdx,2),%edx
sub    %edx,%ecx
movslq %ecx,%rcx
mov    %al,(%r14,%rcx,1)
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@ask_user.history_index = internal global i32 0
@.str = [15 x i8] c"Enter letter: \00"
@.str.1 = [3 x i8] c"%c\00"
@.str.2 = [2 x i8] c"\0A\00"
define signext i8 @ask_user(i8* %0) {
%2 = alloca i8*
%3 = alloca i8
store i8* %0, i8** %2
%4 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %5
5: ; preds = %7, %1
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %3)
br label %7
7: ; preds = %5
%8 = load i8, i8* %3
%9 = call i32 @isalpha(i8 signext %8)
%10 = icmp ne i32 %9, 0
%11 = xor i1 %10, true
br i1 %11, label %5, label %12
12: ; preds = %7
%13 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%14 = load i8, i8* %3
%15 = load i8*, i8** %2
%16 = load i32, i32* @ask_user.history_index
%17 = add nsw i32 %16, 1
store i32 %17, i32* @ask_user.history_index
%18 = srem i32 %16, 15
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %15, i64 %19
store i8 %14, i8* %20
%21 = load i8, i8* %3
ret i8 %21
}

LLVM IR (-O2):
@ask_user.history_index = internal unnamed_addr global i32 0
@.str = [15 x i8] c"Enter letter: \00"
@.str.1 = [3 x i8] c"%c\00"
define signext i8 @ask_user(i8* nocapture writeonly %0) {
%2 = alloca i8
%3 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %4
4: ; preds = %4, %1
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %2)
%6 = load i8, i8* %2
%7 = call i32 @isalpha(i8 signext %6)
%8 = icmp eq i32 %7, 0
br i1 %8, label %4, label %9
9: ; preds = %4
%10 = call i32 @putchar(i32 10)
%11 = load i8, i8* %2
%12 = load i32, i32* @ask_user.history_index
%13 = add nsw i32 %12, 1
store i32 %13, i32* @ask_user.history_index
%14 = srem i32 %12, 15
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %0, i64 %15
store i8 %11, i8* %16
ret i8 %11
}