// File: /workspace/github_c_makefile_star2_O1/aerospike[P]aerospike-common/src/main/aerospike/crypt_blowfish.c
// Function: crypt_blowfish_rn
char *_crypt_blowfish_rn(const char *key, const char *setting,
	char *output, int size)
{
	const char *test_key = "8b \xd0\xc1\xd2\xcf\xcc\xd8";
	const char *test_setting = "$2a$00$abcdefghijklmnopqrstuu";
	static const char * const test_hash[2] =
		{"VUrPmXD6q/nVSSp7pNDhCR9071IfIRe\0\x55", /* $2x$ */
		"i1D709vfamulimlGcq0qq3UvuUasvEa\0\x55"}; /* $2a$, $2y$ */
	char *retval;
	const char *p;
	int save_errno, ok;
	struct {
		char s[7 + 22 + 1];
		char o[7 + 22 + 31 + 1 + 1 + 1];
	} buf;

/* Hash the supplied password */
	_crypt_output_magic(setting, output, size);
	retval = BF_crypt(key, setting, output, size, 16);
	save_errno = errno;

/*
 * Do a quick self-test.  It is important that we make both calls to BF_crypt()
 * from the same scope such that they likely use the same stack locations,
 * which makes the second call overwrite the first call's sensitive data on the
 * stack and makes it more likely that any alignment related issues would be
 * detected by the self-test.
 */
	memcpy(buf.s, test_setting, sizeof(buf.s));
	if (retval)
		buf.s[2] = setting[2];
	memset(buf.o, 0x55, sizeof(buf.o));
	buf.o[sizeof(buf.o) - 1] = 0;
	p = BF_crypt(test_key, buf.s, buf.o, sizeof(buf.o) - (1 + 1), 1);

	ok = (p == buf.o &&
	    !memcmp(p, buf.s, 7 + 22) &&
	    !memcmp(p + (7 + 22),
	    test_hash[(unsigned int)(unsigned char)buf.s[2] & 1],
	    31 + 1 + 1 + 1));

	{
		const char *k = "\xff\xa3" "34" "\xff\xff\xff\xa3" "345";
		BF_key ae, ai, ye, yi;
		BF_set_key(k, ae, ai, 2); /* $2a$ */
		BF_set_key(k, ye, yi, 4); /* $2y$ */
		ai[0] ^= 0x10000; /* undo the safety (for comparison) */
		ok = ok && ai[0] == 0xdb9c59bc && ye[17] == 0x33343500 &&
		    !memcmp(ae, ye, sizeof(ae)) &&
		    !memcmp(ai, yi, sizeof(ai));
	}

	__set_errno(save_errno);
	if (ok)
		return retval;

/* Should not happen */
	_crypt_output_magic(setting, output, size);
	__set_errno(EINVAL); /* pretend we don't support this hash type */
	return NULL;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1a8, %rsp            # imm = 0x1A8
movq %rdx, %rbx
movq %rsi, %r14
cmpl $0x3, %ecx
jl 0x113b3
movw $0x302a, (%rbx)         # imm = 0x302A
movb $0x0, 0x2(%rbx)
cmpb $0x2a, (%r14)
jne 0x113b3
cmpb $0x30, 0x1(%r14)
jne 0x113b3
movb $0x31, 0x1(%rbx)
movq %r14, %rsi
movq %rbx, %rdx
movl %ecx, 0x4(%rsp)
movl $0x10, %r8d
callq 0x115da
movq %rax, %r12
callq 0x8150
movq %rax, %r15
movl (%rax), %eax
movl %eax, (%rsp)
movabsq $0x6124303024613224, %rax # imm = 0x6124303024613224
movq %rax, 0x10(%rsp)
movabsq $0x6968676665646362, %rax # imm = 0x6968676665646362
movq %rax, 0x18(%rsp)
movabsq $0x71706f6e6d6c6b6a, %rax # imm = 0x71706F6E6D6C6B6A
movq %rax, 0x20(%rsp)
movabsq $0x75757473727170, %rax # imm = 0x75757473727170
movq %rax, 0x26(%rsp)
testq %r12, %r12
je 0x11421
movb 0x2(%r14), %al
movb %al, 0x12(%rsp)
leaq 0x2e(%rsp), %r13
movabsq $0x5555555555555555, %rax # imm = 0x5555555555555555
movq %rax, 0x37(%r13)
movq %rax, 0x30(%r13)
movq %rax, 0x28(%r13)
movq %rax, 0x20(%r13)
movq %rax, 0x18(%r13)
movq %rax, 0x10(%r13)
movq %rax, 0x8(%r13)
movq %rax, (%r13)
movb $0x0, 0x3e(%r13)
leaq 0x6faf(%rip), %rdi      # 0x1840b
leaq 0x10(%rsp), %rsi
movq %r13, %rdx
movl $0x3d, %ecx
movl $0x1, %r8d
callq 0x115da
cmpq %r13, %rax
movq %r14, 0x8(%rsp)
jne 0x114af
movdqu (%rax), %xmm0
movdqu 0xd(%rax), %xmm1
movdqu 0x10(%rsp), %xmm2
pcmpeqb %xmm0, %xmm2
movdqu 0x1d(%rsp), %xmm0
pcmpeqb %xmm1, %xmm0
pand %xmm2, %xmm0
pmovmskb %xmm0, %ecx
cmpl $0xffff, %ecx           # imm = 0xFFFF
je 0x115a8
xorl %ebp, %ebp
leaq 0x6f7b(%rip), %r13      # 0x18433
leaq 0x160(%rsp), %rsi
leaq 0x110(%rsp), %r14
movq %r13, %rdi
movq %r14, %rdx
movl $0x2, %ecx
callq 0x134ec
leaq 0x70(%rsp), %rsi
leaq 0xc0(%rsp), %rdx
movq %r13, %rdi
movl $0x4, %ecx
callq 0x134ec
movl (%r14), %eax
movl %eax, %ecx
xorl $0x10000, %ecx          # imm = 0x10000
movl %ecx, (%r14)
testb %bpl, %bpl
je 0x11534
cmpl $0xdb9d59bc, %eax       # imm = 0xDB9D59BC
jne 0x11534
cmpl $0x33343500, 0xb4(%rsp) # imm = 0x33343500
jne 0x11534
leaq 0x160(%rsp), %rdi
leaq 0x70(%rsp), %rsi
movl $0x48, %edx
callq 0x8770
testl %eax, %eax
je 0x1157d
movl (%rsp), %eax
movl %eax, (%r15)
movq 0x8(%rsp), %rax
cmpl $0x3, 0x4(%rsp)
jl 0x1155e
movw $0x302a, (%rbx)         # imm = 0x302A
movb $0x0, 0x2(%rbx)
cmpb $0x2a, (%rax)
jne 0x1155e
cmpb $0x30, 0x1(%rax)
jne 0x1155e
movb $0x31, 0x1(%rbx)
movl $0x16, (%r15)
xorl %r12d, %r12d
movq %r12, %rax
addq $0x1a8, %rsp            # imm = 0x1A8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x110(%rsp), %rdi
leaq 0xc0(%rsp), %rsi
movl $0x48, %edx
callq 0x8770
testl %eax, %eax
movl (%rsp), %eax
movl %eax, (%r15)
movq 0x8(%rsp), %rax
jne 0x1153f
jmp 0x11568
addq $0x1d, %rax
movzbl 0x12(%rsp), %ecx
andl $0x1, %ecx
leaq 0x6e85(%rip), %rdx      # 0x18440
movslq (%rdx,%rcx,4), %rsi
addq %rdx, %rsi
movl $0x22, %edx
movq %rax, %rdi
callq 0x8770
testl %eax, %eax
sete %bpl
jmp 0x114b1