#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int EOF;
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ fputc(int, int /*<<< orphan*/ *);
int readaline_and_out(FILE *fin, FILE *fout) {
  int ch, count = 0;
  do {
    if ((ch = fgetc(fin)) == EOF) {
      if (!count)
        return 1;
      else {
        fputc(0x0a, fout);
        break;
      }
    }
    fputc(ch, fout);
    count++;
  } while (ch != 0x0a);
  return 0;
}


x86 assembly (clang, -O0):
<readaline_and_out>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2e9e(%rip),%rcx
cmp    (%rcx),%eax
jne    117b <readaline_and_out+0x5b>
cmpl   $0x0,-0x20(%rbp)
jne    1168 <readaline_and_out+0x48>
movl   $0x1,-0x4(%rbp)
jmp    11a1 <readaline_and_out+0x81>
mov    -0x18(%rbp),%rsi
mov    $0xa,%edi
call   1040 <fputc@plt>
jmp    119a <readaline_and_out+0x7a>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1040 <fputc@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
cmpl   $0xa,-0x1c(%rbp)
jne    1137 <readaline_and_out+0x17>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readaline_and_out>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
xor    %ebx,%ebx
mov    0x2eb1(%rip),%r12
nopw   0x0(%rax,%rax,1)
mov    %r15,%rdi
call   1030 <fgetc@plt>
cmp    (%r12),%eax
je     1164 <readaline_and_out+0x44>
mov    %eax,%ebp
mov    %eax,%edi
mov    %r14,%rsi
call   1040 <fputc@plt>
add    $0xffffffff,%ebx
cmp    $0xa,%ebp
jne    1140 <readaline_and_out+0x20>
jmp    1175 <readaline_and_out+0x55>
test   %ebx,%ebx
je     1179 <readaline_and_out+0x59>
mov    $0xa,%edi
mov    %r14,%rsi
call   1040 <fputc@plt>
xor    %eax,%eax
jmp    117e <readaline_and_out+0x5e>
mov    $0x1,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@EOF = global i32 0
define i32 @readaline_and_out(i32* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
store i32* %0, i32** %4
store i32* %1, i32** %5
store i32 0, i32* %7
br label %8
8: ; preds = %26, %2
%9 = load i32*, i32** %4
%10 = call i32 @fgetc(i32* %9)
store i32 %10, i32* %6
%11 = load i32, i32* @EOF
%12 = icmp eq i32 %10, %11
br i1 %12, label %13, label %20
13: ; preds = %8
%14 = load i32, i32* %7
%15 = icmp ne i32 %14, 0
br i1 %15, label %17, label %16
16: ; preds = %13
store i32 1, i32* %3
br label %30
17: ; preds = %13
%18 = load i32*, i32** %5
%19 = call i32 @fputc(i32 10, i32* %18)
br label %29
20: ; preds = %8
%21 = load i32, i32* %6
%22 = load i32*, i32** %5
%23 = call i32 @fputc(i32 %21, i32* %22)
%24 = load i32, i32* %7
%25 = add nsw i32 %24, 1
store i32 %25, i32* %7
br label %26
26: ; preds = %20
%27 = load i32, i32* %6
%28 = icmp ne i32 %27, 10
br i1 %28, label %8, label %29
29: ; preds = %26, %17
store i32 0, i32* %3
br label %30
30: ; preds = %29, %16
%31 = load i32, i32* %3
ret i32 %31
}

LLVM IR (-O2):
@EOF = global i32 0
define i32 @readaline_and_out(i32* nocapture %0, i32* nocapture %1) {
br label %3
3: ; preds = %12, %2
%4 = phi i32 [ 0, %2 ], [ %14, %12 ]
%5 = tail call i32 @fgetc(i32* %0)
%6 = load i32, i32* @EOF
%7 = icmp eq i32 %5, %6
br i1 %7, label %8, label %12
8: ; preds = %3
%9 = icmp eq i32 %4, 0
br i1 %9, label %16, label %10
10: ; preds = %8
%11 = tail call i32 @fputc(i32 10, i32* %1)
br label %16
12: ; preds = %3
%13 = tail call i32 @fputc(i32 %5, i32* %1)
%14 = add nuw nsw i32 %4, 1
%15 = icmp eq i32 %5, 10
br i1 %15, label %16, label %3
16: ; preds = %12, %10, %8
%17 = phi i32 [ 1, %8 ], [ 0, %10 ], [ 0, %12 ]
ret i32 %17
}