// File: /workspace/github_c_makefile_star2_O1/buf1024[P]mysch/log.c
// Function: log_file_init_callback_fun
int log_file_init_callback_fun(void* args)
{
    FILE* fp = _file_log_ctx.fp;
    char* rst = NULL;
    int rst_size = 0;
    if(fp != NULL){
        if(_file_log_ctx.buf && _file_log_ctx.w_pos > 0) {
            rst_size = _file_log_ctx.w_pos;
            rst = (char*)malloc(_file_log_ctx.w_pos);
            if(!rst) {
                return LOG_FAIL;
            }
            memcpy(rst, _file_log_ctx.buf, _file_log_ctx.w_pos);
        }

        fclose(fp);

        char old_path[LOG_DEFAULT_MAX_PATH] = {0};
        char new_path[LOG_DEFAULT_MAX_PATH] = {0};

        snprintf(old_path, LOG_DEFAULT_MAX_PATH, "%s/%s.tmp",
                _file_log_ctx.path, _file_log_ctx.name);

        snprintf(new_path, LOG_DEFAULT_MAX_PATH, "%s/%s.log",
                        _file_log_ctx.path, _file_log_ctx.name);

        if(rename(old_path, new_path) != 0) {
            fprintf(stderr, "rename %s - > %s failed: %s\n", old_path, new_path, strerror(errno));
        }

        _file_log_ctx.fp = NULL;
        memset(_file_log_ctx.name, 0, LOG_DEFAULT_MAX_PATH);
        _file_log_ctx.file_count += 1;
        _file_log_ctx.w_size = 0;
        _file_log_ctx.w_pos = 0;
    }

    char file[LOG_DEFAULT_MAX_PATH] = {0};
    pid_t pid = getpid();

    struct timeval tv = {0};
    gettimeofday(&tv, NULL);
    struct tm* tm = localtime(&tv.tv_sec);

    snprintf(_file_log_ctx.name, LOG_DEFAULT_MAX_PATH, "%s_%d_%04d%02d%02d_%d",
            _file_log_ctx.prefix, pid,
            tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
            _file_log_ctx.file_count);

    snprintf(file, LOG_DEFAULT_MAX_PATH, "%s/%s.tmp",
            _file_log_ctx.path, _file_log_ctx.name);

    fp = fopen(file, "a+");
    if(fp == NULL){
        return LOG_FAIL;
    }
    _file_log_ctx.fp = fp;

    if(rst) {
        fwrite(rst, 1, rst_size, _file_log_ctx.fp);
        free(rst);
    }

    return LOG_SUCCESS;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x218, %rsp            # imm = 0x218
movq 0x7943(%rip), %r15      # 0xc538
testq %r15, %r15
je 0x4d0a
movq 0x794b(%rip), %r12      # 0xc550
testq %r12, %r12
setne %cl
movl 0x794f(%rip), %eax      # 0xc560
testl %eax, %eax
setg %dl
andb %cl, %dl
xorl %ebx, %ebx
movl $0x0, %r14d
cmpb $0x1, %dl
jne 0x4c4a
movl %eax, %r14d
movq %r14, %rdi
callq 0x22a0
testq %rax, %rax
je 0x4e0e
movq %rax, %rbx
movq %rax, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x2250
movq %r14, -0x30(%rbp)
movq %rbx, -0x38(%rbp)
movq %r15, %rdi
callq 0x2110
leaq -0x240(%rbp), %r15
movl $0x100, %edx            # imm = 0x100
movq %r15, %rdi
xorl %esi, %esi
callq 0x21a0
leaq -0x140(%rbp), %r12
movl $0x100, %edx            # imm = 0x100
movq %r12, %rdi
xorl %esi, %esi
callq 0x21a0
leaq 0x3579(%rip), %rdx      # 0x8206
leaq 0x759c(%rip), %r14      # 0xc230
leaq 0x7795(%rip), %r13      # 0xc430
movl $0x100, %esi            # imm = 0x100
movq %r15, %rdi
movq %r14, %rcx
movq %r13, %r8
xorl %eax, %eax
callq 0x2170
leaq 0x3559(%rip), %rdx      # 0x8210
movl $0x100, %esi            # imm = 0x100
movq %r12, %rdi
movq %r14, %rcx
movq %r13, %r8
xorl %eax, %eax
callq 0x2170
movq %r15, %rdi
movq %r12, %rsi
callq 0x2310
testl %eax, %eax
jne 0x4e29
xorl %ebx, %ebx
movq %rbx, 0x7850(%rip)      # 0xc538
leaq 0x7741(%rip), %rdi      # 0xc430
movl $0x100, %edx            # imm = 0x100
xorl %esi, %esi
callq 0x21a0
incl 0x783f(%rip)            # 0xc540
movq %rbx, 0x7854(%rip)      # 0xc55c
jmp 0x4d1a
movq $0x0, -0x38(%rbp)
movq $0x0, -0x30(%rbp)
leaq -0x240(%rbp), %r12
xorl %r15d, %r15d
movl $0x100, %edx            # imm = 0x100
movq %r12, %rdi
xorl %esi, %esi
callq 0x21a0
callq 0x2100
movl %eax, %r13d
xorps %xmm0, %xmm0
leaq -0x140(%rbp), %r14
movaps %xmm0, (%r14)
movq %r14, %rdi
xorl %esi, %esi
callq 0x2190
movq %r14, %rdi
callq 0x2050
movl $0x76c, %r9d            # imm = 0x76C
addl 0x14(%rax), %r9d
movl 0xc(%rax), %r10d
movl 0x10(%rax), %r11d
incl %r11d
movl 0x77c9(%rip), %r14d     # 0xc540
subq $0x8, %rsp
leaq 0x76ae(%rip), %rbx      # 0xc430
leaq 0x34ae(%rip), %rdx      # 0x8237
leaq 0x75a0(%rip), %rcx      # 0xc330
movl $0x100, %esi            # imm = 0x100
movq %rbx, %rdi
movl %r13d, %r8d
xorl %eax, %eax
pushq %r14
pushq %r10
pushq %r11
callq 0x2170
addq $0x20, %rsp
leaq 0x3453(%rip), %rdx      # 0x8206
movl $0x100, %esi            # imm = 0x100
movq %r12, %rdi
leaq 0x746e(%rip), %rcx      # 0xc230
movq %rbx, %r8
xorl %eax, %eax
callq 0x2170
leaq 0x347a(%rip), %rsi      # 0x824d
movq %r12, %rdi
callq 0x2300
testq %rax, %rax
je 0x4e0e
movq %rax, 0x7751(%rip)      # 0xc538
movq -0x38(%rbp), %rbx
testq %rbx, %rbx
je 0x4e14
movl $0x1, %esi
movq %rbx, %rdi
movq -0x30(%rbp), %rdx
movq %rax, %rcx
callq 0x2350
movq %rbx, %rdi
callq 0x2030
jmp 0x4e14
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
movl %r15d, %eax
addq $0x218, %rsp            # imm = 0x218
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq -0x240(%rbp), %rdi
leaq -0x140(%rbp), %rsi
callq 0x248f
jmp 0x4cdf