// File: /workspace/github_c_makefile_star2_O2/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 0x925a(%rip), %rax      # 0x11258
cmpl $0x2, (%rax)
jge 0x8256
movl $0x60102, 0x40(%rsp)    # imm = 0x60102
movl (%r14), %eax
movl %eax, 0x44(%rsp)
testq %rbp, %rbp
sete %cl
cmpl $0x14, %ebx
setl %dl
andq $0x0, 0x48(%rsp)
xorl %eax, %eax
orb %cl, %dl
jne 0x8031
movl (%rbp), %eax
leaq 0x6c(%rsp), %r14
movl %eax, -0x1c(%r14)
movl (%r13), %r13d
movl %r13d, -0x18(%r14)
andl $0x0, -0x14(%r14)
movq 0x490(%rsp), %rbp
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 0x80fa
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 0x811a
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
pushq $-0x1
popq %r15
testq %rcx, %rcx
je 0x8195
movswl 0x8(%rcx), %esi
testl %esi, %esi
jle 0x8195
leal (%rax,%rsi,4), %edi
addl $0x8, %edi
cmpl $0x400, %edi            # imm = 0x400
ja 0x8223
movb $0x6, 0x40(%rsp,%rdx)
leal (,%rsi,4), %edx
movb %dl, 0x47(%rsp,%rax)
movq (%rcx), %rcx
movzwl %si, %edx
shll $0x2, %edx
addq $0xc, %rcx
leaq 0x40(%rsp), %rsi
leaq (%rax,%rsi), %rdi
addq $0x8, %rdi
xorl %esi, %esi
cmpq %rsi, %rdx
je 0x8238
movl (%rcx), %r8d
movl %r8d, (%rdi,%rsi)
addq $0x4, %rsi
addq $0x1c, %rcx
jmp 0x817b
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)
andq $0x0, 0x20(%r14)
movl 0x488(%rsp), %edi
movq %r14, %rsi
callq 0x2280
movl 0x902d(%rip), %edi      # 0x111f8
pushq $0x1
popq %rsi
pushq $0x19
popq %rdx
pushq $0x28
popq %r8
movq %r14, %rcx
callq 0x20a0
testl %eax, %eax
js 0x8223
movl 0x9011(%rip), %edi      # 0x111f8
movslq %ebx, %rdx
xorl %ecx, %ecx
cmpl $0x0, 0x4(%rsp)
setne %cl
shll $0x2, %ecx
leaq 0x40(%rsp), %rsi
pushq $0x10
popq %r9
movq 0x8(%rsp), %r8
callq 0x2170
movq %rax, %r15
movl 0x8fe5(%rip), %edi      # 0x111f8
pushq $0x1
popq %rsi
pushq $0x19
popq %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x20a0
movl %r15d, %eax
addq $0x448, %rsp            # imm = 0x448
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq (%rax,%rsi), %rdx
addq $0x8, %rdx
cmpq $0x3ff, %rdx            # imm = 0x3FF
ja 0x8223
leaq (%rax,%rsi), %rbx
addq $0x9, %rbx
jmp 0x8198
leaq 0x4c67(%rip), %rsi      # 0xcec4
pushq $0x2
popq %rdi
movl %r15d, %edx
movl 0x488(%rsp), %ecx
xorl %eax, %eax
callq 0x23c0
jmp 0x8007
nop