// File: /workspace/github_c_makefile_star2_O0/jech[P]shncpd/dhcpv4.c
// Function: dhcpv4_parse
static int
dhcpv4_parse(unsigned char *buf, int buflen,
             struct dhcpv4_request *ret)
{
    int i = 0;
    unsigned char
        xid[4] = {0},
        ciaddr[4] = {0}, yiaddr[4] = {0}, siaddr[4] = {0}, giaddr[4] = {0},
        chaddr[16] = {0}, ip[4] = {0}, sid[4] = {0};
    unsigned char *cid = NULL, *uc = NULL;
    int dhcp_type = -1, broadcast = 0, cidlen = 0, uclen = 0;

    if(buflen < 236)
        goto fail;

    if(buf[0] != 1 || buf[1] != 1 || buf[2] != 6)
        goto fail;
    i += 4;

    memcpy(xid, buf + i, 4);
    i += 4;

    /* secs */
    i += 2;

    /* flags */
    broadcast = (buf[i] & 0x80) != 0;
    i += 2;

    /* ciaddr */
    memcpy(ciaddr, buf + i, 4);
    i += 4;

    /* yiaddr */
    memcpy(yiaddr, buf + i, 4);
    i += 4;

    /* siaddr */
    memcpy(siaddr, buf + i, 4);
    i += 4;

    /* giaddr */
    memcpy(giaddr, buf + i, 4);
    i += 4;

    /* chaddr */
    memcpy(chaddr, buf + i, 16);
    i += 16;

    /* sname */
    i += 64;

    /* file */
    i += 128;

    if(buflen - i < 4)
        goto fail;

    if(memcmp(buf + i, cookie, 4) != 0)
        goto fail;
    i += 4;

    while(i < buflen) {
        unsigned const char *tlv = buf + i;
        int type, bodylen;

        if(buflen - i < 1) {
            fprintf(stderr, "Received truncated DHCPv4 TLV.\n");
            goto fail;
        }

        type = tlv[0];
        if(type == 0) {
            i++;
            continue;
        }

        if(type == 255) {
            i++;
            goto done;
        }

        if(buflen - i < 2) {
            fprintf(stderr, "Received truncated DHCPv4 TLV.\n");
            goto fail;
        }

        bodylen = tlv[1];
        if(buflen - i < 2 + bodylen) {
            fprintf(stderr, "Received truncated DHCPv4 TLV.\n");
            goto fail;
        }

        switch(type) {
        case 50:
            if(bodylen != 4)
                goto fail;
            memcpy(ip, tlv + 2, 4);
            break;
        case 53:
            if(bodylen != 1)
                goto fail;
            dhcp_type = tlv[2];
            break;
        case 54:
            if(bodylen != 4)
                goto fail;
            memcpy(sid, tlv + 2, 4);
            break;
        case 61:
            if(cid != NULL)
                goto fail;
            cid = malloc(bodylen);
            if(cid == NULL)
                goto fail;
            memcpy(cid, tlv + 2, bodylen);
            cidlen = bodylen;
            break;
        case 77:
            if(uc != NULL)
                goto fail;
            uc = malloc(bodylen);
            if(uc == NULL)
                goto fail;
            memcpy(uc, tlv + 2, bodylen);
            uclen = bodylen;
            break;
        }
        i += 2 + bodylen;
    }
    /* Fall through */
 fail:
    fprintf(stderr, "Failed to parse DHCPv4 packet.\n");
    free(cid);
    free(uc);
    return -1;

