#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 {
  char *iov_base;
  int iov_len;
};

/* Variables and functions */
unsigned int htonl(unsigned int);
int /*<<< orphan*/ perror(char *);
int writev(int, struct iovec *, int);
int write_lease_file(int fd, const unsigned char *ipv4, unsigned lease_orig,
                     unsigned lease_time, const unsigned char *client_id,
                     int client_len) {
  struct iovec iov[5];
  int i;
  int rc;
  if (client_len > 650)
    return -1;
  lease_orig = htonl(lease_orig);
  lease_time = htonl(lease_time);
  i = 0;
  iov[i].iov_base = "AHCP\1\0\0\0";
  iov[i++].iov_len = 8;
  iov[i].iov_base = (void *)ipv4;
  iov[i++].iov_len = 4;
  iov[i].iov_base = &lease_orig;
  iov[i++].iov_len = 4;
  iov[i].iov_base = &lease_time;
  iov[i++].iov_len = 4;
  iov[i].iov_base = (void *)client_id;
  iov[i++].iov_len = client_len;
  rc = writev(fd, iov, i);
  if (rc < 20 + client_len) {
    perror("write(lease_file)");
    return -1;
  }
  return 1;
}


x86 assembly (clang, -O0):
<write_lease_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
mov    %r9d,-0x24(%rbp)
cmpl   $0x28a,-0x24(%rbp)
jle    1169 <write_lease_file+0x39>
movl   $0xffffffff,-0x4(%rbp)
jmp    1311 <write_lease_file+0x1e1>
mov    -0x14(%rbp),%edi
call   1040 <htonl@plt>
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%edi
call   1040 <htonl@plt>
mov    %eax,-0x18(%rbp)
movl   $0x0,-0x84(%rbp)
movslq -0x84(%rbp),%rcx
lea    -0x80(%rbp),%rax
shl    $0x4,%rcx
add    %rcx,%rax
lea    0xe5e(%rip),%rcx
mov    %rcx,(%rax)
mov    -0x84(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x84(%rbp)
movslq %eax,%rcx
lea    -0x80(%rbp),%rax
shl    $0x4,%rcx
add    %rcx,%rax
movl   $0x8,0x8(%rax)
mov    -0x10(%rbp),%rcx
movslq -0x84(%rbp),%rdx
lea    -0x80(%rbp),%rax
shl    $0x4,%rdx
add    %rdx,%rax
mov    %rcx,(%rax)
mov    -0x84(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x84(%rbp)
movslq %eax,%rcx
lea    -0x80(%rbp),%rax
shl    $0x4,%rcx
add    %rcx,%rax
movl   $0x4,0x8(%rax)
lea    -0x14(%rbp),%rcx
movslq -0x84(%rbp),%rdx
lea    -0x80(%rbp),%rax
shl    $0x4,%rdx
add    %rdx,%rax
mov    %rcx,(%rax)
mov    -0x84(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x84(%rbp)
movslq %eax,%rcx
lea    -0x80(%rbp),%rax
shl    $0x4,%rcx
add    %rcx,%rax
movl   $0x4,0x8(%rax)
lea    -0x18(%rbp),%rcx
movslq -0x84(%rbp),%rdx
lea    -0x80(%rbp),%rax
shl    $0x4,%rdx
add    %rdx,%rax
mov    %rcx,(%rax)
mov    -0x84(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x84(%rbp)
movslq %eax,%rcx
lea    -0x80(%rbp),%rax
shl    $0x4,%rcx
add    %rcx,%rax
movl   $0x4,0x8(%rax)
mov    -0x20(%rbp),%rcx
movslq -0x84(%rbp),%rdx
lea    -0x80(%rbp),%rax
shl    $0x4,%rdx
add    %rdx,%rax
mov    %rcx,(%rax)
mov    -0x24(%rbp),%ecx
mov    -0x84(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x84(%rbp)
movslq %eax,%rdx
lea    -0x80(%rbp),%rax
shl    $0x4,%rdx
add    %rdx,%rax
mov    %ecx,0x8(%rax)
mov    -0x8(%rbp),%edi
lea    -0x80(%rbp),%rsi
mov    -0x84(%rbp),%edx
call   1030 <writev@plt>
mov    %eax,-0x88(%rbp)
mov    -0x88(%rbp),%eax
mov    -0x24(%rbp),%ecx
add    $0x14,%ecx
cmp    %ecx,%eax
jge    130a <write_lease_file+0x1da>
lea    0xd10(%rip),%rdi
call   1050 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1311 <write_lease_file+0x1e1>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_lease_file>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x60,%rsp
mov    $0xffffffff,%eax
cmp    $0x28a,%r9d
jg     11e0 <write_lease_file+0xb0>
mov    %r9d,%ebx
mov    %r8,%r15
mov    %ecx,%ebp
mov    %rsi,%r12
mov    %edi,%r14d
mov    %edx,%edi
call   1040 <htonl@plt>
mov    %eax,0xc(%rsp)
mov    %ebp,%edi
call   1040 <htonl@plt>
mov    %eax,0x8(%rsp)
lea    0xe87(%rip),%rax
mov    %rax,0x10(%rsp)
movl   $0x8,0x18(%rsp)
mov    %r12,0x20(%rsp)
movl   $0x4,0x28(%rsp)
lea    0xc(%rsp),%rax
mov    %rax,0x30(%rsp)
movl   $0x4,0x38(%rsp)
lea    0x8(%rsp),%rax
mov    %rax,0x40(%rsp)
movl   $0x4,0x48(%rsp)
mov    %r15,0x50(%rsp)
mov    %ebx,0x58(%rsp)
lea    0x10(%rsp),%rsi
mov    %r14d,%edi
mov    $0x5,%edx
call   1030 <writev@plt>
mov    %eax,%ecx
add    $0x14,%ebx
mov    $0x1,%eax
cmp    %ebx,%ecx
jl     11ed <write_lease_file+0xbd>
add    $0x60,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe15(%rip),%rdi
call   1050 <perror@plt>
mov    $0xffffffff,%eax
jmp    11e0 <write_lease_file+0xb0>

LLVM IR (-O0):
%struct.iovec = type { i8*, i32 }
@.str = [9 x i8] c"AHCP\01\00\00\00\00"
@.str.1 = [18 x i8] c"write(lease_file)\00"
define i32 @write_lease_file(i32 %0, i8* %1, i32 %2, i32 %3, i8* %4, i32 %5) {
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i32
%14 = alloca [5 x %struct.iovec]
%15 = alloca i32
%16 = alloca i32
store i32 %0, i32* %8
store i8* %1, i8** %9
store i32 %2, i32* %10
store i32 %3, i32* %11
store i8* %4, i8** %12
store i32 %5, i32* %13
%17 = load i32, i32* %13
%18 = icmp sgt i32 %17, 650
br i1 %18, label %19, label %20
19: ; preds = %6
store i32 -1, i32* %7
br label %86
20: ; preds = %6
%21 = load i32, i32* %10
%22 = call i32 @htonl(i32 %21)
store i32 %22, i32* %10
%23 = load i32, i32* %11
%24 = call i32 @htonl(i32 %23)
store i32 %24, i32* %11
store i32 0, i32* %15
%25 = load i32, i32* %15
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [5 x %struct.iovec], [5 x %struct.iovec]* %14, i64 0, i64 %26
%28 = getelementptr inbounds %struct.iovec, %struct.iovec* %27, i32 0, i32 0
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8** %28
%29 = load i32, i32* %15
%30 = add nsw i32 %29, 1
store i32 %30, i32* %15
%31 = sext i32 %29 to i64
%32 = getelementptr inbounds [5 x %struct.iovec], [5 x %struct.iovec]* %14, i64 0, i64 %31
%33 = getelementptr inbounds %struct.iovec, %struct.iovec* %32, i32 0, i32 1
store i32 8, i32* %33
%34 = load i8*, i8** %9
%35 = load i32, i32* %15
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [5 x %struct.iovec], [5 x %struct.iovec]* %14, i64 0, i64 %36
%38 = getelementptr inbounds %struct.iovec, %struct.iovec* %37, i32 0, i32 0
store i8* %34, i8** %38
%39 = load i32, i32* %15
%40 = add nsw i32 %39, 1
store i32 %40, i32* %15
%41 = sext i32 %39 to i64
%42 = getelementptr inbounds [5 x %struct.iovec], [5 x %struct.iovec]* %14, i64 0, i64 %41
%43 = getelementptr inbounds %struct.iovec, %struct.iovec* %42, i32 0, i32 1
store i32 4, i32* %43
%44 = bitcast i32* %10 to i8*
%45 = load i32, i32* %15
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds [5 x %struct.iovec], [5 x %struct.iovec]* %14, i64 0, i64 %46
%48 = getelementptr inbounds %struct.iovec, %struct.iovec* %47, i32 0, i32 0
store i8* %44, i8** %48
%49 = load i32, i32* %15
%50 = add nsw i32 %49, 1
store i32 %50, i32* %15
%51 = sext i32 %49 to i64
%52 = getelementptr inbounds [5 x %struct.iovec], [5 x %struct.iovec]* %14, i64 0, i64 %51
%53 = getelementptr inbounds %struct.iovec, %struct.iovec* %52, i32 0, i32 1
store i32 4, i32* %53
%54 = bitcast i32* %11 to i8*
%55 = load i32, i32* %15
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds [5 x %struct.iovec], [5 x %struct.iovec]* %14, i64 0, i64 %56
%58 = getelementptr inbounds %struct.iovec, %struct.iovec* %57, i32 0, i32 0
store i8* %54, i8** %58
%59 = load i32, i32* %15
%60 = add nsw i32 %59, 1
store i32 %60, i32* %15
%61 = sext i32 %59 to i64
%62 = getelementptr inbounds [5 x %struct.iovec], [5 x %struct.iovec]* %14, i64 0, i64 %61
%63 = getelementptr inbounds %struct.iovec, %struct.iovec* %62, i32 0, i32 1
store i32 4, i32* %63
%64 = load i8*, i8** %12
%65 = load i32, i32* %15
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds [5 x %struct.iovec], [5 x %struct.iovec]* %14, i64 0, i64 %66
%68 = getelementptr inbounds %struct.iovec, %struct.iovec* %67, i32 0, i32 0
store i8* %64, i8** %68
%69 = load i32, i32* %13
%70 = load i32, i32* %15
%71 = add nsw i32 %70, 1
store i32 %71, i32* %15
%72 = sext i32 %70 to i64
%73 = getelementptr inbounds [5 x %struct.iovec], [5 x %struct.iovec]* %14, i64 0, i64 %72
%74 = getelementptr inbounds %struct.iovec, %struct.iovec* %73, i32 0, i32 1
store i32 %69, i32* %74
%75 = load i32, i32* %8
%76 = getelementptr inbounds [5 x %struct.iovec], [5 x %struct.iovec]* %14, i64 0, i64 0
%77 = load i32, i32* %15
%78 = call i32 @writev(i32 %75, %struct.iovec* %76, i32 %77)
store i32 %78, i32* %16
%79 = load i32, i32* %16
%80 = load i32, i32* %13
%81 = add nsw i32 20, %80
%82 = icmp slt i32 %79, %81
br i1 %82, label %83, label %85
83: ; preds = %20
%84 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %7
br label %86
85: ; preds = %20
store i32 1, i32* %7
br label %86
86: ; preds = %85, %83, %19
%87 = load i32, i32* %7
ret i32 %87
}

LLVM IR (-O2):
%struct.iovec = type { i8*, i32 }
@.str = [9 x i8] c"AHCP\01\00\00\00\00"
@.str.1 = [18 x i8] c"write(lease_file)\00"
define i32 @write_lease_file(i32 %0, i8* %1, i32 %2, i32 %3, i8* %4, i32 %5) {
%7 = alloca i32
%8 = alloca i32
%9 = alloca [5 x %struct.iovec]
%10 = bitcast [5 x %struct.iovec]* %9 to i8*
%11 = icmp sgt i32 %5, 650
br i1 %11, label %33, label %12
12: ; preds = %6
%13 = tail call i32 @htonl(i32 %2)
store i32 %13, i32* %7
%14 = tail call i32 @htonl(i32 %3)
store i32 %14, i32* %8
%15 = getelementptr inbounds [5 x %struct.iovec], [5 x %struct.iovec]* %9, i64 0, i64 0
%16 = getelementptr inbounds [5 x %struct.iovec], [5 x %struct.iovec]* %9, i64 0, i64 0, i32 0
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8** %16
%17 = getelementptr inbounds [5 x %struct.iovec], [5 x %struct.iovec]* %9, i64 0, i64 0, i32 1
store i32 8, i32* %17
%18 = getelementptr inbounds [5 x %struct.iovec], [5 x %struct.iovec]* %9, i64 0, i64 1, i32 0
store i8* %1, i8** %18
%19 = getelementptr inbounds [5 x %struct.iovec], [5 x %struct.iovec]* %9, i64 0, i64 1, i32 1
store i32 4, i32* %19
%20 = getelementptr inbounds [5 x %struct.iovec], [5 x %struct.iovec]* %9, i64 0, i64 2
%21 = bitcast %struct.iovec* %20 to i32**
store i32* %7, i32** %21
%22 = getelementptr inbounds [5 x %struct.iovec], [5 x %struct.iovec]* %9, i64 0, i64 2, i32 1
store i32 4, i32* %22
%23 = getelementptr inbounds [5 x %struct.iovec], [5 x %struct.iovec]* %9, i64 0, i64 3
%24 = bitcast %struct.iovec* %23 to i32**
store i32* %8, i32** %24
%25 = getelementptr inbounds [5 x %struct.iovec], [5 x %struct.iovec]* %9, i64 0, i64 3, i32 1
store i32 4, i32* %25
%26 = getelementptr inbounds [5 x %struct.iovec], [5 x %struct.iovec]* %9, i64 0, i64 4, i32 0
store i8* %4, i8** %26
%27 = getelementptr inbounds [5 x %struct.iovec], [5 x %struct.iovec]* %9, i64 0, i64 4, i32 1
store i32 %5, i32* %27
%28 = call i32 @writev(i32 %0, %struct.iovec* %15, i32 5)
%29 = add nsw i32 %5, 20
%30 = icmp slt i32 %28, %29
br i1 %30, label %31, label %33
31: ; preds = %12
%32 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
br label %33
33: ; preds = %12, %6, %31
%34 = phi i32 [ -1, %31 ], [ -1, %6 ], [ 1, %12 ]
ret i32 %34
}