// File: /workspace/github_cpp_makefile_star2_O1/ethanmick[P]Blowfish482/Blowfish.cpp
// Function: Blowfish::setKey(unsigned char*)
void Blowfish::setKey(uint8_t* key){
    
    for (int i = 0; i < 18; i++) {
        pArray[i] = computeHexPi();
    }
    
    for (int i=0; i < 256; i++) {
    	s1[i] = computeHexPi();
    }
    
    for (int i=0; i < 256; i++) {
    	s2[i] = computeHexPi();
    }
    
    for (int i=0; i < 256; i++) {
    	s3[i] = computeHexPi();
    }
   
    for (int i=0; i < 256; i++) {
    	s4[i] = computeHexPi();
    }

    uint32_t key_size = keySize();
   
    uint32_t subkeyCounter = 0; 
    for (int pI=0; pI < 18; pI++) {
        
        uint32_t subkey = 0; 

        for (int i=0; i < 4; i++, subkeyCounter++) {
            if (subkeyCounter >= key_size) {
                subkeyCounter = 0;
            }
    	    subkey <<= 8;
            subkey |= (uint32_t)key[subkeyCounter];
        }

    	pArray[pI] ^= subkey;
    } 
        
    uint8_t* zeros = new uint8_t[ 8 ];
    for( int i = 0; i < 8; i++ ){
        zeros[ i ] = 0;
    }
        
    for (int i=0; i < 18; i += 2) {
        encrypt(zeros);
        pArray[i] = pack32BitWord(zeros, 0);
        pArray[i+1] = pack32BitWord(zeros, 4);
    }

    for (int i=0; i < 256; i += 2) {
        encrypt(zeros);
        s1[i] = pack32BitWord(zeros, 0);
        s1[i+1] = pack32BitWord(zeros, 4);
    } 

    for (int i=0; i < 256; i += 2) {
        encrypt(zeros);
        s2[i] = pack32BitWord(zeros, 0);
        s2[i+1] = pack32BitWord(zeros, 4);
    } 

    for (int i=0; i < 256; i += 2) {
        encrypt(zeros);
        s3[i] = pack32BitWord(zeros, 0);
        s3[i+1] = pack32BitWord(zeros, 4);
    } 

    for (int i=0; i < 256; i += 2) {
        encrypt(zeros);
        s4[i] = pack32BitWord(zeros, 0);
        s4[i+1] = pack32BitWord(zeros, 4);
    } 

}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
movq %rsi, %r14
movq %rdi, %rbx
movl $0x403, %r15d           # imm = 0x403
movq %rbx, %rdi
callq 0x2620
movl %eax, (%rbx,%r15,4)
incq %r15
cmpq $0x415, %r15            # imm = 0x415
jne 0x234b
movl $0x3, %r15d
movq %rbx, %rdi
callq 0x2620
movl %eax, (%rbx,%r15,4)
incq %r15
cmpq $0x103, %r15            # imm = 0x103
jne 0x2369
movl $0x103, %r15d           # imm = 0x103
movq %rbx, %rdi
callq 0x2620
movl %eax, (%rbx,%r15,4)
incq %r15
cmpq $0x203, %r15            # imm = 0x203
jne 0x2387
movl $0x203, %r15d           # imm = 0x203
movq %rbx, %rdi
callq 0x2620
movl %eax, (%rbx,%r15,4)
incq %r15
cmpq $0x303, %r15            # imm = 0x303
jne 0x23a5
movl $0x303, %r15d           # imm = 0x303
movq %rbx, %rdi
callq 0x2620
movl %eax, (%rbx,%r15,4)
incq %r15
cmpq $0x403, %r15            # imm = 0x403
jne 0x23c3
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x8(%rax)
xorl %ecx, %ecx
xorl %edx, %edx
xorl %esi, %esi
movl $0x4, %edi
xorl %r8d, %r8d
cmpl %eax, %esi
cmovael %ecx, %esi
movl %r8d, %r9d
shll $0x8, %r9d
movzbl (%r14,%rsi), %r8d
orl %r9d, %r8d
incl %esi
decl %edi
jne 0x23f2
xorl %r8d, 0x100c(%rbx,%rdx,4)
incq %rdx
cmpq $0x12, %rdx
jne 0x23ea
movl $0x8, %edi
callq 0x2030
movq %rax, %r14
movq $0x0, (%rax)
xorl %r15d, %r15d
movq (%rbx), %rax
movq %rbx, %rdi
movq %r14, %rsi
callq *0x18(%rax)
xorl %eax, %eax
xorl %ecx, %ecx
movl %ecx, %edx
shll $0x8, %edx
movzbl (%r14,%rax), %ecx
orl %edx, %ecx
incq %rax
cmpq $0x4, %rax
jne 0x2444
movl %ecx, 0x100c(%rbx,%r15,4)
xorl %eax, %eax
movl $0x4, %ecx
movl %eax, %edx
shll $0x8, %edx
movzbl (%r14,%rcx), %eax
orl %edx, %eax
incq %rcx
cmpq $0x8, %rcx
jne 0x2468
movl %eax, 0x1010(%rbx,%r15,4)
leaq 0x2(%r15), %rax
cmpq $0x10, %r15
movq %rax, %r15
jb 0x2434
xorl %r15d, %r15d
movq (%rbx), %rax
movq %rbx, %rdi
movq %r14, %rsi
callq *0x18(%rax)
xorl %eax, %eax
xorl %ecx, %ecx
movl %ecx, %edx
shll $0x8, %edx
movzbl (%r14,%rax), %ecx
orl %edx, %ecx
incq %rax
cmpq $0x4, %rax
jne 0x24a5
movl %ecx, 0xc(%rbx,%r15,4)
xorl %eax, %eax
movl $0x4, %ecx
movl %eax, %edx
shll $0x8, %edx
movzbl (%r14,%rcx), %eax
orl %edx, %eax
incq %rcx
cmpq $0x8, %rcx
jne 0x24c6
movl %eax, 0x10(%rbx,%r15,4)
leaq 0x2(%r15), %rax
cmpq $0xfe, %r15
movq %rax, %r15
jb 0x2495
xorl %r15d, %r15d
movq (%rbx), %rax
movq %rbx, %rdi
movq %r14, %rsi
callq *0x18(%rax)
xorl %eax, %eax
xorl %ecx, %ecx
movl %ecx, %edx
shll $0x8, %edx
movzbl (%r14,%rax), %ecx
orl %edx, %ecx
incq %rax
cmpq $0x4, %rax
jne 0x2503
movl %ecx, 0x40c(%rbx,%r15,4)
xorl %eax, %eax
movl $0x4, %ecx
movl %eax, %edx
shll $0x8, %edx
movzbl (%r14,%rcx), %eax
orl %edx, %eax
incq %rcx
cmpq $0x8, %rcx
jne 0x2527
movl %eax, 0x410(%rbx,%r15,4)
leaq 0x2(%r15), %rax
cmpq $0xfe, %r15
movq %rax, %r15
jb 0x24f3
xorl %r15d, %r15d
movq (%rbx), %rax
movq %rbx, %rdi
movq %r14, %rsi
callq *0x18(%rax)
xorl %eax, %eax
xorl %ecx, %ecx
movl %ecx, %edx
shll $0x8, %edx
movzbl (%r14,%rax), %ecx
orl %edx, %ecx
incq %rax
cmpq $0x4, %rax
jne 0x2567
movl %ecx, 0x80c(%rbx,%r15,4)
xorl %eax, %eax
movl $0x4, %ecx
movl %eax, %edx
shll $0x8, %edx
movzbl (%r14,%rcx), %eax
orl %edx, %eax
incq %rcx
cmpq $0x8, %rcx
jne 0x258b
movl %eax, 0x810(%rbx,%r15,4)
leaq 0x2(%r15), %rax
cmpq $0xfe, %r15
movq %rax, %r15
jb 0x2557
xorl %r15d, %r15d
movq (%rbx), %rax
movq %rbx, %rdi
movq %r14, %rsi
callq *0x18(%rax)
xorl %eax, %eax
xorl %ecx, %ecx
movl %ecx, %edx
shll $0x8, %edx
movzbl (%r14,%rax), %ecx
orl %edx, %ecx
incq %rax
cmpq $0x4, %rax
jne 0x25cb
movl %ecx, 0xc0c(%rbx,%r15,4)
xorl %eax, %eax
xorl %ecx, %ecx
movl %ecx, %edx
shll $0x8, %edx
movzbl 0x4(%r14,%rax), %ecx
orl %edx, %ecx
incq %rax
cmpq $0x4, %rax
jne 0x25ec
movl %ecx, 0xc10(%rbx,%r15,4)
leaq 0x2(%r15), %rax
cmpq $0xfe, %r15
movq %rax, %r15
jb 0x25bb
popq %rbx
popq %r14
popq %r15
retq