// File: /workspace/github_cpp_makefile_star2_O2/AndreRenaud[P]simple_uart/simple_uart_test.c
// Function: test_loopback_random
void test_loopback_random(void)
{
    struct simple_uart *u1, *u2;
    pid_t pid;

    pid = setup_loopback();

    u1 = simple_uart_open(UART_LOOPBACK_1, 115200, "8N1");
    TEST_ASSERT(u1 != NULL);
    u2 = simple_uart_open(UART_LOOPBACK_2, 115200, "8N1");
    TEST_ASSERT(u2 != NULL);

    for (int i = 0; i < 100; i++) {
        unsigned char tx[100];
        unsigned char rx[sizeof(tx) * 2];
        int tx_len = 1 + (rand() % (sizeof(tx) - 1));
        for (int j = 0; j < tx_len; j++)
            tx[j] = rand() % 256;
        memset(rx, 0, sizeof(rx));
        TEST_ASSERT(simple_uart_write(u1, tx, tx_len) == tx_len);
        usleep(1000); // Give it time to get to the other end
        TEST_ASSERT(simple_uart_has_data(u2) == tx_len);
        TEST_ASSERT(simple_uart_read(u2, rx, sizeof(rx)) == tx_len);
        TEST_ASSERT(memcmp(rx, tx, tx_len) == 0);
    }

    simple_uart_close(u1);
    simple_uart_close(u2);
    shutdown_loopback(pid);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x158, %rsp            # imm = 0x158
callq 0x3e43
movl %eax, %ebx
leaq 0x31f1(%rip), %rdi      # 0x7347
leaq 0x31f5(%rip), %rdx      # 0x7352
movl $0x1c200, %esi          # imm = 0x1C200
callq 0x54e4
xorl %edi, %edi
movq %rax, 0x10(%rsp)
testq %rax, %rax
setne %dil
leaq 0x31da(%rip), %rsi      # 0x7356
leaq 0x37a4(%rip), %rcx      # 0x7927
leaq 0x31ec(%rip), %r8       # 0x7376
pushq $0x6b
popq %rdx
xorl %eax, %eax
callq 0x269a
testl %eax, %eax
je 0x4383
movl %ebx, 0x8(%rsp)
leaq 0x31da(%rip), %rdi      # 0x7381
leaq 0x31a4(%rip), %rdx      # 0x7352
movl $0x1c200, %esi          # imm = 0x1C200
callq 0x54e4
movq %rax, %r15
xorl %edi, %edi
testq %rax, %rax
setne %dil
leaq 0x318b(%rip), %rsi      # 0x7356
leaq 0x3755(%rip), %rcx      # 0x7927
leaq 0x31b3(%rip), %r8       # 0x738c
pushq $0x6d
popq %rdx
xorl %eax, %eax
callq 0x269a
testl %eax, %eax
je 0x4383
leaq 0x90(%rsp), %r12
leaq 0x20(%rsp), %rbx
leaq 0x3157(%rip), %r13      # 0x7356
xorl %eax, %eax
movq %r15, 0x18(%rsp)
cmpl $0x64, %eax
je 0x4356
movl %eax, 0xc(%rsp)
movq %r13, %rbp
movq %rbx, %r13
movq %r12, %rbx
callq 0x23e0
cltq
xorl %edx, %edx
pushq $0x63
popq %rcx
divq %rcx
movq %rdx, %r12
movq %rdx, %r14
incq %r14
xorl %r15d, %r15d
cmpq %r15, %r14
je 0x424b
callq 0x23e0
movb %al, 0x20(%rsp,%r15)
incq %r15
jmp 0x4237
leal 0x1(%r12), %r14d
movl $0xc8, %edx
movq %rbx, %r12
movq %rbx, %rdi
xorl %esi, %esi
callq 0x21b0
movq 0x10(%rsp), %rdi
movq %r13, %rbx
movq %r13, %rsi
movq %r14, %rdx
callq 0x53e0
xorl %edi, %edi
cmpq %r14, %rax
sete %dil
movq %rbp, %r13
movq %rbp, %rsi
pushq $0x76
popq %rdx
leaq 0x3699(%rip), %rbp      # 0x7927
movq %rbp, %rcx
leaq 0x31f7(%rip), %r8       # 0x748f
xorl %eax, %eax
callq 0x269a
testl %eax, %eax
je 0x4383
movl $0x3e8, %edi            # imm = 0x3E8
callq 0x2410
movq 0x18(%rsp), %r15
movq %r15, %rdi
callq 0x5a71
xorl %edi, %edi
cmpl %r14d, %eax
sete %dil
movq %r13, %rsi
pushq $0x78
popq %rdx
movq %rbp, %rcx
leaq 0x31e4(%rip), %r8       # 0x74bb
xorl %eax, %eax
callq 0x269a
testl %eax, %eax
je 0x4383
movl $0xc8, %edx
movq %r15, %rdi
movq %r12, %rsi
callq 0x52a4
xorl %edi, %edi
cmpq %r14, %rax
sete %dil
movq %r13, %rsi
pushq $0x79
popq %rdx
movq %rbp, %rcx
leaq 0x31cf(%rip), %r8       # 0x74de
xorl %eax, %eax
callq 0x269a
testl %eax, %eax
je 0x4383
movq %r12, %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x22c0
xorl %edi, %edi
testl %eax, %eax
sete %dil
movq %r13, %rsi
pushq $0x7a
popq %rdx
movq %rbp, %rcx
leaq 0x31cd(%rip), %r8       # 0x750d
xorl %eax, %eax
callq 0x269a
testl %eax, %eax
je 0x4383
movl 0xc(%rsp), %eax
incl %eax
jmp 0x4206
movq 0x10(%rsp), %rdi
callq 0x54b1
movq %r15, %rdi
callq 0x54b1
movl 0x8(%rsp), %edi
callq 0x3eba
addq $0x158, %rsp            # imm = 0x158
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x2f01