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

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ _fsop_close_safe(int);
int _fsop_fxchg(int, int, size_t);
int open(char const *, int /*<<< orphan*/);
ssize_t fsop_fsend(int dfd, const char *file, size_t block) {
  int sfd = 0;
  ssize_t count = 0;
  if ((sfd = open(file, O_RDONLY)) < 0)
    return -1;
  if ((count = _fsop_fxchg(sfd, dfd, block)) < 0)
    return -1;
  _fsop_close_safe(sfd);
  return count;
}


x86 assembly (clang, -O0):
<fsop_fsend>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e8c(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jge    117b <fsop_fsend+0x4b>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b0 <fsop_fsend+0x80>
mov    -0x1c(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0x18(%rbp),%rdx
call   1030 <_fsop_fxchg@plt>
mov    %eax,-0x20(%rbp)
cmp    $0x0,%eax
jge    11a2 <fsop_fsend+0x72>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b0 <fsop_fsend+0x80>
mov    -0x1c(%rbp),%edi
call   1040 <_fsop_close_safe@plt>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fsop_fsend>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%rax
mov    %edi,%r15d
mov    0x2ea1(%rip),%rcx
mov    (%rcx),%esi
mov    %rax,%rdi
call   1050 <open@plt>
mov    $0xffffffff,%ebx
test   %eax,%eax
js     117a <fsop_fsend+0x4a>
mov    %eax,%ebp
mov    %eax,%edi
mov    %r15d,%esi
mov    %r14,%rdx
call   1030 <_fsop_fxchg@plt>
test   %eax,%eax
js     117a <fsop_fsend+0x4a>
mov    %eax,%r14d
mov    %ebp,%edi
call   1040 <_fsop_close_safe@plt>
mov    %r14d,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@O_RDONLY = global i32 0
define i32 @fsop_fsend(i32 %0, i8* %1, i64 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %5
store i8* %1, i8** %6
store i64 %2, i64* %7
store i32 0, i32* %8
store i32 0, i32* %9
%10 = load i8*, i8** %6
%11 = load i32, i32* @O_RDONLY
%12 = call i32 @open(i8* %10, i32 %11)
store i32 %12, i32* %8
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %3
store i32 -1, i32* %4
br label %26
15: ; preds = %3
%16 = load i32, i32* %8
%17 = load i32, i32* %5
%18 = load i64, i64* %7
%19 = call i32 @_fsop_fxchg(i32 %16, i32 %17, i64 %18)
store i32 %19, i32* %9
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %15
store i32 -1, i32* %4
br label %26
22: ; preds = %15
%23 = load i32, i32* %8
%24 = call i32 @_fsop_close_safe(i32 %23)
%25 = load i32, i32* %9
store i32 %25, i32* %4
br label %26
26: ; preds = %22, %21, %14
%27 = load i32, i32* %4
ret i32 %27
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
define i32 @fsop_fsend(i32 %0, i8* nocapture %1, i64 %2) {
%4 = load i32, i32* @O_RDONLY
%5 = tail call i32 @open(i8* %1, i32 %4)
%6 = icmp slt i32 %5, 0
br i1 %6, label %12, label %7
7: ; preds = %3
%8 = tail call i32 @_fsop_fxchg(i32 %5, i32 %0, i64 %2)
%9 = icmp slt i32 %8, 0
br i1 %9, label %12, label %10
10: ; preds = %7
%11 = tail call i32 @_fsop_close_safe(i32 %5)
br label %12
12: ; preds = %7, %3, %10
%13 = phi i32 [ %8, %10 ], [ -1, %3 ], [ -1, %7 ]
ret i32 %13
}