#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*/ ssize_t;

/* Variables and functions */
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ lseek(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ read(int, char *, int);
int /*<<< orphan*/ write(int, char *, int /*<<< orphan*/);
void passthru_file(int source, int destination, int seek) {
  char buf[4096];
  ssize_t len;
  if (seek)
    lseek(source, 0, SEEK_SET);
  while ((len = read(source, buf, 4096))) {
    write(destination, buf, len);
  }
}


x86 assembly (clang, -O0):
<passthru_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1020,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     1161 <passthru_file+0x31>
mov    -0x4(%rbp),%edi
mov    0x2e88(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1040 <lseek@plt>
jmp    1166 <passthru_file+0x36>
mov    -0x4(%rbp),%edi
lea    -0x1010(%rbp),%rsi
mov    $0x1000,%edx
call   1050 <read@plt>
mov    %eax,-0x1014(%rbp)
cmp    $0x0,%eax
je     11a3 <passthru_file+0x73>
mov    -0x8(%rbp),%edi
lea    -0x1010(%rbp),%rsi
mov    -0x1014(%rbp),%edx
call   1030 <write@plt>
jmp    1166 <passthru_file+0x36>
add    $0x1020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<passthru_file>:
push   %rbp
push   %r14
push   %rbx
sub    $0x1000,%rsp
mov    %esi,%r14d
mov    %edi,%ebp
test   %edx,%edx
je     1156 <passthru_file+0x26>
mov    0x2e95(%rip),%rax
mov    (%rax),%edx
mov    %ebp,%edi
xor    %esi,%esi
call   1040 <lseek@plt>
mov    %rsp,%rsi
mov    %ebp,%edi
mov    $0x1000,%edx
call   1050 <read@plt>
test   %eax,%eax
je     1190 <passthru_file+0x60>
mov    %rsp,%rbx
nopl   0x0(%rax)
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x1000,%edx
call   1050 <read@plt>
test   %eax,%eax
jne    1170 <passthru_file+0x40>
add    $0x1000,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@SEEK_SET = global i32 0
define void @passthru_file(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca [4096 x i8]
%8 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%9 = load i32, i32* %6
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %15
11: ; preds = %3
%12 = load i32, i32* %4
%13 = load i32, i32* @SEEK_SET
%14 = call i32 @lseek(i32 %12, i32 0, i32 %13)
br label %15
15: ; preds = %11, %3
br label %16
16: ; preds = %21, %15
%17 = load i32, i32* %4
%18 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%19 = call i32 @read(i32 %17, i8* %18, i32 4096)
store i32 %19, i32* %8
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %26
21: ; preds = %16
%22 = load i32, i32* %5
%23 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%24 = load i32, i32* %8
%25 = call i32 @write(i32 %22, i8* %23, i32 %24)
br label %16
26: ; preds = %16
ret void
}

LLVM IR (-O2):
@SEEK_SET = global i32 0
define void @passthru_file(i32 %0, i32 %1, i32 %2) {
%4 = alloca [4096 x i8]
%5 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%6 = icmp eq i32 %2, 0
br i1 %6, label %10, label %7
7: ; preds = %3
%8 = load i32, i32* @SEEK_SET
%9 = tail call i32 @lseek(i32 %0, i32 0, i32 %8)
br label %10
10: ; preds = %7, %3
%11 = call i32 @read(i32 %0, i8* %5, i32 4096)
%12 = icmp eq i32 %11, 0
br i1 %12, label %18, label %13
13: ; preds = %10, %13
%14 = phi i32 [ %16, %13 ], [ %11, %10 ]
%15 = call i32 @write(i32 %1, i8* %5, i32 %14)
%16 = call i32 @read(i32 %0, i8* %5, i32 4096)
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %13
18: ; preds = %13, %10
ret void
}