// File: /workspace/github_c_makefile_star2_O3/Carton32[P]quectel-CM/qmap_bridge_mode.c
// Function: ql_bridge_mode_detect
int ql_bridge_mode_detect(PROFILE_T *profile) {
    const char *ifname = profile->qmapnet_adapter[0] ? profile->qmapnet_adapter : profile->usbnet_adapter;
    const char *driver;
    char bridge_mode[128];
    char bridge_ipv4[128];
    char ipv4[128];
    char buf[64];
    size_t n;
    int in_bridge = 0;

    driver = profile->driver_name;
    snprintf(bridge_mode, sizeof(bridge_mode), "/sys/class/net/%s/bridge_mode", ifname);
    snprintf(bridge_ipv4, sizeof(bridge_ipv4), "/sys/class/net/%s/bridge_ipv4", ifname);

    if (access(bridge_ipv4, R_OK)) {
        if (errno != ENOENT) {
            dbg_time("fail to access %s, errno: %d (%s)", bridge_mode, errno, strerror(errno));
            return 0;
        }

        snprintf(bridge_mode, sizeof(bridge_mode), "/sys/module/%s/parameters/bridge_mode", driver);
        snprintf(bridge_ipv4, sizeof(bridge_ipv4), "/sys/module/%s/parameters/bridge_ipv4", driver);

        if (access(bridge_mode, R_OK)) {
            if (errno != ENOENT) {
                dbg_time("fail to access %s, errno: %d (%s)", bridge_mode, errno, strerror(errno));
            }
            return 0;
        }
    }

    n = ql_fread(bridge_mode, buf, sizeof(buf));
    if (n > 0) {
        in_bridge = (buf[0] != '0');
    }
    if (!in_bridge)
        return 0;
   
    memset(ipv4, 0, sizeof(ipv4));

    if (strstr(bridge_ipv4, "/sys/class/net/") || profile->qmap_mode == 0 || profile->qmap_mode == 1) {
        snprintf(ipv4, sizeof(ipv4), "0x%x", profile->ipv4.Address);
        dbg_time("echo '%s' > %s", ipv4, bridge_ipv4);
        ql_fwrite(bridge_ipv4, ipv4, strlen(ipv4));
    }
    else {
        snprintf(ipv4, sizeof(ipv4), "0x%x:%d", profile->ipv4.Address, profile->muxid);
        dbg_time("echo '%s' > %s", ipv4, bridge_ipv4);
        ql_fwrite(bridge_ipv4, ipv4, strlen(ipv4));
    }

    return in_bridge;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x1c0, %rsp            # imm = 0x1C0
movq %rdi, %rbx
leaq 0xca(%rdi), %r14
leaq 0xaa(%rdi), %rax
cmpb $0x0, 0xca(%rdi)
cmoveq %rax, %r14
leaq 0x1168e(%rip), %rdx     # 0x20eb0
leaq 0x100(%rsp), %rdi
movl $0x80, %esi
movq %r14, %rcx
xorl %eax, %eax
callq 0x51c0
leaq 0x1168e(%rip), %rdx     # 0x20ece
leaq 0x80(%rsp), %r15
movl $0x80, %esi
movq %r15, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x51c0
movq %r15, %rdi
movl $0x4, %esi
callq 0x5450
testl %eax, %eax
je 0xf973
callq 0x5070
movq %rax, %r14
cmpl $0x2, (%rax)
jne 0xf8e3
leaq 0xea(%rbx), %r15
leaq 0x1168a(%rip), %rdx     # 0x20f14
xorl %ebp, %ebp
leaq 0x100(%rsp), %r12
movl $0x80, %esi
movq %r12, %rdi
movq %r15, %rcx
xorl %eax, %eax
callq 0x51c0
leaq 0x1168d(%rip), %rdx     # 0x20f3a
leaq 0x80(%rsp), %rdi
movl $0x80, %esi
movq %r15, %rcx
xorl %eax, %eax
callq 0x51c0
movq %r12, %rdi
movl $0x4, %esi
callq 0x5450
testl %eax, %eax
je 0xf973
cmpl $0x2, (%r14)
je 0xfaa0
movq 0x1a6d6(%rip), %rax     # 0x29fc0
movq (%rax), %rbx
callq 0xea3b
movq %rax, %r15
movl (%r14), %r12d
movl %r12d, %edi
callq 0x5530
leaq 0x115e5(%rip), %rsi     # 0x20eec
xorl %ebp, %ebp
leaq 0x100(%rsp), %rcx
movq %rbx, %rdi
movq %r15, %rdx
movl %r12d, %r8d
movq %rax, %r9
xorl %eax, %eax
callq 0x52c0
leaq 0x1b37d(%rip), %rax     # 0x2aca8
movq (%rax), %rbx
testq %rbx, %rbx
je 0xfaa0
callq 0xea3b
movq %rax, %r15
movl (%r14), %r14d
movl %r14d, %edi
callq 0x5530
leaq 0x1159b(%rip), %rsi     # 0x20eec
xorl %ebp, %ebp
leaq 0x100(%rsp), %rcx
movq %rbx, %rdi
movq %r15, %rdx
movl %r14d, %r8d
movq %rax, %r9
xorl %eax, %eax
callq 0x52c0
jmp 0xfaa0
leaq 0x100(%rsp), %rdi
leaq 0x180(%rsp), %rsi
movl $0x40, %edx
callq 0xfadd
testq %rax, %rax
je 0xfa9e
cmpb $0x30, 0x180(%rsp)
movl $0x0, %ebp
je 0xfaa0
xorps %xmm0, %xmm0
movaps %xmm0, 0x70(%rsp)
movaps %xmm0, 0x60(%rsp)
movaps %xmm0, 0x50(%rsp)
movaps %xmm0, 0x40(%rsp)
movaps %xmm0, 0x30(%rsp)
movaps %xmm0, 0x20(%rsp)
movaps %xmm0, 0x10(%rsp)
movaps %xmm0, (%rsp)
leaq 0x11586(%rip), %rsi     # 0x20f60
leaq 0x80(%rsp), %rdi
callq 0x5550
testq %rax, %rax
jne 0xf9f9
cmpl $0x1, 0x10a(%rbx)
ja 0xfab2
movl 0x126(%rbx), %ecx
leaq 0x1156a(%rip), %rdx     # 0x20f70
movq %rsp, %rbx
movl $0x80, %esi
movq %rbx, %rdi
xorl %eax, %eax
callq 0x51c0
movq 0x1a5a1(%rip), %rax     # 0x29fc0
movq (%rax), %r14
callq 0xea3b
leaq 0x11547(%rip), %rsi     # 0x20f75
leaq 0x80(%rsp), %r8
movq %r14, %rdi
movq %rax, %rdx
movq %rbx, %rcx
xorl %eax, %eax
callq 0x52c0
leaq 0x1b25b(%rip), %rax     # 0x2aca8
movq (%rax), %rbx
testq %rbx, %rbx
je 0xfa79
callq 0xea3b
leaq 0x11514(%rip), %rsi     # 0x20f75
movq %rsp, %rcx
leaq 0x80(%rsp), %r8
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x52c0
movq %rsp, %rbx
movq %rbx, %rdi
callq 0x5160
leaq 0x80(%rsp), %rdi
movq %rbx, %rsi
movq %rax, %rdx
callq 0xfbee
movl $0x1, %ebp
jmp 0xfaa0
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x1c0, %rsp            # imm = 0x1C0
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movl 0x11e(%rbx), %r8d
movl 0x126(%rbx), %ecx
leaq 0x114c4(%rip), %rdx     # 0x20f8a
movq %rsp, %rbx
movl $0x80, %esi
movq %rbx, %rdi
xorl %eax, %eax
callq 0x51c0
jmp 0xfa18