#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*/ time_t;
struct timeval {
  unsigned int tv_sec;
};

/* Variables and functions */
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ close_lease_file(int, int);
int /*<<< orphan*/ get_real_time(struct timeval *, int *);
int /*<<< orphan*/ gettime(struct timeval *, int /*<<< orphan*/ *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int read_lease_file(int, unsigned char *, unsigned int *, unsigned int *,
                    int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                    int /*<<< orphan*/);
int unlink(char *);
int purge_lease_file(char *fn, unsigned char *ipv4) {
  int fd, rc;
  unsigned lease_orig, lease_time;
  struct timeval now, real;
  time_t stable;
  int clock_status;
  gettime(&now, &stable);
  get_real_time(&real, &clock_status);
  fd = open(fn, O_RDWR);
  if (fd < 0)
    return 0;
  rc = read_lease_file(fd, ipv4, &lease_orig, &lease_time, NULL, NULL, 0);
  if (rc < 0) {
    close_lease_file(fd, 0);
    return 0;
  }
  if (clock_status == 2 && lease_orig > 0) {
    if (lease_orig + lease_time + (16 * 24 * 3600 + 666) < real.tv_sec) {
      rc = unlink(fn);
      if (rc < 0)
        perror("unlink(lease_file)");
      close_lease_file(fd, 1);
      return (rc >= 0);
    }
  }
  close_lease_file(fd, 0);
  return 0;
}


x86 assembly (clang, -O0):
<purge_lease_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    -0x30(%rbp),%rdi
lea    -0x3c(%rbp),%rsi
call   1080 <gettime@plt>
lea    -0x38(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   1090 <get_real_time@plt>
mov    -0x10(%rbp),%rdi
mov    0x2e43(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    11c5 <purge_lease_file+0x55>
movl   $0x0,-0x4(%rbp)
jmp    128e <purge_lease_file+0x11e>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%rsi
lea    -0x24(%rbp),%rdx
lea    -0x28(%rbp),%rcx
xor    %eax,%eax
mov    %eax,%r9d
xor    %eax,%eax
mov    %r9,%r8
movl   $0x0,(%rsp)
call   1070 <read_lease_file@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    120d <purge_lease_file+0x9d>
mov    -0x1c(%rbp),%edi
xor    %esi,%esi
call   1040 <close_lease_file@plt>
movl   $0x0,-0x4(%rbp)
jmp    128e <purge_lease_file+0x11e>
cmpl   $0x2,-0x40(%rbp)
jne    127d <purge_lease_file+0x10d>
cmpl   $0x0,-0x24(%rbp)
jbe    127d <purge_lease_file+0x10d>
mov    -0x24(%rbp),%eax
add    -0x28(%rbp),%eax
add    $0x151a9a,%eax
cmp    -0x38(%rbp),%eax
jae    1278 <purge_lease_file+0x108>
mov    -0x10(%rbp),%rdi
call   1030 <unlink@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    1257 <purge_lease_file+0xe7>
lea    0xdae(%rip),%rdi
call   1060 <perror@plt>
mov    -0x1c(%rbp),%edi
mov    $0x1,%esi
call   1040 <close_lease_file@plt>
cmpl   $0x0,-0x20(%rbp)
setge  %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
jmp    128e <purge_lease_file+0x11e>
jmp    127d <purge_lease_file+0x10d>
mov    -0x1c(%rbp),%edi
xor    %esi,%esi
call   1040 <close_lease_file@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<purge_lease_file>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%r15
mov    %rdi,%r14
lea    0x20(%rsp),%rdi
lea    0x24(%rsp),%rsi
call   1080 <gettime@plt>
lea    0x10(%rsp),%rdi
lea    0x14(%rsp),%rsi
call   1090 <get_real_time@plt>
mov    0x2e43(%rip),%rax
mov    (%rax),%esi
mov    %r14,%rdi
call   1050 <open@plt>
test   %eax,%eax
js     121d <purge_lease_file+0xad>
mov    %eax,%ebp
movl   $0x0,(%rsp)
xor    %ebx,%ebx
lea    0x1c(%rsp),%rdx
lea    0x18(%rsp),%rcx
mov    %eax,%edi
mov    %r15,%rsi
xor    %r8d,%r8d
xor    %r9d,%r9d
call   1070 <read_lease_file@plt>
test   %eax,%eax
js     1223 <purge_lease_file+0xb3>
cmpl   $0x2,0x14(%rsp)
jne    1221 <purge_lease_file+0xb1>
mov    0x1c(%rsp),%eax
test   %eax,%eax
je     1221 <purge_lease_file+0xb1>
mov    0x18(%rsp),%ecx
add    %ecx,%eax
add    $0x151a9a,%eax
cmp    0x10(%rsp),%eax
jae    1221 <purge_lease_file+0xb1>
mov    %r14,%rdi
call   1030 <unlink@plt>
mov    %eax,%ebx
test   %eax,%eax
js     1239 <purge_lease_file+0xc9>
mov    %ebp,%edi
mov    $0x1,%esi
call   1040 <close_lease_file@plt>
not    %ebx
shr    $0x1f,%ebx
jmp    122c <purge_lease_file+0xbc>
xor    %ebx,%ebx
jmp    122c <purge_lease_file+0xbc>
xor    %ebx,%ebx
mov    %ebp,%edi
xor    %esi,%esi
call   1040 <close_lease_file@plt>
mov    %ebx,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdc0(%rip),%rdi
call   1060 <perror@plt>
jmp    120a <purge_lease_file+0x9a>

LLVM IR (-O0):
%struct.timeval = type { i32 }
@O_RDWR = global i32 0
@.str = [19 x i8] c"unlink(lease_file)\00"
define i32 @purge_lease_file(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca %struct.timeval
%11 = alloca %struct.timeval
%12 = alloca i32
%13 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%14 = call i32 @gettime(%struct.timeval* %10, i32* %12)
%15 = call i32 @get_real_time(%struct.timeval* %11, i32* %13)
%16 = load i8*, i8** %4
%17 = load i32, i32* @O_RDWR
%18 = call i32 @open(i8* %16, i32 %17)
store i32 %18, i32* %6
%19 = load i32, i32* %6
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %2
store i32 0, i32* %3
br label %62
22: ; preds = %2
%23 = load i32, i32* %6
%24 = load i8*, i8** %5
%25 = call i32 @read_lease_file(i32 %23, i8* %24, i32* %8, i32* %9, i32* null, i32* null, i32 0)
store i32 %25, i32* %7
%26 = load i32, i32* %7
%27 = icmp slt i32 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %22
%29 = load i32, i32* %6
%30 = call i32 @close_lease_file(i32 %29, i32 0)
store i32 0, i32* %3
br label %62
31: ; preds = %22
%32 = load i32, i32* %13
%33 = icmp eq i32 %32, 2
br i1 %33, label %34, label %59
34: ; preds = %31
%35 = load i32, i32* %8
%36 = icmp ugt i32 %35, 0
br i1 %36, label %37, label %59
37: ; preds = %34
%38 = load i32, i32* %8
%39 = load i32, i32* %9
%40 = add i32 %38, %39
%41 = add i32 %40, 1383066
%42 = getelementptr inbounds %struct.timeval, %struct.timeval* %11, i32 0, i32 0
%43 = load i32, i32* %42
%44 = icmp ult i32 %41, %43
br i1 %44, label %45, label %58
45: ; preds = %37
%46 = load i8*, i8** %4
%47 = call i32 @unlink(i8* %46)
store i32 %47, i32* %7
%48 = load i32, i32* %7
%49 = icmp slt i32 %48, 0
br i1 %49, label %50, label %52
50: ; preds = %45
%51 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %52
52: ; preds = %50, %45
%53 = load i32, i32* %6
%54 = call i32 @close_lease_file(i32 %53, i32 1)
%55 = load i32, i32* %7
%56 = icmp sge i32 %55, 0
%57 = zext i1 %56 to i32
store i32 %57, i32* %3
br label %62
58: ; preds = %37
br label %59
59: ; preds = %58, %34, %31
%60 = load i32, i32* %6
%61 = call i32 @close_lease_file(i32 %60, i32 0)
store i32 0, i32* %3
br label %62
62: ; preds = %59, %52, %28, %21
%63 = load i32, i32* %3
ret i32 %63
}

LLVM IR (-O2):
%struct.timeval = type { i32 }
@O_RDWR = global i32 0
@.str = [19 x i8] c"unlink(lease_file)\00"
define i32 @purge_lease_file(i8* nocapture %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.timeval
%6 = alloca %struct.timeval
%7 = alloca i32
%8 = alloca i32
%9 = bitcast i32* %3 to i8*
%10 = bitcast i32* %4 to i8*
%11 = bitcast %struct.timeval* %5 to i8*
%12 = bitcast %struct.timeval* %6 to i8*
%13 = bitcast i32* %7 to i8*
%14 = bitcast i32* %8 to i8*
%15 = call i32 @gettime(%struct.timeval* %5, i32* %7)
%16 = call i32 @get_real_time(%struct.timeval* %6, i32* %8)
%17 = load i32, i32* @O_RDWR
%18 = call i32 @open(i8* %0, i32 %17)
%19 = icmp slt i32 %18, 0
br i1 %19, label %49, label %20
20: ; preds = %2
%21 = call i32 @read_lease_file(i32 %18, i8* %1, i32* %3, i32* %4, i32* null, i32* null, i32 0)
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %20
%24 = call i32 @close_lease_file(i32 %18, i32 0)
br label %49
25: ; preds = %20
%26 = load i32, i32* %8
%27 = icmp eq i32 %26, 2
%28 = load i32, i32* %3
%29 = icmp ne i32 %28, 0
%30 = select i1 %27, i1 %29, i1 false
br i1 %30, label %31, label %47
31: ; preds = %25
%32 = load i32, i32* %4
%33 = add i32 %28, 1383066
%34 = add i32 %33, %32
%35 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i64 0, i32 0
%36 = load i32, i32* %35
%37 = icmp ult i32 %34, %36
br i1 %37, label %38, label %47
38: ; preds = %31
%39 = call i32 @unlink(i8* %0)
%40 = icmp slt i32 %39, 0
br i1 %40, label %41, label %43
41: ; preds = %38
%42 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %43
43: ; preds = %41, %38
%44 = call i32 @close_lease_file(i32 %18, i32 1)
%45 = xor i32 %39, -1
%46 = lshr i32 %45, 31
br label %49
47: ; preds = %31, %25
%48 = call i32 @close_lease_file(i32 %18, i32 0)
br label %49
49: ; preds = %2, %47, %43, %23
%50 = phi i32 [ 0, %23 ], [ %46, %43 ], [ 0, %47 ], [ 0, %2 ]
ret i32 %50
}