#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 getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ putc(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ ungetc(int, int /*<<< orphan*/ *);
int copyline(FILE *in, FILE *out) {
  int state, flag, c;
  state = 0;
  for (;;) {
    c = getc(in);
    if (c == '\n')
      return 1;
    if (state) {
      ungetc(c, in);
      return 1;
    }
    if (c == EOF)
      return 0;
    if (c == '\r')
      state = 1;
    else
      putc(c, out);
  }
}


x86 assembly (clang, -O0):
<copyline>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <getc@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xa,-0x24(%rbp)
jne    1169 <copyline+0x39>
movl   $0x1,-0x4(%rbp)
jmp    11d0 <copyline+0xa0>
cmpl   $0x0,-0x1c(%rbp)
je     118b <copyline+0x5b>
mov    -0x24(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1040 <ungetc@plt>
movl   $0x1,-0x4(%rbp)
jmp    11d0 <copyline+0xa0>
mov    -0x24(%rbp),%eax
mov    0x2e53(%rip),%rcx
cmp    (%rcx),%eax
jne    11a9 <copyline+0x79>
movl   $0x0,-0x4(%rbp)
jmp    11d0 <copyline+0xa0>
cmpl   $0xd,-0x24(%rbp)
jne    11bf <copyline+0x8f>
movl   $0x1,-0x1c(%rbp)
jmp    11cb <copyline+0x9b>
mov    -0x24(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1030 <putc@plt>
jmp    1147 <copyline+0x17>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<copyline>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r12
call   1050 <getc@plt>
mov    $0x1,%ebp
cmp    $0xa,%eax
je     11a1 <copyline+0x71>
xor    %ebx,%ebx
mov    0x2e92(%rip),%r15
mov    $0x1,%ebp
jmp    116d <copyline+0x3d>
nopl   (%rax)
mov    %r12,%rdi
call   1050 <getc@plt>
cmp    $0xa,%eax
je     11a1 <copyline+0x71>
test   %ebx,%ebx
jne    118e <copyline+0x5e>
cmp    (%r15),%eax
je     119f <copyline+0x6f>
mov    $0x1,%ebx
cmp    $0xd,%eax
je     1160 <copyline+0x30>
mov    %eax,%edi
mov    %r14,%rsi
call   1030 <putc@plt>
xor    %ebx,%ebx
jmp    1160 <copyline+0x30>
mov    %eax,%edi
mov    %r12,%rsi
call   1040 <ungetc@plt>
mov    $0x1,%ebp
jmp    11a1 <copyline+0x71>
xor    %ebp,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@EOF = global i32 0
define i32 @copyline(i32* nocapture %0, i32* nocapture %1) {
%3 = tail call i32 @getc(i32* %0)
%4 = icmp eq i32 %3, 10
br i1 %4, label %22, label %5
5: ; preds = %2, %18
%6 = phi i32 [ %20, %18 ], [ %3, %2 ]
%7 = phi i32 [ %19, %18 ], [ 0, %2 ]
%8 = icmp eq i32 %7, 0
br i1 %8, label %11, label %9
9: ; preds = %5
%10 = tail call i32 @ungetc(i32 %6, i32* %0)
br label %22
11: ; preds = %5
%12 = load i32, i32* @EOF
%13 = icmp eq i32 %6, %12
br i1 %13, label %22, label %14
14: ; preds = %11
%15 = icmp eq i32 %6, 13
br i1 %15, label %18, label %16
16: ; preds = %14
%17 = tail call i32 @putc(i32 %6, i32* %1)
br label %18
18: ; preds = %14, %16
%19 = phi i32 [ 0, %16 ], [ 1, %14 ]
%20 = tail call i32 @getc(i32* %0)
%21 = icmp eq i32 %20, 10
br i1 %21, label %22, label %5
22: ; preds = %18, %11, %2, %9
%23 = phi i32 [ 1, %9 ], [ 1, %2 ], [ 1, %18 ], [ 0, %11 ]
ret i32 %23
}