#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 /*<<< orphan*/ feof(int /*<<< orphan*/ *);
scalar_t__ ferror(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
int fdump(FILE *in, FILE *out) {
  char buffer[128 + 1];
  fgets(buffer, 128, in);
  if (ferror(in))
    return -1;
  while (!feof(in)) {
    fputs(buffer, out);
    fgets(buffer, 128, in);
  }
  return 0;
}


x86 assembly (clang, -O0):
<fdump>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    -0xa0(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x80,%esi
call   1050 <fgets@plt>
mov    -0x10(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     1187 <fdump+0x47>
movl   $0xffffffff,-0x4(%rbp)
jmp    11db <fdump+0x9b>
jmp    118c <fdump+0x4c>
mov    -0x10(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11aa <fdump+0x6a>
jmp    11d4 <fdump+0x94>
lea    -0xa0(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <fputs@plt>
lea    -0xa0(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x80,%esi
call   1050 <fgets@plt>
jmp    118c <fdump+0x4c>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fdump>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x88,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rsp,%rdi
mov    $0x80,%esi
mov    %rbx,%rdx
call   1050 <fgets@plt>
mov    %rbx,%rdi
call   1030 <ferror@plt>
mov    $0xffffffff,%r15d
test   %rax,%rax
jne    11b7 <fdump+0x77>
mov    %rbx,%rdi
call   1060 <feof@plt>
xor    %r15d,%r15d
test   %eax,%eax
jne    11b7 <fdump+0x77>
mov    %rsp,%rbp
nopl   0x0(%rax,%rax,1)
mov    %rbp,%rdi
mov    %r14,%rsi
call   1040 <fputs@plt>
mov    %rbp,%rdi
mov    $0x80,%esi
mov    %rbx,%rdx
call   1050 <fgets@plt>
mov    %rbx,%rdi
call   1060 <feof@plt>
test   %eax,%eax
je     1190 <fdump+0x50>
mov    %r15d,%eax
add    $0x88,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @fdump(i32* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca [129 x i8]
store i32* %0, i32** %4
store i32* %1, i32** %5
%7 = getelementptr inbounds [129 x i8], [129 x i8]* %6, i64 0, i64 0
%8 = load i32*, i32** %4
%9 = call i32 @fgets(i8* %7, i32 128, i32* %8)
%10 = load i32*, i32** %4
%11 = call i64 @ferror(i32* %10)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %2
store i32 -1, i32* %3
br label %28
14: ; preds = %2
br label %15
15: ; preds = %20, %14
%16 = load i32*, i32** %4
%17 = call i32 @feof(i32* %16)
%18 = icmp ne i32 %17, 0
%19 = xor i1 %18, true
br i1 %19, label %20, label %27
20: ; preds = %15
%21 = getelementptr inbounds [129 x i8], [129 x i8]* %6, i64 0, i64 0
%22 = load i32*, i32** %5
%23 = call i32 @fputs(i8* %21, i32* %22)
%24 = getelementptr inbounds [129 x i8], [129 x i8]* %6, i64 0, i64 0
%25 = load i32*, i32** %4
%26 = call i32 @fgets(i8* %24, i32 128, i32* %25)
br label %15
27: ; preds = %15
store i32 0, i32* %3
br label %28
28: ; preds = %27, %13
%29 = load i32, i32* %3
ret i32 %29
}

LLVM IR (-O2):
define i32 @fdump(i32* nocapture %0, i32* nocapture %1) {
%3 = alloca [129 x i8]
%4 = getelementptr inbounds [129 x i8], [129 x i8]* %3, i64 0, i64 0
%5 = call i32 @fgets(i8* %4, i32 128, i32* %0)
%6 = call i64 @ferror(i32* %0)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %16
8: ; preds = %2
%9 = call i32 @feof(i32* %0)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %16
11: ; preds = %8, %11
%12 = call i32 @fputs(i8* %4, i32* %1)
%13 = call i32 @fgets(i8* %4, i32 128, i32* %0)
%14 = call i32 @feof(i32* %0)
%15 = icmp eq i32 %14, 0
br i1 %15, label %11, label %16
16: ; preds = %11, %8, %2
%17 = phi i32 [ -1, %2 ], [ 0, %8 ], [ 0, %11 ]
ret i32 %17
}