// File: /workspace/github_cpp_makefile_star2_O3/AndreRenaud[P]simple_uart/simple_uart_test.c
// Function: test_read_line
void test_read_line(void)
{
    struct simple_uart *u1, *u2;
    char buffer[10];
    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);

    simple_uart_write(u1, "a", 1);
    simple_uart_write(u1, "b", 1);
    simple_uart_write(u1, "\r", 1);
    TEST_ASSERT(simple_uart_read_line(u2, buffer, sizeof(buffer), 100) == 2);
    TEST_ASSERT(strcmp(buffer, "ab") == 0);

    simple_uart_write(u2, "cd\n", 3);
    TEST_ASSERT(simple_uart_read_line(u1, buffer, sizeof(buffer), 100) == 2);
    TEST_ASSERT(strcmp(buffer, "cd") == 0);

    simple_uart_write(u2, "ef", 2);
    TEST_ASSERT(simple_uart_read_line(u1, buffer, sizeof(buffer), 100) < 0);
    TEST_ASSERT(strcmp(buffer, "ef") == 0);

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

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x10, %rsp
callq 0x416a
movl %eax, %ebx
leaq 0x2c73(%rip), %rdi      # 0x737f
leaq 0x2c77(%rip), %rdx      # 0x738a
movl $0x1c200, %esi          # imm = 0x1C200
callq 0x5a07
movq %rax, %r14
xorl %edi, %edi
testq %rax, %rax
setne %dil
leaq 0x2c5e(%rip), %rsi      # 0x738e
leaq 0x3228(%rip), %rcx      # 0x795f
leaq 0x2c70(%rip), %r8       # 0x73ae
movl $0x8b, %edx
xorl %eax, %eax
callq 0x28df
testl %eax, %eax
je 0x49c9
leaq 0x2c60(%rip), %rdi      # 0x73b9
leaq 0x2c2a(%rip), %rdx      # 0x738a
movl $0x1c200, %esi          # imm = 0x1C200
callq 0x5a07
movq %rax, %r15
xorl %edi, %edi
testq %rax, %rax
setne %dil
leaq 0x2c11(%rip), %rsi      # 0x738e
leaq 0x31db(%rip), %rcx      # 0x795f
leaq 0x2c39(%rip), %r8       # 0x73c4
movl $0x8d, %edx
xorl %eax, %eax
callq 0x28df
testl %eax, %eax
je 0x49c9
leaq 0x2dbb(%rip), %rsi      # 0x7561
movl $0x1, %edx
movq %r14, %rdi
callq 0x58f7
leaq 0x2de8(%rip), %rsi      # 0x75a2
movl $0x1, %edx
movq %r14, %rdi
callq 0x58f7
leaq 0x2d95(%rip), %rsi      # 0x7563
movl $0x1, %edx
movq %r14, %rdi
callq 0x58f7
leaq 0x6(%rsp), %rsi
movl $0x64, %ecx
movq %r15, %rdi
movl $0xa, %edx
callq 0x6685
xorl %edi, %edi
cmpq $0x2, %rax
sete %dil
leaq 0x2b8b(%rip), %rsi      # 0x738e
leaq 0x3155(%rip), %rcx      # 0x795f
leaq 0x2d54(%rip), %r8       # 0x7565
movl $0x92, %edx
xorl %eax, %eax
callq 0x28df
testl %eax, %eax
je 0x49c9
movzwl 0x6(%rsp), %eax
xorl $0x6261, %eax           # imm = 0x6261
movzbl 0x8(%rsp), %ecx
xorl %edi, %edi
orw %ax, %cx
sete %dil
leaq 0x2b4a(%rip), %rsi      # 0x738e
leaq 0x3114(%rip), %rcx      # 0x795f
leaq 0x2d52(%rip), %r8       # 0x75a4
movl $0x93, %edx
xorl %eax, %eax
callq 0x28df
testl %eax, %eax
je 0x49c9
leaq 0x2d51(%rip), %rsi      # 0x75be
movl $0x3, %edx
movq %r15, %rdi
callq 0x58f7
leaq 0x6(%rsp), %rsi
movl $0x64, %ecx
movq %r14, %rdi
movl $0xa, %edx
callq 0x6685
xorl %edi, %edi
cmpq $0x2, %rax
sete %dil
leaq 0x2aec(%rip), %rsi      # 0x738e
leaq 0x30b6(%rip), %rcx      # 0x795f
leaq 0x2d12(%rip), %r8       # 0x75c2
movl $0x96, %edx
xorl %eax, %eax
callq 0x28df
testl %eax, %eax
je 0x49c9
movzwl 0x6(%rsp), %eax
xorl $0x6463, %eax           # imm = 0x6463
movzbl 0x8(%rsp), %ecx
xorl %edi, %edi
orw %ax, %cx
sete %dil
leaq 0x2aab(%rip), %rsi      # 0x738e
leaq 0x3075(%rip), %rcx      # 0x795f
leaq 0x2d10(%rip), %r8       # 0x7601
movl $0x97, %edx
xorl %eax, %eax
callq 0x28df
testl %eax, %eax
je 0x49c9
leaq 0x2d0f(%rip), %rsi      # 0x761b
movl $0x2, %edx
movq %r15, %rdi
callq 0x58f7
leaq 0x6(%rsp), %rsi
movl $0x64, %ecx
movq %r14, %rdi
movl $0xa, %edx
callq 0x6685
shrq $0x3f, %rax
leaq 0x2a53(%rip), %rsi      # 0x738e
leaq 0x301d(%rip), %rcx      # 0x795f
leaq 0x2cd5(%rip), %r8       # 0x761e
movl %eax, %edi
movl $0x9a, %edx
xorl %eax, %eax
callq 0x28df
testl %eax, %eax
je 0x49c9
movzwl 0x6(%rsp), %eax
xorl $0x6665, %eax           # imm = 0x6665
movzbl 0x8(%rsp), %ecx
xorl %edi, %edi
orw %ax, %cx
sete %dil
leaq 0x2a14(%rip), %rsi      # 0x738e
leaq 0x2fde(%rip), %rcx      # 0x795f
leaq 0x2cd1(%rip), %r8       # 0x7659
movl $0x9b, %edx
xorl %eax, %eax
callq 0x28df
testl %eax, %eax
je 0x49c9
movq %r14, %rdi
callq 0x59cf
movq %r15, %rdi
callq 0x59cf
movl %ebx, %edi
movl $0x1, %esi
callq 0x2270
movl %ebx, %edi
xorl %esi, %esi
xorl %edx, %edx
callq 0x22f0
addq $0x10, %rsp
popq %rbx
popq %r14
popq %r15
retq
callq 0x31c2