#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 getch();
int /*<<< orphan*/ isalnum(char);
scalar_t__ isalpha(char);
int /*<<< orphan*/ printf(char *, ...);
int get_string(char *word, int lim) {
  char *w = word;
  printf("input word: ");
  for (; --lim > 0; w++) {
    if (!isalnum(*w = getch())) {
      break;
    }
    printf("%c", *w);
  }
  *w = '\0';
  printf("\n");
  if (isalpha(word[0]))
    return 1;
  else
    return 0;
}


x86 assembly (clang, -O0):
<get_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
lea    0xea2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jle    11c0 <get_string+0x80>
mov    $0x0,%al
call   1060 <getch@plt>
mov    -0x20(%rbp),%rcx
mov    %al,(%rcx)
movsbl %al,%edi
call   1040 <isalnum@plt>
cmp    $0x0,%eax
jne    119a <get_string+0x5a>
jmp    11c0 <get_string+0x80>
mov    -0x20(%rbp),%rax
movsbl (%rax),%esi
lea    0xe65(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1165 <get_string+0x25>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
lea    0xe42(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1050 <isalpha@plt>
cmp    $0x0,%rax
je     11f7 <get_string+0xb7>
movl   $0x1,-0x4(%rbp)
jmp    11fe <get_string+0xbe>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_string>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebp
mov    %rdi,%r14
lea    0xea0(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14,%rbx
cmp    $0x2,%ebp
jl     11a9 <get_string+0x59>
add    $0x1,%ebp
mov    %r14,%rbx
cs nopw 0x0(%rax,%rax,1)
nop
xor    %eax,%eax
call   1070 <getch@plt>
mov    %al,(%rbx)
movsbl %al,%edi
call   1050 <isalnum@plt>
test   %eax,%eax
je     11a9 <get_string+0x59>
movsbl (%rbx),%edi
call   1030 <putchar@plt>
add    $0x1,%rbx
add    $0xffffffff,%ebp
cmp    $0x2,%ebp
jg     1180 <get_string+0x30>
movb   $0x0,(%rbx)
mov    $0xa,%edi
call   1030 <putchar@plt>
movsbl (%r14),%edi
call   1060 <isalpha@plt>
xor    %ecx,%ecx
test   %rax,%rax
setne  %cl
mov    %ecx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"input word: \00"
@.str.1 = [3 x i8] c"%c\00"
@.str.2 = [2 x i8] c"\0A\00"
define i32 @get_string(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
store i8* %0, i8** %4
store i32 %1, i32* %5
%7 = load i8*, i8** %4
store i8* %7, i8** %6
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
br label %9
9: ; preds = %24, %2
%10 = load i32, i32* %5
%11 = add nsw i32 %10, -1
store i32 %11, i32* %5
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %27
13: ; preds = %9
%14 = call signext i8 (...) @getch()
%15 = load i8*, i8** %6
store i8 %14, i8* %15
%16 = call i32 @isalnum(i8 signext %14)
%17 = icmp ne i32 %16, 0
br i1 %17, label %19, label %18
18: ; preds = %13
br label %27
19: ; preds = %13
%20 = load i8*, i8** %6
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %22)
br label %24
24: ; preds = %19
%25 = load i8*, i8** %6
%26 = getelementptr inbounds i8, i8* %25, i32 1
store i8* %26, i8** %6
br label %9
27: ; preds = %18, %9
%28 = load i8*, i8** %6
store i8 0, i8* %28
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%30 = load i8*, i8** %4
%31 = getelementptr inbounds i8, i8* %30, i64 0
%32 = load i8, i8* %31
%33 = call i64 @isalpha(i8 signext %32)
%34 = icmp ne i64 %33, 0
br i1 %34, label %35, label %36
35: ; preds = %27
store i32 1, i32* %3
br label %37
36: ; preds = %27
store i32 0, i32* %3
br label %37
37: ; preds = %36, %35
%38 = load i32, i32* %3
ret i32 %38
}

LLVM IR (-O2):
@.str = [13 x i8] c"input word: \00"
define i32 @get_string(i8* nocapture %0, i32 %1) {
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%4 = icmp sgt i32 %1, 1
br i1 %4, label %5, label %18
5: ; preds = %2, %11
%6 = phi i32 [ %12, %11 ], [ %1, %2 ]
%7 = phi i8* [ %16, %11 ], [ %0, %2 ]
%8 = tail call signext i8 (...) @getch()
store i8 %8, i8* %7
%9 = tail call i32 @isalnum(i8 signext %8)
%10 = icmp eq i32 %9, 0
br i1 %10, label %18, label %11
11: ; preds = %5
%12 = add nsw i32 %6, -1
%13 = load i8, i8* %7
%14 = sext i8 %13 to i32
%15 = tail call i32 @putchar(i32 %14)
%16 = getelementptr inbounds i8, i8* %7, i64 1
%17 = icmp sgt i32 %6, 2
br i1 %17, label %5, label %18
18: ; preds = %11, %5, %2
%19 = phi i8* [ %0, %2 ], [ %7, %5 ], [ %16, %11 ]
store i8 0, i8* %19
%20 = tail call i32 @putchar(i32 10)
%21 = load i8, i8* %0
%22 = tail call i64 @isalpha(i8 signext %21)
%23 = icmp ne i64 %22, 0
%24 = zext i1 %23 to i32
ret i32 %24
}