// File: /workspace/github_c_makefile_star2_O2/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 %rdi, %r12
movq %rdx, %r14
movq %rsi, %r15
movq %rsi, %rdi
movq %rdx, %rsi
movl %ecx, %edx
movl %ecx, %ebx
callq 0x8440
pushq $0x10
popq %r8
movq %r12, %rdi
movq %r15, %rsi
movq %r14, %rdx
movl %ebx, %ecx
movq %r14, 0x8(%rsp)
movl %ebx, 0x4(%rsp)
callq 0xf709
movq %rax, %r12
callq 0x8160
movq %rax, %r13
movl (%rax), %eax
movabsq $0x6124303024613224, %rdx # imm = 0x6124303024613224
movabsq $0x6968676665646362, %rcx # imm = 0x6968676665646362
testq %r12, %r12
movq %rdx, 0x10(%rsp)
movq %rcx, 0x18(%rsp)
movabsq $0x71706f6e6d6c6b6a, %rdx # imm = 0x71706F6E6D6C6B6A
movabsq $0x75757473727170, %rcx # imm = 0x75757473727170
movq %rdx, 0x20(%rsp)
movq %rcx, 0x26(%rsp)
movl %eax, (%rsp)
je 0xf58f
movb 0x2(%r15), %al
movb %al, 0x12(%rsp)
movabsq $0x5555555555555555, %rax # imm = 0x5555555555555555
leaq 0x2e(%rsp), %rbx
leaq 0x5e66(%rip), %rdi      # 0x1540b
leaq 0x10(%rsp), %rsi
movq %rax, 0x36(%rbx)
movq %rax, 0x30(%rbx)
movq %rax, 0x28(%rbx)
movq %rax, 0x20(%rbx)
movq %rax, 0x18(%rbx)
movq %rax, 0x10(%rbx)
movq %rax, 0x8(%rbx)
movq %rax, (%rbx)
movb $0x0, 0x3e(%rbx)
pushq $0x3d
popq %rcx
pushq $0x1
popq %r8
movq %rbx, %rdx
callq 0xf709
cmpq %rbx, %rax
jne 0xf5fc
movq %rax, %rbp
leaq 0x10(%rsp), %rsi
pushq $0x1d
popq %rdx
movq %rax, %rdi
callq 0x8800
testl %eax, %eax
je 0xf6d9
xorl %r14d, %r14d
leaq 0x5e2d(%rip), %rbx      # 0x15433
leaq 0x160(%rsp), %rsi
leaq 0x110(%rsp), %rbp
pushq $0x2
popq %rcx
movq %rbx, %rdi
movq %rbp, %rdx
callq 0x116ce
leaq 0x70(%rsp), %rsi
leaq 0xc0(%rsp), %rdx
pushq $0x4
popq %rcx
movq %rbx, %rdi
callq 0x116ce
movl (%rbp), %eax
movl %eax, %ecx
xorl $0x10000, %ecx          # imm = 0x10000
testb %r14b, %r14b
movl %ecx, (%rbp)
je 0xf67c
cmpl $0xdb9d59bc, %eax       # imm = 0xDB9D59BC
jne 0xf67c
cmpl $0x33343500, 0xb4(%rsp) # imm = 0x33343500
jne 0xf67c
leaq 0x160(%rsp), %rdi
leaq 0x70(%rsp), %rsi
pushq $0x48
popq %rdx
callq 0x8800
testl %eax, %eax
je 0xf6b4
movl (%rsp), %eax
movl %eax, (%r13)
movq 0x8(%rsp), %rsi
movl 0x4(%rsp), %edx
movq %r15, %rdi
callq 0x8440
xorl %r12d, %r12d
movl $0x16, (%r13)
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
pushq $0x48
popq %rdx
callq 0x8800
movl (%rsp), %ecx
testl %eax, %eax
movl %ecx, (%r13)
jne 0xf683
jmp 0xf69f
movzbl 0x12(%rsp), %eax
leaq 0x5d5b(%rip), %rcx      # 0x15440
addq $0x1d, %rbp
andl $0x1, %eax
movslq (%rcx,%rax,4), %rsi
addq %rcx, %rsi
pushq $0x22
popq %rdx
movq %rbp, %rdi
callq 0x8800
testl %eax, %eax
sete %r14b
jmp 0xf5ff