#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 /*<<< orphan*/ add_word(char *);
int /*<<< orphan*/ clear_line();
int /*<<< orphan*/ flush_line();
int /*<<< orphan*/ read_word(char *, int);
int space_remaining();
int strlen(char *);
int /*<<< orphan*/ write_line();
int main(void) {
  char word[20 + 2];
  int word_len;
  clear_line();
  for (;;) {
    read_word(word, 20 + 1);
    word_len = strlen(word);
    if (word_len == 0) {
      flush_line();
      return 0;
    }
    if (word_len > 20)
      word[20] = '*';
    if (word_len + 1 > space_remaining()) {
      write_line();
      clear_line();
    }
    add_word(word);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1040 <clear_line@plt>
lea    -0x20(%rbp),%rdi
mov    $0x15,%esi
call   1070 <read_word@plt>
lea    -0x20(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jne    11b9 <main+0x49>
mov    $0x0,%al
call   1090 <flush_line@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret
cmpl   $0x14,-0x24(%rbp)
jle    11c7 <main+0x57>
movb   $0x2a,-0xc(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
mov    $0x0,%al
call   1030 <space_remaining@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%eax
cmp    %ecx,%eax
jle    11f2 <main+0x82>
mov    $0x0,%al
call   1080 <write_line@plt>
mov    $0x0,%al
call   1040 <clear_line@plt>
lea    -0x20(%rbp),%rdi
call   1060 <add_word@plt>
jmp    1186 <main+0x16>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
xor    %eax,%eax
call   1040 <clear_line@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x15,%esi
call   1070 <read_word@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
test   %eax,%eax
je     11e8 <main+0x78>
mov    %eax,%ebp
mov    %rsp,%rbx
jmp    11c3 <main+0x53>
mov    %rbx,%rdi
call   1060 <add_word@plt>
mov    %rbx,%rdi
mov    $0x15,%esi
call   1070 <read_word@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %eax,%ebp
test   %eax,%eax
je     11e8 <main+0x78>
cmp    $0x15,%ebp
jl     11cd <main+0x5d>
movb   $0x2a,0x14(%rsp)
xor    %eax,%eax
call   1030 <space_remaining@plt>
cmp    %eax,%ebp
jl     11a0 <main+0x30>
xor    %eax,%eax
call   1080 <write_line@plt>
xor    %eax,%eax
call   1040 <clear_line@plt>
jmp    11a0 <main+0x30>
xor    %eax,%eax
call   1090 <flush_line@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @main() {
%1 = alloca i32
%2 = alloca [22 x i8]
%3 = alloca i32
store i32 0, i32* %1
%4 = call i32 (...) @clear_line()
br label %5
5: ; preds = %27, %0
%6 = getelementptr inbounds [22 x i8], [22 x i8]* %2, i64 0, i64 0
%7 = call i32 @read_word(i8* %6, i32 21)
%8 = getelementptr inbounds [22 x i8], [22 x i8]* %2, i64 0, i64 0
%9 = call i32 @strlen(i8* %8)
store i32 %9, i32* %3
%10 = load i32, i32* %3
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %5
%13 = call i32 (...) @flush_line()
ret i32 0
14: ; preds = %5
%15 = load i32, i32* %3
%16 = icmp sgt i32 %15, 20
br i1 %16, label %17, label %19
17: ; preds = %14
%18 = getelementptr inbounds [22 x i8], [22 x i8]* %2, i64 0, i64 20
store i8 42, i8* %18
br label %19
19: ; preds = %17, %14
%20 = load i32, i32* %3
%21 = add nsw i32 %20, 1
%22 = call i32 (...) @space_remaining()
%23 = icmp sgt i32 %21, %22
br i1 %23, label %24, label %27
24: ; preds = %19
%25 = call i32 (...) @write_line()
%26 = call i32 (...) @clear_line()
br label %27
27: ; preds = %24, %19
%28 = getelementptr inbounds [22 x i8], [22 x i8]* %2, i64 0, i64 0
%29 = call i32 @add_word(i8* %28)
br label %5
}

LLVM IR (-O2):
define i32 @main() {
%1 = alloca [22 x i8]
%2 = getelementptr inbounds [22 x i8], [22 x i8]* %1, i64 0, i64 0
%3 = tail call i32 (...) @clear_line()
%4 = call i32 @read_word(i8* %2, i32 21)
%5 = call i32 @strlen(i8* %2)
%6 = icmp eq i32 %5, 0
br i1 %6, label %9, label %7
7: ; preds = %0
%8 = getelementptr inbounds [22 x i8], [22 x i8]* %1, i64 0, i64 20
br label %11
9: ; preds = %21, %0
%10 = call i32 (...) @flush_line()
ret i32 0
11: ; preds = %7, %21
%12 = phi i32 [ %5, %7 ], [ %24, %21 ]
%13 = icmp sgt i32 %12, 20
br i1 %13, label %14, label %15
14: ; preds = %11
store i8 42, i8* %8
br label %15
15: ; preds = %14, %11
%16 = call i32 (...) @space_remaining()
%17 = icmp slt i32 %12, %16
br i1 %17, label %21, label %18
18: ; preds = %15
%19 = call i32 (...) @write_line()
%20 = call i32 (...) @clear_line()
br label %21
21: ; preds = %18, %15
%22 = call i32 @add_word(i8* %2)
%23 = call i32 @read_word(i8* %2, i32 21)
%24 = call i32 @strlen(i8* %2)
%25 = icmp eq i32 %24, 0
br i1 %25, label %9, label %11
}