// File: Computer-Kids-Club[P]screenshare-pro-backend/sha1.c
// Function: SHA1PadMessage(SHA1Context*)
void SHA1PadMessage(SHA1Context *context)
{
    /*
     *  Check to see if the current message block is too small to hold
     *  the initial padding bits and length.  If so, we will pad the
     *  block, process it, and then continue padding into a second
     *  block.
     */
    if (context->Message_Block_Index > 55)
    {
        context->Message_Block[context->Message_Block_Index++] = 0x80;
        while(context->Message_Block_Index < 64)
        {
            context->Message_Block[context->Message_Block_Index++] = 0;
        }

        SHA1ProcessMessageBlock(context);

        while(context->Message_Block_Index < 56)
        {
            context->Message_Block[context->Message_Block_Index++] = 0;
        }
    }
    else
    {
        context->Message_Block[context->Message_Block_Index++] = 0x80;
        while(context->Message_Block_Index < 56)
        {
            context->Message_Block[context->Message_Block_Index++] = 0;
        }
    }

    /*
     *  Store the message length as the last 8 octets
     */
    context->Message_Block[56] = (context->Length_High >> 24) & 0xFF;
    context->Message_Block[57] = (context->Length_High >> 16) & 0xFF;
    context->Message_Block[58] = (context->Length_High >> 8) & 0xFF;
    context->Message_Block[59] = (context->Length_High) & 0xFF;
    context->Message_Block[60] = (context->Length_Low >> 24) & 0xFF;
    context->Message_Block[61] = (context->Length_Low >> 16) & 0xFF;
    context->Message_Block[62] = (context->Length_Low >> 8) & 0xFF;
    context->Message_Block[63] = (context->Length_Low) & 0xFF;

    SHA1ProcessMessageBlock(context);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x10, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
cmpl $0x37, 0x5c(%rax)
jle 0xfaba
movq -0x8(%rbp), %rax
movq -0x8(%rbp), %rdx
movl 0x5c(%rdx), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, 0x5c(%rdx)
movslq %ecx, %rcx
movb $-0x80, 0x1c(%rax,%rcx)
movq -0x8(%rbp), %rax
cmpl $0x40, 0x5c(%rax)
jge 0xfa88
movq -0x8(%rbp), %rax
movq -0x8(%rbp), %rdx
movl 0x5c(%rdx), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, 0x5c(%rdx)
movslq %ecx, %rcx
movb $0x0, 0x1c(%rax,%rcx)
jmp 0xfa61
movq -0x8(%rbp), %rdi
callq 0xfcf0
movq -0x8(%rbp), %rax
cmpl $0x38, 0x5c(%rax)
jge 0xfab8
movq -0x8(%rbp), %rax
movq -0x8(%rbp), %rdx
movl 0x5c(%rdx), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, 0x5c(%rdx)
movslq %ecx, %rcx
movb $0x0, 0x1c(%rax,%rcx)
jmp 0xfa91
jmp 0xfafe
movq -0x8(%rbp), %rax
movq -0x8(%rbp), %rdx
movl 0x5c(%rdx), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, 0x5c(%rdx)
movslq %ecx, %rcx
movb $-0x80, 0x1c(%rax,%rcx)
movq -0x8(%rbp), %rax
cmpl $0x38, 0x5c(%rax)
jge 0xfafc
movq -0x8(%rbp), %rax
movq -0x8(%rbp), %rdx
movl 0x5c(%rdx), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, 0x5c(%rdx)
movslq %ecx, %rcx
movb $0x0, 0x1c(%rax,%rcx)
jmp 0xfad5
jmp 0xfafe
movq -0x8(%rbp), %rax
movl 0x18(%rax), %eax
shrl $0x18, %eax
andl $0xff, %eax
movb %al, %cl
movq -0x8(%rbp), %rax
movb %cl, 0x54(%rax)
movq -0x8(%rbp), %rax
movl 0x18(%rax), %eax
shrl $0x10, %eax
andl $0xff, %eax
movb %al, %cl
movq -0x8(%rbp), %rax
movb %cl, 0x55(%rax)
movq -0x8(%rbp), %rax
movl 0x18(%rax), %eax
shrl $0x8, %eax
andl $0xff, %eax
movb %al, %cl
movq -0x8(%rbp), %rax
movb %cl, 0x56(%rax)
movq -0x8(%rbp), %rax
movl 0x18(%rax), %eax
andl $0xff, %eax
movb %al, %cl
movq -0x8(%rbp), %rax
movb %cl, 0x57(%rax)
movq -0x8(%rbp), %rax
movl 0x14(%rax), %eax
shrl $0x18, %eax
andl $0xff, %eax
movb %al, %cl
movq -0x8(%rbp), %rax
movb %cl, 0x58(%rax)
movq -0x8(%rbp), %rax
movl 0x14(%rax), %eax
shrl $0x10, %eax
andl $0xff, %eax
movb %al, %cl
movq -0x8(%rbp), %rax
movb %cl, 0x59(%rax)
movq -0x8(%rbp), %rax
movl 0x14(%rax), %eax
shrl $0x8, %eax
andl $0xff, %eax
movb %al, %cl
movq -0x8(%rbp), %rax
movb %cl, 0x5a(%rax)
movq -0x8(%rbp), %rax
movl 0x14(%rax), %eax
andl $0xff, %eax
movb %al, %cl
movq -0x8(%rbp), %rax
movb %cl, 0x5b(%rax)
movq -0x8(%rbp), %rdi
callq 0xfcf0
addq $0x10, %rsp
popq %rbp
retq
nopw (%rax,%rax)