// File: /workspace/github_cpp_makefile_star2_O1/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 0x883c(%rip), %rdi      # 0xc120
leaq 0x901f(%rip), %rsi      # 0xc90a
callq 0x3370
xorps %xmm0, %xmm0
movaps %xmm0, (%rsp)
movq $0x0, 0x10(%rsp)
testq %rax, %rax
je 0x39c6
movq %rax, %rbx
movl $0x1, %ebp
leaq 0x50(%rsp), %r14
movq %r14, %rdi
movl $0xc8, %esi
movq %rbx, %rdx
callq 0x34b0
decl %ebp
je 0x3916
leaq 0x50(%rsp), %rdi
movl $0xc8, %esi
movq %rbx, %rdx
callq 0x34b0
testq %rax, %rax
je 0x39c6
leaq 0x8dc2(%rip), %r14      # 0xc70e
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 0x39a6
movq 0x20(%rsp), %rax
movq %rax, (%rsi)
addq $0x8, 0x8(%rsp)
jmp 0x39b1
movq %r12, %rdi
movq %r13, %rdx
callq 0x7b0c
movq %r15, %rdi
movl $0xc8, %esi
movq %rbx, %rdx
callq 0x34b0
testq %rax, %rax
jne 0x3959
movq 0x8(%rsp), %rax
cmpq (%rsp), %rax
je 0x3a27
xorl %r15d, %r15d
leaq 0xc9a5(%rip), %r12      # 0x10380
leaq 0x8751(%rip), %rbx      # 0xc133
leaq 0x88ca(%rip), %r14      # 0xc2b3
movq (%r12), %rdi
movq %rbx, %rsi
callq 0xa5cc
movq (%r12), %rdi
movq (%rsp), %rax
movq (%rax,%r15,8), %rsi
callq 0xa57e
movq (%r12), %rdi
movq %r14, %rsi
callq 0xa5cc
incq %r15
movq 0x8(%rsp), %rax
subq (%rsp), %rax
sarq $0x3, %rax
cmpq %rax, %r15
jb 0x39e9
leaq 0x871f(%rip), %rdi      # 0xc14d
leaq 0x8ed5(%rip), %rsi      # 0xc90a
callq 0x3370
movq %rax, %rbx
movl $0x1, %ebp
leaq 0x50(%rsp), %r14
movq %r14, %rdi
movl $0xc8, %esi
movq %rbx, %rdx
callq 0x34b0
decl %ebp
je 0x3a47
leaq 0x50(%rsp), %rdi
movl $0xc8, %esi
movq %rbx, %rdx
callq 0x34b0
testq %rax, %rax
je 0x3b03
leaq 0x50(%rsp), %r15
leaq 0x30(%rsp), %r12
leaq 0xc8f9(%rip), %r14      # 0x10380
leaq 0x86cd(%rip), %r13      # 0xc15b
leaq 0x881e(%rip), %rbp      # 0xc2b3
movq %r15, %rdi
leaq 0x8c6f(%rip), %rsi      # 0xc70e
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 0xa5cc
movq (%r14), %rdi
movq %r12, %rsi
callq 0xa57e
movq (%r14), %rdi
movq %rbp, %rsi
callq 0xa5cc
movq %r12, %rdi
callq 0x3170
cmpl %eax, 0xc802(%rip)      # 0x102e8
jge 0x3aee
movl %eax, 0xc7fa(%rip)      # 0x102e8
movq %r15, %rdi
movl $0xc8, %esi
movq %rbx, %rdx
callq 0x34b0
testq %rax, %rax
jne 0x3a95
incl 0xc7df(%rip)            # 0x102e8
movq %rbx, %rdi
callq 0x32b0
leaq 0x8635(%rip), %rdi      # 0xc14d
leaq 0x8deb(%rip), %rsi      # 0xc90a
callq 0x3370
movq %rax, %rbx
movl $0x1, %ebp
leaq 0x50(%rsp), %r14
movq %r14, %rdi
movl $0xc8, %esi
movq %rbx, %rdx
callq 0x34b0
decl %ebp
je 0x3b31
leaq 0x50(%rsp), %rdi
movl $0xc8, %esi
movq %rbx, %rdx
callq 0x34b0
testq %rax, %rax
je 0x3c61
leaq 0x50(%rsp), %r14
leaq 0x30(%rsp), %r12
leaq 0xc7b7(%rip), %r13      # 0x10328
leaq 0x20(%rsp), %rbp
movq %rbx, 0x28(%rsp)
movq %r14, %rbx
movq %r14, %rdi
leaq 0x8b86(%rip), %rsi      # 0xc70e
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 0x3c43
xorl %r15d, %r15d
movq (%rax,%r15,8), %rsi
movq %r12, %rdi
callq 0x33f0
testl %eax, %eax
je 0x3bf4
movl $0xb8, %edi
callq 0x32c0
movq %rax, %r14
movl 0xc713(%rip), %edx      # 0x102e8
movq %rax, %rdi
movq %r12, %rsi
xorl %ecx, %ecx
callq 0x9676
movq %r14, 0x20(%rsp)
movq %r13, %rdi
movq %rbp, %rsi
callq 0x7c48
jmp 0x3c27
movl $0xb8, %edi
callq 0x32c0
movq %rax, %r14
movl 0xc6e1(%rip), %edx      # 0x102e8
movq %rax, %rdi
movq %r12, %rsi
movl $0x1, %ecx
callq 0x9676
movq %r14, 0x20(%rsp)
movq %r13, %rdi
movq %rbp, %rsi
callq 0x7c48
incq %r15
movq (%rsp), %rax
movq 0x8(%rsp), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
cmpq %rcx, %r15
jb 0x3bb2
movq %rbx, %r14
movq %rbx, %rdi
movl $0xc8, %esi
movq 0x28(%rsp), %rdx
callq 0x34b0
testq %rax, %rax
jne 0x3b7b
movq (%rsp), %rdi
cmpq %rdi, 0x8(%rsp)
je 0x3c71
movq %rdi, 0x8(%rsp)
testq %rdi, %rdi
je 0x3c83
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 0x3cb1
jmp 0x3cb1
jmp 0x3cb1
jmp 0x3c9d
movq %rax, %rbx
movl $0xb8, %esi
movq %r14, %rdi
callq 0x32d0
jmp 0x3cb4
jmp 0x3cb1
movq %rax, %rbx
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x3cca
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x32d0
movq %rbx, %rdi
callq 0x3550