// File: adhipradhana[P]sliding-window-protocol/src/sendfile.cpp
// Function: get_ack()
void get_ack() {
    char ack[ACK_LENGTH];
    unsigned int seq_num;
    bool is_check_sum_valid, is_nak;

    while(true) {
        int ack_size = recvfrom(sock, ack, ACK_LENGTH, MSG_WAITALL,(struct sockaddr *)&from, &sock_length);
        if (ack_size < 0) {
            cout << "Packet loss on receiving message" << endl;
            // exit(1);
        }

        // Create ack from buffer
        read_ack(ack, &is_nak, &seq_num, &is_check_sum_valid);

        if (is_check_sum_valid) {
            mt.lock();
            if (seq_num >= lar + 1 && seq_num <= lfs) {
                if (!is_nak) {
                    has_ack_received[seq_num - (lar + 1)] = true;
                    cout << "Receiving ACK : " << seq_num << endl;
                } else {
                    packet_send_time[seq_num - (lar + 1)] = TMIN;
                    cout << "Receiving NAK : " << seq_num << endl;
                }
            } else {
                cout << "ACK out of bound " << seq_num << endl;
            }
            mt.unlock();
        } else {
            cout << "ERROR ACK : " << seq_num << endl;
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movl 0x49fe(%rip), %edi      # 0x715c
leaq -0x6(%rbp), %rsi
movl $0x6, %edx
movl $0x100, %ecx            # imm = 0x100
leaq 0x4a09(%rip), %r8       # 0x717c
leaq 0x49ea(%rip), %r9       # 0x7164
callq 0x20e0
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
jge 0x27aa
movq 0x4841(%rip), %rdi      # 0x6fd0
leaq 0x186e(%rip), %rsi      # 0x4004
callq 0x2120
movq %rax, %rdi
movq 0x4813(%rip), %rsi      # 0x6fb8
callq 0x2160
leaq -0x6(%rbp), %rdi
leaq -0xe(%rbp), %rsi
leaq -0xc(%rbp), %rdx
leaq -0xd(%rbp), %rcx
callq 0x26c0
testb $0x1, -0xd(%rbp)
je 0x28d4
leaq 0x49f8(%rip), %rdi      # 0x71c8
callq 0x3450
movl -0xc(%rbp), %eax
movl 0x49c2(%rip), %ecx      # 0x71a0
addl $0x1, %ecx
cmpl %ecx, %eax
jb 0x2899
movl -0xc(%rbp), %eax
cmpl 0x49b2(%rip), %eax      # 0x71a4
ja 0x2899
testb $0x1, -0xe(%rbp)
jne 0x2848
movq 0x49a3(%rip), %rax      # 0x71a8
movl -0xc(%rbp), %ecx
movl 0x4992(%rip), %edx      # 0x71a0
addl $0x1, %edx
subl %edx, %ecx
movl %ecx, %ecx
movb $0x1, (%rax,%rcx)
movq 0x47b0(%rip), %rdi      # 0x6fd0
leaq 0x17fe(%rip), %rsi      # 0x4025
callq 0x2120
movq %rax, %rdi
movl -0xc(%rbp), %esi
callq 0x21c0
movq %rax, %rdi
movq 0x4777(%rip), %rsi      # 0x6fb8
callq 0x2160
jmp 0x2897
movq 0x4969(%rip), %rax      # 0x71b8
movl -0xc(%rbp), %ecx
movl 0x4948(%rip), %edx      # 0x71a0
addl $0x1, %edx
subl %edx, %ecx
movl %ecx, %ecx
movq 0x495a(%rip), %rdx      # 0x71c0
movq %rdx, (%rax,%rcx,8)
movq 0x475f(%rip), %rdi      # 0x6fd0
leaq 0x17be(%rip), %rsi      # 0x4036
callq 0x2120
movq %rax, %rdi
movl -0xc(%rbp), %esi
callq 0x21c0
movq %rax, %rdi
movq 0x4726(%rip), %rsi      # 0x6fb8
callq 0x2160
jmp 0x28c6
movq 0x4730(%rip), %rdi      # 0x6fd0
leaq 0x17a0(%rip), %rsi      # 0x4047
callq 0x2120
movq %rax, %rdi
movl -0xc(%rbp), %esi
callq 0x21c0
movq %rax, %rdi
movq 0x46f7(%rip), %rsi      # 0x6fb8
callq 0x2160
leaq 0x48fb(%rip), %rdi      # 0x71c8
callq 0x3480
jmp 0x2901
movq 0x46f5(%rip), %rdi      # 0x6fd0
leaq 0x1777(%rip), %rsi      # 0x4059
callq 0x2120
movq %rax, %rdi
movl -0xc(%rbp), %esi
callq 0x21c0
movq %rax, %rdi
movq 0x46bc(%rip), %rsi      # 0x6fb8
callq 0x2160
jmp 0x2758
nopw %cs:(%rax,%rax)