// File: /workspace/github_cpp_makefile_star2_O2/Stygain[P]bandwidth-monitor/src/main.cpp
// Function: initializeInterfaces()
void initializeInterfaces()
{
	FILE *fp = fopen("/proc/net/wireless", "r");
	char buf[200];
	char ifname[20];
	std::vector<char *> wirelessIfaceNames;
	
	if (fp != NULL)
	{
		// Skip first two lines
		for (int i = 0; i < 2; i++) {
			fgets(buf, 200, fp);
		}

		while (fgets(buf, 200, fp)) {
			char *wirelessInterfaceName = new char[20];
			sscanf(buf, "%s", wirelessInterfaceName);
			wirelessInterfaceName[strlen(wirelessInterfaceName) - 1] = '\0';
			wirelessIfaceNames.push_back(wirelessInterfaceName);
		}
	}
	for (size_t i = 0; i < wirelessIfaceNames.size(); ++i)
	{
		logger->Log("Wireless interface name: ");
		logger->Log(wirelessIfaceNames[i]);
		logger->Log("\n");
	}

	fp = fopen("/proc/net/dev", "r");

	// skip first two lines
	for (int i = 0; i < 2; i++) {
		fgets(buf, 200, fp);
	}

	while (fgets(buf, 200, fp)) {
		sscanf(buf, "%s", ifname);
		ifname[strlen(ifname) - 1] = '\0';
		logger->Log("Found iface name: ");
		logger->Log(ifname);
		logger->Log("\n");

		int len = strlen(ifname);
		if (len > longest)
		{
			longest = len;
		}
	}
	longest++;

	fclose(fp);


	fp = fopen("/proc/net/dev", "r");
	// skip first two lines
	for (int i = 0; i < 2; i++) {
		fgets(buf, 200, fp);
	}

	while (fgets(buf, 200, fp)) {
		sscanf(buf, "%s", ifname);
		ifname[strlen(ifname) - 1] = '\0';

		for (size_t i = 0; i < wirelessIfaceNames.size(); ++i)
		{
			if (strcmp(ifname, wirelessIfaceNames[i]) == 0)
			{
				interfaces.push_back(new Interface(ifname, longest, 1));
			}
			else
			{
				interfaces.push_back(new Interface(ifname, longest, 0));
			}
		}
	}

	wirelessIfaceNames.clear();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x118, %rsp            # imm = 0x118
leaq 0x78fc(%rip), %rdi      # 0xb130
leaq 0x80df(%rip), %rsi      # 0xb91a
callq 0x3360
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
andq $0x0, 0x20(%rsp)
testq %rax, %rax
je 0x38e1
movq %rax, %rbx
pushq $0x2
popq %rbp
leaq 0x50(%rsp), %r14
subl $0x1, %ebp
jb 0x3879
movq %r14, %rdi
movl $0xc8, %esi
movq %rbx, %rdx
callq 0x34b0
jmp 0x3862
leaq 0x50(%rsp), %r14
leaq 0x7e99(%rip), %r12      # 0xb71e
leaq 0x10(%rsp), %r13
leaq 0x8(%rsp), %rbp
movq %r14, %rdi
movl $0xc8, %esi
movq %rbx, %rdx
callq 0x34b0
testq %rax, %rax
je 0x38e1
pushq $0x14
popq %rdi
callq 0x3030
movq %rax, 0x8(%rsp)
movq %r14, %rdi
movq %r12, %rsi
movq %rax, %rdx
xorl %eax, %eax
callq 0x3290
movq 0x8(%rsp), %r15
movq %r15, %rdi
callq 0x3160
movb $0x0, -0x1(%r15,%rax)
movq %r13, %rdi
movq %rbp, %rsi
callq 0x6cae
jmp 0x388f
xorl %r15d, %r15d
leaq 0xca8d(%rip), %r12      # 0x10378
leaq 0x7851(%rip), %rbx      # 0xb143
leaq 0x79ca(%rip), %r14      # 0xb2c3
movq 0x18(%rsp), %rax
subq 0x10(%rsp), %rax
sarq $0x3, %rax
cmpq %rax, %r15
jae 0x393b
movq (%r12), %rdi
movq %rbx, %rsi
callq 0x97a6
movq (%r12), %rdi
movq 0x10(%rsp), %rax
movq (%rax,%r15,8), %rsi
callq 0x9794
movq (%r12), %rdi
movq %r14, %rsi
callq 0x97a6
incq %r15
jmp 0x38f9
leaq 0x781b(%rip), %rdi      # 0xb15d
leaq 0x7fd1(%rip), %rsi      # 0xb91a
callq 0x3360
movq %rax, %r14
pushq $0x2
popq %rbp
leaq 0x50(%rsp), %rbx
subl $0x1, %ebp
jb 0x3970
movq %rbx, %rdi
movl $0xc8, %esi
movq %r14, %rdx
callq 0x34b0
jmp 0x3959
leaq 0x50(%rsp), %r15
leaq 0x30(%rsp), %rbx
leaq 0x77ea(%rip), %r13      # 0xb16b
leaq 0x793b(%rip), %rbp      # 0xb2c3
movq %r15, %rdi
movl $0xc8, %esi
movq %r14, %rdx
callq 0x34b0
testq %rax, %rax
je 0x39fa
movq %r15, %rdi
leaq 0x7d77(%rip), %rsi      # 0xb71e
movq %rbx, %rdx
xorl %eax, %eax
callq 0x3290
movq %rbx, %rdi
callq 0x3160
movb $0x0, -0x1(%rax,%rbx)
movq (%r12), %rdi
movq %r13, %rsi
callq 0x97a6
movq (%r12), %rdi
movq %rbx, %rsi
callq 0x9794
movq (%r12), %rdi
movq %rbp, %rsi
callq 0x97a6
movq %rbx, %rdi
callq 0x3160
cmpl %eax, 0xc8f0(%rip)      # 0x102e0
jge 0x3988
movl %eax, 0xc8e8(%rip)      # 0x102e0
jmp 0x3988
incl 0xc8e0(%rip)            # 0x102e0
movq %r14, %rdi
callq 0x32b0
leaq 0x774e(%rip), %rdi      # 0xb15d
leaq 0x7f04(%rip), %rsi      # 0xb91a
callq 0x3360
movq %rax, %r14
pushq $0x2
popq %rbp
leaq 0x50(%rsp), %r15
subl $0x1, %ebp
jb 0x3a3d
movq %r15, %rdi
movl $0xc8, %esi
movq %r14, %rdx
callq 0x34b0
jmp 0x3a26
movq %r14, 0x28(%rsp)
pushq $0x1
popq %rbp
leaq 0xc8d4(%rip), %r13      # 0x10320
leaq 0x8(%rsp), %r12
leaq 0x50(%rsp), %r14
movq %r14, %rdi
movl $0xc8, %esi
movq 0x28(%rsp), %rdx
callq 0x34b0
testq %rax, %rax
je 0x3b25
movq %r14, %rdi
leaq 0x7ca3(%rip), %rsi      # 0xb71e
movq %rbx, %rdx
xorl %eax, %eax
callq 0x3290
movq %rbx, %rdi
callq 0x3160
movb $0x0, -0x1(%rax,%rbx)
xorl %r14d, %r14d
movq 0x10(%rsp), %rax
movq 0x18(%rsp), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
cmpq %rcx, %r14
jae 0x3a51
movq (%rax,%r14,8), %rsi
movq %rbx, %rdi
callq 0x33f0
testl %eax, %eax
je 0x3aed
movl $0xb8, %edi
callq 0x32c0
movq %rax, %r15
movl 0xc812(%rip), %edx      # 0x102e0
movq %rax, %rdi
movq %rbx, %rsi
xorl %ecx, %ecx
callq 0x8b3c
movq %r15, 0x8(%rsp)
movq %r13, %rdi
movq %r12, %rsi
callq 0x70fe
jmp 0x3b1d
movl $0xb8, %edi
callq 0x32c0
movq %rax, %r15
movl 0xc7e0(%rip), %edx      # 0x102e0
movq %rax, %rdi
movq %rbx, %rsi
movl %ebp, %ecx
callq 0x8b3c
movq %r15, 0x8(%rsp)
movq %r13, %rdi
movq %r12, %rsi
callq 0x70fe
incq %r14
jmp 0x3a95
movq 0x10(%rsp), %rax
cmpq %rax, 0x18(%rsp)
je 0x3b36
movq %rax, 0x18(%rsp)
leaq 0x10(%rsp), %rdi
callq 0x6f86
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x3b6e
jmp 0x3b6e
jmp 0x3b6e
jmp 0x3b5a
movq %rax, %rbx
movl $0xb8, %esi
movq %r15, %rdi
callq 0x32d0
jmp 0x3b71
jmp 0x3b6e
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x6f86
movq %rbx, %rdi
callq 0x3540