#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*/ *fgets(char *, int, int /*<<< orphan*/);
char getchar();
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ stdin;
int main(void) {
  char words[10];
  int i;
  puts("Enter strings (empty line to quit):");
  while (fgets(words, 10, stdin) != NULL && words[0] != '\n') {
    i = 0;
    while (words[i] != '\n' && words[i] != '\0')
      i++;
    if (words[i] == '\n')
      words[i] = '\0';
    else
      while (getchar() != '\n')
        continue;
    puts(words);
  }
  puts("done");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
call   1030 <puts@plt>
lea    -0xe(%rbp),%rdi
mov    0x2e92(%rip),%rax
mov    (%rax),%edx
mov    $0xa,%esi
call   1040 <fgets@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x15(%rbp)
je     1181 <main+0x51>
movsbl -0xe(%rbp),%eax
cmp    $0xa,%eax
setne  %al
mov    %al,-0x15(%rbp)
mov    -0x15(%rbp),%al
test   $0x1,%al
jne    1191 <main+0x61>
jmp    122f <main+0xff>
movl   $0x0,-0x14(%rbp)
movslq -0x14(%rbp),%rax
movsbl -0xe(%rbp,%rax,1),%ecx
xor    %eax,%eax
cmp    $0xa,%ecx
mov    %al,-0x16(%rbp)
je     11c1 <main+0x91>
movslq -0x14(%rbp),%rax
movsbl -0xe(%rbp,%rax,1),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x16(%rbp)
mov    -0x16(%rbp),%al
test   $0x1,%al
jne    11d1 <main+0xa1>
jmp    11df <main+0xaf>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1198 <main+0x68>
movslq -0x14(%rbp),%rax
movsbl -0xe(%rbp,%rax,1),%eax
cmp    $0xa,%eax
jne    11ff <main+0xcf>
movslq -0x14(%rbp),%rax
movb   $0x0,-0xe(%rbp,%rax,1)
jmp    1221 <main+0xf1>
jmp    1204 <main+0xd4>
mov    $0x0,%al
call   1050 <getchar@plt>
movsbl %al,%eax
cmp    $0xa,%eax
je     121c <main+0xec>
jmp    1204 <main+0xd4>
jmp    1221 <main+0xf1>
lea    -0xe(%rbp),%rdi
call   1030 <puts@plt>
jmp    114b <main+0x1b>
lea    0xdee(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
lea    0xec2(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e9e(%rip),%r14
mov    (%r14),%edx
lea    0xe(%rsp),%rdi
mov    $0xa,%esi
call   1040 <fgets@plt>
test   %rax,%rax
je     11d1 <main+0xa1>
mov    0xe(%rsp),%al
cmp    $0xa,%al
je     11d1 <main+0xa1>
lea    0xe(%rsp),%rbx
xor    %ecx,%ecx
jmp    1188 <main+0x58>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    0xf(%rsp,%rcx,1),%al
add    $0x1,%rcx
cmp    $0xa,%al
je     11a0 <main+0x70>
test   %al,%al
jne    1180 <main+0x50>
xor    %eax,%eax
call   1050 <getchar@plt>
cmp    $0xa,%al
jne    1190 <main+0x60>
jmp    11a7 <main+0x77>
nopl   (%rax)
mov    %ecx,%eax
movb   $0x0,0xe(%rsp,%rax,1)
mov    %rbx,%rdi
call   1030 <puts@plt>
mov    (%r14),%edx
mov    %rbx,%rdi
mov    $0xa,%esi
call   1040 <fgets@plt>
test   %rax,%rax
je     11d1 <main+0xa1>
mov    0xe(%rsp),%al
mov    $0x0,%ecx
cmp    $0xa,%al
jne    1188 <main+0x58>
lea    0xe4c(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [36 x i8] c"Enter strings (empty line to quit):\00"
@stdin = global i32 0
@.str.1 = [5 x i8] c"done\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [10 x i8]
%3 = alloca i32
store i32 0, i32* %1
%4 = call i32 @puts(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
br label %5
5: ; preds = %55, %0
%6 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%7 = load i32, i32* @stdin
%8 = call i32* @fgets(i8* %6, i32 10, i32 %7)
%9 = icmp ne i32* %8, null
br i1 %9, label %10, label %15
10: ; preds = %5
%11 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = icmp ne i32 %13, 10
br label %15
15: ; preds = %10, %5
%16 = phi i1 [ false, %5 ], [ %14, %10 ]
br i1 %16, label %17, label %58
17: ; preds = %15
store i32 0, i32* %3
br label %18
18: ; preds = %34, %17
%19 = load i32, i32* %3
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 %20
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp ne i32 %23, 10
br i1 %24, label %25, label %32
25: ; preds = %18
%26 = load i32, i32* %3
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 %27
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = icmp ne i32 %30, 0
br label %32
32: ; preds = %25, %18
%33 = phi i1 [ false, %18 ], [ %31, %25 ]
br i1 %33, label %34, label %37
34: ; preds = %32
%35 = load i32, i32* %3
%36 = add nsw i32 %35, 1
store i32 %36, i32* %3
br label %18
37: ; preds = %32
%38 = load i32, i32* %3
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 %39
%41 = load i8, i8* %40
%42 = sext i8 %41 to i32
%43 = icmp eq i32 %42, 10
br i1 %43, label %44, label %48
44: ; preds = %37
%45 = load i32, i32* %3
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 %46
store i8 0, i8* %47
br label %55
48: ; preds = %37
br label %49
49: ; preds = %53, %48
%50 = call signext i8 (...) @getchar()
%51 = sext i8 %50 to i32
%52 = icmp ne i32 %51, 10
br i1 %52, label %53, label %54
53: ; preds = %49
br label %49
54: ; preds = %49
br label %55
55: ; preds = %54, %44
%56 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%57 = call i32 @puts(i8* %56)
br label %5
58: ; preds = %15
%59 = call i32 @puts(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [36 x i8] c"Enter strings (empty line to quit):\00"
@stdin = global i32 0
@.str.1 = [5 x i8] c"done\00"
define i32 @main() {
%1 = alloca [10 x i8]
%2 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%4 = load i32, i32* @stdin
%5 = call i32* @fgets(i8* %2, i32 10, i32 %4)
%6 = icmp ne i32* %5, null
%7 = load i8, i8* %2
%8 = icmp ne i8 %7, 10
%9 = select i1 %6, i1 %8, i1 false
br i1 %9, label %10, label %34
10: ; preds = %0, %17
%11 = phi i8 [ %18, %17 ], [ %7, %0 ]
%12 = phi i64 [ %19, %17 ], [ 0, %0 ]
switch i8 %11, label %13 [
i8 10, label %20
i8 0, label %23
]
13: ; preds = %10
%14 = add nuw i64 %12, 1
%15 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 %14
%16 = load i8, i8* %15
br label %17
17: ; preds = %13, %26
%18 = phi i8 [ %16, %13 ], [ %31, %26 ]
%19 = phi i64 [ %14, %13 ], [ 0, %26 ]
br label %10
20: ; preds = %10
%21 = and i64 %12, 4294967295
%22 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 %21
store i8 0, i8* %22
br label %26
23: ; preds = %10, %23
%24 = call signext i8 (...) @getchar()
%25 = icmp eq i8 %24, 10
br i1 %25, label %26, label %23
26: ; preds = %23, %20
%27 = call i32 @puts(i8* %2)
%28 = load i32, i32* @stdin
%29 = call i32* @fgets(i8* %2, i32 10, i32 %28)
%30 = icmp ne i32* %29, null
%31 = load i8, i8* %2
%32 = icmp ne i8 %31, 10
%33 = select i1 %30, i1 %32, i1 false
br i1 %33, label %17, label %34
34: ; preds = %26, %0
%35 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
ret i32 0
}