// File: /workspace/github_c_makefile_star2_O1/wjmelements[P]evm/src/uint256.c
// Function: divmod128
void divmod128(const uint128_t *l, const uint128_t *r, uint128_t *retDiv,
               uint128_t *retMod) {
    uint128_t copyd, adder, resDiv, resMod;
    uint128_t one;
    UPPER(one) = 0;
    LOWER(one) = 1;
    uint32_t diffBits = bits128(l) - bits128(r);
    clear128(&resDiv);
    copy128(&resMod, l);
    if (gt128(r, l)) {
        copy128(retMod, l);
        clear128(retDiv);
    } else {
        shiftl128(r, diffBits, &copyd);
        shiftl128(&one, diffBits, &adder);
        if (gt128(&copyd, &resMod)) {
            shiftr128(&copyd, 1, &copyd);
            shiftr128(&adder, 1, &adder);
        }
        while (gte128(&resMod, r)) {
            if (gte128(&resMod, &copyd)) {
                minus128(&resMod, &copyd, &resMod);
                or128(&resDiv, &adder, &resDiv);
            }
            shiftr128(&copyd, 1, &copyd);
            shiftr128(&adder, 1, &adder);
        }
        copy128(retDiv, &resDiv);
        copy128(retMod, &resMod);
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rcx, %rbx
movq %rsi, %r15
movq (%rdi), %r13
testq %r13, %r13
je 0x49e4
bsrq %r13, %rax
xorl $-0x40, %eax
addl $0x81, %eax
jmp 0x49fb
movq 0x8(%rdi), %rax
testq %rax, %rax
je 0x49f9
bsrq %rax, %rax
xorl $-0x40, %eax
addl $0x41, %eax
jmp 0x49fb
xorl %eax, %eax
movq (%r15), %rbp
testq %rbp, %rbp
je 0x4a11
bsrq %rbp, %r12
xorl $0x3f, %r12d
orl $-0x80, %r12d
jmp 0x4a2a
movq 0x8(%r15), %rcx
testq %rcx, %rcx
je 0x4a27
bsrq %rcx, %r12
notl %r12d
orl $-0x40, %r12d
jmp 0x4a2a
xorl %r12d, %r12d
movq 0x8(%rdi), %r14
cmpq %r13, %rbp
jne 0x4a37
cmpq %r14, 0x8(%r15)
seta %cl
testb %cl, %cl
je 0x4a54
movq %r13, (%rbx)
movq 0x8(%rdi), %rax
movq %rax, 0x8(%rbx)
xorps %xmm0, %xmm0
movups %xmm0, (%rdx)
jmp 0x4b87
movq %rdx, 0x10(%rsp)
addl %eax, %r12d
movq %rsp, %rdx
movq %r15, %rdi
movl %r12d, %esi
callq 0x33ec
cmpl $0x7f, %r12d
jbe 0x4a74
xorl %eax, %eax
jmp 0x4a84
cmpl $0x40, %r12d
je 0x4a88
testl %r12d, %r12d
jne 0x4a8f
movl $0x1, %eax
xorl %edx, %edx
jmp 0x4abc
movl $0x1, %edx
jmp 0x4aba
cmpl $0x3f, %r12d
ja 0x4aaf
movl %r12d, %ecx
negb %cl
movl $0x1, %eax
movl $0x1, %edx
shrq %cl, %rdx
movl %r12d, %ecx
shlq %cl, %rax
jmp 0x4abc
movl $0x1, %edx
movl %r12d, %ecx
shlq %cl, %rdx
xorl %eax, %eax
movq (%rsp), %rcx
xorl %esi, %esi
cmpq %r14, 0x8(%rsp)
seta %sil
xorl %edi, %edi
cmpq %r13, %rcx
seta %dil
cmovel %esi, %edi
cmpb $0x1, %dil
jne 0x4afe
movq %rcx, %rsi
movq 0x8(%rsp), %rdi
shrdq $0x1, %rcx, %rdi
shrq %rsi
movq %rsi, (%rsp)
shrdq $0x1, %rdx, %rax
movq %rdi, 0x8(%rsp)
shrq %rdx
movq (%rsp), %r8
movq 0x8(%rsp), %rsi
xorl %ecx, %ecx
xorl %edi, %edi
cmpq %rbp, %r13
jne 0x4b14
cmpq 0x8(%r15), %r14
seta %r9b
cmpq %rbp, %r13
jne 0x4b2a
testb %r9b, %r9b
jne 0x4b2a
cmpq 0x8(%r15), %r14
sete %r9b
testb %r9b, %r9b
je 0x4b6b
xorl %r9d, %r9d
cmpq %rsi, %r14
setae %r9b
xorl %r10d, %r10d
cmpq %r8, %r13
seta %r10b
cmovel %r9d, %r10d
cmpb $0x1, %r10b
jne 0x4b59
subq %rsi, %r14
sbbq %r8, %r13
orq %rdx, %rcx
orq %rax, %rdi
shrdq $0x1, %r8, %rsi
shrq %r8
shrdq $0x1, %rdx, %rax
shrq %rdx
jmp 0x4b0b
movq %rsi, 0x8(%rsp)
movq %r8, (%rsp)
movq 0x10(%rsp), %rax
movq %rcx, (%rax)
movq %rdi, 0x8(%rax)
movq %r13, (%rbx)
movq %r14, 0x8(%rbx)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq