// File: /workspace/github_cpp_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
leaq -0x36(%rbp), %r15
leaq -0x2a(%rbp), %rbx
leaq 0x2bfc(%rip), %r14      # 0x51c8
movq 0x29fd(%rip), %r12      # 0x4fd0
movl 0x2b83(%rip), %edi      # 0x515c
movl $0x6, %edx
movq %r15, %rsi
movl $0x100, %ecx            # imm = 0x100
leaq 0x2b8f(%rip), %r8       # 0x517c
leaq 0x2b70(%rip), %r9       # 0x5164
callq 0x2100
testl %eax, %eax
jns 0x2639
movl $0x20, %edx
movq %r12, %rdi
leaq 0x9f8(%rip), %rsi       # 0x3004
callq 0x21a0
movq (%r12), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x2140
movsbl %al, %esi
movq %r12, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x20e0
movq %r15, %rdi
leaq -0x29(%rbp), %rsi
leaq -0x30(%rbp), %rdx
movq %rbx, %rcx
callq 0x2578
cmpb $0x1, -0x2a(%rbp)
jne 0x26ac
movq %r14, %rdi
callq 0x21e0
testl %eax, %eax
jne 0x276c
movl -0x30(%rbp), %ecx
movl 0x2b35(%rip), %edx      # 0x51a0
incl %edx
movl %ecx, %eax
subl %edx, %eax
jb 0x26fa
cmpl 0x2b27(%rip), %ecx      # 0x51a4
ja 0x26fa
cmpb $0x0, -0x29(%rbp)
je 0x270b
movq 0x2b28(%rip), %rcx      # 0x51b8
movq 0x2b29(%rip), %rdx      # 0x51c0
movq %rdx, (%rcx,%rax,8)
movl $0x10, %edx
movq %r12, %rdi
leaq 0x98c(%rip), %rsi       # 0x3036
jmp 0x2725
movl $0xc, %edx
movq %r12, %rdi
leaq 0x99e(%rip), %rsi       # 0x3059
callq 0x21a0
movl -0x30(%rbp), %esi
movq %r12, %rdi
callq 0x20d0
movq %rax, %r13
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x2140
movsbl %al, %esi
movq %r13, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x20e0
jmp 0x25d3
movl $0x11, %edx
movq %r12, %rdi
leaq 0x93e(%rip), %rsi       # 0x3047
jmp 0x2725
movq 0x2a96(%rip), %rcx      # 0x51a8
movb $0x1, (%rcx,%rax)
movl $0x10, %edx
movq %r12, %rdi
leaq 0x900(%rip), %rsi       # 0x3025
callq 0x21a0
movl -0x30(%rbp), %esi
movq %r12, %rdi
callq 0x20d0
movq %rax, %r13
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x2140
movsbl %al, %esi
movq %r13, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x20e0
movq %r14, %rdi
callq 0x20f0
jmp 0x25d3
movl %eax, %edi
callq 0x20c0