#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 flock {
  int /*<<< orphan*/ l_type;
  scalar_t__ l_len;
  scalar_t__ l_start;
  int /*<<< orphan*/ l_whence;
};
typedef int ssize_t;
typedef scalar_t__ off_t;

/* Variables and functions */
int /*<<< orphan*/ F_SETLKW;
int /*<<< orphan*/ F_UNLCK;
int /*<<< orphan*/ F_WRLCK;
int /*<<< orphan*/ SEEK_SET;
int fcntl(int, int /*<<< orphan*/, struct flock *);
scalar_t__ lseek(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ printoffset(int, scalar_t__, long);
int readoffset(int, scalar_t__ *, scalar_t__ *);
int release(int fdadm, off_t reloff, size_t size) {
  ssize_t wres = -1;
  off_t sres;
  off_t offset;
  off_t newoffset;
  int fres;
  int res;
  struct flock flock;
  flock.l_whence = SEEK_SET;
  flock.l_start = 0;
  flock.l_len = 0;
  flock.l_type = F_WRLCK;
  fres = fcntl(fdadm, F_SETLKW, &flock);
  if (fres < 0)
    goto RETURN;
  sres = lseek(fdadm, 0, SEEK_SET);
  if (sres < 0)
    goto RETURN;
  res = readoffset(fdadm, &offset, &newoffset);
  if (res < 0)
    goto RETURN;
  if (reloff != offset || reloff + (off_t)size != newoffset) {
    wres = -1;
    goto RETURN;
  }
  printoffset(fdadm, newoffset, 0L);
RETURN:
  flock.l_type = F_UNLCK;
  fcntl(fdadm, F_SETLKW, &flock);
  return wres;
}


x86 assembly (clang, -O0):
<release>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0xffffffff,-0x1c(%rbp)
mov    0x2e6f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x48(%rbp)
movq   $0x0,-0x50(%rbp)
movq   $0x0,-0x58(%rbp)
mov    0x2e4b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x60(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e5c(%rip),%rax
mov    (%rax),%esi
lea    -0x60(%rbp),%rdx
call   1030 <fcntl@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0x0,-0x3c(%rbp)
jge    11a9 <release+0x69>
jmp    122e <release+0xee>
mov    -0x4(%rbp),%edi
mov    0x2e1d(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1040 <lseek@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jge    11d0 <release+0x90>
jmp    122e <release+0xee>
mov    -0x4(%rbp),%edi
lea    -0x30(%rbp),%rsi
lea    -0x38(%rbp),%rdx
call   1050 <readoffset@plt>
mov    %eax,-0x40(%rbp)
cmpl   $0x0,-0x40(%rbp)
jge    11f2 <release+0xb2>
jmp    122e <release+0xee>
mov    -0x10(%rbp),%rax
cmp    -0x30(%rbp),%rax
jne    1212 <release+0xd2>
mov    -0x10(%rbp),%rax
add    -0x18(%rbp),%rax
cmp    -0x38(%rbp),%rax
je     121e <release+0xde>
movl   $0xffffffff,-0x1c(%rbp)
jmp    122e <release+0xee>
mov    -0x4(%rbp),%edi
mov    -0x38(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1060 <printoffset@plt>
mov    0x2dab(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x60(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2da4(%rip),%rax
mov    (%rax),%esi
lea    -0x60(%rbp),%rdx
call   1030 <fcntl@plt>
mov    -0x1c(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<release>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x30,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %edi,%ebx
mov    0x2e74(%rip),%r13
mov    0x0(%r13),%eax
mov    %eax,0x28(%rsp)
xorps  %xmm0,%xmm0
movups %xmm0,0x18(%rsp)
mov    0x2e55(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rsp)
mov    0x2e68(%rip),%r12
mov    (%r12),%esi
lea    0x10(%rsp),%rdx
call   1030 <fcntl@plt>
test   %eax,%eax
js     11d3 <release+0x93>
mov    0x0(%r13),%edx
mov    %ebx,%edi
xor    %esi,%esi
call   1040 <lseek@plt>
test   %rax,%rax
js     11d3 <release+0x93>
lea    0x8(%rsp),%rsi
mov    %rsp,%rdx
mov    %ebx,%edi
call   1050 <readoffset@plt>
test   %eax,%eax
js     11d3 <release+0x93>
cmp    %r15,0x8(%rsp)
jne    11d3 <release+0x93>
add    %r15,%r14
cmp    (%rsp),%r14
jne    11d3 <release+0x93>
mov    %ebx,%edi
mov    %r14,%rsi
xor    %edx,%edx
call   1060 <printoffset@plt>
mov    0x2e06(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rsp)
mov    (%r12),%esi
lea    0x10(%rsp),%rdx
mov    %ebx,%edi
call   1030 <fcntl@plt>
mov    $0xffffffff,%eax
add    $0x30,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.flock = type { i32, i64, i64, i32 }
@SEEK_SET = global i32 0
@F_WRLCK = global i32 0
@F_SETLKW = global i32 0
@F_UNLCK = global i32 0
define i32 @release(i32 %0, i64 %1, i64 %2) {
%4 = alloca i32
%5 = alloca i64
%6 = alloca i64
%7 = alloca i32
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
%11 = alloca i32
%12 = alloca i32
%13 = alloca %struct.flock
store i32 %0, i32* %4
store i64 %1, i64* %5
store i64 %2, i64* %6
store i32 -1, i32* %7
%14 = load i32, i32* @SEEK_SET
%15 = getelementptr inbounds %struct.flock, %struct.flock* %13, i32 0, i32 3
store i32 %14, i32* %15
%16 = getelementptr inbounds %struct.flock, %struct.flock* %13, i32 0, i32 2
store i64 0, i64* %16
%17 = getelementptr inbounds %struct.flock, %struct.flock* %13, i32 0, i32 1
store i64 0, i64* %17
%18 = load i32, i32* @F_WRLCK
%19 = getelementptr inbounds %struct.flock, %struct.flock* %13, i32 0, i32 0
store i32 %18, i32* %19
%20 = load i32, i32* %4
%21 = load i32, i32* @F_SETLKW
%22 = call i32 @fcntl(i32 %20, i32 %21, %struct.flock* %13)
store i32 %22, i32* %11
%23 = load i32, i32* %11
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %3
br label %54
26: ; preds = %3
%27 = load i32, i32* %4
%28 = load i32, i32* @SEEK_SET
%29 = call i64 @lseek(i32 %27, i32 0, i32 %28)
store i64 %29, i64* %8
%30 = load i64, i64* %8
%31 = icmp slt i64 %30, 0
br i1 %31, label %32, label %33
32: ; preds = %26
br label %54
33: ; preds = %26
%34 = load i32, i32* %4
%35 = call i32 @readoffset(i32 %34, i64* %9, i64* %10)
store i32 %35, i32* %12
%36 = load i32, i32* %12
%37 = icmp slt i32 %36, 0
br i1 %37, label %38, label %39
38: ; preds = %33
br label %54
39: ; preds = %33
%40 = load i64, i64* %5
%41 = load i64, i64* %9
%42 = icmp ne i64 %40, %41
br i1 %42, label %49, label %43
43: ; preds = %39
%44 = load i64, i64* %5
%45 = load i64, i64* %6
%46 = add nsw i64 %44, %45
%47 = load i64, i64* %10
%48 = icmp ne i64 %46, %47
br i1 %48, label %49, label %50
49: ; preds = %43, %39
store i32 -1, i32* %7
br label %54
50: ; preds = %43
%51 = load i32, i32* %4
%52 = load i64, i64* %10
%53 = call i32 @printoffset(i32 %51, i64 %52, i64 0)
br label %54
54: ; preds = %50, %49, %38, %32, %25
%55 = load i32, i32* @F_UNLCK
%56 = getelementptr inbounds %struct.flock, %struct.flock* %13, i32 0, i32 0
store i32 %55, i32* %56
%57 = load i32, i32* %4
%58 = load i32, i32* @F_SETLKW
%59 = call i32 @fcntl(i32 %57, i32 %58, %struct.flock* %13)
%60 = load i32, i32* %7
ret i32 %60
}

LLVM IR (-O2):
%struct.flock = type { i32, i64, i64, i32 }
@SEEK_SET = global i32 0
@F_WRLCK = global i32 0
@F_SETLKW = global i32 0
@F_UNLCK = global i32 0
define i32 @release(i32 %0, i64 %1, i64 %2) {
%4 = alloca i64
%5 = alloca i64
%6 = alloca %struct.flock
%7 = bitcast i64* %4 to i8*
%8 = bitcast i64* %5 to i8*
%9 = bitcast %struct.flock* %6 to i8*
%10 = load i32, i32* @SEEK_SET
%11 = getelementptr inbounds %struct.flock, %struct.flock* %6, i64 0, i32 3
store i32 %10, i32* %11
%12 = getelementptr inbounds %struct.flock, %struct.flock* %6, i64 0, i32 1
%13 = bitcast i64* %12 to i8*
%14 = load i32, i32* @F_WRLCK
%15 = getelementptr inbounds %struct.flock, %struct.flock* %6, i64 0, i32 0
store i32 %14, i32* %15
%16 = load i32, i32* @F_SETLKW
%17 = call i32 @fcntl(i32 %0, i32 %16, %struct.flock* %6)
%18 = icmp slt i32 %17, 0
br i1 %18, label %35, label %19
19: ; preds = %3
%20 = load i32, i32* @SEEK_SET
%21 = call i64 @lseek(i32 %0, i32 0, i32 %20)
%22 = icmp slt i64 %21, 0
br i1 %22, label %35, label %23
23: ; preds = %19
%24 = call i32 @readoffset(i32 %0, i64* %4, i64* %5)
%25 = icmp sgt i32 %24, -1
%26 = load i64, i64* %4
%27 = icmp eq i64 %26, %1
%28 = select i1 %25, i1 %27, i1 false
br i1 %28, label %29, label %35
29: ; preds = %23
%30 = add nsw i64 %2, %1
%31 = load i64, i64* %5
%32 = icmp eq i64 %30, %31
br i1 %32, label %33, label %35
33: ; preds = %29
%34 = call i32 @printoffset(i32 %0, i64 %30, i64 0)
br label %35
35: ; preds = %29, %23, %19, %3, %33
%36 = load i32, i32* @F_UNLCK
store i32 %36, i32* %15
%37 = load i32, i32* @F_SETLKW
%38 = call i32 @fcntl(i32 %0, i32 %37, %struct.flock* %6)
ret i32 -1
}