// File: /workspace/github_cpp_makefile_star2_O2/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 %r15
pushq %r14
pushq %rbx
subq $0x248, %rsp            # imm = 0x248
callq 0x3ad9
leaq 0x1664d(%rip), %rbx     # 0x1a380
leaq 0xb915(%rip), %rdx      # 0xf64f
leaq -0x58(%rbp), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x4763
movq %r14, %rdi
callq 0x38bc
movl %eax, %r15d
movq %r14, %rdi
callq 0x3598
leaq 0xb8f1(%rip), %rax      # 0xf654
leaq 0xb8f0(%rip), %rsi      # 0xf65a
testb %r15b, %r15b
cmovneq %rax, %rsi
movq %rbx, %rdi
callq 0x3540
leaq 0xb8e0(%rip), %rdx      # 0xf660
leaq -0x260(%rbp), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x4763
leaq 0x16667(%rip), %rdi     # 0x1a400
movq %r14, %rsi
callq 0x33a0
movq %r14, %rdi
callq 0x3598
leaq 0xb8b7(%rip), %rdx      # 0xf667
movq %r14, %rdi
movq %rbx, %rsi
callq 0x4763
leaq 0x1667e(%rip), %rdi     # 0x1a440
movq %r14, %rsi
callq 0x33a0
movq %r14, %rdi
callq 0x3598
leaq 0xb896(%rip), %rdx      # 0xf66f
movq %r14, %rdi
movq %rbx, %rsi
callq 0x4763
leaq 0x16635(%rip), %rdi     # 0x1a420
movq %r14, %rsi
callq 0x33a0
movq %r14, %rdi
callq 0x3598
leaq 0xb875(%rip), %rdx      # 0xf677
movq %r14, %rdi
movq %rbx, %rsi
callq 0x4763
leaq 0x165ac(%rip), %rdi     # 0x1a3c0
movq %r14, %rsi
callq 0x33a0
movq %r14, %rdi
callq 0x3598
leaq 0xb853(%rip), %rdx      # 0xf67e
movq %r14, %rdi
movq %rbx, %rsi
callq 0x4763
leaq 0x165a3(%rip), %rbx     # 0x1a3e0
movq %rbx, %rdi
movq %r14, %rsi
callq 0x33a0
movq %r14, %rdi
callq 0x3598
leaq 0xb7cb(%rip), %rdx      # 0xf622
movq %r14, %rdi
movq %rbx, %rsi
callq 0x4763
movq %r14, %rdi
callq 0x4731
movl %eax, %ebx
leaq -0x260(%rbp), %rdi
callq 0x3598
testb %bl, %bl
pushq $0x57
popq %rax
pushq $0x41
popq %rcx
cmovnel %eax, %ecx
movb %cl, 0x165d7(%rip)      # 0x1a460
callq 0x3410
movq %rax, 0x165d3(%rip)     # 0x1a468
testq %rax, %rax
je 0x3ff0
movq 0x16123(%rip), %r15     # 0x19fc8
movq (%r15), %rdi
pushq $0x1
popq %rsi
callq 0x3110
callq 0x3450
testb %al, %al
jne 0x3ec5
leaq 0xe762(%rip), %rdi      # 0x12622
callq 0x3440
callq 0x30a0
pushq $0x7
popq %rbx
movl %ebx, %edi
xorl %esi, %esi
callq 0x3170
pushq $0x1
popq %r14
movl %r14d, %edi
movl %ebx, %esi
xorl %edx, %edx
callq 0x3070
pushq $0x2
popq %rbx
movl %ebx, %edi
movl %r14d, %esi
xorl %edx, %edx
callq 0x3070
pushq $0x3
popq %rdi
movl %ebx, %esi
xorl %edx, %edx
callq 0x3070
movq (%r15), %rdi
movl $0x100, %esi            # imm = 0x100
callq 0x34c0
xorl %edi, %edi
callq 0x32d0
movl %eax, 0x1644d(%rip)     # 0x1a368
callq 0x38e7
shufps $0x55, %xmm0, %xmm0     # xmm0 = xmm0[1,1,1,1]
movss %xmm0, 0x16438(%rip)    # 0x1a364
leaq 0x1648d(%rip), %rsi     # 0x1a3c0
leaq 0xb767(%rip), %rdx      # 0xf6a1
leaq -0x38(%rbp), %rbx
movq %rbx, %rdi
callq 0x4763
leaq -0x260(%rbp), %rdi
pushq $0x8
popq %rdx
movq %rbx, %rsi
callq 0x3490
leaq -0x38(%rbp), %rdi
callq 0x3598
leaq 0x16458(%rip), %rsi     # 0x1a3c0
leaq 0xb732(%rip), %rdx      # 0xf6a1
leaq -0x38(%rbp), %rdi
callq 0x4763
leaq -0x38(%rbp), %rdi
callq 0x4731
movl %eax, %ebx
leaq -0x38(%rbp), %rdi
callq 0x3598
testb %bl, %bl
jne 0x3fc3
leaq 0x16469(%rip), %rsi     # 0x1a400
leaq 0xb703(%rip), %rdx      # 0xf6a1
leaq -0x38(%rbp), %rdi
callq 0x4763
leaq -0x260(%rbp), %rdi
leaq -0x38(%rbp), %rsi
pushq $0x8
popq %rdx
callq 0x3290
leaq -0x38(%rbp), %rdi
callq 0x3598
leaq 0x1638e(%rip), %rsi     # 0x1a358
leaq -0x260(%rbp), %rdi
callq 0x3580
leaq -0x260(%rbp), %rdi
callq 0x30b0
addq $0x248, %rsp            # imm = 0x248
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movq 0x15fe1(%rip), %rax     # 0x19fd8
movq (%rax), %rcx
leaq 0xb683(%rip), %rdi      # 0xf684
pushq $0x1c
popq %rsi
pushq $0x1
popq %rdx
callq 0x3560
pushq $0x1
popq %rdi
callq 0x3390
jmp 0x401a
jmp 0x4028
jmp 0x4028
movq %rax, %rbx
leaq -0x38(%rbp), %rdi
callq 0x3598
jmp 0x402b
movq %rax, %rbx
leaq -0x260(%rbp), %rdi
callq 0x30b0
jmp 0x4051
movq %rax, %rbx
leaq -0x38(%rbp), %rdi
jmp 0x404c
movq %rax, %rbx
leaq -0x260(%rbp), %rdi
callq 0x3598
movq %rbx, %rdi
callq 0x3520