#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 */
struct fio_ctx {
  int dummy;
};
typedef int ssize_t;
typedef int off_t;

/* Variables and functions */
int /*<<< orphan*/ assert(int);
int sendfile(int const, int const, int /*<<< orphan*/, size_t const,
             int /*<<< orphan*/ *, int *, int /*<<< orphan*/);
ssize_t file_sendfile(const int fd_in, const int fd_out,
                      struct fio_ctx *ctx __attribute__((unused)),
                      const size_t nbytes) {
  assert(nbytes > 0);
  off_t nsent = 0;
  if (sendfile(fd_in, fd_out, 0, nbytes, NULL, &nsent, 0) == -1)
    return -1;
  return nsent;
}


x86 assembly (clang, -O0):
<file_sendfile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
seta   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    -0x20(%rbp),%rcx
xor    %edx,%edx
xor    %eax,%eax
mov    %eax,%r8d
lea    -0x24(%rbp),%r9
movl   $0x0,(%rsp)
call   1040 <sendfile@plt>
cmp    $0xffffffff,%eax
jne    1185 <file_sendfile+0x65>
movl   $0xffffffff,-0x4(%rbp)
jmp    118b <file_sendfile+0x6b>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<file_sendfile>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rcx,%rbx
mov    %esi,%r14d
mov    %edi,%ebp
xor    %edi,%edi
test   %rcx,%rcx
setne  %dil
call   1030 <assert@plt>
movl   $0x0,0xc(%rsp)
movl   $0x0,(%rsp)
lea    0xc(%rsp),%r9
mov    %ebp,%edi
mov    %r14d,%esi
xor    %edx,%edx
mov    %rbx,%rcx
xor    %r8d,%r8d
call   1040 <sendfile@plt>
cmp    $0xffffffff,%eax
je     116d <file_sendfile+0x4d>
mov    0xc(%rsp),%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.fio_ctx = type { i32 }
define i32 @file_sendfile(i32 %0, i32 %1, %struct.fio_ctx* %2, i64 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.fio_ctx*
%9 = alloca i64
%10 = alloca i32
store i32 %0, i32* %6
store i32 %1, i32* %7
store %struct.fio_ctx* %2, %struct.fio_ctx** %8
store i64 %3, i64* %9
%11 = load i64, i64* %9
%12 = icmp ugt i64 %11, 0
%13 = zext i1 %12 to i32
%14 = call i32 @assert(i32 %13)
store i32 0, i32* %10
%15 = load i32, i32* %6
%16 = load i32, i32* %7
%17 = load i64, i64* %9
%18 = call i32 @sendfile(i32 %15, i32 %16, i32 0, i64 %17, i32* null, i32* %10, i32 0)
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %21
20: ; preds = %4
store i32 -1, i32* %5
br label %23
21: ; preds = %4
%22 = load i32, i32* %10
store i32 %22, i32* %5
br label %23
23: ; preds = %21, %20
%24 = load i32, i32* %5
ret i32 %24
}

LLVM IR (-O2):
%struct.fio_ctx = type { i32 }
define i32 @file_sendfile(i32 %0, i32 %1, %struct.fio_ctx* nocapture readnone %2, i64 %3) {
%5 = alloca i32
%6 = icmp ne i64 %3, 0
%7 = zext i1 %6 to i32
%8 = tail call i32 @assert(i32 %7)
%9 = bitcast i32* %5 to i8*
store i32 0, i32* %5
%10 = call i32 @sendfile(i32 %0, i32 %1, i32 0, i64 %3, i32* null, i32* %5, i32 0)
%11 = icmp eq i32 %10, -1
%12 = load i32, i32* %5
%13 = select i1 %11, i32 -1, i32 %12
ret i32 %13
}