#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 iovec {
  unsigned int *iov_base;
  int iov_len;
};
typedef scalar_t__ off_t;

/* Variables and functions */
int /*<<< orphan*/ SEEK_SET;
unsigned int htonl(unsigned int);
scalar_t__ lseek(int, int, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int writev(int, struct iovec *, int);
int update_lease_file(int fd, unsigned lease_orig, unsigned lease_time) {
  off_t lrc;
  int rc, i;
  struct iovec iov[2];
  lease_orig = htonl(lease_orig);
  lease_time = htonl(lease_time);
  lrc = lseek(fd, 12, SEEK_SET);
  if (lrc < 0) {
    perror("lseek(lease_file)");
    return -1;
  }
  i = 0;
  iov[i].iov_base = &lease_orig;
  iov[i++].iov_len = 4;
  iov[i].iov_base = &lease_time;
  iov[i++].iov_len = 4;
  rc = writev(fd, iov, i);
  if (rc < 8) {
    perror("write(lease_file)");
    return -1;
  }
  return 1;
}


x86 assembly (clang, -O0):
<update_lease_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0xc(%rbp),%edi
call   1050 <htonl@plt>
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%edi
call   1050 <htonl@plt>
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e6f(%rip),%rax
mov    (%rax),%edx
mov    $0xc,%esi
call   1040 <lseek@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jge    11a4 <update_lease_file+0x64>
lea    0xe6d(%rip),%rdi
call   1060 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1252 <update_lease_file+0x112>
movl   $0x0,-0x20(%rbp)
movslq -0x20(%rbp),%rcx
lea    -0x40(%rbp),%rax
shl    $0x4,%rcx
add    %rcx,%rax
lea    -0xc(%rbp),%rcx
mov    %rcx,(%rax)
mov    -0x20(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x20(%rbp)
movslq %eax,%rcx
lea    -0x40(%rbp),%rax
shl    $0x4,%rcx
add    %rcx,%rax
movl   $0x4,0x8(%rax)
movslq -0x20(%rbp),%rcx
lea    -0x40(%rbp),%rax
shl    $0x4,%rcx
add    %rcx,%rax
lea    -0x10(%rbp),%rcx
mov    %rcx,(%rax)
mov    -0x20(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x20(%rbp)
movslq %eax,%rcx
lea    -0x40(%rbp),%rax
shl    $0x4,%rcx
add    %rcx,%rax
movl   $0x4,0x8(%rax)
mov    -0x8(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    -0x20(%rbp),%edx
call   1030 <writev@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x8,-0x1c(%rbp)
jge    124b <update_lease_file+0x10b>
lea    0xdd8(%rip),%rdi
call   1060 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1252 <update_lease_file+0x112>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<update_lease_file>:
push   %rbp
push   %rbx
sub    $0x38,%rsp
mov    %edx,%ebp
mov    %edi,%ebx
mov    %esi,%edi
call   1050 <htonl@plt>
mov    %eax,0xc(%rsp)
mov    %ebp,%edi
call   1050 <htonl@plt>
mov    %eax,0x8(%rsp)
mov    0x2e79(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
mov    $0xc,%esi
call   1040 <lseek@plt>
test   %rax,%rax
js     11c2 <update_lease_file+0x82>
lea    0xc(%rsp),%rax
mov    %rax,0x10(%rsp)
movl   $0x4,0x18(%rsp)
lea    0x8(%rsp),%rax
mov    %rax,0x20(%rsp)
movl   $0x4,0x28(%rsp)
lea    0x10(%rsp),%rsi
mov    %ebx,%edi
mov    $0x2,%edx
call   1030 <writev@plt>
mov    %eax,%ecx
mov    $0x1,%eax
cmp    $0x7,%ecx
jle    11cb <update_lease_file+0x8b>
add    $0x38,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe37(%rip),%rdi
jmp    11d2 <update_lease_file+0x92>
lea    0xe40(%rip),%rdi
call   1060 <perror@plt>
mov    $0xffffffff,%eax
jmp    11bb <update_lease_file+0x7b>

LLVM IR (-O0):
%struct.iovec = type { i32*, i32 }
@SEEK_SET = global i32 0
@.str = [18 x i8] c"lseek(lease_file)\00"
@.str.1 = [18 x i8] c"write(lease_file)\00"
define i32 @update_lease_file(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i64
%9 = alloca i32
%10 = alloca i32
%11 = alloca [2 x %struct.iovec]
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%12 = load i32, i32* %6
%13 = call i32 @htonl(i32 %12)
store i32 %13, i32* %6
%14 = load i32, i32* %7
%15 = call i32 @htonl(i32 %14)
store i32 %15, i32* %7
%16 = load i32, i32* %5
%17 = load i32, i32* @SEEK_SET
%18 = call i64 @lseek(i32 %16, i32 12, i32 %17)
store i64 %18, i64* %8
%19 = load i64, i64* %8
%20 = icmp slt i64 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %3
%22 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %4
br label %51
23: ; preds = %3
store i32 0, i32* %10
%24 = load i32, i32* %10
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [2 x %struct.iovec], [2 x %struct.iovec]* %11, i64 0, i64 %25
%27 = getelementptr inbounds %struct.iovec, %struct.iovec* %26, i32 0, i32 0
store i32* %6, i32** %27
%28 = load i32, i32* %10
%29 = add nsw i32 %28, 1
store i32 %29, i32* %10
%30 = sext i32 %28 to i64
%31 = getelementptr inbounds [2 x %struct.iovec], [2 x %struct.iovec]* %11, i64 0, i64 %30
%32 = getelementptr inbounds %struct.iovec, %struct.iovec* %31, i32 0, i32 1
store i32 4, i32* %32
%33 = load i32, i32* %10
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds [2 x %struct.iovec], [2 x %struct.iovec]* %11, i64 0, i64 %34
%36 = getelementptr inbounds %struct.iovec, %struct.iovec* %35, i32 0, i32 0
store i32* %7, i32** %36
%37 = load i32, i32* %10
%38 = add nsw i32 %37, 1
store i32 %38, i32* %10
%39 = sext i32 %37 to i64
%40 = getelementptr inbounds [2 x %struct.iovec], [2 x %struct.iovec]* %11, i64 0, i64 %39
%41 = getelementptr inbounds %struct.iovec, %struct.iovec* %40, i32 0, i32 1
store i32 4, i32* %41
%42 = load i32, i32* %5
%43 = getelementptr inbounds [2 x %struct.iovec], [2 x %struct.iovec]* %11, i64 0, i64 0
%44 = load i32, i32* %10
%45 = call i32 @writev(i32 %42, %struct.iovec* %43, i32 %44)
store i32 %45, i32* %9
%46 = load i32, i32* %9
%47 = icmp slt i32 %46, 8
br i1 %47, label %48, label %50
48: ; preds = %23
%49 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %4
br label %51
50: ; preds = %23
store i32 1, i32* %4
br label %51
51: ; preds = %50, %48, %21
%52 = load i32, i32* %4
ret i32 %52
}

LLVM IR (-O2):
%struct.iovec = type { i32*, i32 }
@SEEK_SET = global i32 0
@.str = [18 x i8] c"lseek(lease_file)\00"
@.str.1 = [18 x i8] c"write(lease_file)\00"
define i32 @update_lease_file(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca [2 x %struct.iovec]
%7 = bitcast [2 x %struct.iovec]* %6 to i8*
%8 = tail call i32 @htonl(i32 %1)
store i32 %8, i32* %4
%9 = tail call i32 @htonl(i32 %2)
store i32 %9, i32* %5
%10 = load i32, i32* @SEEK_SET
%11 = tail call i64 @lseek(i32 %0, i32 12, i32 %10)
%12 = icmp slt i64 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %3
%14 = tail call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
br label %25
15: ; preds = %3
%16 = getelementptr inbounds [2 x %struct.iovec], [2 x %struct.iovec]* %6, i64 0, i64 0
%17 = getelementptr inbounds [2 x %struct.iovec], [2 x %struct.iovec]* %6, i64 0, i64 0, i32 0
store i32* %4, i32** %17
%18 = getelementptr inbounds [2 x %struct.iovec], [2 x %struct.iovec]* %6, i64 0, i64 0, i32 1
store i32 4, i32* %18
%19 = getelementptr inbounds [2 x %struct.iovec], [2 x %struct.iovec]* %6, i64 0, i64 1, i32 0
store i32* %5, i32** %19
%20 = getelementptr inbounds [2 x %struct.iovec], [2 x %struct.iovec]* %6, i64 0, i64 1, i32 1
store i32 4, i32* %20
%21 = call i32 @writev(i32 %0, %struct.iovec* %16, i32 2)
%22 = icmp slt i32 %21, 8
br i1 %22, label %23, label %25
23: ; preds = %15
%24 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
br label %25
25: ; preds = %15, %23, %13
%26 = phi i32 [ -1, %13 ], [ -1, %23 ], [ 1, %15 ]
ret i32 %26
}