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

/* Variables and functions */
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
int getline(char **, size_t *, int /*<<< orphan*/ *);
int /*<<< orphan*/ stdout;
int copy_rest(FILE *stream) {
  char *line = NULL;
  size_t n = 0;
  ssize_t bytes_read = 1;
  while (bytes_read >= 0) {
    bytes_read = getline(&line, &n, stream);
    if (bytes_read > 0 && line != NULL) {
      fputs(line, stdout);
    }
    free(line);
    line = NULL;
    if (bytes_read == -1) {
      break;
    }
  }
  if (line != NULL) {
    free(line);
  }
  return 0;
}


x86 assembly (clang, -O0):
<copy_rest>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jl     11bd <copy_rest+0x8d>
mov    -0x8(%rbp),%rdx
lea    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1050 <getline@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jle    1198 <copy_rest+0x68>
cmpq   $0x0,-0x10(%rbp)
je     1198 <copy_rest+0x68>
mov    -0x10(%rbp),%rdi
mov    0x2e4f(%rip),%rax
mov    (%rax),%esi
call   1040 <fputs@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x10(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    11b8 <copy_rest+0x88>
jmp    11bd <copy_rest+0x8d>
jmp    1153 <copy_rest+0x23>
cmpq   $0x0,-0x10(%rbp)
je     11d1 <copy_rest+0xa1>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<copy_rest>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
movq   $0x0,(%rsp)
movq   $0x0,0x8(%rsp)
mov    %rsp,%r14
lea    0x8(%rsp),%r15
mov    0x2e81(%rip),%r12
jmp    1181 <copy_rest+0x51>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
call   1030 <free@plt>
movq   $0x0,(%rsp)
test   %ebp,%ebp
js     11ad <copy_rest+0x7d>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1050 <getline@plt>
mov    %eax,%ebp
mov    (%rsp),%rdi
test   %eax,%eax
jle    1170 <copy_rest+0x40>
test   %rdi,%rdi
je     1170 <copy_rest+0x40>
mov    (%r12),%esi
call   1040 <fputs@plt>
mov    (%rsp),%rdi
jmp    1170 <copy_rest+0x40>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdout = global i32 0
define i32 @copy_rest(i32* %0) {
%2 = alloca i32*
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32
store i32* %0, i32** %2
store i8* null, i8** %3
store i64 0, i64* %4
store i32 1, i32* %5
br label %6
6: ; preds = %27, %1
%7 = load i32, i32* %5
%8 = icmp sge i32 %7, 0
br i1 %8, label %9, label %28
9: ; preds = %6
%10 = load i32*, i32** %2
%11 = call i32 @getline(i8** %3, i64* %4, i32* %10)
store i32 %11, i32* %5
%12 = load i32, i32* %5
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %21
14: ; preds = %9
%15 = load i8*, i8** %3
%16 = icmp ne i8* %15, null
br i1 %16, label %17, label %21
17: ; preds = %14
%18 = load i8*, i8** %3
%19 = load i32, i32* @stdout
%20 = call i32 @fputs(i8* %18, i32 %19)
br label %21
21: ; preds = %17, %14, %9
%22 = load i8*, i8** %3
%23 = call i32 @free(i8* %22)
store i8* null, i8** %3
%24 = load i32, i32* %5
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %27
26: ; preds = %21
br label %28
27: ; preds = %21
br label %6
28: ; preds = %26, %6
%29 = load i8*, i8** %3
%30 = icmp ne i8* %29, null
br i1 %30, label %31, label %34
31: ; preds = %28
%32 = load i8*, i8** %3
%33 = call i32 @free(i8* %32)
br label %34
34: ; preds = %31, %28
ret i32 0
}

LLVM IR (-O2):
@stdout = global i32 0
define i32 @copy_rest(i32* %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = bitcast i8** %2 to i8*
store i8* null, i8** %2
%5 = bitcast i64* %3 to i8*
store i64 0, i64* %3
br label %6
6: ; preds = %1, %16
%7 = call i32 @getline(i8** %2, i64* %3, i32* %0)
%8 = icmp sgt i32 %7, 0
%9 = load i8*, i8** %2
%10 = icmp ne i8* %9, null
%11 = select i1 %8, i1 %10, i1 false
br i1 %11, label %12, label %16
12: ; preds = %6
%13 = load i32, i32* @stdout
%14 = call i32 @fputs(i8* %9, i32 %13)
%15 = load i8*, i8** %2
br label %16
16: ; preds = %12, %6
%17 = phi i8* [ %15, %12 ], [ %9, %6 ]
%18 = call i32 @free(i8* %17)
store i8* null, i8** %2
%19 = icmp sgt i32 %7, -1
br i1 %19, label %6, label %20
20: ; preds = %16
ret i32 0
}