// File: /workspace/github_cpp_makefile_star2_O3/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 0x3f38
leaq -0x40(%rbp), %r14
movq %r14, -0x10(%r14)
movq 0x1511b(%rip), %rsi     # 0x19388
movq 0x1511c(%rip), %rdx     # 0x19390
addq %rsi, %rdx
leaq -0x50(%rbp), %rbx
movq %rbx, %rdi
callq 0x51f6
leaq 0xc3d5(%rip), %rsi      # 0x1065f
movq %rbx, %rdi
callq 0x3560
movq -0x50(%rbp), %rdi
callq 0x3430
movq %rax, %rbx
testq %rax, %rax
je 0x42ab
movq %rbx, %rdi
callq 0x3490
movq -0x50(%rbp), %rdi
cmpq %r14, %rdi
je 0x42b9
callq 0x32f0
testq %rbx, %rbx
leaq 0xc3a7(%rip), %rax      # 0x1066a
leaq 0xc39a(%rip), %rsi      # 0x10664
cmoveq %rax, %rsi
leaq 0x150b3(%rip), %rdi     # 0x19388
callq 0x3560
leaq -0x248(%rbp), %r14
movq %r14, -0x10(%r14)
movq 0x1509c(%rip), %rsi     # 0x19388
movq 0x1509d(%rip), %rdx     # 0x19390
addq %rsi, %rdx
leaq -0x258(%rbp), %rbx
movq %rbx, %rdi
callq 0x51f6
leaq 0xc364(%rip), %rsi      # 0x10670
movq %rbx, %rdi
callq 0x3560
leaq 0x150ed(%rip), %rdi     # 0x19408
movq %rbx, %rsi
callq 0x33d0
movq (%rbx), %rdi
cmpq %r14, %rdi
je 0x4330
callq 0x32f0
movq %r14, (%rbx)
movq 0x1504e(%rip), %rsi     # 0x19388
movq 0x1504f(%rip), %rdx     # 0x19390
addq %rsi, %rdx
movq %rbx, %rdi
callq 0x51f6
leaq 0xc324(%rip), %rsi      # 0x10677
movq %rbx, %rdi
callq 0x3560
leaq 0x150e6(%rip), %rdi     # 0x19448
movq %rbx, %rsi
callq 0x33d0
movq (%rbx), %rdi
cmpq %r14, %rdi
je 0x4377
callq 0x32f0
movq %r14, (%rbx)
movq 0x15007(%rip), %rsi     # 0x19388
movq 0x15008(%rip), %rdx     # 0x19390
addq %rsi, %rdx
movq %rbx, %rdi
callq 0x51f6
leaq 0xc2e5(%rip), %rsi      # 0x1067f
movq %rbx, %rdi
callq 0x3560
leaq 0x1507f(%rip), %rdi     # 0x19428
movq %rbx, %rsi
callq 0x33d0
movq (%rbx), %rdi
cmpq %r14, %rdi
je 0x43be
callq 0x32f0
movq %r14, (%rbx)
movq 0x14fc0(%rip), %rsi     # 0x19388
movq 0x14fc1(%rip), %rdx     # 0x19390
addq %rsi, %rdx
movq %rbx, %rdi
callq 0x51f6
leaq 0xc2a6(%rip), %rsi      # 0x10687
movq %rbx, %rdi
callq 0x3560
leaq 0x14fd8(%rip), %rdi     # 0x193c8
movq %rbx, %rsi
callq 0x33d0
movq (%rbx), %rdi
cmpq %r14, %rdi
je 0x4405
callq 0x32f0
movq %r14, (%rbx)
movq 0x14f79(%rip), %rsi     # 0x19388
movq 0x14f7a(%rip), %rdx     # 0x19390
addq %rsi, %rdx
movq %rbx, %rdi
callq 0x51f6
leaq 0xc266(%rip), %rsi      # 0x1068e
movq %rbx, %rdi
callq 0x3560
leaq 0x14fb1(%rip), %rdi     # 0x193e8
movq %rbx, %rsi
callq 0x33d0
movq (%rbx), %rdi
cmpq %r14, %rdi
je 0x444c
callq 0x32f0
movq %r14, (%rbx)
movq 0x14f92(%rip), %rsi     # 0x193e8
movq 0x14f93(%rip), %rdx     # 0x193f0
addq %rsi, %rdx
movq %rbx, %rdi
callq 0x51f6
leaq 0xc1c3(%rip), %rsi      # 0x10632
movq %rbx, %rdi
callq 0x3560
movq -0x258(%rbp), %rdi
leaq 0xd06c(%rip), %rsi      # 0x114f1
callq 0x33b0
movq %rax, %rbx
testq %rax, %rax
je 0x449a
movq %rbx, %rdi
callq 0x3310
movq -0x258(%rbp), %rdi
cmpq %r14, %rdi
je 0x44ab
callq 0x32f0
testq %rbx, %rbx
movl $0x41, %eax
movl $0x57, %ecx
cmovel %eax, %ecx
movb %cl, 0x14fa7(%rip)      # 0x19468
callq 0x3420
movq %rax, 0x14fa3(%rip)     # 0x19470
testq %rax, %rax
je 0x46a0
movq 0x14aeb(%rip), %rbx     # 0x18fc8
movq (%rbx), %rdi
movl $0x1, %esi
callq 0x3130
callq 0x3460
testb %al, %al
jne 0x44ff
leaq 0xef96(%rip), %rdi      # 0x13490
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, 0x14e13(%rip)     # 0x19370
callq 0x3c67
shufps $0x55, %xmm0, %xmm0     # xmm0 = xmm0[1,1,1,1]
movss %xmm0, 0x14dfe(%rip)    # 0x1936c
leaq -0x20(%rbp), %r14
movq %r14, -0x10(%r14)
movq 0x14e4b(%rip), %rsi     # 0x193c8
movq 0x14e4c(%rip), %rdx     # 0x193d0
addq %rsi, %rdx
leaq -0x30(%rbp), %rbx
movq %rbx, %rdi
callq 0x51f6
leaq 0xc117(%rip), %rsi      # 0x106b1
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 0x45c5
callq 0x32f0
leaq -0x30(%rbp), %rdi
movq %r14, (%rdi)
movq 0x14df5(%rip), %rsi     # 0x193c8
movq 0x14df6(%rip), %rdx     # 0x193d0
addq %rsi, %rdx
callq 0x51f6
leaq 0xc0c8(%rip), %rsi      # 0x106b1
leaq -0x30(%rbp), %rdi
callq 0x3560
movq -0x30(%rbp), %rdi
leaq 0xcef4(%rip), %rsi      # 0x114f1
callq 0x33b0
movq %rax, %rbx
testq %rax, %rax
je 0x4612
movq %rbx, %rdi
callq 0x3310
movq -0x30(%rbp), %rdi
cmpq %r14, %rdi
je 0x4620
callq 0x32f0
testq %rbx, %rbx
jne 0x4675
leaq -0x30(%rbp), %rdi
movq %r14, (%rdi)
movq 0x14dd5(%rip), %rsi     # 0x19408
movq 0x14dd6(%rip), %rdx     # 0x19410
addq %rsi, %rdx
callq 0x51f6
leaq 0xc068(%rip), %rsi      # 0x106b1
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 0x4675
callq 0x32f0
leaq 0x14ce4(%rip), %rsi     # 0x19360
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 0x3674
jmp 0x46ad
jmp 0x46ad
jmp 0x46c0
jmp 0x46c0
movq %rax, %rbx
movq -0x30(%rbp), %rdi
cmpq %r14, %rdi
je 0x46c3
callq 0x32f0
jmp 0x46c3
movq %rax, %rbx
leaq -0x258(%rbp), %rdi
callq 0x30c0
jmp 0x46fa
jmp 0x46d3
movq %rax, %rbx
movq -0x30(%rbp), %rdi
jmp 0x46f0
jmp 0x46e6
jmp 0x46e6
jmp 0x46e6
jmp 0x46e6
jmp 0x46e6
movq %rax, %rbx
movq -0x258(%rbp), %rdi
cmpq %r14, %rdi
je 0x46fa
callq 0x32f0
movq %rbx, %rdi
callq 0x3530
movq %rax, %rbx
movq -0x50(%rbp), %rdi
jmp 0x46f0