// File: /workspace/github_c_makefile_star2_O0/ulisses[P]ftp-client-server/servidorc2.c
// Function: trataPedido
void trataPedido(int te, int tp, Datagrama *novo, int newSock, ConState *con, struct sockaddr_in *from, int fromlen){
	char *buffer;
	if((novo->flags & FL_DIR) /*&& strstr(novo->data, "dir.cmd")*/) { //corresponde ao comando DIR
		int status, pid = fork();
		if(pid == 0){//executar comando ls
			execl("./dir", NULL,NULL);
			exit(1);
		}
		wait(&status);
		transfereFich( te, tp, newSock, "dir.cmd", con->clientBuffer, con, from, fromlen);
		return ;
	}
	if((novo->flags & FL_GET) && strstr(novo->data, "wait")){
		Datagrama *res = initDatagrama();
		strcpy(res->data, "fim de wait\n");
		printf("A preparar para domir...\n");
		sleep(10);
		printf("Acordou\n");
		res->flags = FL_FIN;
		buffer = muxDatagrama(res);
		n = sendto(newSock,buffer,strlen(buffer), 0, (struct sockaddr *)from, fromlen);
		return ;
	}
	if((novo->flags & FL_GET)) { 
		printf("get %s\n", novo->data);
		transfereFich(te, tp, newSock, novo->data, con->clientBuffer, con, from, fromlen);
		return ;
	}
	if((novo->flags & FL_PUT)) {
		FILE *f = NULL;
		f = fopen(novo->data, "w+");
		printf("put %s\n", novo->data);
		recebeFicheiro(f, newSock, from, fromlen);
		return ;
	}
	else {
		Datagrama *dados;
		dados = initDatagrama();
		dados->flags = (FL_ERRO | FL_FIN) ;
		buffer = muxDatagrama(dados);
		n = sendto(newSock,buffer,strlen(buffer), 0, (struct sockaddr *)from, fromlen);
		free(dados);
		free(buffer);
		return ;
	}
	
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movl 0x10(%rbp), %eax
movl %edi, -0x4(%rbp)
movl %esi, -0x8(%rbp)
movq %rdx, -0x10(%rbp)
movl %ecx, -0x14(%rbp)
movq %r8, -0x20(%rbp)
movq %r9, -0x28(%rbp)
movq -0x10(%rbp), %rax
movl 0x10(%rax), %eax
andl $0x20, %eax
cmpl $0x0, %eax
je 0x29bc
callq 0x1220
movl %eax, -0x38(%rbp)
cmpl $0x0, -0x38(%rbp)
jne 0x297f
leaq 0x17fe(%rip), %rdi      # 0x4165
xorl %eax, %eax
movl %eax, %edx
movq %rdx, %rsi
movb $0x0, %al
callq 0x11f0
movl $0x1, %edi
callq 0x11c0
leaq -0x34(%rbp), %rdi
callq 0x1210
movl -0x4(%rbp), %edi
movl -0x8(%rbp), %esi
movl -0x14(%rbp), %edx
movq -0x20(%rbp), %rax
movl (%rax), %r8d
movq -0x20(%rbp), %r9
movq -0x28(%rbp), %r10
movl 0x10(%rbp), %eax
leaq 0x17c1(%rip), %rcx      # 0x416b
movq %r10, (%rsp)
movl %eax, 0x8(%rsp)
callq 0x23b0
jmp 0x2ba0
movq -0x10(%rbp), %rax
movl 0x10(%rax), %eax
andl $0x8, %eax
cmpl $0x0, %eax
je 0x2a83
movq -0x10(%rbp), %rdi
addq $0x18, %rdi
leaq 0x1795(%rip), %rsi      # 0x4173
callq 0x1230
cmpq $0x0, %rax
je 0x2a83
callq 0x1760
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rdi
addq $0x18, %rdi
leaq 0x1773(%rip), %rsi      # 0x4178
callq 0x1050
leaq 0x1774(%rip), %rdi      # 0x4185
movb $0x0, %al
callq 0x1090
movl $0xa, %edi
callq 0x1200
leaq 0x1776(%rip), %rdi      # 0x419f
movb $0x0, %al
callq 0x1090
movq -0x40(%rbp), %rax
movl $0x4, 0x10(%rax)
movq -0x40(%rbp), %rdi
callq 0x1900
movq %rax, -0x30(%rbp)
movl -0x14(%rbp), %eax
movl %eax, -0x5c(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x30(%rbp), %rdi
callq 0x1070
movl -0x5c(%rbp), %edi
movq -0x58(%rbp), %rsi
movq %rax, %rdx
movq -0x28(%rbp), %r8
movl 0x10(%rbp), %r9d
xorl %ecx, %ecx
callq 0x10b0
movl %eax, 0x3ba2(%rip)      # 0x6620
jmp 0x2ba0
movq -0x10(%rbp), %rax
movl 0x10(%rax), %eax
andl $0x8, %eax
cmpl $0x0, %eax
je 0x2add
movq -0x10(%rbp), %rsi
addq $0x18, %rsi
leaq 0x1707(%rip), %rdi      # 0x41a8
movb $0x0, %al
callq 0x1090
movl -0x4(%rbp), %edi
movl -0x8(%rbp), %esi
movl -0x14(%rbp), %edx
movq -0x10(%rbp), %rcx
addq $0x18, %rcx
movq -0x20(%rbp), %rax
movl (%rax), %r8d
movq -0x20(%rbp), %r9
movq -0x28(%rbp), %r10
movl 0x10(%rbp), %eax
movq %r10, (%rsp)
movl %eax, 0x8(%rsp)
callq 0x23b0
jmp 0x2ba0
movq -0x10(%rbp), %rax
movl 0x10(%rax), %eax
andl $0x40, %eax
cmpl $0x0, %eax
je 0x2b37
movq $0x0, -0x48(%rbp)
movq -0x10(%rbp), %rdi
addq $0x18, %rdi
leaq 0x16ad(%rip), %rsi      # 0x41b0
callq 0x1170
movq %rax, -0x48(%rbp)
movq -0x10(%rbp), %rsi
addq $0x18, %rsi
leaq 0x1698(%rip), %rdi      # 0x41b3
movb $0x0, %al
callq 0x1090
movq -0x48(%rbp), %rdi
movl -0x14(%rbp), %esi
movq -0x28(%rbp), %rdx
movl 0x10(%rbp), %ecx
callq 0x1cd0
jmp 0x2ba0
callq 0x1760
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
movl $0x14, 0x10(%rax)
movq -0x50(%rbp), %rdi
callq 0x1900
movq %rax, -0x30(%rbp)
movl -0x14(%rbp), %eax
movl %eax, -0x6c(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x30(%rbp), %rdi
callq 0x1070
movl -0x6c(%rbp), %edi
movq -0x68(%rbp), %rsi
movq %rax, %rdx
movq -0x28(%rbp), %r8
movl 0x10(%rbp), %r9d
xorl %ecx, %ecx
callq 0x10b0
movl %eax, 0x3a92(%rip)      # 0x6620
movq -0x50(%rbp), %rdi
callq 0x1030
movq -0x30(%rbp), %rdi
callq 0x1030
addq $0x80, %rsp
popq %rbp
retq
nopl (%rax)