#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*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ *strchr(char *, char);
int strlen(char *);
void type_mode(void) {
  char buf[513];
  while (1) {
    if (fgets(buf, 513, stdin) == NULL) {
      exit(0);
    }
    if (strchr(buf, '\n') != NULL) {
      buf[strlen(buf) - 1] = '\0';
    } else {
      fflush(stdin);
    }
    printf("%s\n", buf);
  }
}


x86 assembly (clang, -O0):
<type_mode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x210,%rsp
lea    -0x210(%rbp),%rdi
mov    0x2e6f(%rip),%rax
mov    (%rax),%edx
mov    $0x201,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
jne    1196 <type_mode+0x36>
xor    %edi,%edi
call   1080 <exit@plt>
lea    -0x210(%rbp),%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
cmp    $0x0,%rax
je     11cf <type_mode+0x6f>
lea    -0x210(%rbp),%rdi
call   1030 <strlen@plt>
sub    $0x1,%eax
cltq
movb   $0x0,-0x210(%rbp,%rax,1)
jmp    11dd <type_mode+0x7d>
mov    0x2e12(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
lea    -0x210(%rbp),%rsi
lea    0xe15(%rip),%rdi
call   1050 <printf@plt>
jmp    116b <type_mode+0xb>

x86 assembly (clang, -O2):
<type_mode>:
push   %r15
push   %r14
push   %rbx
sub    $0x210,%rsp
mov    0x2e75(%rip),%r15
mov    (%r15),%edx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x201,%esi
call   1060 <fgets@plt>
test   %rax,%rax
jne    1192 <type_mode+0x32>
xor    %edi,%edi
call   1080 <exit@plt>
lea    0xe67(%rip),%r14
jmp    11c8 <type_mode+0x68>
nopl   0x0(%rax,%rax,1)
mov    (%r15),%edi
call   1070 <fflush@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
mov    (%r15),%edx
mov    %rbx,%rdi
mov    $0x201,%esi
call   1060 <fgets@plt>
test   %rax,%rax
je     118b <type_mode+0x2b>
mov    %rbx,%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     11a0 <type_mode+0x40>
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
jmp    11a8 <type_mode+0x48>

LLVM IR (-O0):
@stdin = global i32 0
@.str = [4 x i8] c"%s\0A\00"
define void @type_mode() {
%1 = alloca [513 x i8]
br label %2
2: ; preds = %0, %22
%3 = getelementptr inbounds [513 x i8], [513 x i8]* %1, i64 0, i64 0
%4 = load i32, i32* @stdin
%5 = call i32* @fgets(i8* %3, i32 513, i32 %4)
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = call i32 @exit(i32 0)
unreachable
9: ; preds = %2
%10 = getelementptr inbounds [513 x i8], [513 x i8]* %1, i64 0, i64 0
%11 = call i32* @strchr(i8* %10, i8 signext 10)
%12 = icmp ne i32* %11, null
br i1 %12, label %13, label %19
13: ; preds = %9
%14 = getelementptr inbounds [513 x i8], [513 x i8]* %1, i64 0, i64 0
%15 = call i32 @strlen(i8* %14)
%16 = sub nsw i32 %15, 1
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [513 x i8], [513 x i8]* %1, i64 0, i64 %17
store i8 0, i8* %18
br label %22
19: ; preds = %9
%20 = load i32, i32* @stdin
%21 = call i32 @fflush(i32 %20)
br label %22
22: ; preds = %19, %13
%23 = getelementptr inbounds [513 x i8], [513 x i8]* %1, i64 0, i64 0
%24 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %23)
br label %2
}

LLVM IR (-O2):
@stdin = global i32 0
@.str = [4 x i8] c"%s\0A\00"
define void @type_mode() {
%1 = alloca [513 x i8]
%2 = getelementptr inbounds [513 x i8], [513 x i8]* %1, i64 0, i64 0
%3 = load i32, i32* @stdin
%4 = call i32* @fgets(i8* %2, i32 513, i32 %3)
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %8
6: ; preds = %19, %0
%7 = call i32 @exit(i32 0)
unreachable
8: ; preds = %0, %19
%9 = call i32* @strchr(i8* %2, i8 signext 10)
%10 = icmp eq i32* %9, null
br i1 %10, label %16, label %11
11: ; preds = %8
%12 = call i32 @strlen(i8* %2)
%13 = add nsw i32 %12, -1
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds [513 x i8], [513 x i8]* %1, i64 0, i64 %14
store i8 0, i8* %15
br label %19
16: ; preds = %8
%17 = load i32, i32* @stdin
%18 = call i32 @fflush(i32 %17)
br label %19
19: ; preds = %16, %11
%20 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %2)
%21 = load i32, i32* @stdin
%22 = call i32* @fgets(i8* %2, i32 513, i32 %21)
%23 = icmp eq i32* %22, null
br i1 %23, label %6, label %8
}