// File: /workspace/github_c_makefile_star2_O2/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 0x6db6(%rip), %r15      # 0xb538
testq %r15, %r15
je 0x4897
movq 0x6dbe(%rip), %r12      # 0xb550
testq %r12, %r12
setne %cl
movl 0x6dc2(%rip), %eax      # 0xb560
testl %eax, %eax
setg %dl
andb %cl, %dl
xorl %ebx, %ebx
movl $0x0, %r14d
cmpb $0x1, %dl
jne 0x47d7
movl %eax, %r14d
movq %r14, %rdi
callq 0x22a0
testq %rax, %rax
je 0x4999
movq %rax, %rbx
movq %rax, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x2250
movq %r14, -0x30(%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 0x29f0(%rip), %rdx      # 0x7206
leaq 0x6a13(%rip), %r14      # 0xb230
leaq 0x6c0c(%rip), %r13      # 0xb430
movl $0x100, %esi            # imm = 0x100
movq %r15, %rdi
movq %r14, %rcx
movq %r13, %r8
xorl %eax, %eax
callq 0x2170
leaq 0x29d0(%rip), %rdx      # 0x7210
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 0x49b2
movq %rbx, -0x38(%rbp)
andq $0x0, 0x6cc4(%rip)      # 0xb538
leaq 0x6bb5(%rip), %rdi      # 0xb430
movl $0x100, %edx            # imm = 0x100
xorl %esi, %esi
callq 0x21a0
incl 0x6cb3(%rip)            # 0xb540
andq $0x0, 0x6cc7(%rip)      # 0xb55c
jmp 0x48a7
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 0x6c3c(%rip), %r14d     # 0xb540
subq $0x8, %rsp
leaq 0x6b21(%rip), %rbx      # 0xb430
leaq 0x2921(%rip), %rdx      # 0x7237
leaq 0x6a13(%rip), %rcx      # 0xb330
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 0x28c6(%rip), %rdx      # 0x7206
movl $0x100, %esi            # imm = 0x100
movq %r12, %rdi
leaq 0x68e1(%rip), %rcx      # 0xb230
movq %rbx, %r8
xorl %eax, %eax
callq 0x2170
leaq 0x28ed(%rip), %rsi      # 0x724d
movq %r12, %rdi
callq 0x2300
testq %rax, %rax
je 0x4999
movq %rax, 0x6bc4(%rip)      # 0xb538
movq -0x38(%rbp), %rbx
testq %rbx, %rbx
je 0x499d
pushq $0x1
popq %rsi
movq %rbx, %rdi
movq -0x30(%rbp), %rdx
movq %rax, %rcx
callq 0x2350
movq %rbx, %rdi
callq 0x2030
jmp 0x499d
pushq $-0x1
popq %r15
movl %r15d, %eax
addq $0x218, %rsp            # imm = 0x218
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x663f(%rip), %rax      # 0xaff8
movq (%rax), %r14
callq 0x2060
movl (%rax), %edi
callq 0x2370
leaq 0x284b(%rip), %rsi      # 0x721a
leaq -0x240(%rbp), %rdx
leaq -0x140(%rbp), %rcx
movq %r14, %rdi
movq %rax, %r8
xorl %eax, %eax
callq 0x2220
jmp 0x4868