// File: /workspace/github_cpp_makefile_star2_O1/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
pushq %r14
pushq %rbx
subq $0x250, %rsp            # imm = 0x250
callq 0x3ec8
leaq -0x40(%rbp), %r14
movq %r14, -0x10(%r14)
movq 0x1618b(%rip), %rsi     # 0x1a388
movq 0x1618c(%rip), %rdx     # 0x1a390
addq %rsi, %rdx
leaq -0x50(%rbp), %rbx
movq %rbx, %rdi
callq 0x518a
leaq 0xd445(%rip), %rsi      # 0x1165f
movq %rbx, %rdi
callq 0x3560
movq -0x50(%rbp), %rdi
callq 0x3430
movq %rax, %rbx
testq %rax, %rax
je 0x423b
movq %rbx, %rdi
callq 0x3490
movq -0x50(%rbp), %rdi
cmpq %r14, %rdi
je 0x4249
callq 0x32f0
testq %rbx, %rbx
leaq 0xd417(%rip), %rax      # 0x1166a
leaq 0xd40a(%rip), %rsi      # 0x11664
cmoveq %rax, %rsi
leaq 0x16123(%rip), %rdi     # 0x1a388
callq 0x3560
leaq -0x248(%rbp), %r14
movq %r14, -0x10(%r14)
movq 0x1610c(%rip), %rsi     # 0x1a388
movq 0x1610d(%rip), %rdx     # 0x1a390
addq %rsi, %rdx
leaq -0x258(%rbp), %rbx
movq %rbx, %rdi
callq 0x518a
leaq 0xd3d4(%rip), %rsi      # 0x11670
movq %rbx, %rdi
callq 0x3560
leaq 0x1615d(%rip), %rdi     # 0x1a408
movq %rbx, %rsi
callq 0x33d0
movq (%rbx), %rdi
cmpq %r14, %rdi
je 0x42c0
callq 0x32f0
movq %r14, (%rbx)
movq 0x160be(%rip), %rsi     # 0x1a388
movq 0x160bf(%rip), %rdx     # 0x1a390
addq %rsi, %rdx
movq %rbx, %rdi
callq 0x518a
leaq 0xd394(%rip), %rsi      # 0x11677
movq %rbx, %rdi
callq 0x3560
leaq 0x16156(%rip), %rdi     # 0x1a448
movq %rbx, %rsi
callq 0x33d0
movq (%rbx), %rdi
cmpq %r14, %rdi
je 0x4307
callq 0x32f0
movq %r14, (%rbx)
movq 0x16077(%rip), %rsi     # 0x1a388
movq 0x16078(%rip), %rdx     # 0x1a390
addq %rsi, %rdx
movq %rbx, %rdi
callq 0x518a
leaq 0xd355(%rip), %rsi      # 0x1167f
movq %rbx, %rdi
callq 0x3560
leaq 0x160ef(%rip), %rdi     # 0x1a428
movq %rbx, %rsi
callq 0x33d0
movq (%rbx), %rdi
cmpq %r14, %rdi
je 0x434e
callq 0x32f0
movq %r14, (%rbx)
movq 0x16030(%rip), %rsi     # 0x1a388
movq 0x16031(%rip), %rdx     # 0x1a390
addq %rsi, %rdx
movq %rbx, %rdi
callq 0x518a
leaq 0xd316(%rip), %rsi      # 0x11687
movq %rbx, %rdi
callq 0x3560
leaq 0x16048(%rip), %rdi     # 0x1a3c8
movq %rbx, %rsi
callq 0x33d0
movq (%rbx), %rdi
cmpq %r14, %rdi
je 0x4395
callq 0x32f0
movq %r14, (%rbx)
movq 0x15fe9(%rip), %rsi     # 0x1a388
movq 0x15fea(%rip), %rdx     # 0x1a390
addq %rsi, %rdx
movq %rbx, %rdi
callq 0x518a
leaq 0xd2d6(%rip), %rsi      # 0x1168e
movq %rbx, %rdi
callq 0x3560
leaq 0x16021(%rip), %rdi     # 0x1a3e8
movq %rbx, %rsi
callq 0x33d0
movq (%rbx), %rdi
cmpq %r14, %rdi
je 0x43dc
callq 0x32f0
movq %r14, (%rbx)
movq 0x16002(%rip), %rsi     # 0x1a3e8
movq 0x16003(%rip), %rdx     # 0x1a3f0
addq %rsi, %rdx
movq %rbx, %rdi
callq 0x518a
leaq 0xd233(%rip), %rsi      # 0x11632
movq %rbx, %rdi
callq 0x3560
movq -0x258(%rbp), %rdi
leaq 0xe0dc(%rip), %rsi      # 0x124f1
callq 0x33b0
movq %rax, %rbx
testq %rax, %rax
je 0x442a
movq %rbx, %rdi
callq 0x3310
movq -0x258(%rbp), %rdi
cmpq %r14, %rdi
je 0x443b
callq 0x32f0
testq %rbx, %rbx
movl $0x41, %eax
movl $0x57, %ecx
cmovel %eax, %ecx
movb %cl, 0x16017(%rip)      # 0x1a468
callq 0x3420
movq %rax, 0x16013(%rip)     # 0x1a470
testq %rax, %rax
je 0x4630
movq 0x15b5b(%rip), %rbx     # 0x19fc8
movq (%rbx), %rdi
movl $0x1, %esi
callq 0x3130
callq 0x3460
testb %al, %al
jne 0x448f
leaq 0x10006(%rip), %rdi     # 0x14490
callq 0x3450
callq 0x30b0
movl $0x7, %edi
xorl %esi, %esi
callq 0x3190
movl $0x1, %edi
movl $0x7, %esi
xorl %edx, %edx
callq 0x3080
movl $0x2, %edi
movl $0x1, %esi
xorl %edx, %edx
callq 0x3080
movl $0x3, %edi
movl $0x2, %esi
xorl %edx, %edx
callq 0x3080
movq (%rbx), %rdi
movl $0x100, %esi            # imm = 0x100
callq 0x34d0
xorl %edi, %edi
callq 0x32e0
movl %eax, 0x15e83(%rip)     # 0x1a370
callq 0x3bf7
shufps $0x55, %xmm0, %xmm0     # xmm0 = xmm0[1,1,1,1]
movss %xmm0, 0x15e6e(%rip)    # 0x1a36c
leaq -0x20(%rbp), %r14
movq %r14, -0x10(%r14)
movq 0x15ebb(%rip), %rsi     # 0x1a3c8
movq 0x15ebc(%rip), %rdx     # 0x1a3d0
addq %rsi, %rdx
leaq -0x30(%rbp), %rbx
movq %rbx, %rdi
callq 0x518a
leaq 0xd187(%rip), %rsi      # 0x116b1
movq %rbx, %rdi
callq 0x3560
leaq -0x258(%rbp), %rdi
leaq -0x30(%rbp), %rsi
movl $0x8, %edx
callq 0x34a0
movq -0x30(%rbp), %rdi
cmpq %r14, %rdi
je 0x4555
callq 0x32f0
leaq -0x30(%rbp), %rdi
movq %r14, (%rdi)
movq 0x15e65(%rip), %rsi     # 0x1a3c8
movq 0x15e66(%rip), %rdx     # 0x1a3d0
addq %rsi, %rdx
callq 0x518a
leaq 0xd138(%rip), %rsi      # 0x116b1
leaq -0x30(%rbp), %rdi
callq 0x3560
movq -0x30(%rbp), %rdi
leaq 0xdf64(%rip), %rsi      # 0x124f1
callq 0x33b0
movq %rax, %rbx
testq %rax, %rax
je 0x45a2
movq %rbx, %rdi
callq 0x3310
movq -0x30(%rbp), %rdi
cmpq %r14, %rdi
je 0x45b0
callq 0x32f0
testq %rbx, %rbx
jne 0x4605
leaq -0x30(%rbp), %rdi
movq %r14, (%rdi)
movq 0x15e45(%rip), %rsi     # 0x1a408
movq 0x15e46(%rip), %rdx     # 0x1a410
addq %rsi, %rdx
callq 0x518a
leaq 0xd0d8(%rip), %rsi      # 0x116b1
leaq -0x30(%rbp), %rdi
callq 0x3560
leaq -0x258(%rbp), %rdi
leaq -0x30(%rbp), %rsi
movl $0x8, %edx
callq 0x32b0
movq -0x30(%rbp), %rdi
cmpq %r14, %rdi
je 0x4605
callq 0x32f0
leaq 0x15d54(%rip), %rsi     # 0x1a360
leaq -0x258(%rbp), %rdi
callq 0x3590
leaq -0x258(%rbp), %rdi
callq 0x30c0
addq $0x250, %rsp            # imm = 0x250
popq %rbx
popq %r14
popq %rbp
retq
callq 0x361a
jmp 0x463d
jmp 0x463d
jmp 0x4650
jmp 0x4650
movq %rax, %rbx
movq -0x30(%rbp), %rdi
cmpq %r14, %rdi
je 0x4653
callq 0x32f0
jmp 0x4653
movq %rax, %rbx
leaq -0x258(%rbp), %rdi
callq 0x30c0
jmp 0x468a
jmp 0x4663
movq %rax, %rbx
movq -0x30(%rbp), %rdi
jmp 0x4680
jmp 0x4676
jmp 0x4676
jmp 0x4676
jmp 0x4676
jmp 0x4676
movq %rax, %rbx
movq -0x258(%rbp), %rdi
cmpq %r14, %rdi
je 0x468a
callq 0x32f0
movq %rbx, %rdi
callq 0x3530
movq %rax, %rbx
movq -0x50(%rbp), %rdi
jmp 0x4680