#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__ malloc(int);
int /*<<< orphan*/ scanf(char *, char *);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ ungetc(char, int /*<<< orphan*/);
char *readName() {
  char *res = (char *)malloc(sizeof(char) * 21);
  int i = -1;
  do {
    i++;
    scanf(" %c", res + i);
  } while (((res[i]) <= 'Z' && (res[i]) >= 'A'));
  ungetc(res[i], stdin);
  res[i] = 0;
  return res;
}


x86 assembly (clang, -O0):
<readName>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x15,%edi
call   1030 <malloc@plt>
mov    %rax,-0x8(%rbp)
movl   $0xffffffff,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rsi
movslq -0xc(%rbp),%rax
add    %rax,%rsi
lea    0xe98(%rip),%rdi
call   1050 <scanf@plt>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%ecx
xor    %eax,%eax
cmp    $0x5a,%ecx
mov    %al,-0xd(%rbp)
jg     119c <readName+0x6c>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x41,%eax
setge  %al
mov    %al,-0xd(%rbp)
mov    -0xd(%rbp),%al
test   $0x1,%al
jne    114d <readName+0x1d>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    0x2e2f(%rip),%rcx
mov    (%rcx),%esi
movsbl %al,%edi
call   1040 <ungetc@plt>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readName>:
push   %r15
push   %r14
push   %rbx
mov    $0x15,%edi
call   1030 <malloc@plt>
mov    %rax,%r14
lea    0xeb7(%rip),%r15
mov    %rax,%rbx
nopl   0x0(%rax)
mov    %r15,%rdi
mov    %rbx,%rsi
call   1050 <scanf@plt>
movzbl (%rbx),%eax
lea    -0x41(%rax),%ecx
add    $0x1,%rbx
cmp    $0x1a,%cl
jb     1150 <readName+0x20>
mov    0x2e77(%rip),%rcx
mov    (%rcx),%esi
movsbl %al,%edi
call   1040 <ungetc@plt>
movb   $0x0,-0x1(%rbx)
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [4 x i8] c" %c\00"
@stdin = global i32 0
define i8* @readName() {
%1 = alloca i8*
%2 = alloca i32
%3 = call i64 @malloc(i32 21)
%4 = inttoptr i64 %3 to i8*
store i8* %4, i8** %1
store i32 -1, i32* %2
br label %5
5: ; preds = %29, %0
%6 = load i32, i32* %2
%7 = add nsw i32 %6, 1
store i32 %7, i32* %2
%8 = load i8*, i8** %1
%9 = load i32, i32* %2
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds i8, i8* %8, i64 %10
%12 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %11)
br label %13
13: ; preds = %5
%14 = load i8*, i8** %1
%15 = load i32, i32* %2
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %14, i64 %16
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp sle i32 %19, 90
br i1 %20, label %21, label %29
21: ; preds = %13
%22 = load i8*, i8** %1
%23 = load i32, i32* %2
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %22, i64 %24
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp sge i32 %27, 65
br label %29
29: ; preds = %21, %13
%30 = phi i1 [ false, %13 ], [ %28, %21 ]
br i1 %30, label %5, label %31
31: ; preds = %29
%32 = load i8*, i8** %1
%33 = load i32, i32* %2
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %32, i64 %34
%36 = load i8, i8* %35
%37 = load i32, i32* @stdin
%38 = call i32 @ungetc(i8 signext %36, i32 %37)
%39 = load i8*, i8** %1
%40 = load i32, i32* %2
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %39, i64 %41
store i8 0, i8* %42
%43 = load i8*, i8** %1
ret i8* %43
}

LLVM IR (-O2):
@.str = [4 x i8] c" %c\00"
@stdin = global i32 0
define i8* @readName() {
%1 = tail call i64 @malloc(i32 21)
%2 = inttoptr i64 %1 to i8*
br label %3
3: ; preds = %3, %0
%4 = phi i64 [ %5, %3 ], [ -1, %0 ]
%5 = add nsw i64 %4, 1
%6 = getelementptr inbounds i8, i8* %2, i64 %5
%7 = tail call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = load i8, i8* %6
%9 = add i8 %8, -65
%10 = icmp ult i8 %9, 26
br i1 %10, label %3, label %11
11: ; preds = %3
%12 = load i32, i32* @stdin
%13 = tail call i32 @ungetc(i8 signext %8, i32 %12)
store i8 0, i8* %6
ret i8* %2
}