// File: /workspace/github_cpp_makefile_star2_O1/AndreRenaud[P]simple_uart/simple_uart_test.c
// Function: test_logfile
void test_logfile(void)
{
    struct simple_uart *u1, *u2;
    char buffer[20];
    pid_t pid;
    const char *logfile = "/tmp/simple_uart_test.log";
    FILE *fp;
    char log_contents[100];

    /* Remove any existing log file */
    unlink(logfile);

    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);

    /* Set logfile on u1 */
    TEST_ASSERT(simple_uart_set_logfile(u1, logfile) == 0);

    /* Test error cases */
    TEST_ASSERT(simple_uart_set_logfile(NULL, logfile) == -EINVAL);
    TEST_ASSERT(simple_uart_set_logfile(u1, NULL) == -EINVAL);

    TEST_ASSERT(simple_uart_write(u1, "hello", 5) == 5);
    TEST_ASSERT(simple_uart_read(u2, buffer, sizeof(buffer)) == 5);
    TEST_ASSERT(simple_uart_write(u2, "world", 5) == 5);
    TEST_ASSERT(simple_uart_read(u1, buffer, sizeof(buffer)) == 5);

    /* Close connections to flush logs */
    simple_uart_close(u1);
    simple_uart_close(u2);
    shutdown_loopback(pid);

    /* Check that logfile was created and contains expected data */
    fp = fopen(logfile, "r");
    TEST_ASSERT(fp != NULL);

    size_t read_size = fread(log_contents, 1, sizeof(log_contents) - 1, fp);
    TEST_ASSERT(read_size > 0); // Ensure we read something
    log_contents[read_size] = '\0';
    fclose(fp);

    TEST_ASSERT(strcmp(log_contents, "helloworld") == 0);

    /* Clean up */
    unlink(logfile);
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x90, %rsp
leaq 0x27aa(%rip), %rdi      # 0x76e7
callq 0x2070
callq 0x4256
movl %eax, %ebx
leaq 0x23f7(%rip), %rdi      # 0x7347
leaq 0x23fb(%rip), %rdx      # 0x7352
movl $0x1c200, %esi          # imm = 0x1C200
callq 0x5b0d
movq %rax, %r14
xorl %edi, %edi
testq %rax, %rax
setne %dil
leaq 0x23e2(%rip), %rsi      # 0x7356
leaq 0x29af(%rip), %rcx      # 0x792a
leaq 0x23f4(%rip), %r8       # 0x7376
movl $0xe1, %edx
xorl %eax, %eax
callq 0x28d6
testl %eax, %eax
je 0x52e3
leaq 0x23e4(%rip), %rdi      # 0x7381
leaq 0x23ae(%rip), %rdx      # 0x7352
movl $0x1c200, %esi          # imm = 0x1C200
callq 0x5b0d
movq %rax, %r15
xorl %edi, %edi
testq %rax, %rax
setne %dil
leaq 0x2395(%rip), %rsi      # 0x7356
leaq 0x2962(%rip), %rcx      # 0x792a
leaq 0x23bd(%rip), %r8       # 0x738c
movl $0xe3, %edx
xorl %eax, %eax
callq 0x28d6
testl %eax, %eax
je 0x52e3
leaq 0x26fd(%rip), %rsi      # 0x76e7
movq %r14, %rdi
xorl %eax, %eax
callq 0x6749
xorl %edi, %edi
testl %eax, %eax
sete %dil
leaq 0x2353(%rip), %rsi      # 0x7356
leaq 0x2920(%rip), %rcx      # 0x792a
leaq 0x26f0(%rip), %r8       # 0x7701
movl $0xe6, %edx
xorl %eax, %eax
callq 0x28d6
testl %eax, %eax
je 0x52e3
leaq 0x26bb(%rip), %rsi      # 0x76e7
xorl %edi, %edi
xorl %eax, %eax
callq 0x6749
xorl %edi, %edi
cmpl $-0x16, %eax
sete %dil
leaq 0x2311(%rip), %rsi      # 0x7356
leaq 0x28de(%rip), %rcx      # 0x792a
leaq 0x26d8(%rip), %r8       # 0x772b
movl $0xe9, %edx
xorl %eax, %eax
callq 0x28d6
testl %eax, %eax
je 0x52e3
movq %r14, %rdi
xorl %esi, %esi
xorl %eax, %eax
callq 0x6749
xorl %edi, %edi
cmpl $-0x16, %eax
sete %dil
leaq 0x22d3(%rip), %rsi      # 0x7356
leaq 0x28a0(%rip), %rcx      # 0x792a
leaq 0x26cc(%rip), %r8       # 0x775d
movl $0xea, %edx
xorl %eax, %eax
callq 0x28d6
testl %eax, %eax
je 0x52e3
leaq 0x26de(%rip), %rsi      # 0x778a
movl $0x5, %edx
movq %r14, %rdi
callq 0x59df
xorl %edi, %edi
cmpq $0x5, %rax
sete %dil
leaq 0x228c(%rip), %rsi      # 0x7356
leaq 0x2859(%rip), %rcx      # 0x792a
leaq 0x26b8(%rip), %r8       # 0x7790
movl $0xec, %edx
xorl %eax, %eax
callq 0x28d6
testl %eax, %eax
je 0x52e3
movq %rsp, %rsi
movl $0x14, %edx
movq %r15, %rdi
callq 0x5868
xorl %edi, %edi
cmpq $0x5, %rax
sete %dil
leaq 0x2249(%rip), %rsi      # 0x7356
leaq 0x2816(%rip), %rcx      # 0x792a
leaq 0x269c(%rip), %r8       # 0x77b7
movl $0xed, %edx
xorl %eax, %eax
callq 0x28d6
testl %eax, %eax
je 0x52e3
leaq 0x26f8(%rip), %rsi      # 0x782e
movl $0x5, %edx
movq %r15, %rdi
callq 0x59df
xorl %edi, %edi
cmpq $0x5, %rax
sete %dil
leaq 0x2202(%rip), %rsi      # 0x7356
leaq 0x27cf(%rip), %rcx      # 0x792a
leaq 0x2687(%rip), %r8       # 0x77e9
movl $0xee, %edx
xorl %eax, %eax
callq 0x28d6
testl %eax, %eax
je 0x52e3
movq %rsp, %rsi
movl $0x14, %edx
movq %r14, %rdi
callq 0x5868
xorl %edi, %edi
cmpq $0x5, %rax
sete %dil
leaq 0x21bf(%rip), %rsi      # 0x7356
leaq 0x278c(%rip), %rcx      # 0x792a
leaq 0x2298(%rip), %r8       # 0x743d
movl $0xef, %edx
xorl %eax, %eax
callq 0x28d6
testl %eax, %eax
je 0x52e3
movq %r14, %rdi
callq 0x5ad5
movq %r15, %rdi
callq 0x5ad5
movl %ebx, %edi
movl $0x1, %esi
callq 0x2270
movl %ebx, %edi
xorl %esi, %esi
xorl %edx, %edx
callq 0x22f0
leaq 0x2500(%rip), %rdi      # 0x76e7
leaq 0x2786(%rip), %rsi      # 0x7974
callq 0x2330
movq %rax, %rbx
xorl %edi, %edi
testq %rax, %rax
setne %dil
leaq 0x2150(%rip), %rsi      # 0x7356
leaq 0x271d(%rip), %rcx      # 0x792a
leaq 0x25fc(%rip), %r8       # 0x7810
movl $0xf8, %edx
xorl %eax, %eax
callq 0x28d6
testl %eax, %eax
je 0x52e3
leaq 0x20(%rsp), %rdi
movl $0x1, %esi
movl $0x63, %edx
movq %rbx, %rcx
callq 0x20c0
movq %rax, %r14
xorl %edi, %edi
testq %rax, %rax
setne %dil
leaq 0x2104(%rip), %rsi      # 0x7356
leaq 0x26d1(%rip), %rcx      # 0x792a
leaq 0x25bb(%rip), %r8       # 0x781b
movl $0xfb, %edx
xorl %eax, %eax
callq 0x28d6
testl %eax, %eax
je 0x52e3
movb $0x0, 0x20(%rsp,%r14)
movq %rbx, %rdi
callq 0x2130
movabsq $0x726f776f6c6c6568, %rax # imm = 0x726F776F6C6C6568
xorq 0x20(%rsp), %rax
movabsq $0x646c726f776f6c, %rcx # imm = 0x646C726F776F6C
xorq 0x23(%rsp), %rcx
xorl %edi, %edi
orq %rax, %rcx
sete %dil
leaq 0x20aa(%rip), %rsi      # 0x7356
leaq 0x2677(%rip), %rcx      # 0x792a
leaq 0x257a(%rip), %r8       # 0x7834
movl $0xff, %edx
xorl %eax, %eax
callq 0x28d6
testl %eax, %eax
je 0x52e3
leaq 0x2416(%rip), %rdi      # 0x76e7
callq 0x2070
addq $0x90, %rsp
popq %rbx
popq %r14
popq %r15
retq
callq 0x31a2