 done:
    ret->type = dhcp_type;
    ret->broadcast = broadcast;
    memcpy(ret->chaddr, chaddr, 16);
    memcpy(ret->xid, xid, 4);
    memcpy(ret->ciaddr, ciaddr, 4);
    memcpy(ret->yiaddr, yiaddr, 4);
    memcpy(ret->siaddr, siaddr, 4);
    memcpy(ret->giaddr, giaddr, 4);
    memcpy(ret->ip, ip, 4);
    memcpy(ret->sid, sid, 4);
    ret->cid = cid;
    ret->cidlen = cidlen;
    ret->uc = uc;
    ret->uclen = uclen;
    return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
leaq -0x28(%rbp), %rdi
xorl %esi, %esi
movl $0x4, %edx
callq 0x2170
leaq -0x2c(%rbp), %rdi
xorl %esi, %esi
movl $0x4, %edx
callq 0x2170
leaq -0x30(%rbp), %rdi
xorl %esi, %esi
movl $0x4, %edx
callq 0x2170
leaq -0x34(%rbp), %rdi
xorl %esi, %esi
movl $0x4, %edx
callq 0x2170
leaq -0x38(%rbp), %rdi
xorl %esi, %esi
movl $0x4, %edx
callq 0x2170
leaq -0x50(%rbp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x2170
leaq -0x54(%rbp), %rdi
xorl %esi, %esi
movl $0x4, %edx
callq 0x2170
leaq -0x58(%rbp), %rdi
xorl %esi, %esi
movl $0x4, %edx
callq 0x2170
movq $0x0, -0x60(%rbp)
movq $0x0, -0x68(%rbp)
movl $0xffffffff, -0x6c(%rbp) # imm = 0xFFFFFFFF
movl $0x0, -0x70(%rbp)
movl $0x0, -0x74(%rbp)
movl $0x0, -0x78(%rbp)
cmpl $0xec, -0x14(%rbp)
jge 0xaca7
jmp 0xafff
movq -0x10(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x1, %eax
jne 0xaccd
movq -0x10(%rbp), %rax
movzbl 0x1(%rax), %eax
cmpl $0x1, %eax
jne 0xaccd
movq -0x10(%rbp), %rax
movzbl 0x2(%rax), %eax
cmpl $0x6, %eax
je 0xacd2
jmp 0xafff
movl -0x24(%rbp), %eax
addl $0x4, %eax
movl %eax, -0x24(%rbp)
movq -0x10(%rbp), %rax
movslq -0x24(%rbp), %rcx
movl (%rax,%rcx), %eax
movl %eax, -0x28(%rbp)
movl -0x24(%rbp), %eax
addl $0x4, %eax
movl %eax, -0x24(%rbp)
movl -0x24(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x24(%rbp)
movq -0x10(%rbp), %rax
movslq -0x24(%rbp), %rcx
movzbl (%rax,%rcx), %eax
andl $0x80, %eax
cmpl $0x0, %eax
setne %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x70(%rbp)
movl -0x24(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x24(%rbp)
movq -0x10(%rbp), %rax
movslq -0x24(%rbp), %rcx
movl (%rax,%rcx), %eax
movl %eax, -0x2c(%rbp)
movl -0x24(%rbp), %eax
addl $0x4, %eax
movl %eax, -0x24(%rbp)
movq -0x10(%rbp), %rax
movslq -0x24(%rbp), %rcx
movl (%rax,%rcx), %eax
movl %eax, -0x30(%rbp)
movl -0x24(%rbp), %eax
addl $0x4, %eax
movl %eax, -0x24(%rbp)
movq -0x10(%rbp), %rax
movslq -0x24(%rbp), %rcx
movl (%rax,%rcx), %eax
movl %eax, -0x34(%rbp)
movl -0x24(%rbp), %eax
addl $0x4, %eax
movl %eax, -0x24(%rbp)
movq -0x10(%rbp), %rax
movslq -0x24(%rbp), %rcx
movl (%rax,%rcx), %eax
movl %eax, -0x38(%rbp)
movl -0x24(%rbp), %eax
addl $0x4, %eax
movl %eax, -0x24(%rbp)
movq -0x10(%rbp), %rax
movslq -0x24(%rbp), %rcx
movq (%rax,%rcx), %rdx
movq %rdx, -0x50(%rbp)
movq 0x8(%rax,%rcx), %rax
movq %rax, -0x48(%rbp)
movl -0x24(%rbp), %eax
addl $0x10, %eax
movl %eax, -0x24(%rbp)
movl -0x24(%rbp), %eax
addl $0x40, %eax
movl %eax, -0x24(%rbp)
movl -0x24(%rbp), %eax
addl $0x80, %eax
movl %eax, -0x24(%rbp)
movl -0x14(%rbp), %eax
subl -0x24(%rbp), %eax
cmpl $0x4, %eax
jge 0xadc5
jmp 0xafff
movq -0x10(%rbp), %rax
movslq -0x24(%rbp), %rcx
addq %rcx, %rax
movl (%rax), %eax
subl $0x63538263, %eax       # imm = 0x63538263
setne %al
movzbl %al, %eax
cmpl $0x0, %eax
je 0xade7
jmp 0xafff
movl -0x24(%rbp), %eax
addl $0x4, %eax
movl %eax, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0xaffd
movq -0x10(%rbp), %rax
movslq -0x24(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x80(%rbp)
movl -0x14(%rbp), %eax
subl -0x24(%rbp), %eax
cmpl $0x1, %eax
jge 0xae33
movq 0xb1db(%rip), %rax      # 0x15ff8
movq (%rax), %rdi
leaq 0x7eec(%rip), %rsi      # 0x12d13
movb $0x0, %al
callq 0x21f0
jmp 0xafff
movq -0x80(%rbp), %rax
movzbl (%rax), %eax
movl %eax, -0x84(%rbp)
cmpl $0x0, -0x84(%rbp)
jne 0xae54
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0xadf0
cmpl $0xff, -0x84(%rbp)
jne 0xae6e
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0xb035
movl -0x14(%rbp), %eax
subl -0x24(%rbp), %eax
cmpl $0x2, %eax
jge 0xae96
movq 0xb178(%rip), %rax      # 0x15ff8
movq (%rax), %rdi
leaq 0x7e89(%rip), %rsi      # 0x12d13
movb $0x0, %al
callq 0x21f0
jmp 0xafff
movq -0x80(%rbp), %rax
movzbl 0x1(%rax), %eax
movl %eax, -0x88(%rbp)
movl -0x14(%rbp), %eax
subl -0x24(%rbp), %eax
movl -0x88(%rbp), %ecx
addl $0x2, %ecx
cmpl %ecx, %eax
jge 0xaed4
movq 0xb13a(%rip), %rax      # 0x15ff8
movq (%rax), %rdi
leaq 0x7e4b(%rip), %rsi      # 0x12d13
movb $0x0, %al
callq 0x21f0
jmp 0xafff
movl -0x84(%rbp), %eax
addl $-0x32, %eax
movl %eax, %ecx
movq %rcx, -0x90(%rbp)
subl $0x1b, %eax
ja 0xafe9
movq -0x90(%rbp), %rax
leaq 0x7f6b(%rip), %rcx      # 0x12e68
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
cmpl $0x4, -0x88(%rbp)
je 0xaf14
jmp 0xafff
movq -0x80(%rbp), %rax
movl 0x2(%rax), %eax
movl %eax, -0x54(%rbp)
jmp 0xafe9
cmpl $0x1, -0x88(%rbp)
je 0xaf31
jmp 0xafff
movq -0x80(%rbp), %rax
movzbl 0x2(%rax), %eax
movl %eax, -0x6c(%rbp)
jmp 0xafe9
cmpl $0x4, -0x88(%rbp)
je 0xaf4f
jmp 0xafff
movq -0x80(%rbp), %rax
movl 0x2(%rax), %eax
movl %eax, -0x58(%rbp)
jmp 0xafe9
cmpq $0x0, -0x60(%rbp)
je 0xaf6a
jmp 0xafff
movslq -0x88(%rbp), %rdi
callq 0x2260
movq %rax, -0x60(%rbp)
cmpq $0x0, -0x60(%rbp)
jne 0xaf83
jmp 0xafff
movq -0x60(%rbp), %rdi
movq -0x80(%rbp), %rsi
addq $0x2, %rsi
movslq -0x88(%rbp), %rdx
callq 0x2230
movl -0x88(%rbp), %eax
movl %eax, -0x74(%rbp)
jmp 0xafe9
cmpq $0x0, -0x68(%rbp)
je 0xafaf
jmp 0xafff
movslq -0x88(%rbp), %rdi
callq 0x2260
movq %rax, -0x68(%rbp)
cmpq $0x0, -0x68(%rbp)
jne 0xafc8
jmp 0xafff
movq -0x68(%rbp), %rdi
movq -0x80(%rbp), %rsi
addq $0x2, %rsi
movslq -0x88(%rbp), %rdx
callq 0x2230
movl -0x88(%rbp), %eax
movl %eax, -0x78(%rbp)
movl -0x88(%rbp), %eax
addl $0x2, %eax
addl -0x24(%rbp), %eax
movl %eax, -0x24(%rbp)
jmp 0xadf0
jmp 0xafff
movq 0xaff2(%rip), %rax      # 0x15ff8
movq (%rax), %rdi
leaq 0x7f99(%rip), %rsi      # 0x12fa9
movb $0x0, %al
callq 0x21f0
movq -0x60(%rbp), %rdi
callq 0x2040
movq -0x68(%rbp), %rdi
callq 0x2040
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xb0d5
movl -0x6c(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
movl -0x70(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0x20(%rbp), %rax
movq -0x50(%rbp), %rcx
movq %rcx, 0x1c(%rax)
movq -0x48(%rbp), %rcx
movq %rcx, 0x24(%rax)
movq -0x20(%rbp), %rax
movl -0x28(%rbp), %ecx
movl %ecx, 0x8(%rax)
movq -0x20(%rbp), %rax
movl -0x2c(%rbp), %ecx
movl %ecx, 0xc(%rax)
movq -0x20(%rbp), %rax
movl -0x30(%rbp), %ecx
movl %ecx, 0x10(%rax)
movq -0x20(%rbp), %rax
movl -0x34(%rbp), %ecx
movl %ecx, 0x14(%rax)
movq -0x20(%rbp), %rax
movl -0x38(%rbp), %ecx
movl %ecx, 0x18(%rax)
movq -0x20(%rbp), %rax
movl -0x54(%rbp), %ecx
movl %ecx, 0x2c(%rax)
movq -0x20(%rbp), %rax
movl -0x58(%rbp), %ecx
movl %ecx, 0x30(%rax)
movq -0x60(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x38(%rax)
movl -0x74(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x40(%rax)
movq -0x68(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x48(%rax)
movl -0x78(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x50(%rax)
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x90, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)