// File: vianna274[P]dropbox/src/Client.cpp
// Function: Dropbox::Client::eventsInotify(int*)
void Client::eventsInotify(int* fd){
	int length, i = 0;
	char buffer[BUF_LEN];
	struct pollfd pfd = { *fd, POLLIN, 0 };
	int ret = poll(&pfd, 1, 50);  // timeout of 50ms
	if (ret < 0) {
		fprintf(stderr, "poll failed: %s\n", strerror(errno));
	} else if (ret == 0) {
		// Timeout with no events, move on.
	} else {
		// Process the new event.
		length = read(*fd, buffer, BUF_LEN);  
		while (i < length) {
			struct inotify_event *event = ( struct inotify_event * ) &buffer[ i ];
			if (event->len ) {
				string filename(event->name);
				string path = syncDirPath + filename;
				vector<FileRecord> tempFiles = this->getFileList(this->getSyncDirPath());
				if(event->mask & IN_MOVED_TO){
					socketMtx.lock();
					FileRecord newRecord = this->sendFileClient(this->socket, path.c_str(), this->username);
					socketMtx.unlock();
					this->updateFileRecord(newRecord);
				}
			
				if(event->mask & IN_MOVED_FROM || event->mask & IN_DELETE){
					socketMtx.lock();
					this->sendDeleteFile(this->socket, filename.c_str(), this->username);
					socketMtx.unlock();
					this->removeFileRecord(filename);
				}  
		
				if(event->mask & IN_CLOSE_WRITE){
					socketMtx.lock();
					this->sendDeleteFile(this->socket, filename.c_str(), this->username);
					FileRecord newRecord = this->sendFileClient(this->socket, path.c_str(), this->username);
					socketMtx.unlock();
					this->updateFileRecord(newRecord);
				} 
	
			i += EVENT_SIZE + event->len;
			}
		}
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x36720, %rsp          # imm = 0x36720
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x365b0(%rbp)
movl $0x0, -0x18(%rbp)
movq -0x10(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x36028(%rbp)
movw $0x1, -0x36024(%rbp)
movw $0x0, -0x36022(%rbp)
leaq -0x36028(%rbp), %rdi
movl $0x1, %esi
movl $0x32, %edx
callq 0x3530
movl %eax, -0x3602c(%rbp)
cmpl $0x0, -0x3602c(%rbp)
jge 0x4bf2
movq 0x1e411(%rip), %rax     # 0x22fd0
movq (%rax), %rax
movq %rax, -0x365b8(%rbp)
callq 0x3070
movl (%rax), %edi
callq 0x3130
movq -0x365b8(%rbp), %rdi
movq %rax, %rdx
leaq 0x144df(%rip), %rsi     # 0x190c5
movb $0x0, %al
callq 0x34b0
jmp 0x5403
cmpl $0x0, -0x3602c(%rbp)
jne 0x4c00
jmp 0x5401
movq -0x10(%rbp), %rax
movl (%rax), %edi
leaq -0x36020(%rbp), %rsi
movl $0x36000, %edx          # imm = 0x36000
callq 0x34c0
movl %eax, -0x14(%rbp)
movl -0x18(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x53ff
movslq -0x18(%rbp), %rcx
leaq -0x36020(%rbp), %rax
addq %rcx, %rax
movq %rax, -0x36038(%rbp)
movq -0x36038(%rbp), %rax
cmpl $0x0, 0xc(%rax)
je 0x53fa
movq -0x36038(%rbp), %rax
addq $0x10, %rax
movq %rax, -0x365c8(%rbp)
leaq -0x36059(%rbp), %rdi
movq %rdi, -0x365c0(%rbp)
callq 0x3620
movq -0x365c8(%rbp), %rsi
movq -0x365c0(%rbp), %rdx
leaq -0x36058(%rbp), %rdi
callq 0x3480
jmp 0x4c8d
leaq -0x36059(%rbp), %rdi
callq 0x33e0
movq -0x365b0(%rbp), %rsi
addq $0x50, %rsi
leaq -0x36090(%rbp), %rdi
leaq -0x36058(%rbp), %rdx
callq 0x7210
jmp 0x4cb9
movq -0x365b0(%rbp), %rsi
leaq -0x360c8(%rbp), %rdi
callq 0x6d80
jmp 0x4cce
movq -0x365b0(%rbp), %rsi
leaq -0x360a8(%rbp), %rdi
leaq -0x360c8(%rbp), %rdx
callq 0x9910
jmp 0x4cea
leaq -0x360c8(%rbp), %rdi
callq 0x3280
movq -0x36038(%rbp), %rax
movl 0x4(%rax), %eax
andl $0x80, %eax
cmpl $0x0, %eax
je 0x4f21
movq -0x365b0(%rbp), %rdi
addq $0x98, %rdi
callq 0x6a60
jmp 0x4d23
movq -0x365b0(%rbp), %rax
movq 0x40(%rax), %rax
movq %rax, -0x365e0(%rbp)
leaq -0x36090(%rbp), %rdi
callq 0x3180
movq %rax, -0x365d8(%rbp)
leaq -0x361d1(%rbp), %rdi
movq %rdi, -0x365d0(%rbp)
callq 0x3620
movq -0x365d8(%rbp), %rsi
movq -0x365d0(%rbp), %rdx
leaq -0x361d0(%rbp), %rdi
callq 0x3480
jmp 0x4d77
movq -0x365b0(%rbp), %rsi
leaq -0x361f8(%rbp), %rdi
callq 0x3190
jmp 0x4d8c
movq -0x365e0(%rbp), %rdx
movq -0x365b0(%rbp), %rsi
leaq -0x361b0(%rbp), %rdi
leaq -0x361d0(%rbp), %rcx
leaq -0x361f8(%rbp), %r8
callq 0xacc0
jmp 0x4db6
leaq -0x361f8(%rbp), %rdi
callq 0x3280
leaq -0x361d0(%rbp), %rdi
callq 0x3280
leaq -0x361d1(%rbp), %rdi
callq 0x33e0
movq -0x365b0(%rbp), %rdi
addq $0x98, %rdi
callq 0x6a90
jmp 0x4def
leaq -0x362e0(%rbp), %rdi
movq %rdi, -0x365e8(%rbp)
leaq -0x361b0(%rbp), %rsi
movl $0xe8, %edx
callq 0x3300
movq -0x365e8(%rbp), %rsi
movq %rsp, %rdi
movl $0x1d, %ecx
rep  movsq (%rsi), %es:(%rdi)
movq -0x365b0(%rbp), %rdi
callq 0x5ff0
jmp 0x4e2e
jmp 0x4f21
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x36068(%rbp)
movl %eax, -0x3606c(%rbp)
leaq -0x36059(%rbp), %rdi
callq 0x33e0
jmp 0x540c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x36068(%rbp)
movl %eax, -0x3606c(%rbp)
jmp 0x53ec
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x36068(%rbp)
movl %eax, -0x3606c(%rbp)
jmp 0x53e0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x36068(%rbp)
movl %eax, -0x3606c(%rbp)
leaq -0x360c8(%rbp), %rdi
callq 0x3280
jmp 0x53e0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x36068(%rbp)
movl %eax, -0x3606c(%rbp)
jmp 0x53d4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x36068(%rbp)
movl %eax, -0x3606c(%rbp)
jmp 0x4f10
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x36068(%rbp)
movl %eax, -0x3606c(%rbp)
jmp 0x4f04
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x36068(%rbp)
movl %eax, -0x3606c(%rbp)
leaq -0x361f8(%rbp), %rdi
callq 0x3280
leaq -0x361d0(%rbp), %rdi
callq 0x3280
leaq -0x361d1(%rbp), %rdi
callq 0x33e0
jmp 0x53d4
movq -0x36038(%rbp), %rax
movl 0x4(%rax), %eax
andl $0x40, %eax
cmpl $0x0, %eax
jne 0x4f4b
movq -0x36038(%rbp), %rax
movl 0x4(%rax), %eax
andl $0x200, %eax            # imm = 0x200
cmpl $0x0, %eax
je 0x50e6
movq -0x365b0(%rbp), %rdi
addq $0x98, %rdi
callq 0x6a60
jmp 0x4f60
movq -0x365b0(%rbp), %rax
movq 0x40(%rax), %rax
movq %rax, -0x36600(%rbp)
leaq -0x36058(%rbp), %rdi
callq 0x3180
movq %rax, -0x365f8(%rbp)
leaq -0x36301(%rbp), %rdi
movq %rdi, -0x365f0(%rbp)
callq 0x3620
movq -0x365f8(%rbp), %rsi
movq -0x365f0(%rbp), %rdx
leaq -0x36300(%rbp), %rdi
callq 0x3480
jmp 0x4fb4
movq -0x365b0(%rbp), %rsi
leaq -0x36328(%rbp), %rdi
callq 0x3190
jmp 0x4fc9
movq -0x36600(%rbp), %rsi
movq -0x365b0(%rbp), %rdi
leaq -0x36300(%rbp), %rdx
leaq -0x36328(%rbp), %rcx
callq 0xb920
jmp 0x4fec
leaq -0x36328(%rbp), %rdi
callq 0x3280
leaq -0x36300(%rbp), %rdi
callq 0x3280
leaq -0x36301(%rbp), %rdi
callq 0x33e0
movq -0x365b0(%rbp), %rdi
addq $0x98, %rdi
callq 0x6a90
jmp 0x5025
leaq -0x36348(%rbp), %rdi
leaq -0x36058(%rbp), %rsi
callq 0x3190
jmp 0x503a
movq -0x365b0(%rbp), %rdi
leaq -0x36348(%rbp), %rsi
callq 0x5e90
jmp 0x504f
leaq -0x36348(%rbp), %rdi
callq 0x3280
jmp 0x50e6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x36068(%rbp)
movl %eax, -0x3606c(%rbp)
jmp 0x50b2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x36068(%rbp)
movl %eax, -0x3606c(%rbp)
jmp 0x50a6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x36068(%rbp)
movl %eax, -0x3606c(%rbp)
leaq -0x36328(%rbp), %rdi
callq 0x3280
leaq -0x36300(%rbp), %rdi
callq 0x3280
leaq -0x36301(%rbp), %rdi
callq 0x33e0
jmp 0x53d4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x36068(%rbp)
movl %eax, -0x3606c(%rbp)
leaq -0x36348(%rbp), %rdi
callq 0x3280
jmp 0x53d4
movq -0x36038(%rbp), %rax
movl 0x4(%rax), %eax
andl $0x8, %eax
cmpl $0x0, %eax
je 0x5394
movq -0x365b0(%rbp), %rdi
addq $0x98, %rdi
callq 0x6a60
jmp 0x5111
movq -0x365b0(%rbp), %rax
movq 0x40(%rax), %rax
movq %rax, -0x36618(%rbp)
leaq -0x36058(%rbp), %rdi
callq 0x3180
movq %rax, -0x36610(%rbp)
leaq -0x36369(%rbp), %rdi
movq %rdi, -0x36608(%rbp)
callq 0x3620
movq -0x36610(%rbp), %rsi
movq -0x36608(%rbp), %rdx
leaq -0x36368(%rbp), %rdi
callq 0x3480
jmp 0x5165
movq -0x365b0(%rbp), %rsi
leaq -0x36390(%rbp), %rdi
callq 0x3190
jmp 0x517a
movq -0x36618(%rbp), %rsi
movq -0x365b0(%rbp), %rdi
leaq -0x36368(%rbp), %rdx
leaq -0x36390(%rbp), %rcx
callq 0xb920
jmp 0x519d
leaq -0x36390(%rbp), %rdi
callq 0x3280
leaq -0x36368(%rbp), %rdi
callq 0x3280
leaq -0x36369(%rbp), %rdi
callq 0x33e0
movq -0x365b0(%rbp), %rax
movq 0x40(%rax), %rax
movq %rax, -0x36630(%rbp)
leaq -0x36090(%rbp), %rdi
callq 0x3180
movq %rax, -0x36628(%rbp)
leaq -0x36499(%rbp), %rdi
movq %rdi, -0x36620(%rbp)
callq 0x3620
movq -0x36628(%rbp), %rsi
movq -0x36620(%rbp), %rdx
leaq -0x36498(%rbp), %rdi
callq 0x3480
jmp 0x5215
movq -0x365b0(%rbp), %rsi
leaq -0x364c0(%rbp), %rdi
callq 0x3190
jmp 0x522a
movq -0x36630(%rbp), %rdx
movq -0x365b0(%rbp), %rsi
leaq -0x36478(%rbp), %rdi
leaq -0x36498(%rbp), %rcx
leaq -0x364c0(%rbp), %r8
callq 0xacc0
jmp 0x5254
leaq -0x364c0(%rbp), %rdi
callq 0x3280
leaq -0x36498(%rbp), %rdi
callq 0x3280
leaq -0x36499(%rbp), %rdi
callq 0x33e0
movq -0x365b0(%rbp), %rdi
addq $0x98, %rdi
callq 0x6a90
jmp 0x528d
leaq -0x365a8(%rbp), %rdi
movq %rdi, -0x36638(%rbp)
leaq -0x36478(%rbp), %rsi
movl $0xe8, %edx
callq 0x3300
movq -0x36638(%rbp), %rsi
movq %rsp, %rdi
movl $0x1d, %ecx
rep  movsq (%rsi), %es:(%rdi)
movq -0x365b0(%rbp), %rdi
callq 0x5ff0
jmp 0x52cc
jmp 0x5394
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x36068(%rbp)
movl %eax, -0x3606c(%rbp)
jmp 0x5323
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x36068(%rbp)
movl %eax, -0x3606c(%rbp)
jmp 0x5317
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x36068(%rbp)
movl %eax, -0x3606c(%rbp)
leaq -0x36390(%rbp), %rdi
callq 0x3280
leaq -0x36368(%rbp), %rdi
callq 0x3280
leaq -0x36369(%rbp), %rdi
callq 0x33e0
jmp 0x53d4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x36068(%rbp)
movl %eax, -0x3606c(%rbp)
jmp 0x5386
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x36068(%rbp)
movl %eax, -0x3606c(%rbp)
jmp 0x537a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x36068(%rbp)
movl %eax, -0x3606c(%rbp)
leaq -0x364c0(%rbp), %rdi
callq 0x3280
leaq -0x36498(%rbp), %rdi
callq 0x3280
leaq -0x36499(%rbp), %rdi
callq 0x33e0
jmp 0x53d4
movq -0x36038(%rbp), %rax
movl 0xc(%rax), %eax
movl %eax, %ecx
addq $0x10, %rcx
movslq -0x18(%rbp), %rax
addq %rcx, %rax
movl %eax, -0x18(%rbp)
leaq -0x360a8(%rbp), %rdi
callq 0x6a00
leaq -0x36090(%rbp), %rdi
callq 0x3280
leaq -0x36058(%rbp), %rdi
callq 0x3280
jmp 0x53fa
leaq -0x360a8(%rbp), %rdi
callq 0x6a00
leaq -0x36090(%rbp), %rdi
callq 0x3280
leaq -0x36058(%rbp), %rdi
callq 0x3280
jmp 0x540c
jmp 0x4c1a
jmp 0x5401
jmp 0x5403
addq $0x36720, %rsp          # imm = 0x36720
popq %rbp
retq
movq -0x36068(%rbp), %rdi
callq 0x3610
nopl (%rax,%rax)