// File: /workspace/github_c_makefile_star2_O0/seojangho[P]clee/simclist.c
// Function: list_dump_filedescriptor
int list_dump_filedescriptor(const list_t *restrict l, int fd, size_t *restrict len) {
    struct list_entry_s *x;
    void *ser_buf;
    uint32_t bufsize;
    struct timeval timeofday;
    struct list_dump_header_s header;

    if (l->attrs.meter == NULL && l->attrs.serializer == NULL) {
        errno = ENOTTY;
        return -1;
    }

    /****       DUMP FORMAT      ****

    [ ver   timestamp   |  totlen   numels  elemlen     hash    |   DATA ]
    
    where DATA can be:
    @ for constant-size list (element size is constant; elemlen > 0)
    [ elem    elem    ...    elem ]
    @ for other lists (element size dictated by element_meter each time; elemlen <= 0)
    [ size elem     size elem       ...     size elem ]
    
    all integers are encoded in NETWORK BYTE FORMAT
    *****/


    /* prepare HEADER */
    /* version */
    header.ver = htons( SIMCLIST_DUMPFORMAT_VERSION );

    /* timestamp */
    gettimeofday(&timeofday, NULL);
    header.timestamp = (int64_t)timeofday.tv_sec * 1000000 + (int64_t)timeofday.tv_usec;
    header.timestamp = hton64(header.timestamp);

    header.rndterm = htonl((int32_t)get_random());

    /* total list size is postprocessed afterwards */

    /* number of elements */
    header.numels = htonl(l->numels);

    /* include an hash, if possible */
    if (l->attrs.hasher != NULL) {
        if (htonl(list_hash(l, & header.listhash)) != 0) {
            /* could not compute list hash! */
            return -1;
        }
    } else {
        header.listhash = htonl(0);
    }

    header.totlistlen = header.elemlen = 0;

    /* leave room for the header at the beginning of the file */
    if (lseek(fd, SIMCLIST_DUMPFORMAT_HEADERLEN, SEEK_SET) < 0) {
        /* errno set by lseek() */
        return -1;
    }

    /* write CONTENT */
    if (l->numels > 0) {
        /* SPECULATE that the list has constant element size */
        
        if (l->attrs.serializer != NULL) {  /* user user-specified serializer */
            /* get preliminary length of serialized element in header.elemlen */
            ser_buf = l->attrs.serializer(l->head_sentinel->next->data, & header.elemlen);
            free(ser_buf);
            /* request custom serialization of each element */
            for (x = l->head_sentinel->next; x != l->tail_sentinel; x = x->next) {
                ser_buf = l->attrs.serializer(x->data, &bufsize);
                header.totlistlen += bufsize;
                if (header.elemlen != 0) {      /* continue on speculation */
                    if (header.elemlen != bufsize) {
                        free(ser_buf);
                        /* constant element length speculation broken! */
                        header.elemlen = 0;
                        header.totlistlen = 0;
                        x = l->head_sentinel;
                        if (lseek(fd, SIMCLIST_DUMPFORMAT_HEADERLEN, SEEK_SET) < 0) {
                            /* errno set by lseek() */
                            return -1;
                        }
                        /* restart from the beginning */
                        continue;
                    }
                    /* speculation confirmed */
                    WRITE_ERRCHECK(fd, ser_buf, bufsize);
                } else {                        /* speculation found broken */
                    WRITE_ERRCHECK(fd, & bufsize, sizeof(size_t));
                    WRITE_ERRCHECK(fd, ser_buf, bufsize);
                }
                free(ser_buf);
            }
        } else if (l->attrs.meter != NULL) {
            header.elemlen = (uint32_t)l->attrs.meter(l->head_sentinel->next->data);

            /* serialize the element straight from its data */
            for (x = l->head_sentinel->next; x != l->tail_sentinel; x = x->next) {
                bufsize = l->attrs.meter(x->data);
                header.totlistlen += bufsize;
                if (header.elemlen != 0) {
                    if (header.elemlen != bufsize) {
                        /* constant element length speculation broken! */
                        header.elemlen = 0;
                        header.totlistlen = 0;
                        x = l->head_sentinel;
                        /* restart from the beginning */
                        continue;
                    }
                    WRITE_ERRCHECK(fd, x->data, bufsize);
                } else {
                    WRITE_ERRCHECK(fd, &bufsize, sizeof(size_t));
                    WRITE_ERRCHECK(fd, x->data, bufsize);
                }
            }
        }
        /* adjust endianness */
        header.elemlen = htonl(header.elemlen);
        header.totlistlen = htonl(header.totlistlen);
    }

    /* write random terminator */
    WRITE_ERRCHECK(fd, & header.rndterm, sizeof(header.rndterm));        /* list terminator */


    /* write header */
    lseek(fd, 0, SEEK_SET);

    WRITE_ERRCHECK(fd, & header.ver, sizeof(header.ver));                        /* version */
    WRITE_ERRCHECK(fd, & header.timestamp, sizeof(header.timestamp));            /* timestamp */
    WRITE_ERRCHECK(fd, & header.rndterm, sizeof(header.rndterm));                /* random terminator */

    WRITE_ERRCHECK(fd, & header.totlistlen, sizeof(header.totlistlen));          /* total length of elements */
    WRITE_ERRCHECK(fd, & header.numels, sizeof(header.numels));                  /* number of elements */
    WRITE_ERRCHECK(fd, & header.elemlen, sizeof(header.elemlen));                /* size of each element, or 0 for independent */
    WRITE_ERRCHECK(fd, & header.listhash, sizeof(header.listhash));             /* list hash, or 0 for "ignore" */


    /* possibly store total written length in "len" */
    if (len != NULL) {
        *len = sizeof(header) + ntohl(header.totlistlen);
    }

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x50(%rax)
jne 0x61e3
movq -0x10(%rbp), %rax
cmpq $0x0, 0x68(%rax)
jne 0x61e3
callq 0x3040
movl $0x19, (%rax)
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x6799
movl $0x1, %edi
callq 0x3080
movw %ax, -0x70(%rbp)
leaq -0x48(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x30b0
imulq $0xf4240, -0x48(%rbp), %rax # imm = 0xF4240
addq -0x40(%rbp), %rax
movq %rax, -0x68(%rbp)
movl $0x1, %edi
callq 0x3080
movzwl %ax, %eax
cmpl $0x1, %eax
jne 0x622d
movq -0x68(%rbp), %rax
movq %rax, -0x78(%rbp)
jmp 0x62cd
movabsq $-0x100000000000000, %rax # imm = 0xFF00000000000000
andq -0x68(%rbp), %rax
shrq $0x38, %rax
movabsq $0xff000000000000, %rcx # imm = 0xFF000000000000
andq -0x68(%rbp), %rcx
shrq $0x28, %rcx
orq %rcx, %rax
movabsq $0xff0000000000, %rcx   # imm = 0xFF0000000000
andq -0x68(%rbp), %rcx
shrq $0x18, %rcx
orq %rcx, %rax
movabsq $0xff00000000, %rcx     # imm = 0xFF00000000
andq -0x68(%rbp), %rcx
shrq $0x8, %rcx
orq %rcx, %rax
movabsq $0xff000000, %rcx       # imm = 0xFF000000
andq -0x68(%rbp), %rcx
shlq $0x8, %rcx
orq %rcx, %rax
movq -0x68(%rbp), %rcx
andq $0xff0000, %rcx         # imm = 0xFF0000
shlq $0x18, %rcx
orq %rcx, %rax
movq -0x68(%rbp), %rcx
andq $0xff00, %rcx           # imm = 0xFF00
shlq $0x28, %rcx
orq %rcx, %rax
movq -0x68(%rbp), %rcx
andq $0xff, %rcx
shlq $0x38, %rcx
orq %rcx, %rax
movq %rax, -0x78(%rbp)
movq -0x78(%rbp), %rax
movq %rax, -0x68(%rbp)
callq 0x3220
movl %eax, %edi
callq 0x30d0
movl %eax, -0x60(%rbp)
movq -0x10(%rbp), %rax
movl 0x18(%rax), %edi
callq 0x30d0
movl %eax, -0x58(%rbp)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x60(%rax)
je 0x6329
movq -0x10(%rbp), %rdi
leaq -0x70(%rbp), %rsi
addq $0x20, %rsi
callq 0x5d30
movl %eax, %edi
callq 0x30d0
cmpl $0x0, %eax
je 0x6327
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x6799
jmp 0x6333
xorl %edi, %edi
callq 0x30d0
movl %eax, -0x50(%rbp)
movl $0x0, -0x54(%rbp)
movl $0x0, -0x5c(%rbp)
movl -0x14(%rbp), %edi
movl $0x1e, %esi
xorl %edx, %edx
callq 0x30a0
cmpq $0x0, %rax
jge 0x6362
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x6799
movq -0x10(%rbp), %rax
cmpl $0x0, 0x18(%rax)
jbe 0x661d
movq -0x10(%rbp), %rax
cmpq $0x0, 0x68(%rax)
je 0x64dd
movq -0x10(%rbp), %rax
movq 0x68(%rax), %rax
movq -0x10(%rbp), %rcx
movq (%rcx), %rcx
movq 0x8(%rcx), %rcx
movq (%rcx), %rdi
leaq -0x70(%rbp), %rsi
addq $0x1c, %rsi
callq *%rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rdi
callq 0x3030
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq 0x8(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x8(%rcx), %rax
je 0x64d8
movq -0x10(%rbp), %rax
movq 0x68(%rax), %rax
movq -0x28(%rbp), %rcx
movq (%rcx), %rdi
leaq -0x34(%rbp), %rsi
callq *%rax
movq %rax, -0x30(%rbp)
movl -0x34(%rbp), %eax
addl -0x5c(%rbp), %eax
movl %eax, -0x5c(%rbp)
cmpl $0x0, -0x54(%rbp)
je 0x646e
movl -0x54(%rbp), %eax
cmpl -0x34(%rbp), %eax
je 0x6445
movq -0x30(%rbp), %rdi
callq 0x3030
movl $0x0, -0x54(%rbp)
movl $0x0, -0x5c(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x28(%rbp)
movl -0x14(%rbp), %edi
movl $0x1e, %esi
xorl %edx, %edx
callq 0x30a0
cmpq $0x0, %rax
jge 0x6440
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x6799
jmp 0x64c7
jmp 0x6447
movl -0x14(%rbp), %edi
movq -0x30(%rbp), %rsi
movl -0x34(%rbp), %eax
movl %eax, %edx
callq 0x3060
cmpq $0x0, %rax
jge 0x646a
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x6799
jmp 0x646c
jmp 0x64be
jmp 0x6470
movl -0x14(%rbp), %edi
leaq -0x34(%rbp), %rsi
movl $0x8, %edx
callq 0x3060
cmpq $0x0, %rax
jge 0x6493
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x6799
jmp 0x6495
jmp 0x6497
movl -0x14(%rbp), %edi
movq -0x30(%rbp), %rsi
movl -0x34(%rbp), %eax
movl %eax, %edx
callq 0x3060
cmpq $0x0, %rax
jge 0x64ba
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x6799
jmp 0x64bc
jmp 0x64be
movq -0x30(%rbp), %rdi
callq 0x3030
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x28(%rbp)
jmp 0x63bb
jmp 0x6607
movq -0x10(%rbp), %rax
cmpq $0x0, 0x50(%rax)
je 0x6605
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rax
movq -0x10(%rbp), %rcx
movq (%rcx), %rcx
movq 0x8(%rcx), %rcx
movq (%rcx), %rdi
callq *%rax
movl %eax, -0x54(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq 0x8(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x8(%rcx), %rax
je 0x6603
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rax
movq -0x28(%rbp), %rcx
movq (%rcx), %rdi
callq *%rax
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %eax
addl -0x5c(%rbp), %eax
movl %eax, -0x5c(%rbp)
cmpl $0x0, -0x54(%rbp)
je 0x659d
movl -0x54(%rbp), %eax
cmpl -0x34(%rbp), %eax
je 0x6571
movl $0x0, -0x54(%rbp)
movl $0x0, -0x5c(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x28(%rbp)
jmp 0x65f2
jmp 0x6573
movl -0x14(%rbp), %edi
movq -0x28(%rbp), %rax
movq (%rax), %rsi
movl -0x34(%rbp), %eax
movl %eax, %edx
callq 0x3060
cmpq $0x0, %rax
jge 0x6599
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x6799
jmp 0x659b
jmp 0x65f0
jmp 0x659f
movl -0x14(%rbp), %edi
leaq -0x34(%rbp), %rsi
movl $0x8, %edx
callq 0x3060
cmpq $0x0, %rax
jge 0x65c2
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x6799
jmp 0x65c4
jmp 0x65c6
movl -0x14(%rbp), %edi
movq -0x28(%rbp), %rax
movq (%rax), %rsi
movl -0x34(%rbp), %eax
movl %eax, %edx
callq 0x3060
cmpq $0x0, %rax
jge 0x65ec
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x6799
jmp 0x65ee
jmp 0x65f0
jmp 0x65f2
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x28(%rbp)
jmp 0x6516
jmp 0x6605
jmp 0x6607
movl -0x54(%rbp), %edi
callq 0x30d0
movl %eax, -0x54(%rbp)
movl -0x5c(%rbp), %edi
callq 0x30d0
movl %eax, -0x5c(%rbp)
jmp 0x661f
movl -0x14(%rbp), %edi
leaq -0x70(%rbp), %rsi
addq $0x10, %rsi
movl $0x4, %edx
callq 0x3060
cmpq $0x0, %rax
jge 0x6646
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x6799
jmp 0x6648
movl -0x14(%rbp), %edi
xorl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x30a0
movl -0x14(%rbp), %edi
leaq -0x70(%rbp), %rsi
movl $0x2, %edx
callq 0x3060
cmpq $0x0, %rax
jge 0x6679
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x6799
jmp 0x667b
jmp 0x667d
movl -0x14(%rbp), %edi
leaq -0x70(%rbp), %rsi
addq $0x8, %rsi
movl $0x8, %edx
callq 0x3060
cmpq $0x0, %rax
jge 0x66a4
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x6799
jmp 0x66a6
jmp 0x66a8
movl -0x14(%rbp), %edi
leaq -0x70(%rbp), %rsi
addq $0x10, %rsi
movl $0x4, %edx
callq 0x3060
cmpq $0x0, %rax
jge 0x66cf
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x6799
jmp 0x66d1
jmp 0x66d3
movl -0x14(%rbp), %edi
leaq -0x70(%rbp), %rsi
addq $0x14, %rsi
movl $0x4, %edx
callq 0x3060
cmpq $0x0, %rax
jge 0x66fa
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x6799
jmp 0x66fc
jmp 0x66fe
movl -0x14(%rbp), %edi
leaq -0x70(%rbp), %rsi
addq $0x18, %rsi
movl $0x4, %edx
callq 0x3060
cmpq $0x0, %rax
jge 0x6722
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x6799
jmp 0x6724
jmp 0x6726
movl -0x14(%rbp), %edi
leaq -0x70(%rbp), %rsi
addq $0x1c, %rsi
movl $0x4, %edx
callq 0x3060
cmpq $0x0, %rax
jge 0x674a
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x6799
jmp 0x674c
jmp 0x674e
movl -0x14(%rbp), %edi
leaq -0x70(%rbp), %rsi
addq $0x20, %rsi
movl $0x4, %edx
callq 0x3060
cmpq $0x0, %rax
jge 0x6772
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x6799
jmp 0x6774
cmpq $0x0, -0x20(%rbp)
je 0x6792
movl -0x5c(%rbp), %edi
callq 0x3200
movl %eax, %eax
movl %eax, %ecx
addq $0x28, %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x80, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)