// File: /workspace/github_c_makefile_star2_O1/zecoxao[P]ps3_decrypt_tools/lib/aes_omac.c
// Function: aes_omac1
void aes_omac1(u8 *digest, u8 *input, u32 length, u8 *key, u32 keybits) {
    u32 i, j;
    u32 overflow;
    aes_context ctxt;
    unsigned char buffer1[16], buffer2[16], dbuf[16];

    memset(buffer1, 0, 16);

    aes_setkey_enc(&ctxt, key, keybits);

    aes_crypt_ecb(&ctxt, AES_ENCRYPT, buffer1, buffer2);
    _gf_mul(buffer2);

    if (length > 16) {
        for (i = 0; i < length - 16; i += 16) {
            for (j = 0; j < 16; j++)
                dbuf[j] = buffer1[j] ^ input[i + j];
            aes_crypt_ecb(&ctxt, AES_ENCRYPT, dbuf, buffer1);
        }
    }

    overflow = length & 0xf;
    if (length % 16 == 0)
        overflow = 16;

    memset(dbuf, 0, 16);
    memcpy(dbuf, &(input[i]), overflow);

    if (overflow != 16) {
        dbuf[overflow] = 0x80;
        _gf_mul(buffer2);
    }

    for (i = 0; i < 16; i++)
        dbuf[i] ^= buffer1[i] ^ buffer2[i];

    aes_crypt_ecb(&ctxt, AES_ENCRYPT, dbuf, digest);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x288, %rsp            # imm = 0x288
movl %edx, %ebp
movq %rsi, 0x38(%rsp)
movq %rdi, %r14
xorps %xmm0, %xmm0
leaq 0x40(%rsp), %r15
movaps %xmm0, (%r15)
leaq 0x58(%rsp), %r12
movq %r12, %rdi
movq %rcx, %rsi
movl %r8d, %edx
callq 0x125c
movq %rsp, %r13
movq %r12, %rdi
movl $0x1, %esi
movq %r15, %rdx
movq %r13, %rcx
callq 0x16d7
movl $0x1, %ecx
movb (%r13), %al
movb -0x1(%rsp,%rcx), %dl
movb (%rsp,%rcx), %sil
shrb $0x7, %sil
addb %dl, %dl
orb %sil, %dl
movb %dl, -0x1(%rsp,%rcx)
incq %rcx
cmpq $0x10, %rcx
jne 0x50a6
sarb $0x7, %al
andb $-0x79, %al
movb 0xf(%rsp), %cl
addb %cl, %cl
xorb %al, %cl
movb %cl, 0xf(%rsp)
cmpl $0x11, %ebp
jb 0x5148
movl %ebp, %eax
addl $-0x10, %eax
je 0x5148
movl %ebp, 0x1c(%rsp)
movq %r14, 0x50(%rsp)
movl %eax, %r14d
xorl %ebx, %ebx
leaq 0x58(%rsp), %r15
leaq 0x20(%rsp), %r12
leaq 0x40(%rsp), %r13
movq 0x38(%rsp), %rbp
xorl %eax, %eax
movb (%rbp,%rax), %cl
xorb 0x40(%rsp,%rax), %cl
movb %cl, 0x20(%rsp,%rax)
incq %rax
cmpq $0x10, %rax
jne 0x5105
movq %r15, %rdi
movl $0x1, %esi
movq %r12, %rdx
movq %r13, %rcx
callq 0x16d7
addq $0x10, %rbx
addq $0x10, %rbp
cmpq %r14, %rbx
jb 0x5103
andl $-0x10, %ebx
movq 0x50(%rsp), %r14
movl 0x1c(%rsp), %ebp
jmp 0x514a
xorl %ebx, %ebx
andl $0xf, %ebp
movl $0x10, %r15d
cmovnel %ebp, %r15d
movl $0x10, %eax
subq %r15, %rax
xorl %edx, %edx
testl %ebp, %ebp
cmovneq %rax, %rdx
movq 0x38(%rsp), %r12
addq %rbx, %r12
leaq (%rsp,%r15), %rdi
addq $0x20, %rdi
xorl %esi, %esi
callq 0x10a0
leaq 0x20(%rsp), %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x10f0
testl %ebp, %ebp
je 0x51cf
movb $-0x80, 0x20(%rsp,%r15)
movl $0x1, %ecx
movb (%rsp), %al
movb -0x1(%rsp,%rcx), %dl
movb (%rsp,%rcx), %sil
shrb $0x7, %sil
addb %dl, %dl
orb %sil, %dl
movb %dl, -0x1(%rsp,%rcx)
incq %rcx
cmpq $0x10, %rcx
jne 0x51a0
sarb $0x7, %al
andb $-0x79, %al
movb 0xf(%rsp), %cl
addb %cl, %cl
xorb %al, %cl
movb %cl, 0xf(%rsp)
xorl %eax, %eax
movb (%rsp,%rax), %cl
xorb 0x40(%rsp,%rax), %cl
xorb %cl, 0x20(%rsp,%rax)
incq %rax
cmpq $0x10, %rax
jne 0x51d1
leaq 0x58(%rsp), %rdi
leaq 0x20(%rsp), %rdx
movl $0x1, %esi
movq %r14, %rcx
callq 0x16d7
addq $0x288, %rsp            # imm = 0x288
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop