// File: /workspace/github_cpp_makefile_star2_O3/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, %r12d
cmpl $0xffcd, %ecx           # imm = 0xFFCD
jb 0x6a8d
leaq 0x1a90(%rip), %rsi      # 0x8501
movl $0xffcc, %edx           # imm = 0xFFCC
xorl %edi, %edi
movl %r12d, %ecx
xorl %eax, %eax
callq 0x273c
movl $0xfffffffb, %r15d      # imm = 0xFFFFFFFB
jmp 0x6bb5
movq %rdx, %rbp
movl %esi, %edx
leal -0x10(%r12), %eax
cmpl %esi, %eax
jle 0x6ab9
leaq 0x1a9c(%rip), %rsi      # 0x853e
xorl %edi, %edi
movl %r12d, %ecx
xorl %eax, %eax
callq 0x273c
movl $0xfffffffa, %r15d      # imm = 0xFFFFFFFA
jmp 0x6bb5
movq %r9, %r15
movq %r8, %r14
movq %rdi, 0x10(%rsp)
movl %edx, 0xc(%rsp)
movslq %r12d, %r13
movq %r13, %rdi
callq 0x2030
movq %rax, %rbx
movq 0x50(%rsp), %rax
movq %rax, (%rsp)
movq %rbx, %rdi
movl %r12d, %esi
movq %rbp, %rdx
movl %r12d, %ecx
movq %r14, %r8
movq %r15, %r9
callq 0x677c
testl %eax, %eax
je 0x6b1a
movl %eax, %r15d
movq %rbx, %rdi
callq 0x2240
leaq 0x1a61(%rip), %rsi      # 0x856d
xorl %edi, %edi
xorl %eax, %eax
callq 0x273c
jmp 0x6bb5
movl %r12d, %eax
cmpb $0x0, -0x1(%rbx,%rax)
jne 0x6b42
jmp 0x6b35
leaq -0x1(%r13), %rax
cmpb $0x0, -0x2(%rbx,%r13)
movq %rax, %r13
jne 0x6b3f
cmpb $0xf, -0x2(%rbx,%rax)
jne 0x6b26
movq %r13, %rax
movl %eax, %r12d
movslq %r12d, %r15
cmpb $0xf, -0x2(%rbx,%r15)
jne 0x6b7d
addq $-0x2, %r15
movl 0xc(%rsp), %edx
cmpl %edx, %r15d
jle 0x6b9d
leaq 0x1a2a(%rip), %rsi      # 0x858b
xorl %edi, %edi
movl %r15d, %ecx
xorl %eax, %eax
callq 0x273c
movq %rbx, %rdi
callq 0x2240
movl $0xfffffff8, %r15d      # imm = 0xFFFFFFF8
jmp 0x6bb5
leaq 0x19f9(%rip), %rsi      # 0x857d
xorl %edi, %edi
xorl %eax, %eax
callq 0x273c
movq %rbx, %rdi
callq 0x2240
movl $0xfffffff9, %r15d      # imm = 0xFFFFFFF9
jmp 0x6bb5
movq 0x10(%rsp), %rdi
movq %rbx, %rsi
movq %r15, %rdx
callq 0x2150
movq %rbx, %rdi
callq 0x2240
movl %r15d, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq