// File: /workspace/github_c_makefile_star2_O2/Carton32[P]quectel-CM/qmap_bridge_mode.c
// Function: ql_enable_qmi_wwan_rawip_mode
int ql_enable_qmi_wwan_rawip_mode(PROFILE_T *profile) {
    char filename[256];
    char buf[4];
    size_t n;
    FILE *fp;

    if (!qmidev_is_qmiwwan(profile->qmichannel))
        return 0;

    snprintf(filename, sizeof(filename), "/sys/class/net/%s/qmi/rawip", profile->usbnet_adapter);
    n = ql_fread(filename, buf, sizeof(buf));

    if (n == 0)
        return 0;

    if (buf[0] == '1' || buf[0] == 'Y')
        return 0;

    fp = fopen(filename , "w");
    if (fp == NULL) {
        dbg_time("Fail to fopen(%s, \"w\"), errno: %d (%s)", filename, errno, strerror(errno));
        return 1;
    }

    buf[0] = 'Y';
    n = fwrite(buf, 1, 1, fp);
    if (n != 1) {
        dbg_time("Fail to fwrite(%s), errno: %d (%s)", filename, errno, strerror(errno));
        fclose(fp);
        return 1;
    }
    fclose(fp);

    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x110, %rsp            # imm = 0x110
movq %rdi, %r14
addq $0x8a, %rdi
leaq 0xfa17(%rip), %rsi      # 0x1efaa
pushq $0xc
popq %rdx
callq 0x5090
xorl %ebx, %ebx
testl %eax, %eax
je 0xf5b3
movl %ebx, %eax
addq $0x110, %rsp            # imm = 0x110
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
addq $0xaa, %r14
leaq 0xf9f6(%rip), %rdx      # 0x1efb7
xorl %ebx, %ebx
leaq 0x10(%rsp), %r15
movl $0x100, %esi            # imm = 0x100
movq %r15, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x51c0
leaq 0xc(%rsp), %rsi
pushq $0x4
popq %rdx
movq %r15, %rdi
callq 0xf365
testq %rax, %rax
je 0xf5a1
movzbl 0xc(%rsp), %eax
cmpl $0x31, %eax
je 0xf5a1
cmpl $0x59, %eax
je 0xf5a1
leaq 0x10058(%rip), %rsi     # 0x1f65d
leaq 0x10(%rsp), %rdi
callq 0x5480
testq %rax, %rax
je 0xf644
movq %rax, %r14
leaq 0xc(%rsp), %rdi
movb $0x59, (%rdi)
pushq $0x1
popq %rdx
movq %rdx, %rsi
movq %rax, %rcx
callq 0x5510
cmpq $0x1, %rax
jne 0xf6d2
movq %r14, %rdi
callq 0x5130
jmp 0xf5a1
movq 0x1996d(%rip), %rax     # 0x28fb8
movq (%rax), %rbx
callq 0xe343
movq %rax, %r15
callq 0x5070
movq %rax, %r14
movl (%rax), %ebp
movl %ebp, %edi
callq 0x5540
leaq 0xf965(%rip), %rsi      # 0x1efd3
leaq 0x10(%rsp), %rcx
movq %rbx, %rdi
movq %r15, %rdx
movl %ebp, %r8d
movq %rax, %r9
xorl %eax, %eax
callq 0x52c0
leaq 0x1a61b(%rip), %rax     # 0x29ca8
movq (%rax), %r15
pushq $0x1
popq %rbx
testq %r15, %r15
je 0xf5a1
callq 0xe343
movq %rax, %r12
movl (%r14), %ebp
movl %ebp, %edi
callq 0x5540
leaq 0xf91e(%rip), %rsi      # 0x1efd3
leaq 0x10(%rsp), %rcx
movq %r15, %rdi
movq %r12, %rdx
movl %ebp, %r8d
movq %rax, %r9
xorl %eax, %eax
callq 0x52c0
jmp 0xf5a1
movq 0x198df(%rip), %rax     # 0x28fb8
movq (%rax), %r15
callq 0xe343
movq %rax, %r12
callq 0x5070
movq %rax, %rbx
movl (%rax), %ebp
movl %ebp, %edi
callq 0x5540
leaq 0xf904(%rip), %rsi      # 0x1f000
leaq 0x10(%rsp), %rcx
movq %r15, %rdi
movq %r12, %rdx
movl %ebp, %r8d
movq %rax, %r9
xorl %eax, %eax
callq 0x52c0
leaq 0x1a58d(%rip), %rax     # 0x29ca8
movq (%rax), %r15
testq %r15, %r15
je 0xf753
callq 0xe343
movq %rax, %r12
movl (%rbx), %ebx
movl %ebx, %edi
callq 0x5540
leaq 0xf8c5(%rip), %rsi      # 0x1f000
leaq 0x10(%rsp), %rcx
movq %r15, %rdi
movq %r12, %rdx
movl %ebx, %r8d
movq %rax, %r9
xorl %eax, %eax
callq 0x52c0
movq %r14, %rdi
callq 0x5130
pushq $0x1
popq %rbx
jmp 0xf5a1