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

/* Variables and functions */
int /*<<< orphan*/ SEEK_SET;
scalar_t__ lseek(int, int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ read(int, unsigned char *, int);
int write(int, unsigned char *, int);
int copyfile(int ofno, int ifno, off_t offset) {
  unsigned char c;
  if (lseek(ifno, offset, SEEK_SET) < 0)
    return (-1);
  for (; read(ifno, &c, sizeof(unsigned char)) > 0;) {
    if (write(ofno, &c, sizeof(unsigned char)) != sizeof(unsigned char))
      return (-1);
  }
  return (0);
}


x86 assembly (clang, -O0):
<copyfile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x10(%rbp),%esi
mov    0x2e92(%rip),%rax
mov    (%rax),%edx
call   1040 <lseek@plt>
cmp    $0x0,%rax
jge    116b <copyfile+0x3b>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c0 <copyfile+0x90>
jmp    1170 <copyfile+0x40>
mov    -0xc(%rbp),%edi
lea    -0x11(%rbp),%rsi
mov    $0x1,%edx
call   1050 <read@plt>
cmp    $0x0,%rax
jle    11b9 <copyfile+0x89>
mov    -0x8(%rbp),%edi
lea    -0x11(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
cltq
cmp    $0x1,%rax
je     11b4 <copyfile+0x84>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c0 <copyfile+0x90>
jmp    1170 <copyfile+0x40>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<copyfile>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %edi,%r15d
mov    0x2e9d(%rip),%rax
mov    (%rax),%eax
mov    %esi,%edi
mov    %edx,%esi
mov    %eax,%edx
call   1040 <lseek@plt>
mov    $0xffffffff,%r14d
test   %rax,%rax
js     118e <copyfile+0x5e>
lea    0x7(%rsp),%rbp
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0x1,%edx
call   1050 <read@plt>
test   %rax,%rax
jle    118b <copyfile+0x5b>
mov    %r15d,%edi
mov    %rbp,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
cmp    $0x1,%eax
je     1160 <copyfile+0x30>
jmp    118e <copyfile+0x5e>
xor    %r14d,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@SEEK_SET = global i32 0
define i32 @copyfile(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%9 = load i32, i32* %6
%10 = load i32, i32* %7
%11 = load i32, i32* @SEEK_SET
%12 = call i64 @lseek(i32 %9, i32 %10, i32 %11)
%13 = icmp slt i64 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %3
store i32 -1, i32* %4
br label %28
15: ; preds = %3
br label %16
16: ; preds = %26, %15
%17 = load i32, i32* %6
%18 = call i64 @read(i32 %17, i8* %8, i32 1)
%19 = icmp sgt i64 %18, 0
br i1 %19, label %20, label %27
20: ; preds = %16
%21 = load i32, i32* %5
%22 = call i32 @write(i32 %21, i8* %8, i32 1)
%23 = sext i32 %22 to i64
%24 = icmp ne i64 %23, 1
br i1 %24, label %25, label %26
25: ; preds = %20
store i32 -1, i32* %4
br label %28
26: ; preds = %20
br label %16
27: ; preds = %16
store i32 0, i32* %4
br label %28
28: ; preds = %27, %25, %14
%29 = load i32, i32* %4
ret i32 %29
}

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