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

/* Variables and functions */
int EINTR;
int close(int);
int errno;
int fsync(int);
int close_lease_file(int fd, int modified) {
  int rc;
again:
  if (modified) {
    rc = fsync(fd);
    if (rc < 0) {
      int save;
      if (errno == EINTR)
        goto again;
      save = errno;
      close(fd);
      errno = save;
      return -1;
    }
  }
  rc = close(fd);
  if (rc < 1 && errno == EINTR)
    goto again;
  return rc;
}


x86 assembly (clang, -O0):
<close_lease_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     119b <close_lease_file+0x7b>
mov    -0x8(%rbp),%edi
call   1040 <fsync@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    1196 <close_lease_file+0x76>
mov    0x2e8c(%rip),%rax
mov    (%rax),%eax
mov    0x2e7b(%rip),%rcx
cmp    (%rcx),%eax
jne    116a <close_lease_file+0x4a>
jmp    112e <close_lease_file+0xe>
mov    0x2e6f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%edi
call   1030 <close@plt>
mov    -0x14(%rbp),%ecx
mov    0x2e58(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    11d3 <close_lease_file+0xb3>
jmp    119b <close_lease_file+0x7b>
mov    -0x8(%rbp),%edi
call   1030 <close@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x1,-0x10(%rbp)
jge    11cd <close_lease_file+0xad>
mov    0x2e29(%rip),%rax
mov    (%rax),%eax
mov    0x2e18(%rip),%rcx
cmp    (%rcx),%eax
jne    11cd <close_lease_file+0xad>
jmp    112e <close_lease_file+0xe>
mov    -0x10(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<close_lease_file>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%r12d
mov    %edi,%ebx
mov    0x2eac(%rip),%r14
mov    0x2e9d(%rip),%r15
jmp    1148 <close_lease_file+0x28>
nopl   (%rax)
mov    (%r14),%ebp
cmp    (%r15),%ebp
jne    116d <close_lease_file+0x4d>
test   %r12d,%r12d
je     1158 <close_lease_file+0x38>
mov    %ebx,%edi
call   1040 <fsync@plt>
test   %eax,%eax
js     1140 <close_lease_file+0x20>
mov    %ebx,%edi
call   1030 <close@plt>
test   %eax,%eax
jg     117c <close_lease_file+0x5c>
mov    (%r14),%ecx
cmp    (%r15),%ecx
je     1148 <close_lease_file+0x28>
jmp    117c <close_lease_file+0x5c>
mov    %ebx,%edi
call   1030 <close@plt>
mov    %ebp,(%r14)
mov    $0xffffffff,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@errno = global i32 0
@EINTR = global i32 0
define i32 @close_lease_file(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
br label %8
8: ; preds = %36, %20, %2
%9 = load i32, i32* %5
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %27
11: ; preds = %8
%12 = load i32, i32* %4
%13 = call i32 @fsync(i32 %12)
store i32 %13, i32* %6
%14 = load i32, i32* %6
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %26
16: ; preds = %11
%17 = load i32, i32* @errno
%18 = load i32, i32* @EINTR
%19 = icmp eq i32 %17, %18
br i1 %19, label %20, label %21
20: ; preds = %16
br label %8
21: ; preds = %16
%22 = load i32, i32* @errno
store i32 %22, i32* %7
%23 = load i32, i32* %4
%24 = call i32 @close(i32 %23)
%25 = load i32, i32* %7
store i32 %25, i32* @errno
store i32 -1, i32* %3
br label %39
26: ; preds = %11
br label %27
27: ; preds = %26, %8
%28 = load i32, i32* %4
%29 = call i32 @close(i32 %28)
store i32 %29, i32* %6
%30 = load i32, i32* %6
%31 = icmp slt i32 %30, 1
br i1 %31, label %32, label %37
32: ; preds = %27
%33 = load i32, i32* @errno
%34 = load i32, i32* @EINTR
%35 = icmp eq i32 %33, %34
br i1 %35, label %36, label %37
36: ; preds = %32
br label %8
37: ; preds = %32, %27
%38 = load i32, i32* %6
store i32 %38, i32* %3
br label %39
39: ; preds = %37, %21
%40 = load i32, i32* %3
ret i32 %40
}

LLVM IR (-O2):
@errno = global i32 0
@EINTR = global i32 0
define i32 @close_lease_file(i32 %0, i32 %1) {
%3 = icmp eq i32 %1, 0
br label %4
4: ; preds = %21, %2
br i1 %3, label %14, label %5
5: ; preds = %4
%6 = tail call i32 @fsync(i32 %0)
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %14
8: ; preds = %5
%9 = load i32, i32* @errno
%10 = load i32, i32* @EINTR
%11 = icmp eq i32 %9, %10
br i1 %11, label %21, label %12
12: ; preds = %8
%13 = tail call i32 @close(i32 %0)
store i32 %9, i32* @errno
br label %22
14: ; preds = %5, %4
%15 = tail call i32 @close(i32 %0)
%16 = icmp slt i32 %15, 1
br i1 %16, label %17, label %22
17: ; preds = %14
%18 = load i32, i32* @errno
%19 = load i32, i32* @EINTR
%20 = icmp eq i32 %18, %19
br i1 %20, label %21, label %22
21: ; preds = %17, %8
br label %4
22: ; preds = %14, %17, %12
%23 = phi i32 [ -1, %12 ], [ %15, %17 ], [ %15, %14 ]
ret i32 %23
}