#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*/ stdin;
int /*<<< orphan*/ stdout;
int main() {
  char line[20];
  while (fgets(line, 20, stdin) != NULL && line[0] != '\n') {
    fputs("result: ", stdout);
    fputs(line, stdout);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x20(%rbp),%rdi
mov    0x2eae(%rip),%rax
mov    (%rax),%edx
mov    $0x14,%esi
call   1040 <fgets@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x21(%rbp)
je     1165 <main+0x45>
movsbl -0x20(%rbp),%eax
cmp    $0xa,%eax
setne  %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    1175 <main+0x55>
jmp    11a1 <main+0x81>
mov    0x2e5c(%rip),%rax
mov    (%rax),%esi
lea    0xe7b(%rip),%rdi
call   1030 <fputs@plt>
lea    -0x20(%rbp),%rdi
mov    0x2e43(%rip),%rax
mov    (%rax),%esi
call   1030 <fputs@plt>
jmp    112f <main+0xf>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    0x2eb6(%rip),%r15
mov    (%r15),%edx
mov    %rsp,%rdi
mov    $0x14,%esi
call   1040 <fgets@plt>
test   %rax,%rax
je     1193 <main+0x73>
cmpb   $0xa,(%rsp)
je     1193 <main+0x73>
mov    0x2e84(%rip),%r12
lea    0xea5(%rip),%r14
mov    %rsp,%rbx
xchg   %ax,%ax
mov    (%r12),%esi
mov    %r14,%rdi
call   1030 <fputs@plt>
mov    (%r12),%esi
mov    %rbx,%rdi
call   1030 <fputs@plt>
mov    (%r15),%edx
mov    %rbx,%rdi
mov    $0x14,%esi
call   1040 <fgets@plt>
test   %rax,%rax
je     1193 <main+0x73>
cmpb   $0xa,(%rsp)
jne    1160 <main+0x40>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@stdin = global i32 0
@.str = [9 x i8] c"result: \00"
@stdout = global i32 0
define i32 @main() {
%1 = alloca [20 x i8]
%2 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 0
%3 = load i32, i32* @stdin
%4 = call i32* @fgets(i8* %2, i32 20, i32 %3)
%5 = icmp ne i32* %4, null
%6 = load i8, i8* %2
%7 = icmp ne i8 %6, 10
%8 = select i1 %5, i1 %7, i1 false
br i1 %8, label %9, label %20
9: ; preds = %0, %9
%10 = load i32, i32* @stdout
%11 = call i32 @fputs(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %10)
%12 = load i32, i32* @stdout
%13 = call i32 @fputs(i8* %2, i32 %12)
%14 = load i32, i32* @stdin
%15 = call i32* @fgets(i8* %2, i32 20, i32 %14)
%16 = icmp ne i32* %15, null
%17 = load i8, i8* %2
%18 = icmp ne i8 %17, 10
%19 = select i1 %16, i1 %18, i1 false
br i1 %19, label %9, label %20
20: ; preds = %9, %0
ret i32 0
}