#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 */
char getchar();
int /*<<< orphan*/ printf(char *);
int read_char(char str[], int n) {
  int i = 0, j;
  char ch;
  printf("Enter word: ");
  while ((ch = getchar()) != '\n' && i < 20) {
    if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z')) {
      str[i++] = ch;
    }
  }
  str[i] = '\0';
  return i;
}


x86 assembly (clang, -O0):
<read_char>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
lea    0xec3(%rip),%rdi
call   1030 <printf@plt>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %al,-0x15(%rbp)
movsbl %al,%ecx
xor    %eax,%eax
cmp    $0xa,%ecx
mov    %al,-0x16(%rbp)
je     1167 <read_char+0x47>
cmpl   $0x14,-0x10(%rbp)
setl   %al
mov    %al,-0x16(%rbp)
mov    -0x16(%rbp),%al
test   $0x1,%al
jne    1177 <read_char+0x57>
jmp    11c8 <read_char+0xa8>
movsbl -0x15(%rbp),%eax
cmp    $0x61,%eax
jl     1191 <read_char+0x71>
movsbl -0x15(%rbp),%eax
cmp    $0x7a,%eax
jle    11ab <read_char+0x8b>
movsbl -0x15(%rbp),%eax
cmp    $0x41,%eax
jl     11c3 <read_char+0xa3>
movsbl -0x15(%rbp),%eax
cmp    $0x5a,%eax
jg     11c3 <read_char+0xa3>
mov    -0x15(%rbp),%dl
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x10(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
jmp    1142 <read_char+0x22>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_char>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
lea    0xed3(%rip),%rdi
call   1030 <printf@plt>
xor    %ebp,%ebp
xor    %eax,%eax
call   1040 <getchar@plt>
cmp    $0xa,%al
je     1176 <read_char+0x56>
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %eax,%ecx
and    $0xdf,%cl
add    $0xbf,%cl
cmp    $0x19,%cl
ja     1166 <read_char+0x46>
movslq %ebp,%rcx
add    $0x1,%ebp
mov    %al,(%rbx,%rcx,1)
xor    %eax,%eax
call   1040 <getchar@plt>
cmp    $0xa,%al
je     1176 <read_char+0x56>
cmp    $0x14,%ebp
jl     1150 <read_char+0x30>
movslq %ebp,%rax
movb   $0x0,(%rbx,%rax,1)
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [13 x i8] c"Enter word: \00"
define i32 @read_char(i8* nocapture writeonly %0, i32 %1) {
%3 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%4 = tail call signext i8 (...) @getchar()
%5 = icmp eq i8 %4, 10
br i1 %5, label %22, label %6
6: ; preds = %2, %16
%7 = phi i8 [ %18, %16 ], [ %4, %2 ]
%8 = phi i32 [ %17, %16 ], [ 0, %2 ]
%9 = and i8 %7, -33
%10 = add i8 %9, -65
%11 = icmp ult i8 %10, 26
br i1 %11, label %12, label %16
12: ; preds = %6
%13 = add nsw i32 %8, 1
%14 = sext i32 %8 to i64
%15 = getelementptr inbounds i8, i8* %0, i64 %14
store i8 %7, i8* %15
br label %16
16: ; preds = %6, %12
%17 = phi i32 [ %13, %12 ], [ %8, %6 ]
%18 = tail call signext i8 (...) @getchar()
%19 = icmp ne i8 %18, 10
%20 = icmp slt i32 %17, 20
%21 = select i1 %19, i1 %20, i1 false
br i1 %21, label %6, label %22
22: ; preds = %16, %2
%23 = phi i32 [ 0, %2 ], [ %17, %16 ]
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %0, i64 %24
store i8 0, i8* %25
ret i32 %23
}