// File: /workspace/github_cpp_makefile_star2_O1/renzibei[P]TSProxy/aes.cpp
// Function: decrypt(char*, int, char const*, int, char const (&) [16], char const (&) [16], char const (&) [16])
int decrypt(char *dst, int dst_size, const char *src, int src_size, const char (&key)[16], const char (&random)[16], const char (&mac)[16]) {
	if (src_size > constants::AES_MAX_DATA_LENGTH) {
		LogHelper::log(Error, "src_size size should be no longer than: %lu, but size is: %d", constants::AES_MAX_DATA_LENGTH, src_size);
		return -5;
	}
	if (dst_size < src_size - 16) {
		LogHelper::log(Error, "dst size too small, dst size: %d, src size: %d", dst_size, src_size);
		return -6;
	}
	char *buf = new char[src_size];
	int deRet = decode(buf, src_size, src, src_size, key, random, mac);
	if (deRet != 0) {
		delete[] buf;
		LogHelper::log(Error, "Fail to decrypt");
		return deRet;
	}
	int real_size = src_size;
	while (buf[real_size - 1] == 0 && buf[real_size - 2] != 0xf) {
		real_size--;
	}
	if (buf[real_size - 2] != 0xf) {
		LogHelper::log(Error, "Padding error");
		delete[] buf;
		return -7;
	}
	real_size -= 2;
	if (dst_size < real_size) {
		LogHelper::log(Error, "dst_size less than real size, dist_size: %d, real_size: %d",dst_size, real_size);
		delete[] buf;
		return -8;
	}
	memcpy(dst, buf, real_size);
	delete[] buf;
	return real_size;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %ecx, %r15d
cmpl $0xffcd, %ecx           # imm = 0xFFCD
jb 0x6ca8
leaq 0x2885(%rip), %rsi      # 0x9511
movl $0xffcc, %edx           # imm = 0xFFCC
xorl %edi, %edi
movl %r15d, %ecx
xorl %eax, %eax
callq 0x273c
movl $0xfffffffb, %r12d      # imm = 0xFFFFFFFB
jmp 0x6dc4
movl %esi, %ebp
leal -0x10(%r15), %eax
cmpl %esi, %eax
jle 0x6cd2
leaq 0x2895(%rip), %rsi      # 0x954e
xorl %edi, %edi
movl %ebp, %edx
movl %r15d, %ecx
xorl %eax, %eax
callq 0x273c
movl $0xfffffffa, %r12d      # imm = 0xFFFFFFFA
jmp 0x6dc4
movq %r9, %r12
movq %r8, %r13
movq %rdx, %r14
movq %rdi, 0x10(%rsp)
movslq %r15d, %rdi
callq 0x2030
movq %rax, %rbx
movq 0x50(%rsp), %rax
movq %rax, (%rsp)
movq %rbx, %rdi
movl %r15d, %esi
movq %r14, %rdx
movl %r15d, %ecx
movq %r13, %r8
movq %r12, %r9
callq 0x6997
testl %eax, %eax
je 0x6d2f
movl %eax, %r12d
movq %rbx, %rdi
callq 0x2240
leaq 0x285c(%rip), %rsi      # 0x957d
xorl %edi, %edi
xorl %eax, %eax
callq 0x273c
jmp 0x6dc4
movl %r15d, %eax
cmpb $0x0, -0x1(%rbx,%rax)
jne 0x6d53
jmp 0x6d49
leaq -0x1(%rax), %r15
cmpb $0x0, -0x2(%rbx,%rax)
movq %r15, %rax
jne 0x6d53
cmpb $0xf, -0x2(%rbx,%rax)
jne 0x6d3b
movq %rax, %r15
movslq %r15d, %r12
cmpb $0xf, -0x2(%rbx,%r12)
jne 0x6d8c
addq $-0x2, %r12
cmpl %ebp, %r12d
jle 0x6dac
leaq 0x282d(%rip), %rsi      # 0x959b
xorl %edi, %edi
movl %ebp, %edx
movl %r12d, %ecx
xorl %eax, %eax
callq 0x273c
movq %rbx, %rdi
callq 0x2240
movl $0xfffffff8, %r12d      # imm = 0xFFFFFFF8
jmp 0x6dc4
leaq 0x27fa(%rip), %rsi      # 0x958d
xorl %edi, %edi
xorl %eax, %eax
callq 0x273c
movq %rbx, %rdi
callq 0x2240
movl $0xfffffff9, %r12d      # imm = 0xFFFFFFF9
jmp 0x6dc4
movq 0x10(%rsp), %rdi
movq %rbx, %rsi
movq %r12, %rdx
callq 0x2150
movq %rbx, %rdi
callq 0x2240
movl %r12d, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq