// File: /workspace/github_c_makefile_star2_O3/jech[P]shncpd/dhcpv4.c
// Function: dhcpv4_send
static int
dhcpv4_send(int s, struct sockaddr_in *to, int dontroute,
            int type, const unsigned char *xid,
            const unsigned char *chaddr, const unsigned char *myaddr,
            const unsigned char *ip, int ifindex,
            const unsigned char *netmask, struct prefix_list *dns,
            int lease_time)
{
    int buflen = 1024;
    unsigned char buf[buflen];
    int i = 0;
    int rc;
    struct ifreq ifr;

    debugf("-> DHCPv4 (type %d) on interface %d\n", type, ifindex);

    MEM_UNDEFINED(buf, buflen);

    CHECK(236);
    BYTE(2);
    BYTE(1);
    BYTE(6);
    BYTE(0);
    BYTES(xid, 4);
    SHORT(0);
    SHORT(0);

    ZEROS(4);                   /* ciaddr */
    if(ip && lease_time >= 20) {
        BYTES(ip, 4);           /* yiaddr */
    } else {
        ZEROS(4);
    }
    BYTES(myaddr, 4);           /* siaddr */
    ZEROS(4);                   /* giaddr */
    BYTES(chaddr, 16);          /* chaddr */
    ZEROS(64);                  /* sname */
    ZEROS(128);                 /* file */

    CHECK(4);
    BYTES(cookie, 4);

    CHECK(3);
    BYTE(53);                   /* DHCP Message Type */
    BYTE(1);
    BYTE(type);

    CHECK(6);
    BYTE(54);                   /* Server Identifier */
    BYTE(4);
    BYTES(myaddr, 4);

    if(lease_time >= 20) {
        CHECK(6);
        BYTE(51);               /* IP Address Lease Time */
        BYTE(4);
        LONG(lease_time);

        CHECK(6);
        BYTE(58);               /* T1 */
        BYTE(4);
        LONG(min(RENEW_TIME, lease_time - 10));

        CHECK(6);
        BYTE(59);               /* T2 */
        BYTE(4);
        LONG(min(REBIND_TIME, lease_time - 15));
    }

    if(netmask) {
        CHECK(6);
        BYTE(1);
        BYTE(4);
        BYTES(netmask, 4);
    }

    CHECK(6);
    BYTE(3);
    BYTE(4);
    BYTES(myaddr, 4);

    if(dns && dns->numprefixes > 0) {
        int j;
        CHECK(2 + 4 * dns->numprefixes);
        BYTE(6);
        BYTE(4 * dns->numprefixes);
        for(j = 0; j < dns->numprefixes; j++) {
            BYTES((char*)&dns->prefixes[j].p + 12, 4);
        }
    }

    CHECK(1);
    BYTE(255);

    memset(&ifr, 0, sizeof(ifr));
    if_indextoname(ifindex, ifr.ifr_name);
    rc = setsockopt(dhcpv4_socket, SOL_SOCKET, SO_BINDTODEVICE,
                    &ifr, sizeof(ifr));
    if(rc < 0)
        return -1;

    rc = sendto(dhcpv4_socket, buf, i, dontroute ? MSG_DONTROUTE : 0,
                (struct sockaddr*)to, sizeof(*to));

    setsockopt(dhcpv4_socket, SOL_SOCKET, SO_BINDTODEVICE, NULL, 0);
    return rc;

 fail:
    return -1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x448, %rsp            # imm = 0x448
movq %r9, %r13
movq %r8, %r12
movq %rcx, %r14
movl %edx, %r15d
movl %esi, 0x4(%rsp)
movq %rdi, 0x8(%rsp)
movl 0x4a0(%rsp), %ebx
movq 0x480(%rsp), %rbp
leaq 0xa60a(%rip), %rax      # 0x13258
cmpl $0x2, (%rax)
jge 0x8ecb
movl $0x60102, 0x40(%rsp)    # imm = 0x60102
movl (%r14), %eax
movl %eax, 0x44(%rsp)
testq %rbp, %rbp
sete %cl
cmpl $0x14, %ebx
setl %dl
movq $0x0, 0x48(%rsp)
xorl %eax, %eax
orb %cl, %dl
jne 0x8c84
movl (%rbp), %eax
movq 0x490(%rsp), %rbp
leaq 0x6c(%rsp), %r14
movl %eax, -0x1c(%r14)
movl (%r13), %r13d
movl %r13d, -0x18(%r14)
movl $0x0, -0x14(%r14)
movups (%r12), %xmm0
movups %xmm0, -0x10(%r14)
movl $0xc0, %edx
movq %r14, %rdi
xorl %esi, %esi
callq 0x2160
movl $0x63538263, 0xc0(%r14) # imm = 0x63538263
movw $0x135, 0xc4(%r14)      # imm = 0x135
movb %r15b, 0xc6(%r14)
movw $0x436, 0xc7(%r14)      # imm = 0x436
movl %r13d, 0xc9(%r14)
movl $0xf9, %eax
cmpl $0x14, %ebx
jl 0x8d50
movw $0x433, 0x139(%rsp)     # imm = 0x433
movl %ebx, %eax
bswapl %eax
movl %eax, 0x13b(%rsp)
leal -0xa(%rbx), %eax
movl $0xf0, %ecx
cmpl %ecx, %eax
cmovbl %eax, %ecx
movw $0x43a, 0x13f(%rsp)     # imm = 0x43A
shll $0x18, %ecx
movl %ecx, 0x141(%rsp)
addl $-0xf, %ebx
movl $0x12c, %eax            # imm = 0x12C
cmpl %eax, %ebx
cmovael %eax, %ebx
movw $0x43b, 0x145(%rsp)     # imm = 0x43B
bswapl %ebx
movl %ebx, 0x147(%rsp)
movl $0x10b, %eax            # imm = 0x10B
movq 0x498(%rsp), %rcx
testq %rbp, %rbp
je 0x8d70
movl %eax, %edx
movw $0x401, 0x40(%rsp,%rdx) # imm = 0x401
movl (%rbp), %esi
movl %esi, 0x42(%rsp,%rdx)
addl $0x6, %eax
movl %eax, %eax
movw $0x403, 0x40(%rsp,%rax) # imm = 0x403
movl %r13d, 0x42(%rsp,%rax)
leaq 0x6(%rax), %rdx
testq %rcx, %rcx
je 0x8e11
movswl 0x8(%rcx), %esi
testl %esi, %esi
jle 0x8e11
leal (%rax,%rsi,4), %edi
addl $0x8, %edi
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
cmpl $0x400, %edi            # imm = 0x400
ja 0x8eb6
movb $0x6, 0x40(%rsp,%rdx)
leal (,%rsi,4), %edx
movb %dl, 0x47(%rsp,%rax)
movq (%rcx), %rcx
leaq 0x40(%rsp), %rdx
addq %rax, %rdx
addq $0x8, %rdx
addq $0xc, %rcx
movzwl %si, %edi
shll $0x2, %edi
xorl %esi, %esi
movl (%rcx), %r8d
movl %r8d, (%rdx,%rsi)
addq $0x4, %rsi
addq $0x1c, %rcx
cmpq %rsi, %rdi
jne 0x8dd6
leaq (%rax,%rsi), %rcx
addq $0x4, %rcx
cmpq $0x3fb, %rcx            # imm = 0x3FB
ja 0x8eb6
leaq (%rax,%rsi), %rdx
addq $0x8, %rdx
leaq (%rax,%rsi), %rbx
addq $0x9, %rbx
jmp 0x8e14
leal 0x7(%rax), %ebx
movslq %edx, %rax
movb $-0x1, 0x40(%rsp,%rax)
xorps %xmm0, %xmm0
leaq 0x10(%rsp), %r14
movaps %xmm0, (%r14)
movaps %xmm0, 0x10(%r14)
movq $0x0, 0x20(%r14)
movl 0x488(%rsp), %edi
movq %r14, %rsi
callq 0x2270
movl 0xa3a6(%rip), %edi      # 0x131f0
movl $0x1, %esi
movl $0x19, %edx
movq %r14, %rcx
movl $0x28, %r8d
callq 0x20a0
testl %eax, %eax
js 0x8eb0
movl 0xa384(%rip), %edi      # 0x131f0
movslq %ebx, %rdx
xorl %ecx, %ecx
cmpl $0x0, 0x4(%rsp)
setne %cl
shll $0x2, %ecx
leaq 0x40(%rsp), %rsi
movq 0x8(%rsp), %r8
movl $0x10, %r9d
callq 0x2170
movq %rax, %r15
movl 0xa356(%rip), %edi      # 0x131f0
movl $0x1, %esi
movl $0x19, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x20a0
jmp 0x8eb6
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
movl %r15d, %eax
addq $0x448, %rsp            # imm = 0x448
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x5012(%rip), %rsi      # 0xdee4
movl $0x2, %edi
movl %r15d, %edx
movl 0x488(%rsp), %ecx
xorl %eax, %eax
callq 0x30a8
jmp 0x8c57
nopl (%rax)