// File: tsoding[P]wcc/src/./wcc_wat_compiler.cpp
// Function: Wat_Compiler::compile_rem(Binary_Op)
S_Expr *Wat_Compiler::compile_rem(Binary_Op rem)
{
    assert(rem.lhs->type == rem.rhs->type && "Type Checking step didn't work correctly.");
    switch (rem.lhs->type) {
    case Type::U0:
        assert(0 && "Type checking did not work correctly. There is no Rem operation defined for Type::U0.");
        break;
    case Type::Bool:
        assert(0 && "Type checking did not work correctly. There is no Rem operation defined for Type::Bool.");
        break;
    case Type::U8:
    case Type::U32:
        return list(atom("i32.rem_u"_sv), compile_expression(rem.lhs), compile_expression(rem.rhs));
    case Type::U64:
        return list(atom("i64.rem_u"_sv), compile_expression(rem.lhs), compile_expression(rem.rhs));
    case Type::Unchecked:
        assert(0 && "Unchecked type in a checked context");
        break;
    }

    assert(0 && "Memory corruption?");
    return nullptr;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rsi, -0x18(%rbp)
movq %rdx, -0x10(%rbp)
movq %rdi, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x18(%rbp), %rax
movl 0x4(%rax), %ecx
movq -0x10(%rbp), %rdx
xorl %eax, %eax
cmpl 0x4(%rdx), %ecx
movb %al, -0x41(%rbp)
jne 0x6f1b
movb $0x1, %al
movb %al, -0x41(%rbp)
jmp 0x6f1b
movb -0x41(%rbp), %al
testb $0x1, %al
jne 0x6f24
jmp 0x6f26
jmp 0x6f45
leaq 0x807c(%rip), %rdi      # 0xefa9
leaq 0x7f84(%rip), %rsi      # 0xeeb8
movl $0x7d, %edx
leaq 0x80b7(%rip), %rcx      # 0xeff7
callq 0x10c0
movq -0x18(%rbp), %rax
movl 0x4(%rax), %eax
movq %rax, -0x58(%rbp)
subq $0x5, %rax
ja 0x709a
movq -0x58(%rbp), %rax
leaq 0x745b(%rip), %rcx      # 0xe3c0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x80af(%rip), %rdi      # 0xf024
leaq 0x7f3c(%rip), %rsi      # 0xeeb8
movl $0x80, %edx
leaq 0x806f(%rip), %rcx      # 0xeff7
callq 0x10c0
leaq 0x80ed(%rip), %rdi      # 0xf081
leaq 0x7f1d(%rip), %rsi      # 0xeeb8
movl $0x83, %edx
leaq 0x8050(%rip), %rcx      # 0xeff7
callq 0x10c0
leaq 0x812d(%rip), %rdi      # 0xf0e0
movl $0x9, %esi
callq 0x12e0
movq -0x50(%rbp), %rdi
movq %rax, -0x30(%rbp)
movq %rdx, -0x28(%rbp)
movq -0x30(%rbp), %rsi
movq -0x28(%rbp), %rdx
callq 0xb5c0
movq -0x50(%rbp), %rdi
movq %rax, -0x68(%rbp)
movq -0x18(%rbp), %rsi
callq 0x70d0
movq -0x50(%rbp), %rdi
movq %rax, -0x60(%rbp)
movq -0x10(%rbp), %rsi
callq 0x70d0
movq -0x50(%rbp), %rdi
movq -0x68(%rbp), %rsi
movq -0x60(%rbp), %rdx
movq %rax, %rcx
callq 0xb6d0
movq %rax, -0x8(%rbp)
jmp 0x70b9
leaq 0x80ce(%rip), %rdi      # 0xf0ea
movl $0x9, %esi
callq 0x12e0
movq -0x50(%rbp), %rdi
movq %rax, -0x40(%rbp)
movq %rdx, -0x38(%rbp)
movq -0x40(%rbp), %rsi
movq -0x38(%rbp), %rdx
callq 0xb5c0
movq -0x50(%rbp), %rdi
movq %rax, -0x78(%rbp)
movq -0x18(%rbp), %rsi
callq 0x70d0
movq -0x50(%rbp), %rdi
movq %rax, -0x70(%rbp)
movq -0x10(%rbp), %rsi
callq 0x70d0
movq -0x50(%rbp), %rdi
movq -0x78(%rbp), %rsi
movq -0x70(%rbp), %rdx
movq %rax, %rcx
callq 0xb6d0
movq %rax, -0x8(%rbp)
jmp 0x70b9
leaq 0x8072(%rip), %rdi      # 0xf0f4
leaq 0x7e2f(%rip), %rsi      # 0xeeb8
movl $0x8b, %edx
leaq 0x7f62(%rip), %rcx      # 0xeff7
callq 0x10c0
leaq 0x807e(%rip), %rdi      # 0xf11f
leaq 0x7e10(%rip), %rsi      # 0xeeb8
movl $0x8f, %edx
leaq 0x7f43(%rip), %rcx      # 0xeff7
callq 0x10c0
movq -0x8(%rbp), %rax
addq $0x80, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)