// File: /workspace/github_c_makefile_star2_O0/lupyuen[P]lora-sx1262/src/sx126x-linux.c
// Function: sx126x_hal_read
static int sx126x_hal_read( 
    const void* context, const uint8_t* command, const uint16_t command_length,
    uint8_t* data, const uint16_t data_length, uint8_t *status ) {
    printf("sx126x_hal_read: command_length=%d, data_length=%d\n", command_length, data_length);

    //  Total length is command + data length
    uint16_t len = command_length + data_length;
    assert(len > 0);
    assert(len <= SPI_BUFFER_SIZE);

    //  Clear the SPI Transmit and Receive buffers
    memset(&spi_tx_buf, 0, len);
    memset(&spi_rx_buf, 0, len);

    //  Copy command bytes to SPI Transmit Buffer
    memcpy(&spi_tx_buf, command, command_length);

    //  Transmit and receive the SPI buffers
    int rc = transfer_spi(spi_tx_buf, spi_rx_buf, len);
    assert(rc == 0);

    //  Copy SPI Receive buffer to data buffer
    memcpy(data, &spi_rx_buf[command_length], data_length);

    //  Return the second SPI byte received as status
    if (status != NULL) {
        assert(len >= 2);
        *status = spi_rx_buf[1];
    }
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movw %r8w, %ax
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movw %dx, -0x12(%rbp)
movq %rcx, -0x20(%rbp)
movw %ax, -0x22(%rbp)
movq %r9, -0x30(%rbp)
movzwl -0x12(%rbp), %esi
movzwl -0x22(%rbp), %edx
leaq 0x2d3e(%rip), %rdi      # 0x9c01
movb $0x0, %al
callq 0x2050
movzwl -0x12(%rbp), %eax
movzwl -0x22(%rbp), %ecx
addl %ecx, %eax
movw %ax, -0x32(%rbp)
movzwl -0x32(%rbp), %eax
cmpl $0x0, %eax
jle 0x6ee3
jmp 0x6f02
leaq 0x2c26(%rip), %rdi      # 0x9b10
leaq 0x2842(%rip), %rsi      # 0x9733
movl $0x250, %edx            # imm = 0x250
leaq 0x2d38(%rip), %rcx      # 0x9c35
callq 0x2130
movzwl -0x32(%rbp), %eax
cmpl $0x400, %eax            # imm = 0x400
jg 0x6f0f
jmp 0x6f2e
leaq 0x2c67(%rip), %rdi      # 0x9b7d
leaq 0x2816(%rip), %rsi      # 0x9733
movl $0x251, %edx            # imm = 0x251
leaq 0x2d0c(%rip), %rcx      # 0x9c35
callq 0x2130
movzwl -0x32(%rbp), %eax
movl %eax, %edx
leaq 0x75b5(%rip), %rdi      # 0xe4f0
xorl %esi, %esi
callq 0x2100
movzwl -0x32(%rbp), %eax
movl %eax, %edx
leaq 0x79a1(%rip), %rdi      # 0xe8f0
xorl %esi, %esi
callq 0x2100
movq -0x10(%rbp), %rsi
movzwl -0x12(%rbp), %eax
movl %eax, %edx
leaq 0x7589(%rip), %rdi      # 0xe4f0
callq 0x2180
leaq 0x757d(%rip), %rdi      # 0xe4f0
leaq 0x7976(%rip), %rsi      # 0xe8f0
movzwl -0x32(%rbp), %edx
callq 0x76c0
movl %eax, -0x38(%rbp)
cmpl $0x0, -0x38(%rbp)
jne 0x6f8e
jmp 0x6fad
leaq 0x2796(%rip), %rdi      # 0x972b
leaq 0x2797(%rip), %rsi      # 0x9733
movl $0x25c, %edx            # imm = 0x25C
leaq 0x2c8d(%rip), %rcx      # 0x9c35
callq 0x2130
movq -0x20(%rbp), %rdi
movzwl -0x12(%rbp), %eax
leaq 0x7934(%rip), %rsi      # 0xe8f0
addq %rax, %rsi
movzwl -0x22(%rbp), %eax
movl %eax, %edx
callq 0x2180
cmpq $0x0, -0x30(%rbp)
je 0x7007
movzwl -0x32(%rbp), %eax
cmpl $0x2, %eax
jl 0x6fdc
jmp 0x6ffb
leaq 0x2cbb(%rip), %rdi      # 0x9c9e
leaq 0x2749(%rip), %rsi      # 0x9733
movl $0x263, %edx            # imm = 0x263
leaq 0x2c3f(%rip), %rcx      # 0x9c35
callq 0x2130
movb 0x78f0(%rip), %cl       # 0xe8f1
movq -0x30(%rbp), %rax
movb %cl, (%rax)
xorl %eax, %eax
addq $0x40, %rsp
popq %rbp
retq
nop