// File: /workspace/github_c_makefile_star2_O3/wjmelements[P]evm/src/uint256.c
// Function: divmod512
void divmod512(const uint512_t *l, const uint512_t *r, uint512_t *retDiv, uint512_t *retMod) {
    if (gt512(r, l)) {
        copy512(retMod, l);
        clear512(retDiv);
    } else {
        uint512_t copyd, adder, resDiv, resMod;
        uint512_t one;
        clear512(&one);
        LOWER(LOWER(LOWER(one))) = 1;
        uint32_t diffBits = bits512(l) - bits512(r);
        copy512(&resMod, l);
        shiftl512(r, diffBits, &copyd);
        shiftl512(&one, diffBits, &adder);
        if (gt512(&copyd, &resMod)) {
            shiftr512(&copyd, 1, &copyd);
            shiftr512(&adder, 1, &adder);
        }
        clear512(&resDiv);
        while (gte512(&resMod, r)) {
            if (gte512(&resMod, &copyd)) {
                minus512(&resMod, &copyd, &resMod);
                or512(&resDiv, &adder, &resDiv);
            }
            shiftr512(&copyd, 1, &copyd);
            shiftr512(&adder, 1, &adder);
        }
        copy512(retDiv, &resDiv);
        copy512(retMod, &resMod);
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x158, %rsp            # imm = 0x158
movq %rcx, %rbx
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %r12
movq %rsi, %rdi
movq %r12, %rsi
callq 0x3c41
testb %al, %al
je 0x4ccb
movq (%r12), %rax
movq %rax, (%rbx)
movq 0x8(%r12), %rax
movq %rax, 0x8(%rbx)
movq 0x10(%r12), %rax
movq %rax, 0x10(%rbx)
movq 0x18(%r12), %rax
movq %rax, 0x18(%rbx)
movq 0x20(%r12), %rax
movq %rax, 0x20(%rbx)
movq 0x28(%r12), %rax
movq %rax, 0x28(%rbx)
movq 0x30(%r12), %rax
movq %rax, 0x30(%rbx)
movq 0x38(%r12), %rax
movq %rax, 0x38(%rbx)
xorps %xmm0, %xmm0
movups %xmm0, 0x30(%r14)
movups %xmm0, 0x20(%r14)
movups %xmm0, 0x10(%r14)
movups %xmm0, (%r14)
jmp 0x4f4d
movq %r14, 0x48(%rsp)
xorps %xmm1, %xmm1
leaq 0x110(%rsp), %r13
movaps %xmm1, 0x20(%r13)
movaps %xmm1, 0x10(%r13)
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rsp)
movaps %xmm1, (%r13)
movq $0x0, 0x30(%r13)
movq $0x1, 0x38(%r13)
movq %r12, %rdi
callq 0x3b3f
movl %eax, %ebp
movq %r15, %rdi
callq 0x3b3f
subl %eax, %ebp
movups (%r12), %xmm0
leaq 0x50(%rsp), %r14
movaps %xmm0, (%r14)
movups 0x10(%r12), %xmm0
movaps %xmm0, 0x10(%r14)
movups 0x20(%r12), %xmm0
movaps %xmm0, 0x20(%r14)
movups 0x30(%r12), %xmm0
movaps %xmm0, 0x30(%r14)
leaq 0x90(%rsp), %r12
movq %r15, %rdi
movl %ebp, %esi
movq %r12, %rdx
callq 0x35dc
leaq 0xd0(%rsp), %rdx
movq %r13, %rdi
movl %ebp, %esi
callq 0x35dc
movq %r12, %rdi
movq %r14, %rsi
callq 0x3c41
testb %al, %al
je 0x4da5
leaq 0x90(%rsp), %rdi
movl $0x1, %esi
movq %rdi, %rdx
callq 0x38a2
leaq 0xd0(%rsp), %rdi
movl $0x1, %esi
movq %rdi, %rdx
callq 0x38a2
leaq 0x50(%rsp), %r12
leaq 0x90(%rsp), %r13
leaq 0xd0(%rsp), %rbp
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
movaps %xmm0, 0x10(%rsp)
movaps %xmm0, (%rsp)
movq 0x48(%rsp), %r14
movq %r12, %rdi
movq %r15, %rsi
callq 0x3c41
testb %al, %al
jne 0x4df2
movq %r12, %rdi
movq %r15, %rsi
callq 0x3bb2
testb %al, %al
je 0x4f01
movq %r12, %rdi
movq %r13, %rsi
callq 0x3c41
testb %al, %al
je 0x4e5a
movq %r12, %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0x3e8c
movaps 0x30(%rsp), %xmm0
orps 0xd0(%rsp), %xmm0
movaps %xmm0, 0x30(%rsp)
movaps 0x20(%rsp), %xmm0
orps 0xe0(%rsp), %xmm0
movaps %xmm0, 0x20(%rsp)
movaps 0x10(%rsp), %xmm0
orps 0xf0(%rsp), %xmm0
movaps %xmm0, 0x10(%rsp)
movaps (%rsp), %xmm0
orps 0x100(%rsp), %xmm0
movaps %xmm0, (%rsp)
jmp 0x4edc
movq 0x50(%rsp), %rax
cmpq 0x90(%rsp), %rax
jne 0x4edc
movq 0x58(%rsp), %rax
cmpq 0x98(%rsp), %rax
jne 0x4edc
movq 0x60(%rsp), %rax
cmpq 0xa0(%rsp), %rax
jne 0x4edc
movq 0x68(%rsp), %rax
cmpq 0xa8(%rsp), %rax
jne 0x4edc
movq 0x70(%rsp), %rax
cmpq 0xb0(%rsp), %rax
jne 0x4edc
movq 0x78(%rsp), %rax
cmpq 0xb8(%rsp), %rax
jne 0x4edc
movq 0x80(%rsp), %rax
cmpq 0xc0(%rsp), %rax
jne 0x4edc
movq 0x88(%rsp), %rax
cmpq 0xc8(%rsp), %rax
je 0x4e01
movq %r13, %rdi
movl $0x1, %esi
movq %r13, %rdx
callq 0x38a2
movq %rbp, %rdi
movl $0x1, %esi
movq %rbp, %rdx
callq 0x38a2
jmp 0x4dd0
movaps 0x30(%rsp), %xmm0
movups %xmm0, (%r14)
movaps 0x20(%rsp), %xmm0
movups %xmm0, 0x10(%r14)
movaps 0x10(%rsp), %xmm0
movups %xmm0, 0x20(%r14)
movaps (%rsp), %xmm0
movups %xmm0, 0x30(%r14)
movaps 0x50(%rsp), %xmm0
movups %xmm0, (%rbx)
movaps 0x60(%rsp), %xmm0
movups %xmm0, 0x10(%rbx)
movaps 0x70(%rsp), %xmm0
movups %xmm0, 0x20(%rbx)
movaps 0x80(%rsp), %xmm0
movups %xmm0, 0x30(%rbx)
addq $0x158, %rsp            # imm = 0x158
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq