// File: /workspace/github_c_makefile_star2_O1/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 0x11566(%rip), %rdx     # 0x20eb4
leaq 0x100(%rsp), %rdi
movl $0x80, %esi
movq %r14, %rcx
xorl %eax, %eax
callq 0x51c0
leaq 0x11566(%rip), %rdx     # 0x20ed2
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 0xfa9f
callq 0x5070
movq %rax, %r14
cmpl $0x2, (%rax)
jne 0xfa0f
leaq 0xea(%rbx), %r15
leaq 0x11562(%rip), %rdx     # 0x20f18
xorl %ebp, %ebp
leaq 0x100(%rsp), %r12
movl $0x80, %esi
movq %r12, %rdi
movq %r15, %rcx
xorl %eax, %eax
callq 0x51c0
leaq 0x11565(%rip), %rdx     # 0x20f3e
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 0xfa9f
cmpl $0x2, (%r14)
je 0xfbcc
movq 0x1a5aa(%rip), %rax     # 0x29fc0
movq (%rax), %rbx
callq 0xeb2f
movq %rax, %r15
movl (%r14), %r12d
movl %r12d, %edi
callq 0x5530
leaq 0x114bd(%rip), %rsi     # 0x20ef0
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 0x1b251(%rip), %rax     # 0x2aca8
movq (%rax), %rbx
testq %rbx, %rbx
je 0xfbcc
callq 0xeb2f
movq %rax, %r15
movl (%r14), %r14d
movl %r14d, %edi
callq 0x5530
leaq 0x11473(%rip), %rsi     # 0x20ef0
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 0xfbcc
leaq 0x100(%rsp), %rdi
leaq 0x180(%rsp), %rsi
movl $0x40, %edx
callq 0xfc09
testq %rax, %rax
je 0xfbca
cmpb $0x30, 0x180(%rsp)
movl $0x0, %ebp
je 0xfbcc
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 0x1145e(%rip), %rsi     # 0x20f64
leaq 0x80(%rsp), %rdi
callq 0x5550
testq %rax, %rax
jne 0xfb25
cmpl $0x1, 0x10a(%rbx)
ja 0xfbde
movl 0x126(%rbx), %ecx
leaq 0x11442(%rip), %rdx     # 0x20f74
movq %rsp, %rbx
movl $0x80, %esi
movq %rbx, %rdi
xorl %eax, %eax
callq 0x51c0
movq 0x1a475(%rip), %rax     # 0x29fc0
movq (%rax), %r14
callq 0xeb2f
leaq 0x1141f(%rip), %rsi     # 0x20f79
leaq 0x80(%rsp), %r8
movq %r14, %rdi
movq %rax, %rdx
movq %rbx, %rcx
xorl %eax, %eax
callq 0x52c0
leaq 0x1b12f(%rip), %rax     # 0x2aca8
movq (%rax), %rbx
testq %rbx, %rbx
je 0xfba5
callq 0xeb2f
leaq 0x113ec(%rip), %rsi     # 0x20f79
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 0xfd1a
movl $0x1, %ebp
jmp 0xfbcc
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 0x1139c(%rip), %rdx     # 0x20f8e
movq %rsp, %rbx
movl $0x80, %esi
movq %rbx, %rdi
xorl %eax, %eax
callq 0x51c0
jmp 0xfb44