// File: /workspace/github_cpp_makefile_star2_O3/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 0x28ca(%rip), %rdi      # 0x771f
callq 0x2070
callq 0x416a
movl %eax, %ebx
leaq 0x2517(%rip), %rdi      # 0x737f
leaq 0x251b(%rip), %rdx      # 0x738a
movl $0x1c200, %esi          # imm = 0x1C200
callq 0x5a07
movq %rax, %r14
xorl %edi, %edi
testq %rax, %rax
setne %dil
leaq 0x2502(%rip), %rsi      # 0x738e
leaq 0x2acc(%rip), %rcx      # 0x795f
leaq 0x2514(%rip), %r8       # 0x73ae
movl $0xe1, %edx
xorl %eax, %eax
callq 0x28df
testl %eax, %eax
je 0x51fb
leaq 0x2504(%rip), %rdi      # 0x73b9
leaq 0x24ce(%rip), %rdx      # 0x738a
movl $0x1c200, %esi          # imm = 0x1C200
callq 0x5a07
movq %rax, %r15
xorl %edi, %edi
testq %rax, %rax
setne %dil
leaq 0x24b5(%rip), %rsi      # 0x738e
leaq 0x2a7f(%rip), %rcx      # 0x795f
leaq 0x24dd(%rip), %r8       # 0x73c4
movl $0xe3, %edx
xorl %eax, %eax
callq 0x28df
testl %eax, %eax
je 0x51fb
leaq 0x281d(%rip), %rsi      # 0x771f
movq %r14, %rdi
xorl %eax, %eax
callq 0x6571
xorl %edi, %edi
testl %eax, %eax
sete %dil
leaq 0x2473(%rip), %rsi      # 0x738e
leaq 0x2a3d(%rip), %rcx      # 0x795f
leaq 0x2810(%rip), %r8       # 0x7739
movl $0xe6, %edx
xorl %eax, %eax
callq 0x28df
testl %eax, %eax
je 0x51fb
leaq 0x27db(%rip), %rsi      # 0x771f
xorl %edi, %edi
xorl %eax, %eax
callq 0x6571
xorl %edi, %edi
cmpl $-0x16, %eax
sete %dil
leaq 0x2431(%rip), %rsi      # 0x738e
leaq 0x29fb(%rip), %rcx      # 0x795f
leaq 0x27f8(%rip), %r8       # 0x7763
movl $0xe9, %edx
xorl %eax, %eax
callq 0x28df
testl %eax, %eax
je 0x51fb
movq %r14, %rdi
xorl %esi, %esi
xorl %eax, %eax
callq 0x6571
xorl %edi, %edi
cmpl $-0x16, %eax
sete %dil
leaq 0x23f3(%rip), %rsi      # 0x738e
leaq 0x29bd(%rip), %rcx      # 0x795f
leaq 0x27ec(%rip), %r8       # 0x7795
movl $0xea, %edx
xorl %eax, %eax
callq 0x28df
testl %eax, %eax
je 0x51fb
leaq 0x27fe(%rip), %rsi      # 0x77c2
movl $0x5, %edx
movq %r14, %rdi
callq 0x58f7
xorl %edi, %edi
cmpq $0x5, %rax
sete %dil
leaq 0x23ac(%rip), %rsi      # 0x738e
leaq 0x2976(%rip), %rcx      # 0x795f
leaq 0x27d8(%rip), %r8       # 0x77c8
movl $0xec, %edx
xorl %eax, %eax
callq 0x28df
testl %eax, %eax
je 0x51fb
movq %rsp, %rsi
movl $0x14, %edx
movq %r15, %rdi
callq 0x5780
xorl %edi, %edi
cmpq $0x5, %rax
sete %dil
leaq 0x2369(%rip), %rsi      # 0x738e
leaq 0x2933(%rip), %rcx      # 0x795f
leaq 0x27bc(%rip), %r8       # 0x77ef
movl $0xed, %edx
xorl %eax, %eax
callq 0x28df
testl %eax, %eax
je 0x51fb
leaq 0x2818(%rip), %rsi      # 0x7866
movl $0x5, %edx
movq %r15, %rdi
callq 0x58f7
xorl %edi, %edi
cmpq $0x5, %rax
sete %dil
leaq 0x2322(%rip), %rsi      # 0x738e
leaq 0x28ec(%rip), %rcx      # 0x795f
leaq 0x27a7(%rip), %r8       # 0x7821
movl $0xee, %edx
xorl %eax, %eax
callq 0x28df
testl %eax, %eax
je 0x51fb
movq %rsp, %rsi
movl $0x14, %edx
movq %r14, %rdi
callq 0x5780
xorl %edi, %edi
cmpq $0x5, %rax
sete %dil
leaq 0x22df(%rip), %rsi      # 0x738e
leaq 0x28a9(%rip), %rcx      # 0x795f
leaq 0x23b8(%rip), %r8       # 0x7475
movl $0xef, %edx
xorl %eax, %eax
callq 0x28df
testl %eax, %eax
je 0x51fb
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
leaq 0x2620(%rip), %rdi      # 0x771f
leaq 0x28a3(%rip), %rsi      # 0x79a9
callq 0x2330
movq %rax, %rbx
xorl %edi, %edi
testq %rax, %rax
setne %dil
leaq 0x2270(%rip), %rsi      # 0x738e
leaq 0x283a(%rip), %rcx      # 0x795f
leaq 0x271c(%rip), %r8       # 0x7848
movl $0xf8, %edx
xorl %eax, %eax
callq 0x28df
testl %eax, %eax
je 0x51fb
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 0x2224(%rip), %rsi      # 0x738e
leaq 0x27ee(%rip), %rcx      # 0x795f
leaq 0x26db(%rip), %r8       # 0x7853
movl $0xfb, %edx
xorl %eax, %eax
callq 0x28df
testl %eax, %eax
je 0x51fb
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 0x21ca(%rip), %rsi      # 0x738e
leaq 0x2794(%rip), %rcx      # 0x795f
leaq 0x269a(%rip), %r8       # 0x786c
movl $0xff, %edx
xorl %eax, %eax
callq 0x28df
testl %eax, %eax
je 0x51fb
leaq 0x2536(%rip), %rdi      # 0x771f
callq 0x2070
addq $0x90, %rsp
popq %rbx
popq %r14
popq %r15
retq
callq 0x31c2