// File: tonymuu[P]distributed-kv-store/Application.cpp
// Function: Application::Application(char*)
Application::Application(char *infile) {
	int i;
	par = new Params();
	srand (time(NULL));
	par->setparams(infile);
	log = new Log(par);
	en = new EmulNet(par);
	en1 = new EmulNet(par);
	mp1 = (MP1Node **) malloc(par->EN_GPSZ * sizeof(MP1Node *));
	mp2 = (MP2Node **) malloc(par->EN_GPSZ * sizeof(MP2Node *));
    members = (Member** ) malloc(par->EN_GPSZ * sizeof(Member *));

	/*
	 * Init all nodes
	 */
	for( i = 0; i < par->EN_GPSZ; i++ ) {
		members[i] = new Member;
		members[i]->inited = false;
		Address *addressOfMemberNode = new Address();
		Address joinaddr;
		joinaddr = getjoinaddr();
		addressOfMemberNode = (Address *) en->ENinit(addressOfMemberNode, par->PORTNUM);
		mp1[i] = new MP1Node(members[i], par, en, log, addressOfMemberNode);
		mp2[i] = new MP2Node(members[i], par, en1, log, addressOfMemberNode);
		log->LOG(&(mp1[i]->getMemberNode()->addr), "APP");
		log->LOG(&(mp2[i]->getMemberNode()->addr), "APP MP2");
		delete addressOfMemberNode;
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x58(%rbp)
leaq 0x2e2be(%rip), %rax     # 0x3dce0
movq %rax, (%rdi)
addq $0x60, %rdi
movq %rdi, -0x50(%rbp)
callq 0x14ad0
movl $0x38, %edi
callq 0x4350
movq %rax, -0x48(%rbp)
jmp 0xfa42
movq -0x48(%rbp), %rdi
callq 0x189c0
jmp 0xfa4d
movq -0x58(%rbp), %rax
movq -0x48(%rbp), %rcx
movq %rcx, 0x58(%rax)
xorl %eax, %eax
movl %eax, %edi
callq 0x42f0
movl %eax, %edi
callq 0x4320
movq -0x58(%rbp), %rax
movq 0x58(%rax), %rdi
movq -0x10(%rbp), %rsi
callq 0x189e0
jmp 0xfa7c
movl $0x18, %edi
callq 0x4350
movq %rax, -0x60(%rbp)
jmp 0xfa8c
movq -0x60(%rbp), %rdi
movq -0x58(%rbp), %rax
movq 0x58(%rax), %rsi
callq 0x17a00
jmp 0xfa9f
movq -0x58(%rbp), %rax
movq -0x60(%rbp), %rcx
movq %rcx, 0x38(%rax)
movl $0x1bb8e30, %edi        # imm = 0x1BB8E30
callq 0x4350
movq %rax, -0x68(%rbp)
jmp 0xfabb
movq -0x68(%rbp), %rdi
movq -0x58(%rbp), %rax
movq 0x58(%rax), %rsi
callq 0xeb20
jmp 0xface
movq -0x58(%rbp), %rax
movq -0x68(%rbp), %rcx
movq %rcx, 0x28(%rax)
movl $0x1bb8e30, %edi        # imm = 0x1BB8E30
callq 0x4350
movq %rax, -0x70(%rbp)
jmp 0xfaea
movq -0x70(%rbp), %rdi
movq -0x58(%rbp), %rax
movq 0x58(%rax), %rsi
callq 0xeb20
jmp 0xfafd
movq -0x58(%rbp), %rax
movq -0x70(%rbp), %rcx
movq %rcx, 0x30(%rax)
movq 0x58(%rax), %rax
movslq 0x18(%rax), %rdi
shlq $0x3, %rdi
callq 0x4490
movq %rax, %rcx
movq -0x58(%rbp), %rax
movq %rcx, 0x40(%rax)
movq 0x58(%rax), %rax
movslq 0x18(%rax), %rdi
shlq $0x3, %rdi
callq 0x4490
movq %rax, %rcx
movq -0x58(%rbp), %rax
movq %rcx, 0x48(%rax)
movq 0x58(%rax), %rax
movslq 0x18(%rax), %rdi
shlq $0x3, %rdi
callq 0x4490
movq %rax, %rcx
movq -0x58(%rbp), %rax
movq %rcx, 0x50(%rax)
movl $0x0, -0x14(%rbp)
movq -0x58(%rbp), %rcx
movl -0x14(%rbp), %eax
movq 0x58(%rcx), %rcx
cmpl 0x18(%rcx), %eax
jge 0xfea4
movl $0xe8, %edi
callq 0x4350
movq %rax, -0x78(%rbp)
jmp 0xfb88
movq -0x78(%rbp), %rdi
callq 0x70b0
jmp 0xfb93
movq -0x58(%rbp), %rax
movq -0x78(%rbp), %rsi
movq 0x50(%rax), %rcx
movslq -0x14(%rbp), %rdx
movq %rsi, (%rcx,%rdx,8)
movq 0x50(%rax), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movb $0x0, 0xe(%rax)
movl $0x6, %edi
callq 0x4350
movq %rax, -0x80(%rbp)
jmp 0xfbc7
movq -0x80(%rbp), %rdi
callq 0x71f0
jmp 0xfbd2
movq -0x80(%rbp), %rax
movq %rax, -0x30(%rbp)
leaq -0x36(%rbp), %rdi
callq 0x71f0
jmp 0xfbe5
movq -0x58(%rbp), %rsi
leaq -0x3c(%rbp), %rdi
callq 0xfec0
jmp 0xfbf4
leaq -0x36(%rbp), %rdi
leaq -0x3c(%rbp), %rsi
callq 0x18e70
jmp 0xfc03
movq -0x58(%rbp), %rax
movq -0x30(%rbp), %rsi
movq 0x28(%rax), %rdi
movq 0x58(%rax), %rax
movswl 0x30(%rax), %edx
callq 0xef20
movq %rax, -0x88(%rbp)
jmp 0xfc25
movq -0x88(%rbp), %rax
movq %rax, -0x30(%rbp)
movl $0x40, %edi
callq 0x4350
movq %rax, -0x90(%rbp)
jmp 0xfc43
movq -0x90(%rbp), %rdi
movq -0x58(%rbp), %rax
movq 0x50(%rax), %rcx
movslq -0x14(%rbp), %rdx
movq (%rcx,%rdx,8), %rsi
movq 0x58(%rax), %rdx
movq 0x28(%rax), %rcx
movq 0x38(%rax), %r8
movq -0x30(%rbp), %r9
callq 0x5a30
jmp 0xfc71
movq -0x90(%rbp), %rdx
movq -0x58(%rbp), %rax
movq 0x40(%rax), %rax
movslq -0x14(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movl $0xf0, %edi
callq 0x4350
movq %rax, -0x98(%rbp)
jmp 0xfc9b
movq -0x98(%rbp), %rdi
movq -0x58(%rbp), %rax
movq 0x50(%rax), %rcx
movslq -0x14(%rbp), %rdx
movq (%rcx,%rdx,8), %rsi
movq 0x58(%rax), %rdx
movq 0x30(%rax), %rcx
movq 0x38(%rax), %r8
movq -0x30(%rbp), %r9
callq 0x1dbf0
jmp 0xfcc9
movq -0x58(%rbp), %rax
movq -0x98(%rbp), %rsi
movq 0x48(%rax), %rcx
movslq -0x14(%rbp), %rdx
movq %rsi, (%rcx,%rdx,8)
movq 0x38(%rax), %rcx
movq %rcx, -0xa8(%rbp)
movq 0x40(%rax), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x14af0
movq %rax, -0xa0(%rbp)
jmp 0xfd05
movq -0xa8(%rbp), %rdi
movq -0xa0(%rbp), %rsi
addq $0x8, %rsi
leaq 0x1c5d9(%rip), %rdx     # 0x2c2f7
xorl %eax, %eax
callq 0x17ae0
jmp 0xfd27
movq -0x58(%rbp), %rax
movq 0x38(%rax), %rcx
movq %rcx, -0xb8(%rbp)
movq 0x48(%rax), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x14b10
movq %rax, -0xb0(%rbp)
jmp 0xfd50
movq -0xb8(%rbp), %rdi
movq -0xb0(%rbp), %rsi
addq $0x8, %rsi
leaq 0x1c592(%rip), %rdx     # 0x2c2fb
xorl %eax, %eax
callq 0x17ae0
jmp 0xfd72
movq -0x30(%rbp), %rax
movq %rax, -0xc0(%rbp)
cmpq $0x0, %rax
je 0xfd94
movq -0xc0(%rbp), %rdi
movl $0x6, %esi
callq 0x4360
jmp 0xfd96
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0xfb64
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
jmp 0xfead
movq -0x48(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
movl $0x38, %esi
callq 0x4360
jmp 0xfead
movq -0x60(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
movl $0x18, %esi
callq 0x4360
jmp 0xfead
movq -0x68(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
movl $0x1bb8e30, %esi        # imm = 0x1BB8E30
callq 0x4360
jmp 0xfead
movq -0x70(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
movl $0x1bb8e30, %esi        # imm = 0x1BB8E30
callq 0x4360
jmp 0xfead
movq -0x78(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
movl $0xe8, %esi
callq 0x4360
jmp 0xfead
movq -0x80(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
movl $0x6, %esi
callq 0x4360
jmp 0xfead
movq -0x90(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
movl $0x40, %esi
callq 0x4360
jmp 0xfead
movq -0x98(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
movl $0xf0, %esi
callq 0x4360
jmp 0xfead
addq $0xc0, %rsp
popq %rbp
retq
movq -0x50(%rbp), %rdi
callq 0x14b30
movq -0x20(%rbp), %rdi
callq 0x45b0
nop