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


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%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   1050 <fgets@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0xf(%rbp)
je     1181 <main+0x51>
movsbl -0xe(%rbp),%eax
cmp    $0xa,%eax
setne  %al
mov    %al,-0xf(%rbp)
mov    -0xf(%rbp),%al
test   $0x1,%al
jne    1191 <main+0x61>
jmp    11a8 <main+0x78>
lea    -0xe(%rbp),%rdi
mov    0x2e3c(%rip),%rax
mov    (%rax),%esi
call   1040 <fputs@plt>
jmp    114b <main+0x1b>
lea    0xe75(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xec0(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e9c(%rip),%r14
mov    (%r14),%edx
lea    0x6(%rsp),%rdi
mov    $0xa,%esi
call   1050 <fgets@plt>
test   %rax,%rax
je     11a7 <main+0x77>
cmpb   $0xa,0x6(%rsp)
je     11a7 <main+0x77>
mov    0x2e67(%rip),%r15
lea    0x6(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
mov    (%r15),%esi
mov    %rbx,%rdi
call   1040 <fputs@plt>
mov    (%r14),%edx
mov    %rbx,%rdi
mov    $0xa,%esi
call   1050 <fgets@plt>
test   %rax,%rax
je     11a7 <main+0x77>
cmpb   $0xa,0x6(%rsp)
jne    1180 <main+0x50>
lea    0xe76(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [36 x i8] c"Enter strings (empty line to quit):\00"
@stdin = global i32 0
@stdout = global i32 0
@.str.1 = [6 x i8] c"Done.\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [10 x i8]
store i32 0, i32* %1
%3 = call i32 @puts(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
br label %4
4: ; preds = %16, %0
%5 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%6 = load i32, i32* @stdin
%7 = call i32* @fgets(i8* %5, i32 10, i32 %6)
%8 = icmp ne i32* %7, null
br i1 %8, label %9, label %14
9: ; preds = %4
%10 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
%13 = icmp ne i32 %12, 10
br label %14
14: ; preds = %9, %4
%15 = phi i1 [ false, %4 ], [ %13, %9 ]
br i1 %15, label %16, label %20
16: ; preds = %14
%17 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%18 = load i32, i32* @stdout
%19 = call i32 @fputs(i8* %17, i32 %18)
br label %4
20: ; preds = %14
%21 = call i32 @puts(i8* getelementptr inbounds ([6 x i8], [6 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
@stdout = global i32 0
@.str.1 = [6 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 %19
10: ; preds = %0, %10
%11 = load i32, i32* @stdout
%12 = call i32 @fputs(i8* %2, i32 %11)
%13 = load i32, i32* @stdin
%14 = call i32* @fgets(i8* %2, i32 10, i32 %13)
%15 = icmp ne i32* %14, null
%16 = load i8, i8* %2
%17 = icmp ne i8 %16, 10
%18 = select i1 %15, i1 %17, i1 false
br i1 %18, label %10, label %19
19: ; preds = %10, %0
%20 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
ret i32 0
}