// File: /workspace/github_c_makefile_star2_O3/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 0x7a67(%rip), %r15      # 0xc538
testq %r15, %r15
je 0x4be6
movq 0x7a6f(%rip), %r12      # 0xc550
testq %r12, %r12
setne %cl
movl 0x7a73(%rip), %eax      # 0xc560
testl %eax, %eax
setg %dl
andb %cl, %dl
xorl %ebx, %ebx
movl $0x0, %r14d
cmpb $0x1, %dl
jne 0x4b26
movl %eax, %r14d
movq %r14, %rdi
callq 0x22a0
testq %rax, %rax
je 0x4cea
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 0x369d(%rip), %rdx      # 0x8206
leaq 0x76c0(%rip), %r14      # 0xc230
leaq 0x78b9(%rip), %r13      # 0xc430
movl $0x100, %esi            # imm = 0x100
movq %r15, %rdi
movq %r14, %rcx
movq %r13, %r8
xorl %eax, %eax
callq 0x2170
leaq 0x367d(%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 0x4d05
xorl %ebx, %ebx
movq %rbx, 0x7974(%rip)      # 0xc538
leaq 0x7865(%rip), %rdi      # 0xc430
movl $0x100, %edx            # imm = 0x100
xorl %esi, %esi
callq 0x21a0
incl 0x7963(%rip)            # 0xc540
movq %rbx, 0x7978(%rip)      # 0xc55c
jmp 0x4bf6
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 0x78ed(%rip), %r14d     # 0xc540
subq $0x8, %rsp
leaq 0x77d2(%rip), %rbx      # 0xc430
leaq 0x35d2(%rip), %rdx      # 0x8237
leaq 0x76c4(%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 0x3577(%rip), %rdx      # 0x8206
movl $0x100, %esi            # imm = 0x100
movq %r12, %rdi
leaq 0x7592(%rip), %rcx      # 0xc230
movq %rbx, %r8
xorl %eax, %eax
callq 0x2170
leaq 0x359e(%rip), %rsi      # 0x824d
movq %r12, %rdi
callq 0x2300
testq %rax, %rax
je 0x4cea
movq %rax, 0x7875(%rip)      # 0xc538
movq -0x38(%rbp), %rbx
testq %rbx, %rbx
je 0x4cf0
movl $0x1, %esi
movq %rbx, %rdi
movq -0x30(%rbp), %rdx
movq %rax, %rcx
callq 0x2350
movq %rbx, %rdi
callq 0x2030
jmp 0x4cf0
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 0x4bbb