// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x2c0, %rsp            # imm = 0x2C0
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movsbl 0xca(%rax), %eax
cmpl $0x0, %eax
je 0x14ec2
movq -0x10(%rbp), %rax
addq $0xca, %rax
movq %rax, -0x1f8(%rbp)
jmp 0x14ed3
movq -0x10(%rbp), %rax
addq $0xaa, %rax
movq %rax, -0x1f8(%rbp)
movq -0x1f8(%rbp), %rax
movq %rax, -0x18(%rbp)
movl $0x0, -0x1ec(%rbp)
movq -0x10(%rbp), %rax
addq $0xea, %rax
movq %rax, -0x20(%rbp)
leaq -0xa0(%rbp), %rdi
movq -0x18(%rbp), %rcx
movl $0x80, %esi
leaq 0x1919b(%rip), %rdx     # 0x2e0a8
movb $0x0, %al
callq 0x51c0
leaq -0x120(%rbp), %rdi
movq -0x18(%rbp), %rcx
movl $0x80, %esi
leaq 0x1919b(%rip), %rdx     # 0x2e0c6
movb $0x0, %al
callq 0x51c0
leaq -0x120(%rbp), %rdi
movl $0x4, %esi
callq 0x5460
cmpl $0x0, %eax
je 0x151c0
callq 0x5070
cmpl $0x2, (%rax)
je 0x15059
jmp 0x14f5c
movq 0x2207d(%rip), %rax     # 0x36fe0
movq (%rax), %rax
movq %rax, -0x218(%rbp)
callq 0x13930
movq %rax, -0x210(%rbp)
leaq -0xa0(%rbp), %rax
movq %rax, -0x208(%rbp)
callq 0x5070
movl (%rax), %eax
movl %eax, -0x1fc(%rbp)
callq 0x5070
movl (%rax), %edi
callq 0x5540
movq -0x218(%rbp), %rdi
movq -0x210(%rbp), %rdx
movq -0x208(%rbp), %rcx
movl -0x1fc(%rbp), %r8d
movq %rax, %r9
leaq 0x1911e(%rip), %rsi     # 0x2e0e4
movb $0x0, %al
callq 0x52c0
leaq 0x22e94(%rip), %rax     # 0x37e68
cmpq $0x0, (%rax)
je 0x1504b
leaq 0x22e87(%rip), %rax     # 0x37e68
movq (%rax), %rax
movq %rax, -0x238(%rbp)
callq 0x13930
movq %rax, -0x230(%rbp)
leaq -0xa0(%rbp), %rax
movq %rax, -0x228(%rbp)
callq 0x5070
movl (%rax), %eax
movl %eax, -0x21c(%rbp)
callq 0x5070
movl (%rax), %edi
callq 0x5540
movq -0x238(%rbp), %rdi
movq -0x230(%rbp), %rdx
movq -0x228(%rbp), %rcx
movl -0x21c(%rbp), %r8d
movq %rax, %r9
leaq 0x190a0(%rip), %rsi     # 0x2e0e4
movb $0x0, %al
callq 0x52c0
jmp 0x1504d
movl $0x0, -0x4(%rbp)
jmp 0x1544b
leaq -0xa0(%rbp), %rdi
movq -0x20(%rbp), %rcx
movl $0x80, %esi
leaq 0x1909c(%rip), %rdx     # 0x2e10c
movb $0x0, %al
callq 0x51c0
leaq -0x120(%rbp), %rdi
movq -0x20(%rbp), %rcx
movl $0x80, %esi
leaq 0x190a4(%rip), %rdx     # 0x2e132
movb $0x0, %al
callq 0x51c0
leaq -0xa0(%rbp), %rdi
movl $0x4, %esi
callq 0x5460
cmpl $0x0, %eax
je 0x151be
callq 0x5070
cmpl $0x2, (%rax)
je 0x151b2
jmp 0x150bf
movq 0x21f1a(%rip), %rax     # 0x36fe0
movq (%rax), %rax
movq %rax, -0x258(%rbp)
callq 0x13930
movq %rax, -0x250(%rbp)
leaq -0xa0(%rbp), %rax
movq %rax, -0x248(%rbp)
callq 0x5070
movl (%rax), %eax
movl %eax, -0x23c(%rbp)
callq 0x5070
movl (%rax), %edi
callq 0x5540
movq -0x258(%rbp), %rdi
movq -0x250(%rbp), %rdx
movq -0x248(%rbp), %rcx
movl -0x23c(%rbp), %r8d
movq %rax, %r9
leaq 0x18fbb(%rip), %rsi     # 0x2e0e4
movb $0x0, %al
callq 0x52c0
leaq 0x22d31(%rip), %rax     # 0x37e68
cmpq $0x0, (%rax)
je 0x151ae
leaq 0x22d24(%rip), %rax     # 0x37e68
movq (%rax), %rax
movq %rax, -0x278(%rbp)
callq 0x13930
movq %rax, -0x270(%rbp)
leaq -0xa0(%rbp), %rax
movq %rax, -0x268(%rbp)
callq 0x5070
movl (%rax), %eax
movl %eax, -0x25c(%rbp)
callq 0x5070
movl (%rax), %edi
callq 0x5540
movq -0x278(%rbp), %rdi
movq -0x270(%rbp), %rdx
movq -0x268(%rbp), %rcx
movl -0x25c(%rbp), %r8d
movq %rax, %r9
leaq 0x18f3d(%rip), %rsi     # 0x2e0e4
movb $0x0, %al
callq 0x52c0
jmp 0x151b0
jmp 0x151b2
movl $0x0, -0x4(%rbp)
jmp 0x1544b
jmp 0x151c0
leaq -0xa0(%rbp), %rdi
leaq -0x1e0(%rbp), %rsi
movl $0x40, %edx
callq 0x15460
movq %rax, -0x1e8(%rbp)
cmpq $0x0, -0x1e8(%rbp)
jbe 0x15201
movsbl -0x1e0(%rbp), %eax
cmpl $0x30, %eax
setne %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x1ec(%rbp)
cmpl $0x0, -0x1ec(%rbp)
jne 0x15216
movl $0x0, -0x4(%rbp)
jmp 0x1544b
leaq -0x1a0(%rbp), %rdi
xorl %esi, %esi
movl $0x80, %edx
callq 0x5200
leaq -0x120(%rbp), %rdi
leaq 0x18f21(%rip), %rsi     # 0x2e158
callq 0x5560
cmpq $0x0, %rax
jne 0x15260
movq -0x10(%rbp), %rax
cmpl $0x0, 0x10a(%rax)
je 0x15260
movq -0x10(%rbp), %rax
cmpl $0x1, 0x10a(%rax)
jne 0x1534e
leaq -0x1a0(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x126(%rax), %ecx
movl $0x80, %esi
leaq 0x18eeb(%rip), %rdx     # 0x2e168
movb $0x0, %al
callq 0x51c0
movq 0x21d55(%rip), %rax     # 0x36fe0
movq (%rax), %rax
movq %rax, -0x280(%rbp)
callq 0x13930
movq -0x280(%rbp), %rdi
movq %rax, %rdx
leaq -0x1a0(%rbp), %rcx
leaq -0x120(%rbp), %r8
leaq 0x18eb4(%rip), %rsi     # 0x2e16d
movb $0x0, %al
callq 0x52c0
leaq 0x22ba1(%rip), %rax     # 0x37e68
cmpq $0x0, (%rax)
je 0x15309
leaq 0x22b94(%rip), %rax     # 0x37e68
movq (%rax), %rax
movq %rax, -0x288(%rbp)
callq 0x13930
movq -0x288(%rbp), %rdi
movq %rax, %rdx
leaq -0x1a0(%rbp), %rcx
leaq -0x120(%rbp), %r8
leaq 0x18e6b(%rip), %rsi     # 0x2e16d
movb $0x0, %al
callq 0x52c0
jmp 0x1530b
leaq -0x120(%rbp), %rax
movq %rax, -0x298(%rbp)
leaq -0x1a0(%rbp), %rax
movq %rax, -0x290(%rbp)
leaq -0x1a0(%rbp), %rdi
callq 0x5160
movq -0x298(%rbp), %rdi
movq -0x290(%rbp), %rsi
movq %rax, %rdx
callq 0x155e0
jmp 0x15442
leaq -0x1a0(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x126(%rax), %ecx
movq -0x10(%rbp), %rax
movl 0x11e(%rax), %r8d
movl $0x80, %esi
leaq 0x18e0c(%rip), %rdx     # 0x2e182
movb $0x0, %al
callq 0x51c0
movq 0x21c5c(%rip), %rax     # 0x36fe0
movq (%rax), %rax
movq %rax, -0x2a0(%rbp)
callq 0x13930
movq -0x2a0(%rbp), %rdi
movq %rax, %rdx
leaq -0x1a0(%rbp), %rcx
leaq -0x120(%rbp), %r8
leaq 0x18dbb(%rip), %rsi     # 0x2e16d
movb $0x0, %al
callq 0x52c0
leaq 0x22aa8(%rip), %rax     # 0x37e68
cmpq $0x0, (%rax)
je 0x15402
leaq 0x22a9b(%rip), %rax     # 0x37e68
movq (%rax), %rax
movq %rax, -0x2a8(%rbp)
callq 0x13930
movq -0x2a8(%rbp), %rdi
movq %rax, %rdx
leaq -0x1a0(%rbp), %rcx
leaq -0x120(%rbp), %r8
leaq 0x18d72(%rip), %rsi     # 0x2e16d
movb $0x0, %al
callq 0x52c0
jmp 0x15404
leaq -0x120(%rbp), %rax
movq %rax, -0x2b8(%rbp)
leaq -0x1a0(%rbp), %rax
movq %rax, -0x2b0(%rbp)
leaq -0x1a0(%rbp), %rdi
callq 0x5160
movq -0x2b8(%rbp), %rdi
movq -0x2b0(%rbp), %rsi
movq %rax, %rdx
callq 0x155e0
movl -0x1ec(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x2c0, %rsp            # imm = 0x2C0
popq %rbp
retq
nopw (%rax,%rax)