// File: /workspace/github_cpp_makefile_star2_O1/Stygain[P]bandwidth-monitor/src/interface.cpp
// Function: Interface::Update()
void Interface::Update()
{
	extern Logger *logger;
	FILE *fp = fopen("/proc/net/dev", "r");
	char buf[200];
	char ifname[20];
	unsigned long int r_bytes;
	unsigned long int t_bytes;
	unsigned long int r_packets;
	unsigned long int t_packets;

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

		while (fgets(buf, 200, fp)) {
			sscanf(buf, "%s %lu %lu %*lu %*lu %*lu %*lu %*lu %*lu %lu %lu",
					ifname, &r_bytes, &r_packets, &t_bytes, &t_packets);
			ifname[strlen(ifname) - 1] = '\0';

			if (strcmp(ifname, this->name) == 0)
			{
				this->r_bytesLastLast = this->r_bytesLast;
				this->r_bytesLast = this->r_bytes;
				this->r_bytes = r_bytes;
				this->t_bytesLastLast = this->t_bytesLast;
				this->t_bytesLast = this->t_bytes;
				this->t_bytes = t_bytes;
				this->r_packetsLast = this->r_packets;
				this->r_packets = r_packets;
				this->t_packetsLast = this->t_packets;
				this->t_packets = t_packets;

				if (((this->r_bytes - this->r_bytesLast) + (this->r_bytesLast - this->r_bytesLastLast)) == 0)
				{
					this->r_bps = 0;
				}
				else
				{
					this->r_bps = (int)(((this->r_bytes - this->r_bytesLast) + (this->r_bytesLast - this->r_bytesLastLast)) / 2);
				}
				if (((this->t_bytes - this->t_bytesLast) + (this->t_bytesLast - this->t_bytesLastLast)) == 0)
				{
					this->t_bps = 0;
				}
				else
				{
					this->t_bps = (int)(((this->t_bytes - this->t_bytesLast) + (this->t_bytesLast - this->t_bytesLastLast)) / 2);
				}
				break;
			}
		}

		fclose(fp);
	}

	char ifaceType[] = "/sys/class/net/";
	strcat(ifaceType, this->name);
	strcat(ifaceType, "/operstate");
	fp = fopen(ifaceType, "r");

	logger->Log("Iface file: ");
	logger->Log(ifaceType);
	logger->Log("\n");
	if (fp != NULL)
	{
		fgets(buf, 200, fp);
		sscanf(buf, "%s", this->operstate);
		logger->Log("This operstate: ");
		logger->Log(this->operstate);
		logger->Log("\n");

		fclose(fp);
	}

	if (this->wireless)
	{
		fp = fopen("/proc/net/wireless", "r");

		if (fp != NULL)
		{
			logger->Log("In /proc/net/wireless\n");
			// Skip first two lines
			for (int i = 0; i < 2; i++) {
				fgets(buf, 200, fp);
			}

			int linkQual;
			int levelQual;
			int noiseQual;

			char wirelessInterfaceName[20];
			while (fgets(buf, 200, fp)) {
				sscanf(buf, "%s %*lu %d. %d. %d",
						wirelessInterfaceName, &linkQual, &levelQual, &noiseQual);
				wirelessInterfaceName[strlen(wirelessInterfaceName) - 1] = '\0';

				if (strcmp(wirelessInterfaceName, this->name) == 0)
				{
					logger->Log("Read: ");
					logger->Log(std::to_string(linkQual));
					logger->Log(", ");
					logger->Log(std::to_string(levelQual));
					logger->Log(", ");
					logger->Log(std::to_string(noiseQual));
					logger->Log("\n");
					this->linkQual = linkQual;
					this->levelQual = levelQual;
					this->noiseQual = noiseQual;
				}
			}
		}
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1c8, %rsp            # imm = 0x1C8
movq %rdi, %r12
leaq 0x2a1e(%rip), %rdi      # 0xc14d
leaq 0x31d4(%rip), %rsi      # 0xc90a
callq 0x3370
testq %rax, %rax
movq %r12, 0x18(%rsp)
je 0x986d
movq %rax, %r14
movl $0x1, %ebp
leaq 0x100(%rsp), %rbx
movq %rbx, %rdi
movl $0xc8, %esi
movq %r14, %rdx
callq 0x34b0
decl %ebp
je 0x9759
leaq 0x100(%rsp), %r15
leaq 0xe0(%rsp), %r13
leaq 0x68(%rsp), %rbp
leaq 0x58(%rsp), %rbx
leaq 0x60(%rsp), %r12
movq %r15, %rdi
movl $0xc8, %esi
movq %r14, %rdx
callq 0x34b0
testq %rax, %rax
je 0x9860
leaq 0x50(%rsp), %rax
movq %rax, (%rsp)
movq %r15, %rdi
leaq 0x2e8b(%rip), %rsi      # 0xc643
movq %r13, %rdx
movq %rbp, %rcx
movq %rbx, %r8
movq %r12, %r9
xorl %eax, %eax
callq 0x32a0
movq %r13, %rdi
callq 0x3170
movb $0x0, -0x1(%rax,%r13)
movq 0x18(%rsp), %rax
movq (%rax), %rsi
movq %r13, %rdi
callq 0x33f0
testl %eax, %eax
jne 0x978c
movq 0x18(%rsp), %r8
movq 0x8(%r8), %rax
movq 0x10(%r8), %rcx
movq %rcx, 0x18(%r8)
movq %rax, 0x10(%r8)
movq 0x68(%rsp), %rax
movq %rax, 0x8(%r8)
movq 0x30(%r8), %rdx
movq %rdx, 0x38(%r8)
movq 0x28(%r8), %rsi
movq %rsi, 0x30(%r8)
movq 0x60(%rsp), %rsi
movq %rsi, 0x28(%r8)
movq 0x48(%r8), %rdi
movq %rdi, 0x50(%r8)
movq 0x58(%rsp), %rdi
movq %rdi, 0x48(%r8)
movq 0x60(%r8), %rdi
movq %rdi, 0x68(%r8)
movq 0x50(%rsp), %rdi
movq %rdi, 0x60(%r8)
subq %rcx, %rax
shrq %rax
movl %eax, 0x9c(%r8)
subq %rdx, %rsi
shrq %rsi
movl %esi, 0xa0(%r8)
movq %r14, %rdi
callq 0x32b0
movq 0x18(%rsp), %r12
movaps 0x2efc(%rip), %xmm0     # 0xc770
leaq 0xb0(%rsp), %rbx
movaps %xmm0, (%rbx)
movq (%r12), %rsi
movq %rbx, %rdi
callq 0x3560
movq %rbx, %rdi
callq 0x3170
movabsq $0x6174737265706f2f, %rcx # imm = 0x6174737265706F2F
movq %rcx, 0xb0(%rsp,%rax)
movl $0x657461, 0xb7(%rsp,%rax) # imm = 0x657461
leaq 0x3053(%rip), %rsi      # 0xc90a
movq %rbx, %rdi
callq 0x3370
movq %rax, %r14
leaq 0x6ab7(%rip), %r15      # 0x10380
movq (%r15), %rdi
leaq 0x2dac(%rip), %rsi      # 0xc67f
callq 0xa5cc
movq (%r15), %rdi
movq %rbx, %rsi
movq %r15, %rbx
callq 0xa57e
movq (%r15), %rdi
leaq 0x29c3(%rip), %rsi      # 0xc2b3
callq 0xa5cc
testq %r14, %r14
je 0x9963
leaq 0x100(%rsp), %rbx
movq %rbx, %rdi
movl $0xc8, %esi
movq %r14, %rdx
callq 0x34b0
leaq 0x78(%r12), %r15
leaq 0x2df0(%rip), %rsi      # 0xc70e
movq %rbx, %rdi
leaq 0x6a58(%rip), %rbx      # 0x10380
movq %r15, %rdx
xorl %eax, %eax
callq 0x32a0
movq (%rbx), %rdi
leaq 0x2d50(%rip), %rsi      # 0xc68c
callq 0xa5cc
movq (%rbx), %rdi
movq %r15, %rsi
callq 0xa57e
movq (%rbx), %rdi
leaq 0x295d(%rip), %rsi      # 0xc2b3
callq 0xa5cc
movq %r14, %rdi
callq 0x32b0
cmpb $0x1, 0x8c(%r12)
jne 0x9d35
leaq 0x27a7(%rip), %rdi      # 0xc120
leaq 0x2f8a(%rip), %rsi      # 0xc90a
callq 0x3370
testq %rax, %rax
je 0x9d35
movq %rax, %r14
movq (%rbx), %rdi
leaq 0x2d02(%rip), %rsi      # 0xc69d
callq 0xa5cc
movl $0x1, %ebp
leaq 0x100(%rsp), %rbx
movq %rbx, %rdi
movl $0xc8, %esi
movq %r14, %rdx
callq 0x34b0
decl %ebp
je 0x99ad
leaq 0x100(%rsp), %rdi
movl $0xc8, %esi
movq %r14, %rdx
callq 0x34b0
testq %rax, %rax
leaq 0x69a0(%rip), %r13      # 0x10380
je 0x9d35
leaq 0x38(%rsp), %rax
movq %rax, 0x20(%rsp)
leaq 0x2cbd(%rip), %r15      # 0xc6b4
leaq 0x100(%rsp), %rbp
movq %r14, 0x48(%rsp)
movq %rbp, %rdi
movq %r15, %rsi
leaq 0xc0(%rsp), %rbx
movq %rbx, %rdx
leaq 0x14(%rsp), %rcx
leaq 0x10(%rsp), %r8
leaq 0xc(%rsp), %r9
xorl %eax, %eax
callq 0x32a0
movq %rbx, %rdi
callq 0x3170
movb $0x0, -0x1(%rax,%rbx)
movq (%r12), %rsi
movq %rbx, %rdi
callq 0x33f0
testl %eax, %eax
jne 0x9d1c
movq %r13, %rbx
movq (%r13), %rdi
leaq 0x2c6d(%rip), %rsi      # 0xc6c7
callq 0xa5cc
movl 0x14(%rsp), %r12d
movl %r12d, %r15d
negl %r15d
cmovsl %r12d, %r15d
movl $0x1, %ebp
cmpl $0xa, %r15d
leaq 0x38(%rsp), %r14
leaq 0xa0(%rsp), %r13
jb 0x9ac8
movl $0x4, %ebp
movl %r15d, %eax
movl $0xd1b71759, %esi       # imm = 0xD1B71759
cmpl $0x63, %eax
jbe 0x9ac1
cmpl $0x3e7, %eax            # imm = 0x3E7
jbe 0x9ac6
cmpl $0x2710, %eax           # imm = 0x2710
jb 0x9ac8
movl %eax, %ecx
imulq %rsi, %rcx
shrq $0x2d, %rcx
addl $0x4, %ebp
cmpl $0x1869f, %eax          # imm = 0x1869F
movl %ecx, %eax
ja 0x9a93
addl $-0x3, %ebp
jmp 0x9ac8
addl $-0x2, %ebp
jmp 0x9ac8
decl %ebp
movq (%rbx), %rbx
shrl $0x1f, %r12d
movl %r12d, %esi
addl %ebp, %esi
movq %r14, 0x28(%rsp)
leaq 0x28(%rsp), %rdi
movl $0x2d, %edx
callq 0x3340
movq 0x28(%rsp), %rdi
addq %r12, %rdi
movl %ebp, %esi
movl %r15d, %edx
callq 0x7a24
movq %rbx, %rdi
leaq 0x28(%rsp), %rsi
callq 0xa61a
movq 0x28(%rsp), %rdi
cmpq %r14, %rdi
je 0x9b1e
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x32d0
leaq 0x685b(%rip), %rbx      # 0x10380
movq (%rbx), %rdi
leaq 0x2b9f(%rip), %rsi      # 0xc6ce
callq 0xa5cc
movq (%rbx), %r15
movl 0x10(%rsp), %ebx
movl %ebx, %ebp
negl %ebp
cmovsl %ebx, %ebp
movl $0x1, %r12d
cmpl $0xa, %ebp
jb 0x9b93
movl $0x4, %r12d
movl %ebp, %eax
movl $0xd1b71759, %edx       # imm = 0xD1B71759
cmpl $0x63, %eax
jbe 0x9b8a
cmpl $0x3e7, %eax            # imm = 0x3E7
jbe 0x9b90
cmpl $0x2710, %eax           # imm = 0x2710
jb 0x9b93
movl %eax, %ecx
imulq %rdx, %rcx
shrq $0x2d, %rcx
addl $0x4, %r12d
cmpl $0x1869f, %eax          # imm = 0x1869F
movl %ecx, %eax
ja 0x9b5a
addl $-0x3, %r12d
jmp 0x9b93
addl $-0x2, %r12d
jmp 0x9b93
decl %r12d
shrl $0x1f, %ebx
movl %ebx, %esi
addl %r12d, %esi
movq %r13, 0x90(%rsp)
leaq 0x90(%rsp), %r14
movq %r14, %rdi
movl $0x2d, %edx
callq 0x3340
movq 0x90(%rsp), %rdi
addq %rbx, %rdi
movl %r12d, %esi
movl %ebp, %edx
callq 0x7a24
movq %r15, %rdi
movq %r14, %rsi
callq 0xa61a
movq 0x90(%rsp), %rdi
cmpq %r13, %rdi
leaq 0x6796(%rip), %rbx      # 0x10380
je 0x9bfc
movq 0xa0(%rsp), %rsi
incq %rsi
callq 0x32d0
movq (%rbx), %rdi
leaq 0x2ac8(%rip), %rsi      # 0xc6ce
callq 0xa5cc
movq (%rbx), %r15
movl 0xc(%rsp), %ebx
movl %ebx, %ebp
negl %ebp
cmovsl %ebx, %ebp
movl $0x1, %r12d
cmpl $0xa, %ebp
jb 0x9c6a
movl $0x4, %r12d
movl %ebp, %eax
movl $0xd1b71759, %edx       # imm = 0xD1B71759
cmpl $0x63, %eax
jbe 0x9c61
cmpl $0x3e7, %eax            # imm = 0x3E7
jbe 0x9c67
cmpl $0x2710, %eax           # imm = 0x2710
jb 0x9c6a
movl %eax, %ecx
imulq %rdx, %rcx
shrq $0x2d, %rcx
addl $0x4, %r12d
cmpl $0x1869f, %eax          # imm = 0x1869F
movl %ecx, %eax
ja 0x9c31
addl $-0x3, %r12d
jmp 0x9c6a
addl $-0x2, %r12d
jmp 0x9c6a
decl %r12d
shrl $0x1f, %ebx
movl %ebx, %esi
addl %r12d, %esi
leaq 0x80(%rsp), %r13
movq %r13, 0x70(%rsp)
leaq 0x70(%rsp), %r14
movq %r14, %rdi
movl $0x2d, %edx
callq 0x3340
movq 0x70(%rsp), %rdi
addq %rbx, %rdi
movl %r12d, %esi
movl %ebp, %edx
callq 0x7a24
movq %r15, %rdi
movq %r14, %rsi
callq 0xa61a
movq 0x70(%rsp), %rdi
cmpq %r13, %rdi
movq 0x18(%rsp), %r12
leaq 0x66be(%rip), %r13      # 0x10380
movq 0x48(%rsp), %r14
leaq 0x29e6(%rip), %r15      # 0xc6b4
leaq 0x100(%rsp), %rbp
je 0x9ce8
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x32d0
movq (%r13), %rdi
leaq 0x25c0(%rip), %rsi      # 0xc2b3
callq 0xa5cc
movl 0x14(%rsp), %eax
movl %eax, 0x90(%r12)
movl 0x10(%rsp), %eax
movl %eax, 0x94(%r12)
movl 0xc(%rsp), %eax
movl %eax, 0x98(%r12)
movq %rbp, %rdi
movl $0xc8, %esi
movq %r14, %rdx
callq 0x34b0
testq %rax, %rax
jne 0x9a04
addq $0x1c8, %rsp            # imm = 0x1C8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq 0x90(%rsp), %rdi
jmp 0x9d6b
movq %rax, %rbx
movq 0x28(%rsp), %rdi
cmpq %r14, %rdi
jne 0x9d75
jmp 0x9d85
movq %rax, %rbx
movq 0x70(%rsp), %rdi
movq %r13, 0x20(%rsp)
cmpq %r13, %rdi
je 0x9d85
movq 0x20(%rsp), %rax
movq (%rax), %rsi
incq %rsi
callq 0x32d0
movq %rbx, %rdi
callq 0x3550
nop