// File: /workspace/github_cpp_makefile_star2_O3/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 0x886c(%rip), %rdi      # 0xc130
leaq 0x904f(%rip), %rsi      # 0xc91a
callq 0x3370
xorps %xmm0, %xmm0
movaps %xmm0, (%rsp)
movq $0x0, 0x10(%rsp)
testq %rax, %rax
je 0x39ab
movq %rax, %rbx
leaq 0x50(%rsp), %r14
movq %r14, %rdi
movl $0xc8, %esi
movq %rax, %rdx
callq 0x34b0
movq %r14, %rdi
movl $0xc8, %esi
movq %rbx, %rdx
callq 0x34b0
movq %r14, %rdi
movl $0xc8, %esi
movq %rbx, %rdx
callq 0x34b0
testq %rax, %rax
je 0x39ab
leaq 0x8ded(%rip), %r14      # 0xc71e
leaq 0x50(%rsp), %r15
movq %rsp, %r12
leaq 0x20(%rsp), %r13
movl $0x14, %edi
callq 0x3030
movq %rax, 0x20(%rsp)
movq %r15, %rdi
movq %r14, %rsi
movq %rax, %rdx
xorl %eax, %eax
callq 0x32a0
movq 0x20(%rsp), %rbp
movq %rbp, %rdi
callq 0x3170
movb $0x0, -0x1(%rbp,%rax)
movq 0x8(%rsp), %rsi
cmpq 0x10(%rsp), %rsi
je 0x398b
movq 0x20(%rsp), %rax
movq %rax, (%rsi)
addq $0x8, 0x8(%rsp)
jmp 0x3996
movq %r12, %rdi
movq %r13, %rdx
callq 0x7ab2
movq %r15, %rdi
movl $0xc8, %esi
movq %rbx, %rdx
callq 0x34b0
testq %rax, %rax
jne 0x393e
movq 0x8(%rsp), %rax
cmpq (%rsp), %rax
je 0x3a0c
xorl %r15d, %r15d
leaq 0xc9c0(%rip), %r12      # 0x10380
leaq 0x877c(%rip), %rbx      # 0xc143
leaq 0x88f5(%rip), %r14      # 0xc2c3
movq (%r12), %rdi
movq %rbx, %rsi
callq 0xa57c
movq (%r12), %rdi
movq (%rsp), %rax
movq (%rax,%r15,8), %rsi
callq 0xa52e
movq (%r12), %rdi
movq %r14, %rsi
callq 0xa57c
incq %r15
movq 0x8(%rsp), %rax
subq (%rsp), %rax
sarq $0x3, %rax
cmpq %rax, %r15
jb 0x39ce
leaq 0x874a(%rip), %rdi      # 0xc15d
leaq 0x8f00(%rip), %rsi      # 0xc91a
callq 0x3370
movq %rax, %rbx
leaq 0x50(%rsp), %r14
movq %r14, %rdi
movl $0xc8, %esi
movq %rax, %rdx
callq 0x34b0
movq %r14, %rdi
movl $0xc8, %esi
movq %rbx, %rdx
callq 0x34b0
movq %r14, %rdi
movl $0xc8, %esi
movq %rbx, %rdx
callq 0x34b0
testq %rax, %rax
je 0x3aed
leaq 0x50(%rsp), %r15
leaq 0x30(%rsp), %r12
leaq 0xc90f(%rip), %r14      # 0x10380
leaq 0x86f3(%rip), %r13      # 0xc16b
leaq 0x8844(%rip), %rbp      # 0xc2c3
movq %r15, %rdi
leaq 0x8c95(%rip), %rsi      # 0xc71e
movq %r12, %rdx
xorl %eax, %eax
callq 0x32a0
movq %r12, %rdi
callq 0x3170
movb $0x0, -0x1(%rax,%r12)
movq (%r14), %rdi
movq %r13, %rsi
callq 0xa57c
movq (%r14), %rdi
movq %r12, %rsi
callq 0xa52e
movq (%r14), %rdi
movq %rbp, %rsi
callq 0xa57c
movq %r12, %rdi
callq 0x3170
cmpl %eax, 0xc818(%rip)      # 0x102e8
jge 0x3ad8
movl %eax, 0xc810(%rip)      # 0x102e8
movq %r15, %rdi
movl $0xc8, %esi
movq %rbx, %rdx
callq 0x34b0
testq %rax, %rax
jne 0x3a7f
incl 0xc7f5(%rip)            # 0x102e8
movq %rbx, %rdi
callq 0x32b0
leaq 0x865b(%rip), %rdi      # 0xc15d
leaq 0x8e11(%rip), %rsi      # 0xc91a
callq 0x3370
movq %rax, %rbx
leaq 0x50(%rsp), %r14
movq %r14, %rdi
movl $0xc8, %esi
movq %rax, %rdx
callq 0x34b0
movq %r14, %rdi
movl $0xc8, %esi
movq %rbx, %rdx
callq 0x34b0
movq %r14, %rdi
movl $0xc8, %esi
movq %rbx, 0x28(%rsp)
movq %rbx, %rdx
callq 0x34b0
testq %rax, %rax
je 0x3c50
leaq 0x50(%rsp), %r14
leaq 0x30(%rsp), %r12
leaq 0xc7c3(%rip), %r13      # 0x10328
leaq 0x20(%rsp), %rbp
movq %r14, %rbx
movq %r14, %rdi
leaq 0x8ba7(%rip), %rsi      # 0xc71e
movq %r12, %rdx
xorl %eax, %eax
callq 0x32a0
movq %r12, %rdi
callq 0x3170
movb $0x0, -0x1(%rax,%r12)
movq (%rsp), %rax
cmpq %rax, 0x8(%rsp)
je 0x3c32
xorl %r15d, %r15d
movq (%rax,%r15,8), %rsi
movq %r12, %rdi
callq 0x33f0
testl %eax, %eax
je 0x3be3
movl $0xb8, %edi
callq 0x32c0
movq %rax, %r14
movl 0xc724(%rip), %edx      # 0x102e8
movq %rax, %rdi
movq %r12, %rsi
xorl %ecx, %ecx
callq 0x95d6
movq %r14, 0x20(%rsp)
movq %r13, %rdi
movq %rbp, %rsi
callq 0x7bee
jmp 0x3c16
movl $0xb8, %edi
callq 0x32c0
movq %rax, %r14
movl 0xc6f2(%rip), %edx      # 0x102e8
movq %rax, %rdi
movq %r12, %rsi
movl $0x1, %ecx
callq 0x95d6
movq %r14, 0x20(%rsp)
movq %r13, %rdi
movq %rbp, %rsi
callq 0x7bee
incq %r15
movq (%rsp), %rax
movq 0x8(%rsp), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
cmpq %rcx, %r15
jb 0x3ba1
movq %rbx, %r14
movq %rbx, %rdi
movl $0xc8, %esi
movq 0x28(%rsp), %rdx
callq 0x34b0
testq %rax, %rax
jne 0x3b6a
movq (%rsp), %rdi
cmpq %rdi, 0x8(%rsp)
je 0x3c60
movq %rdi, 0x8(%rsp)
testq %rdi, %rdi
je 0x3c72
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x32d0
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x3ca0
jmp 0x3ca0
jmp 0x3ca0
jmp 0x3c8c
movq %rax, %rbx
movl $0xb8, %esi
movq %r14, %rdi
callq 0x32d0
jmp 0x3ca3
jmp 0x3ca0
movq %rax, %rbx
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x3cb9
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x32d0
movq %rbx, %rdi
callq 0x3550