#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 */
size_t fread(char *, int, int, int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ fwrite(char *, int, size_t, int /*<<< orphan*/);
char *malloc(int);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
int main() {
  char *bufor = malloc(sizeof(char) * 17);
  size_t r;
  for (;;) {
    r = fread(bufor, sizeof(char), 16, stdin);
    bufor[r] = '\n';
    fwrite(bufor, sizeof(char), r + 1, stdout);
    if (bufor[r - 1] == '\0' || r == 0)
      break;
  };
  free(bufor);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x11,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e80(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%esi
mov    $0x10,%edx
call   1040 <fread@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
movb   $0xa,(%rax,%rcx,1)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
add    $0x1,%rdx
mov    0x2e3c(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%esi
call   1060 <fwrite@plt>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    $0x1,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     11cc <main+0x8c>
cmpq   $0x0,-0x18(%rbp)
jne    11d1 <main+0x91>
jmp    11d6 <main+0x96>
jmp    115d <main+0x1d>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    $0x11,%edi
call   1050 <malloc@plt>
mov    %rax,%r14
mov    0x2e8c(%rip),%r15
mov    0x2e75(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    (%r15),%ecx
mov    %r14,%rdi
mov    $0x1,%esi
mov    $0x10,%edx
call   1040 <fread@plt>
mov    %rax,%rbx
movb   $0xa,(%r14,%rax,1)
lea    0x1(%rax),%rdx
mov    (%r12),%ecx
mov    %r14,%rdi
mov    $0x1,%esi
call   1060 <fwrite@plt>
sub    $0x1,%rbx
setb   %al
cmpb   $0x0,(%r14,%rbx,1)
je     11b4 <main+0x74>
test   %al,%al
je     1170 <main+0x30>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stdin = global i32 0
@stdout = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i64
store i32 0, i32* %1
%4 = call i8* @malloc(i32 17)
store i8* %4, i8** %2
br label %5
5: ; preds = %28, %0
%6 = load i8*, i8** %2
%7 = load i32, i32* @stdin
%8 = call i64 @fread(i8* %6, i32 1, i32 16, i32 %7)
store i64 %8, i64* %3
%9 = load i8*, i8** %2
%10 = load i64, i64* %3
%11 = getelementptr inbounds i8, i8* %9, i64 %10
store i8 10, i8* %11
%12 = load i8*, i8** %2
%13 = load i64, i64* %3
%14 = add i64 %13, 1
%15 = load i32, i32* @stdout
%16 = call i32 @fwrite(i8* %12, i32 1, i64 %14, i32 %15)
%17 = load i8*, i8** %2
%18 = load i64, i64* %3
%19 = sub i64 %18, 1
%20 = getelementptr inbounds i8, i8* %17, i64 %19
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp eq i32 %22, 0
br i1 %23, label %27, label %24
24: ; preds = %5
%25 = load i64, i64* %3
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %28
27: ; preds = %24, %5
br label %29
28: ; preds = %24
br label %5
29: ; preds = %27
%30 = load i8*, i8** %2
%31 = call i32 @free(i8* %30)
ret i32 0
}

LLVM IR (-O2):
@stdin = global i32 0
@stdout = global i32 0
define i32 @main() {
%1 = tail call dereferenceable_or_null(17) i8* @malloc(i32 17)
br label %2
2: ; preds = %2, %0
%3 = load i32, i32* @stdin
%4 = tail call i64 @fread(i8* %1, i32 1, i32 16, i32 %3)
%5 = getelementptr inbounds i8, i8* %1, i64 %4
store i8 10, i8* %5
%6 = add i64 %4, 1
%7 = load i32, i32* @stdout
%8 = tail call i32 @fwrite(i8* %1, i32 1, i64 %6, i32 %7)
%9 = add i64 %4, -1
%10 = getelementptr inbounds i8, i8* %1, i64 %9
%11 = load i8, i8* %10
%12 = icmp eq i8 %11, 0
%13 = icmp eq i64 %4, 0
%14 = select i1 %12, i1 true, i1 %13
br i1 %14, label %15, label %2
15: ; preds = %2
%16 = tail call i32 @free(i8* %1)
ret i32 0
}