// File: /workspace/github_c_makefile_star2_O0/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
subq $0x380, %rsp            # imm = 0x380
movq %rdi, -0x10(%rbp)
movq 0x8832(%rip), %rax      # 0xe538
movq %rax, -0x18(%rbp)
movq $0x0, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x5ebe
cmpq $0x0, 0x8824(%rip)      # 0xe550
je 0x5d7a
cmpl $0x0, 0x882b(%rip)      # 0xe560
jle 0x5d7a
movl 0x8823(%rip), %eax      # 0xe560
movl %eax, -0x24(%rbp)
movslq 0x8819(%rip), %rdi      # 0xe560
callq 0x22b0
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x5d63
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x6010
movq -0x20(%rbp), %rdi
movq 0x87e2(%rip), %rsi      # 0xe550
movslq 0x87eb(%rip), %rdx      # 0xe560
callq 0x2250
movq -0x18(%rbp), %rdi
callq 0x2100
leaq -0x130(%rbp), %rdi
xorl %esi, %esi
movl $0x100, %edx            # imm = 0x100
callq 0x2190
leaq -0x230(%rbp), %rdi
xorl %esi, %esi
movl $0x100, %edx            # imm = 0x100
callq 0x2190
leaq -0x130(%rbp), %rdi
movl $0x100, %esi            # imm = 0x100
leaq 0x4450(%rip), %rdx      # 0xa20c
leaq 0x846d(%rip), %rcx      # 0xe230
movq %rcx, %r8
addq $0x200, %r8             # imm = 0x200
movb $0x0, %al
callq 0x2160
leaq -0x230(%rbp), %rdi
movl $0x100, %esi            # imm = 0x100
leaq 0x442f(%rip), %rdx      # 0xa216
leaq 0x8442(%rip), %rcx      # 0xe230
movq %rcx, %r8
addq $0x200, %r8             # imm = 0x200
movb $0x0, %al
callq 0x2160
leaq -0x130(%rbp), %rdi
leaq -0x230(%rbp), %rsi
callq 0x2310
cmpl $0x0, %eax
je 0x5e76
movq 0x81da(%rip), %rax      # 0xdff8
movq (%rax), %rax
movq %rax, -0x368(%rbp)
leaq -0x130(%rbp), %rax
movq %rax, -0x360(%rbp)
leaq -0x230(%rbp), %rax
movq %rax, -0x358(%rbp)
callq 0x2060
movl (%rax), %edi
callq 0x2370
movq -0x368(%rbp), %rdi
movq -0x360(%rbp), %rdx
movq -0x358(%rbp), %rcx
movq %rax, %r8
leaq 0x43b1(%rip), %rsi      # 0xa220
movb $0x0, %al
callq 0x2220
movq $0x0, 0x86b7(%rip) # 0xe538
leaq 0x83a8(%rip), %rdi      # 0xe230
addq $0x200, %rdi            # imm = 0x200
xorl %esi, %esi
movl $0x100, %edx            # imm = 0x100
callq 0x2190
movl 0x869f(%rip), %eax      # 0xe540
addl $0x1, %eax
movl %eax, 0x8696(%rip)      # 0xe540
movl $0x0, 0x86a8(%rip)      # 0xe55c
movl $0x0, 0x86a2(%rip)      # 0xe560
leaq -0x330(%rbp), %rdi
xorl %esi, %esi
movl $0x100, %edx            # imm = 0x100
callq 0x2190
callq 0x20f0
movl %eax, -0x334(%rbp)
leaq -0x348(%rbp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x2190
leaq -0x348(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x2180
leaq -0x348(%rbp), %rdi
callq 0x2050
movq %rax, -0x350(%rbp)
movl -0x334(%rbp), %r8d
movq -0x350(%rbp), %rax
movl 0x14(%rax), %r9d
addl $0x76c, %r9d            # imm = 0x76C
movq -0x350(%rbp), %rax
movl 0x10(%rax), %r11d
addl $0x1, %r11d
movq -0x350(%rbp), %rax
movl 0xc(%rax), %r10d
movl 0x85f5(%rip), %eax      # 0xe540
leaq 0x82de(%rip), %rcx      # 0xe230
movq %rcx, %rdi
addq $0x200, %rdi            # imm = 0x200
movl $0x100, %esi            # imm = 0x100
leaq 0x42d5(%rip), %rdx      # 0xa23d
addq $0x100, %rcx            # imm = 0x100
movl %r11d, (%rsp)
movl %r10d, 0x8(%rsp)
movl %eax, 0x10(%rsp)
movb $0x0, %al
callq 0x2160
leaq -0x330(%rbp), %rdi
movl $0x100, %esi            # imm = 0x100
leaq 0x4276(%rip), %rdx      # 0xa20c
leaq 0x8293(%rip), %rcx      # 0xe230
movq %rcx, %r8
addq $0x200, %r8             # imm = 0x200
movb $0x0, %al
callq 0x2160
leaq -0x330(%rbp), %rdi
leaq 0x4297(%rip), %rsi      # 0xa253
callq 0x2300
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x5fd5
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x6010
movq -0x18(%rbp), %rax
movq %rax, 0x8558(%rip)      # 0xe538
cmpq $0x0, -0x20(%rbp)
je 0x6009
movq -0x20(%rbp), %rdi
movslq -0x24(%rbp), %rdx
movq 0x8542(%rip), %rcx      # 0xe538
movl $0x1, %esi
callq 0x2350
movq -0x20(%rbp), %rdi
callq 0x2030
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x380, %rsp            # imm = 0x380
popq %rbp
retq
nopl (%rax)