// File: Juve45[P]batstat/main.cpp
// Function: init()
void init()
{

	load_config();

	if(checkdir(Path + "BAT0")) {
		Path += "BAT0/";
	} else {
		Path += "BAT1/";
	}

	// Case 1: battery info is stored in charge + current. If voltage is present, 
	// then we are able to compute watts, otherwise print in amps
	chargePath = Path + "charge";
	currentPath = Path + "current";
	voltagePath = Path + "voltage";

	// Case 2: battery info provides energy and power. Always print in watts
	energyPath = Path + "energy";
	powerPath = Path + "power";

	if(checkfile(powerPath + "_now") /*or 
		(checkdir(voltagePath + "_now") and checkdir(currentPath + "_now"))*/) 
		// currently disabled voltage readings due to bug
		powerUnit = 'W';
	else
		powerUnit = 'A';

	if ( (mainwin = initscr()) == NULL ) {
		fprintf(stderr, "Error initializing ncurses.\n");
		exit(EXIT_FAILURE);
	}
	keypad(stdscr, TRUE);
	
	if(has_colors() == FALSE) {
		printf("Your terminal does not support color\n");
	}
	start_color();

	assume_default_colors(COLOR_WHITE,COLOR_BLACK);

	init_pair(1, COLOR_WHITE, COLOR_BLACK);
	init_pair(2, COLOR_RED, COLOR_BLACK);
	init_pair(3, COLOR_GREEN, COLOR_BLACK);

	bkgd(COLOR_PAIR(1));

	initTime = time(NULL);

	auto batInit = getBatteryInfo();
	initEnergy = batInit.energy;
	
	ifstream maxEnergyFile(energyPath + "_full");
	if(!checkfile(energyPath + "_full"))
		maxEnergyFile.open(chargePath + "_full");

	maxEnergyFile >> maxEnergy;

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x3e0, %rsp            # imm = 0x3E0
callq 0x4ea0
leaq 0x371a1(%rip), %rsi     # 0x3c408
leaq 0x22971(%rip), %rdx     # 0x27bdf
leaq -0x20(%rbp), %rdi
movq %rdi, -0x370(%rbp)
callq 0x61e0
movq -0x370(%rbp), %rdi
callq 0x4b50
movb %al, -0x361(%rbp)
jmp 0x5292
leaq -0x20(%rbp), %rdi
callq 0x46a8
movb -0x361(%rbp), %al
testb $0x1, %al
jne 0x52a7
jmp 0x52d6
leaq 0x3715a(%rip), %rdi     # 0x3c408
leaq 0x2292f(%rip), %rsi     # 0x27be4
callq 0x4390
jmp 0x52e9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
leaq -0x20(%rbp), %rdi
callq 0x46a8
jmp 0x5735
leaq 0x3712b(%rip), %rdi     # 0x3c408
leaq 0x22906(%rip), %rsi     # 0x27bea
callq 0x4390
leaq 0x37118(%rip), %rsi     # 0x3c408
movq %rsi, -0x398(%rbp)
leaq 0x228f2(%rip), %rdx     # 0x27bf0
leaq -0x50(%rbp), %rdi
movq %rdi, -0x3b8(%rbp)
callq 0x61e0
movq -0x3b8(%rbp), %rsi
leaq 0x3716c(%rip), %rdi     # 0x3c488
callq 0x4460
movq -0x3b8(%rbp), %rdi
callq 0x46a8
movq -0x398(%rbp), %rsi
leaq 0x228bc(%rip), %rdx     # 0x27bf7
leaq -0x70(%rbp), %rdi
movq %rdi, -0x3b0(%rbp)
callq 0x61e0
movq -0x3b0(%rbp), %rsi
leaq 0x3716f(%rip), %rdi     # 0x3c4c8
callq 0x4460
movq -0x3b0(%rbp), %rdi
callq 0x46a8
movq -0x398(%rbp), %rsi
leaq 0x22887(%rip), %rdx     # 0x27bff
leaq -0x90(%rbp), %rdi
movq %rdi, -0x3a8(%rbp)
callq 0x61e0
movq -0x3a8(%rbp), %rsi
leaq 0x3710f(%rip), %rdi     # 0x3c4a8
callq 0x4460
movq -0x3a8(%rbp), %rdi
callq 0x46a8
movq -0x398(%rbp), %rsi
leaq 0x2284f(%rip), %rdx     # 0x27c07
leaq -0xb0(%rbp), %rdi
movq %rdi, -0x3a0(%rbp)
callq 0x61e0
movq -0x3a0(%rbp), %rsi
leaq 0x3706f(%rip), %rdi     # 0x3c448
callq 0x4460
movq -0x3a0(%rbp), %rdi
callq 0x46a8
movq -0x398(%rbp), %rsi
leaq 0x22816(%rip), %rdx     # 0x27c0e
leaq -0xd0(%rbp), %rdi
movq %rdi, -0x390(%rbp)
callq 0x61e0
movq -0x390(%rbp), %rsi
leaq 0x3704f(%rip), %rdi     # 0x3c468
movq %rdi, -0x388(%rbp)
callq 0x4460
movq -0x390(%rbp), %rdi
callq 0x46a8
movq -0x388(%rbp), %rsi
leaq 0x22773(%rip), %rdx     # 0x27bb2
leaq -0xf0(%rbp), %rdi
movq %rdi, -0x380(%rbp)
callq 0x61e0
movq -0x380(%rbp), %rdi
callq 0x6190
movb %al, -0x371(%rbp)
jmp 0x5466
leaq -0xf0(%rbp), %rdi
callq 0x46a8
movb -0x371(%rbp), %al
testb $0x1, %al
jne 0x547e
jmp 0x54a4
movb $0x57, 0x37063(%rip)    # 0x3c4e8
jmp 0x54ab
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
leaq -0xf0(%rbp), %rdi
callq 0x46a8
jmp 0x5735
movb $0x41, 0x3703d(%rip)    # 0x3c4e8
callq 0x4510
movq %rax, 0x37039(%rip)     # 0x3c4f0
cmpq $0x0, %rax
jne 0x54df
movq 0x36b14(%rip), %rax     # 0x3bfd8
movq (%rax), %rdi
leaq 0x22746(%rip), %rsi     # 0x27c14
movb $0x0, %al
callq 0x44f0
movl $0x1, %edi
callq 0x4450
movq 0x36ada(%rip), %rax     # 0x3bfc0
movq (%rax), %rdi
movl $0x1, %esi
callq 0x4150
callq 0x4540
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x5510
leaq 0x22728(%rip), %rdi     # 0x27c31
movb $0x0, %al
callq 0x4060
callq 0x40e0
movl $0x7, %edi
movl %edi, -0x3d0(%rbp)
xorl %esi, %esi
movl %esi, -0x3c4(%rbp)
callq 0x41c0
movl -0x3d0(%rbp), %esi
movl -0x3c4(%rbp), %edx
movl $0x1, %edi
movl %edi, -0x3cc(%rbp)
callq 0x4090
movl -0x3cc(%rbp), %esi
movl -0x3c4(%rbp), %edx
movl $0x2, %edi
movl %edi, -0x3c8(%rbp)
callq 0x4090
movl -0x3c8(%rbp), %esi
movl -0x3c4(%rbp), %edx
movl $0x3, %edi
callq 0x4090
movq 0x36a3e(%rip), %rax     # 0x3bfc0
movq (%rax), %rdi
movl $0x100, %esi            # imm = 0x100
callq 0x45d0
movl -0x3c4(%rbp), %eax
movl %eax, %edi
callq 0x4370
movl %eax, 0x36e4e(%rip)     # 0x3c3f0
callq 0x4ba0
movlpd %xmm0, -0xf8(%rbp)
movss -0xf4(%rbp), %xmm0
movss %xmm0, 0x36e2d(%rip)    # 0x3c3ec
leaq 0x36e82(%rip), %rsi     # 0x3c448
leaq 0x2268a(%rip), %rdx     # 0x27c57
leaq -0x320(%rbp), %rdi
movq %rdi, -0x3c0(%rbp)
callq 0x61e0
movq -0x3c0(%rbp), %rsi
leaq -0x300(%rbp), %rdi
movl $0x8, %edx
callq 0x4580
jmp 0x55fa
leaq -0x320(%rbp), %rdi
callq 0x46a8
leaq 0x36e3b(%rip), %rsi     # 0x3c448
leaq 0x22643(%rip), %rdx     # 0x27c57
leaq -0x340(%rbp), %rdi
callq 0x61e0
jmp 0x5622
leaq -0x340(%rbp), %rdi
callq 0x6190
movb %al, -0x3d1(%rbp)
jmp 0x5636
movb -0x3d1(%rbp), %al
xorb $-0x1, %al
movb %al, -0x3d2(%rbp)
leaq -0x340(%rbp), %rdi
callq 0x46a8
movb -0x3d2(%rbp), %al
testb $0x1, %al
jne 0x565f
jmp 0x56ff
leaq 0x36e22(%rip), %rsi     # 0x3c488
leaq 0x225ea(%rip), %rdx     # 0x27c57
leaq -0x360(%rbp), %rdi
callq 0x61e0
jmp 0x567b
leaq -0x300(%rbp), %rdi
leaq -0x360(%rbp), %rsi
movl $0x8, %edx
callq 0x4320
jmp 0x5695
leaq -0x360(%rbp), %rdi
callq 0x46a8
jmp 0x56ff
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
leaq -0x320(%rbp), %rdi
callq 0x46a8
jmp 0x5735
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
jmp 0x5729
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
leaq -0x340(%rbp), %rdi
callq 0x46a8
jmp 0x5729
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
leaq -0x360(%rbp), %rdi
callq 0x46a8
jmp 0x5729
leaq 0x36cda(%rip), %rsi     # 0x3c3e0
leaq -0x300(%rbp), %rdi
callq 0x40d0
jmp 0x5714
leaq -0x300(%rbp), %rdi
callq 0x40f0
addq $0x3e0, %rsp            # imm = 0x3E0
popq %rbp
retq
leaq -0x300(%rbp), %rdi
callq 0x40f0
movq -0x28(%rbp), %rdi
callq 0x4630
nop