// File: /workspace/github_cpp_makefile_star2_O2/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 0x2d03(%rip), %rdi      # 0x76e7
callq 0x2070
callq 0x3e43
movl %eax, %ebx
leaq 0x2950(%rip), %rdi      # 0x7347
leaq 0x2954(%rip), %rdx      # 0x7352
movl $0x1c200, %esi          # imm = 0x1C200
callq 0x54e4
movq %rax, %r14
xorl %edi, %edi
testq %rax, %rax
setne %dil
leaq 0x293b(%rip), %rsi      # 0x7356
leaq 0x2f05(%rip), %rcx      # 0x7927
leaq 0x294d(%rip), %r8       # 0x7376
movl $0xe1, %edx
xorl %eax, %eax
callq 0x269a
testl %eax, %eax
je 0x4d63
leaq 0x293d(%rip), %rdi      # 0x7381
leaq 0x2907(%rip), %rdx      # 0x7352
movl $0x1c200, %esi          # imm = 0x1C200
callq 0x54e4
movq %rax, %r15
xorl %edi, %edi
testq %rax, %rax
setne %dil
leaq 0x28ee(%rip), %rsi      # 0x7356
leaq 0x2eb8(%rip), %rcx      # 0x7927
leaq 0x2916(%rip), %r8       # 0x738c
movl $0xe3, %edx
xorl %eax, %eax
callq 0x269a
testl %eax, %eax
je 0x4d63
leaq 0x2c56(%rip), %rsi      # 0x76e7
movq %r14, %rdi
xorl %eax, %eax
callq 0x5f8c
xorl %edi, %edi
testl %eax, %eax
sete %dil
leaq 0x28ac(%rip), %rsi      # 0x7356
leaq 0x2e76(%rip), %rcx      # 0x7927
leaq 0x2c49(%rip), %r8       # 0x7701
movl $0xe6, %edx
xorl %eax, %eax
callq 0x269a
testl %eax, %eax
je 0x4d63
leaq 0x2c14(%rip), %rsi      # 0x76e7
xorl %edi, %edi
xorl %eax, %eax
callq 0x5f8c
xorl %edi, %edi
cmpl $-0x16, %eax
sete %dil
leaq 0x286a(%rip), %rsi      # 0x7356
leaq 0x2e34(%rip), %rcx      # 0x7927
leaq 0x2c31(%rip), %r8       # 0x772b
movl $0xe9, %edx
xorl %eax, %eax
callq 0x269a
testl %eax, %eax
je 0x4d63
movq %r14, %rdi
xorl %esi, %esi
xorl %eax, %eax
callq 0x5f8c
xorl %edi, %edi
cmpl $-0x16, %eax
sete %dil
leaq 0x282c(%rip), %rsi      # 0x7356
leaq 0x2df6(%rip), %rcx      # 0x7927
leaq 0x2c25(%rip), %r8       # 0x775d
movl $0xea, %edx
xorl %eax, %eax
callq 0x269a
testl %eax, %eax
je 0x4d63
leaq 0x2c37(%rip), %rsi      # 0x778a
pushq $0x5
popq %rdx
movq %r14, %rdi
callq 0x53e0
xorl %edi, %edi
cmpq $0x5, %rax
sete %dil
leaq 0x27e7(%rip), %rsi      # 0x7356
leaq 0x2db1(%rip), %rcx      # 0x7927
leaq 0x2c13(%rip), %r8       # 0x7790
movl $0xec, %edx
xorl %eax, %eax
callq 0x269a
testl %eax, %eax
je 0x4d63
movq %rsp, %rsi
pushq $0x14
popq %rdx
movq %r15, %rdi
callq 0x52a4
xorl %edi, %edi
cmpq $0x5, %rax
sete %dil
leaq 0x27a6(%rip), %rsi      # 0x7356
leaq 0x2d70(%rip), %rcx      # 0x7927
leaq 0x2bf9(%rip), %r8       # 0x77b7
movl $0xed, %edx
xorl %eax, %eax
callq 0x269a
testl %eax, %eax
je 0x4d63
leaq 0x2c55(%rip), %rsi      # 0x782e
pushq $0x5
popq %rdx
movq %r15, %rdi
callq 0x53e0
xorl %edi, %edi
cmpq $0x5, %rax
sete %dil
leaq 0x2761(%rip), %rsi      # 0x7356
leaq 0x2d2b(%rip), %rcx      # 0x7927
leaq 0x2be6(%rip), %r8       # 0x77e9
movl $0xee, %edx
xorl %eax, %eax
callq 0x269a
testl %eax, %eax
je 0x4d63
movq %rsp, %rsi
pushq $0x14
popq %rdx
movq %r14, %rdi
callq 0x52a4
xorl %edi, %edi
cmpq $0x5, %rax
sete %dil
leaq 0x2720(%rip), %rsi      # 0x7356
leaq 0x2cea(%rip), %rcx      # 0x7927
leaq 0x27f9(%rip), %r8       # 0x743d
movl $0xef, %edx
xorl %eax, %eax
callq 0x269a
testl %eax, %eax
je 0x4d63
movq %r14, %rdi
callq 0x54b1
movq %r15, %rdi
callq 0x54b1
movl %ebx, %edi
callq 0x3eba
leaq 0x2a71(%rip), %rdi      # 0x76e7
leaq 0x2cf4(%rip), %rsi      # 0x7971
callq 0x2330
movq %rax, %rbx
xorl %edi, %edi
testq %rax, %rax
setne %dil
leaq 0x26c1(%rip), %rsi      # 0x7356
leaq 0x2c8b(%rip), %rcx      # 0x7927
leaq 0x2b6d(%rip), %r8       # 0x7810
movl $0xf8, %edx
xorl %eax, %eax
callq 0x269a
testl %eax, %eax
je 0x4d63
leaq 0x20(%rsp), %rdi
pushq $0x1
popq %rsi
pushq $0x63
popq %rdx
movq %rbx, %rcx
callq 0x20c0
movq %rax, %r14
xorl %edi, %edi
testq %rax, %rax
setne %dil
leaq 0x2679(%rip), %rsi      # 0x7356
leaq 0x2c43(%rip), %rcx      # 0x7927
leaq 0x2b30(%rip), %r8       # 0x781b
movl $0xfb, %edx
xorl %eax, %eax
callq 0x269a
testl %eax, %eax
je 0x4d63
movb $0x0, 0x20(%rsp,%r14)
movq %rbx, %rdi
callq 0x2130
leaq 0x2b19(%rip), %rsi      # 0x7829
leaq 0x20(%rsp), %rdi
pushq $0xb
popq %rdx
callq 0x22c0
xorl %edi, %edi
testl %eax, %eax
sete %dil
leaq 0x262a(%rip), %rsi      # 0x7356
leaq 0x2bf4(%rip), %rcx      # 0x7927
leaq 0x2afa(%rip), %r8       # 0x7834
movl $0xff, %edx
xorl %eax, %eax
callq 0x269a
testl %eax, %eax
je 0x4d63
leaq 0x2996(%rip), %rdi      # 0x76e7
callq 0x2070
addq $0x90, %rsp
popq %rbx
popq %r14
popq %r15
retq
callq 0x2f01