// File: /workspace/github_c_makefile_star2_O2/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 0xfe16(%rip), %rdx      # 0x1eec8
leaq 0x100(%rsp), %rdi
movl $0x80, %esi
movq %r14, %rcx
xorl %eax, %eax
callq 0x51c0
leaq 0xfe16(%rip), %rdx      # 0x1eee6
leaq 0x80(%rsp), %r15
movl $0x80, %esi
movq %r15, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x51c0
pushq $0x4
popq %rsi
movq %r15, %rdi
callq 0x5460
testl %eax, %eax
je 0xf1ff
callq 0x5070
movq %rax, %r14
cmpl $0x2, (%rax)
jne 0xf16f
leaq 0xea(%rbx), %r15
leaq 0xfe14(%rip), %rdx      # 0x1ef2c
xorl %ebp, %ebp
leaq 0x100(%rsp), %r12
movl $0x80, %esi
movq %r12, %rdi
movq %r15, %rcx
xorl %eax, %eax
callq 0x51c0
leaq 0xfe17(%rip), %rdx      # 0x1ef52
leaq 0x80(%rsp), %rdi
movl $0x80, %esi
movq %r15, %rcx
xorl %eax, %eax
callq 0x51c0
pushq $0x4
popq %rsi
movq %r12, %rdi
callq 0x5460
testl %eax, %eax
je 0xf1ff
cmpl $0x2, (%r14)
je 0xf328
movq 0x19e42(%rip), %rax     # 0x28fb8
movq (%rax), %rbx
callq 0xe343
movq %rax, %r15
movl (%r14), %r12d
movl %r12d, %edi
callq 0x5540
leaq 0xfd71(%rip), %rsi      # 0x1ef04
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 0x1aaf1(%rip), %rax     # 0x29ca8
movq (%rax), %rbx
testq %rbx, %rbx
je 0xf328
callq 0xe343
movq %rax, %r15
movl (%r14), %r14d
movl %r14d, %edi
callq 0x5540
leaq 0xfd27(%rip), %rsi      # 0x1ef04
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 0xf328
leaq 0x100(%rsp), %rdi
leaq 0x180(%rsp), %rsi
pushq $0x40
popq %rdx
callq 0xf365
testq %rax, %rax
je 0xf326
cmpb $0x30, 0x180(%rsp)
movl $0x0, %ebp
je 0xf328
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 0xfd14(%rip), %rsi      # 0x1ef78
leaq 0x80(%rsp), %rdi
callq 0x5560
testq %rax, %rax
jne 0xf283
cmpl $0x1, 0x10a(%rbx)
ja 0xf33a
movl 0x126(%rbx), %ecx
leaq 0xfcf8(%rip), %rdx      # 0x1ef88
movq %rsp, %rbx
movl $0x80, %esi
movq %rbx, %rdi
xorl %eax, %eax
callq 0x51c0
movq 0x19d0f(%rip), %rax     # 0x28fb8
movq (%rax), %r14
callq 0xe343
leaq 0xfcd5(%rip), %rsi      # 0x1ef8d
leaq 0x80(%rsp), %r8
movq %r14, %rdi
movq %rax, %rdx
movq %rbx, %rcx
xorl %eax, %eax
callq 0x52c0
leaq 0x1a9d1(%rip), %rax     # 0x29ca8
movq (%rax), %rbx
testq %rbx, %rbx
je 0xf303
callq 0xe343
leaq 0xfca2(%rip), %rsi      # 0x1ef8d
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 0xf474
pushq $0x1
popq %rbp
jmp 0xf328
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 0xfc54(%rip), %rdx      # 0x1efa2
movq %rsp, %rbx
movl $0x80, %esi
movq %rbx, %rdi
xorl %eax, %eax
callq 0x51c0
jmp 0xf2a2