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

/* Variables and functions */
scalar_t__ feof(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgetpos(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/ *);
int /*<<< orphan*/ fsetpos(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
void print_file(FILE *fin, FILE *fout) {
  fpos_t pos;
  fgetpos(fin, &pos);
  rewind(fin);
  for (;;) {
    char peek = fgetc(fin);
    if (feof(fin))
      break;
    fputc(peek, fout);
  }
  fsetpos(fin, &pos);
}


x86 assembly (clang, -O0):
<print_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x14(%rbp),%rsi
call   1030 <fgetpos@plt>
mov    -0x8(%rbp),%rdi
call   1040 <rewind@plt>
mov    -0x8(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %al,-0x15(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%rax
je     11aa <print_file+0x4a>
jmp    11be <print_file+0x5e>
mov    -0x15(%rbp),%al
mov    -0x10(%rbp),%rsi
movsbl %al,%edi
call   1060 <fputc@plt>
jmp    1186 <print_file+0x26>
mov    -0x8(%rbp),%rdi
lea    -0x14(%rbp),%rsi
call   1080 <fsetpos@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_file>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
lea    0xc(%rsp),%rsi
call   1030 <fgetpos@plt>
mov    %r15,%rdi
call   1040 <rewind@plt>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
call   1050 <fgetc@plt>
mov    %eax,%ebx
mov    %r15,%rdi
call   1070 <feof@plt>
test   %rax,%rax
jne    11b4 <print_file+0x54>
movsbl %bl,%edi
mov    %r14,%rsi
call   1060 <fputc@plt>
jmp    1190 <print_file+0x30>
lea    0xc(%rsp),%rsi
mov    %r15,%rdi
call   1080 <fsetpos@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @print_file(i32* %0, i32* %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i8
store i32* %0, i32** %3
store i32* %1, i32** %4
%7 = load i32*, i32** %3
%8 = call i32 @fgetpos(i32* %7, i32* %5)
%9 = load i32*, i32** %3
%10 = call i32 @rewind(i32* %9)
br label %11
11: ; preds = %18, %2
%12 = load i32*, i32** %3
%13 = call signext i8 @fgetc(i32* %12)
store i8 %13, i8* %6
%14 = load i32*, i32** %3
%15 = call i64 @feof(i32* %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %11
br label %22
18: ; preds = %11
%19 = load i8, i8* %6
%20 = load i32*, i32** %4
%21 = call i32 @fputc(i8 signext %19, i32* %20)
br label %11
22: ; preds = %17
%23 = load i32*, i32** %3
%24 = call i32 @fsetpos(i32* %23, i32* %5)
ret void
}

LLVM IR (-O2):
define void @print_file(i32* nocapture %0, i32* nocapture %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = call i32 @fgetpos(i32* %0, i32* %3)
%6 = tail call i32 @rewind(i32* %0)
%7 = tail call signext i8 @fgetc(i32* %0)
%8 = tail call i64 @feof(i32* %0)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %16
10: ; preds = %2, %10
%11 = phi i8 [ %13, %10 ], [ %7, %2 ]
%12 = tail call i32 @fputc(i8 signext %11, i32* %1)
%13 = tail call signext i8 @fgetc(i32* %0)
%14 = tail call i64 @feof(i32* %0)
%15 = icmp eq i64 %14, 0
br i1 %15, label %10, label %16
16: ; preds = %10, %2
%17 = call i32 @fsetpos(i32* %0, i32* %3)
ret void
}