#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[100];
  int i;
  puts("Enter strings (empty line to quit):");
  while (fgets(words, 100, 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    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeb7(%rip),%rdi
call   1030 <puts@plt>
lea    -0x70(%rbp),%rdi
mov    0x2e8f(%rip),%rax
mov    (%rax),%edx
mov    $0x64,%esi
call   1040 <fgets@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x75(%rbp)
je     1184 <main+0x54>
movsbl -0x70(%rbp),%eax
cmp    $0xa,%eax
setne  %al
mov    %al,-0x75(%rbp)
mov    -0x75(%rbp),%al
test   $0x1,%al
jne    1194 <main+0x64>
jmp    1232 <main+0x102>
movl   $0x0,-0x74(%rbp)
movslq -0x74(%rbp),%rax
movsbl -0x70(%rbp,%rax,1),%ecx
xor    %eax,%eax
cmp    $0xa,%ecx
mov    %al,-0x76(%rbp)
je     11c4 <main+0x94>
movslq -0x74(%rbp),%rax
movsbl -0x70(%rbp,%rax,1),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x76(%rbp)
mov    -0x76(%rbp),%al
test   $0x1,%al
jne    11d4 <main+0xa4>
jmp    11e2 <main+0xb2>
mov    -0x74(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x74(%rbp)
jmp    119b <main+0x6b>
movslq -0x74(%rbp),%rax
movsbl -0x70(%rbp,%rax,1),%eax
cmp    $0xa,%eax
jne    1202 <main+0xd2>
movslq -0x74(%rbp),%rax
movb   $0x0,-0x70(%rbp,%rax,1)
jmp    1224 <main+0xf4>
jmp    1207 <main+0xd7>
mov    $0x0,%al
call   1050 <getchar@plt>
movsbl %al,%eax
cmp    $0xa,%eax
je     121f <main+0xef>
jmp    1207 <main+0xd7>
jmp    1224 <main+0xf4>
lea    -0x70(%rbp),%rdi
call   1030 <puts@plt>
jmp    114e <main+0x1e>
lea    0xdeb(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x68,%rsp
lea    0xec2(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e9e(%rip),%r14
mov    (%r14),%edx
mov    %rsp,%rdi
mov    $0x64,%esi
call   1040 <fgets@plt>
test   %rax,%rax
je     11bf <main+0x8f>
mov    (%rsp),%al
cmp    $0xa,%al
je     11bf <main+0x8f>
mov    %rsp,%rbx
xor    %ecx,%ecx
jmp    1178 <main+0x48>
nopl   (%rax)
mov    0x1(%rsp,%rcx,1),%al
add    $0x1,%rcx
cmp    $0xa,%al
je     1190 <main+0x60>
test   %al,%al
jne    1170 <main+0x40>
xor    %eax,%eax
call   1050 <getchar@plt>
cmp    $0xa,%al
jne    1180 <main+0x50>
jmp    1196 <main+0x66>
nopl   (%rax)
mov    %ecx,%eax
movb   $0x0,(%rsp,%rax,1)
mov    %rbx,%rdi
call   1030 <puts@plt>
mov    (%r14),%edx
mov    %rbx,%rdi
mov    $0x64,%esi
call   1040 <fgets@plt>
test   %rax,%rax
je     11bf <main+0x8f>
mov    (%rsp),%al
mov    $0x0,%ecx
cmp    $0xa,%al
jne    1178 <main+0x48>
lea    0xe5e(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x68,%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 [100 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 [100 x i8], [100 x i8]* %2, i64 0, i64 0
%7 = load i32, i32* @stdin
%8 = call i32* @fgets(i8* %6, i32 100, i32 %7)
%9 = icmp ne i32* %8, null
br i1 %9, label %10, label %15
10: ; preds = %5
%11 = getelementptr inbounds [100 x i8], [100 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 [100 x i8], [100 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 [100 x i8], [100 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 [100 x i8], [100 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 [100 x i8], [100 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 [100 x i8], [100 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 [100 x i8]
%2 = getelementptr inbounds [100 x i8], [100 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 100, 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 [100 x i8], [100 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 [100 x i8], [100 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 100, 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
}