#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*/ puts(char *);
void fig08_11() {
  int c;
  char sentence[80];
  int i = 0;
  puts("Enter o line of text:");
  while (i < 80 - 1 && (c = getchar()) != '\n') {
    sentence[i++] = c;
  }
  sentence[i] = '\0';
  puts("\nThe line entered was:");
  puts(sentence);
}


x86 assembly (clang, -O0):
<fig08_11>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x64(%rbp)
lea    0xeca(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
cmpl   $0x4f,-0x64(%rbp)
mov    %al,-0x65(%rbp)
jge    115d <fig08_11+0x3d>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %eax,-0x4(%rbp)
cmp    $0xa,%eax
setne  %al
mov    %al,-0x65(%rbp)
mov    -0x65(%rbp),%al
test   $0x1,%al
jne    116d <fig08_11+0x4d>
jmp    1188 <fig08_11+0x68>
mov    -0x4(%rbp),%eax
mov    %al,%cl
mov    -0x64(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x64(%rbp)
cltq
mov    %cl,-0x60(%rbp,%rax,1)
jmp    113b <fig08_11+0x1b>
movslq -0x64(%rbp),%rax
movb   $0x0,-0x60(%rbp,%rax,1)
lea    0xe7e(%rip),%rdi
call   1030 <puts@plt>
lea    -0x60(%rbp),%rdi
call   1030 <puts@plt>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fig08_11>:
push   %rbx
sub    $0x50,%rsp
lea    0xed4(%rip),%rdi
call   1030 <puts@plt>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %eax,%eax
call   1040 <getchar@plt>
cmp    $0xa,%eax
je     115e <fig08_11+0x3e>
mov    %al,(%rsp,%rbx,1)
add    $0x1,%rbx
cmp    $0x4f,%rbx
jne    1140 <fig08_11+0x20>
mov    $0x4f,%ebx
mov    %ebx,%eax
movb   $0x0,(%rsp,%rax,1)
lea    0xeab(%rip),%rdi
call   1030 <puts@plt>
mov    %rsp,%rdi
call   1030 <puts@plt>
add    $0x50,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
@.str = [22 x i8] c"Enter o line of text:\00"
@.str.1 = [23 x i8] c"\0AThe line entered was:\00"
define void @fig08_11() {
%1 = alloca [80 x i8]
%2 = getelementptr inbounds [80 x i8], [80 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
br label %4
4: ; preds = %0, %8
%5 = phi i64 [ 0, %0 ], [ %10, %8 ]
%6 = tail call i32 (...) @getchar()
%7 = icmp eq i32 %6, 10
br i1 %7, label %13, label %8
8: ; preds = %4
%9 = trunc i32 %6 to i8
%10 = add nuw nsw i64 %5, 1
%11 = getelementptr inbounds [80 x i8], [80 x i8]* %1, i64 0, i64 %5
store i8 %9, i8* %11
%12 = icmp eq i64 %10, 79
br i1 %12, label %13, label %4
13: ; preds = %8, %4
%14 = phi i64 [ 79, %8 ], [ %5, %4 ]
%15 = and i64 %14, 4294967295
%16 = getelementptr inbounds [80 x i8], [80 x i8]* %1, i64 0, i64 %15
store i8 0, i8* %16
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
%18 = call i32 @puts(i8* %2)
ret void
}