// File: /workspace/github_c_makefile_star2_O1/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 0xa0e4(%rip), %rax      # 0x13258
cmpl $0x2, (%rax)
jge 0x93d8
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 0x91aa
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, %ecx
cmpl $0x14, %ebx
jl 0x9275
movw $0x433, 0x139(%rsp)     # imm = 0x433
movl %ebx, %eax
bswapl %eax
movl %eax, 0x13b(%rsp)
movw $0x43a, 0x13f(%rsp)     # imm = 0x43A
movl $0xfa, %eax
cmpl %eax, %ebx
cmovll %ebx, %eax
addl $-0xa, %eax
bswapl %eax
movl %eax, 0x141(%rsp)
movw $0x43b, 0x145(%rsp)     # imm = 0x43B
movl $0x13b, %eax            # imm = 0x13B
cmpl %eax, %ebx
cmovll %ebx, %eax
addl $-0xf, %eax
bswapl %eax
movl %eax, 0x147(%rsp)
movl $0x10b, %ecx            # imm = 0x10B
movq 0x498(%rsp), %rdx
testq %rbp, %rbp
je 0x9295
movl %ecx, %eax
movw $0x401, 0x40(%rsp,%rax) # imm = 0x401
movl (%rbp), %esi
movl %esi, 0x42(%rsp,%rax)
addl $0x6, %ecx
movl %ecx, %eax
movw $0x403, 0x40(%rsp,%rax) # imm = 0x403
movl %r13d, 0x42(%rsp,%rax)
leaq 0x6(%rax), %rbx
testq %rdx, %rdx
je 0x9315
movswl 0x8(%rdx), %esi
testl %esi, %esi
jle 0x9315
leal (%rcx,%rsi,4), %ecx
addl $0x8, %ecx
cmpl $0x400, %ecx            # imm = 0x400
jg 0x9303
movb $0x6, 0x40(%rsp,%rbx)
leal (,%rsi,4), %edi
movb %dil, 0x47(%rsp,%rax)
movq (%rdx), %rdx
addq $0x8, %rax
movslq %esi, %rdi
leaq (%rdi,%rdi,8), %rsi
leaq (%rsi,%rsi,2), %rsi
addq %rdi, %rsi
xorl %edi, %edi
movl 0xc(%rdx,%rdi), %r8d
movl %r8d, 0x40(%rsp,%rax)
addq $0x4, %rax
addq $0x1c, %rdi
cmpq %rdi, %rsi
jne 0x92ea
movl %eax, %ebx
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
cmpl $0x400, %ecx            # imm = 0x400
jg 0x93c3
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
cmpl $0x3ff, %ebx            # imm = 0x3FF
jg 0x93c3
movslq %ebx, %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 0x9e93(%rip), %edi      # 0x131f0
movl $0x1, %esi
movl $0x19, %edx
movq %r14, %rcx
movl $0x28, %r8d
callq 0x20a0
testl %eax, %eax
js 0x93c3
incl %ebx
movl 0x9e6f(%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 0x9e41(%rip), %edi      # 0x131f0
movl $0x1, %esi
movl $0x19, %edx
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 0x4b3d(%rip), %rsi      # 0xdf1c
movl $0x2, %edi
movl %r15d, %edx
movl 0x488(%rsp), %ecx
xorl %eax, %eax
callq 0x319e
jmp 0x917d
nop