// File: ethanmick[P]Blowfish482/Profile.cpp
// Function: main
int main( int argc, char* argv[] ){
    Blowfish b;

    if (argc != 2) {
        cout << "usage: Profile <num-iterations>" << endl;
        return 0;
    }

    string str(argv[1]);
    istringstream is(str);
    uint32_t numIter = 0;
    is >> numIter;

    uint8_t* key = new uint8_t[ b.keySize() ];
    
    for( unsigned int i = 0; i < b.keySize(); i++ ){
        key[ i ] = 0x00;
    }
    
    time_t start = time(NULL) * 1000;
    print_uint8_hex(key, b.keySize(), "Key: ");
    b.setKey( key );


    uint8_t* text;// = new uint8_t[ b.blockSize() ];
    for (unsigned int i = 0; i < numIter; i++) {
        text = new uint8_t[ b.blockSize() ];
    
        for( unsigned int i = 0; i < b.blockSize(); i++ ){
            text[ i ] = 0x00;
        }

        b.encrypt( text );
        delete[] text;
    }
    time_t end = time(NULL) * 1000;

    cout << "Running Time: " << (end - start) << " msec" << endl;
    //print_uint8_hex(text, b.blockSize(), "Plaintext");
    //print_uint8_hex(text, b.blockSize(), "Ciphertext");
    
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x12d0, %rsp           # imm = 0x12D0
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
leaq -0x1068(%rbp), %rdi
callq 0x23f0
cmpl $0x2, -0x8(%rbp)
je 0x2f69
movq 0x3096(%rip), %rdi      # 0x5fd8
leaq 0x1104(%rip), %rsi      # 0x404d
callq 0x2120
movq %rax, %rdi
movq 0x3070(%rip), %rsi      # 0x5fc8
callq 0x2130
movl $0x0, -0x4(%rbp)
jmp 0x32e7
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x1268(%rbp)
leaq -0x1089(%rbp), %rdi
movq %rdi, -0x1260(%rbp)
callq 0x2220
movq -0x1268(%rbp), %rsi
movq -0x1260(%rbp), %rdx
leaq -0x1088(%rbp), %rdi
callq 0x3310
jmp 0x2fa7
leaq -0x1089(%rbp), %rdi
callq 0x2150
leaq -0x1220(%rbp), %rdi
leaq -0x1088(%rbp), %rsi
movl $0x8, %edx
callq 0x21e0
jmp 0x2fcd
movl $0x0, -0x1224(%rbp)
leaq -0x1220(%rbp), %rdi
leaq -0x1224(%rbp), %rsi
callq 0x2050
jmp 0x2fec
leaq -0x1068(%rbp), %rdi
callq 0x2440
movl %eax, -0x126c(%rbp)
jmp 0x3000
movl -0x126c(%rbp), %eax
movl %eax, %eax
movl %eax, %edi
callq 0x2030
movq %rax, -0x1278(%rbp)
jmp 0x3018
movq -0x1278(%rbp), %rax
movq %rax, -0x1230(%rbp)
movl $0x0, -0x1234(%rbp)
movl -0x1234(%rbp), %eax
movl %eax, -0x1280(%rbp)
leaq -0x1068(%rbp), %rdi
callq 0x2440
movl %eax, -0x127c(%rbp)
jmp 0x3050
movl -0x1280(%rbp), %eax
movl -0x127c(%rbp), %ecx
cmpl %ecx, %eax
jae 0x30df
movq -0x1230(%rbp), %rax
movl -0x1234(%rbp), %ecx
movb $0x0, (%rax,%rcx)
movl -0x1234(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1234(%rbp)
jmp 0x3030
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1098(%rbp)
movl %eax, -0x109c(%rbp)
leaq -0x1089(%rbp), %rdi
callq 0x2150
jmp 0x32ff
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1098(%rbp)
movl %eax, -0x109c(%rbp)
jmp 0x32f3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1098(%rbp)
movl %eax, -0x109c(%rbp)
leaq -0x1220(%rbp), %rdi
callq 0x20a0
jmp 0x32f3
xorl %eax, %eax
movl %eax, %edi
callq 0x2110
imulq $0x3e8, %rax, %rax      # imm = 0x3E8
movq %rax, -0x1240(%rbp)
movq -0x1230(%rbp), %rax
movq %rax, -0x1290(%rbp)
leaq -0x1068(%rbp), %rdi
callq 0x2440
movl %eax, -0x1284(%rbp)
jmp 0x3118
movl -0x1284(%rbp), %esi
movq -0x1290(%rbp), %rdi
leaq 0xf41(%rip), %rdx       # 0x406d
callq 0x2ea0
jmp 0x3133
movq -0x1230(%rbp), %rsi
leaq -0x1068(%rbp), %rdi
callq 0x2450
jmp 0x3148
movl $0x0, -0x124c(%rbp)
movl -0x124c(%rbp), %eax
cmpl -0x1224(%rbp), %eax
jae 0x3245
leaq -0x1068(%rbp), %rdi
callq 0x2430
movl %eax, -0x1294(%rbp)
jmp 0x3178
movl -0x1294(%rbp), %eax
movl %eax, %eax
movl %eax, %edi
callq 0x2030
movq %rax, -0x12a0(%rbp)
jmp 0x3190
movq -0x12a0(%rbp), %rax
movq %rax, -0x1248(%rbp)
movl $0x0, -0x1250(%rbp)
movl -0x1250(%rbp), %eax
movl %eax, -0x12a8(%rbp)
leaq -0x1068(%rbp), %rdi
callq 0x2430
movl %eax, -0x12a4(%rbp)
jmp 0x31c8
movl -0x12a8(%rbp), %eax
movl -0x12a4(%rbp), %ecx
cmpl %ecx, %eax
jae 0x31fa
movq -0x1248(%rbp), %rax
movl -0x1250(%rbp), %ecx
movb $0x0, (%rax,%rcx)
movl -0x1250(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1250(%rbp)
jmp 0x31a8
movq -0x1248(%rbp), %rsi
leaq -0x1068(%rbp), %rdi
callq 0x2a20
jmp 0x320f
movq -0x1248(%rbp), %rax
movq %rax, -0x12b0(%rbp)
cmpq $0x0, %rax
je 0x322f
movq -0x12b0(%rbp), %rdi
callq 0x2190
jmp 0x3231
movl -0x124c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x124c(%rbp)
jmp 0x3152
xorl %eax, %eax
movl %eax, %edi
callq 0x2110
imulq $0x3e8, %rax, %rax      # imm = 0x3E8
movq %rax, -0x1258(%rbp)
movq 0x2d75(%rip), %rdi      # 0x5fd8
leaq 0xe09(%rip), %rsi       # 0x4073
callq 0x2120
movq %rax, -0x12b8(%rbp)
jmp 0x3278
movq -0x12b8(%rbp), %rdi
movq -0x1258(%rbp), %rsi
movq -0x1240(%rbp), %rax
subq %rax, %rsi
callq 0x2250
movq %rax, -0x12c0(%rbp)
jmp 0x329e
movq -0x12c0(%rbp), %rdi
leaq 0xdd6(%rip), %rsi       # 0x4082
callq 0x2120
movq %rax, -0x12c8(%rbp)
jmp 0x32ba
movq -0x12c8(%rbp), %rdi
movq 0x2d00(%rip), %rsi      # 0x5fc8
callq 0x2130
jmp 0x32cf
leaq -0x1220(%rbp), %rdi
callq 0x20a0
leaq -0x1088(%rbp), %rdi
callq 0x20b0
movl -0x4(%rbp), %eax
addq $0x12d0, %rsp           # imm = 0x12D0
popq %rbp
retq
leaq -0x1088(%rbp), %rdi
callq 0x20b0
movq -0x1098(%rbp), %rdi
callq 0x2210
nopl (%rax,%rax)