#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 getchar();
int /*<<< orphan*/ printf(char *);
void read_input(char str[]) {
  int i = 0;
  int ch;
  printf("Enter word: ");
  while ((ch = getchar()) != '\n') {
    if (i < 81) {
      str[i] = (char)ch;
      i += 1;
    }
  }
  str[i] = '\0';
}


x86 assembly (clang, -O0):
<read_input>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
lea    0xec6(%rip),%rdi
call   1030 <printf@plt>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %eax,-0x10(%rbp)
cmp    $0xa,%eax
je     117a <read_input+0x5a>
cmpl   $0x51,-0xc(%rbp)
jge    1175 <read_input+0x55>
mov    -0x10(%rbp),%eax
mov    %al,%dl
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    113f <read_input+0x1f>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_input>:
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,%eax
jne    114e <read_input+0x2e>
movslq %ebp,%rax
movb   $0x0,(%rbx,%rax,1)
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
xor    %ebp,%ebp
jmp    116c <read_input+0x4c>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %eax,%eax
call   1040 <getchar@plt>
cmp    $0xa,%eax
je     1140 <read_input+0x20>
cmp    $0x50,%ebp
jg     1160 <read_input+0x40>
movslq %ebp,%rcx
mov    %al,(%rbx,%rcx,1)
add    $0x1,%ebp
jmp    1160 <read_input+0x40>

LLVM IR (-O0):
@.str = [13 x i8] c"Enter word: \00"
define void @read_input(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %3
%5 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
br label %6
6: ; preds = %21, %1
%7 = call i32 (...) @getchar()
store i32 %7, i32* %4
%8 = icmp ne i32 %7, 10
br i1 %8, label %9, label %22
9: ; preds = %6
%10 = load i32, i32* %3
%11 = icmp slt i32 %10, 81
br i1 %11, label %12, label %21
12: ; preds = %9
%13 = load i32, i32* %4
%14 = trunc i32 %13 to i8
%15 = load i8*, i8** %2
%16 = load i32, i32* %3
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %15, i64 %17
store i8 %14, i8* %18
%19 = load i32, i32* %3
%20 = add nsw i32 %19, 1
store i32 %20, i32* %3
br label %21
21: ; preds = %12, %9
br label %6
22: ; preds = %6
%23 = load i8*, i8** %2
%24 = load i32, i32* %3
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %23, i64 %25
store i8 0, i8* %26
ret void
}

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