#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ F_OK;
int /*<<< orphan*/ *_get_current_date_string(char *, int);
scalar_t__ access(char const *, int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(int);
int rename(char const *, char *);
int /*<<< orphan*/ sprintf(char *, char *, char const *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char const *);
int _bkp_logfile(const char *file) {
  char *buffer = NULL;
  int ret = 0;
  if (!file || 0 != access(file, F_OK)) {
    return -1;
  }
  buffer = (char *)malloc(strlen(file) + strlen(".yyyy-mm-dd HH:ii:ss") +
                          sizeof(char));
  if (buffer == NULL) {
    return -1;
  }
  sprintf(buffer, "%s.", file);
  if (NULL == _get_current_date_string(buffer + strlen(file) + strlen("."),
                                       strlen("yyyy-mm-dd HH:ii:ss") + 1)) {
    strcpy(buffer + strlen(file) + strlen("."), "0000-00-00 00:00:00");
  }
  ret = rename(file, buffer);
  free(buffer);
  return ret;
}


x86 assembly (clang, -O0):
<_bkp_logfile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11c6 <_bkp_logfile+0x46>
mov    -0x10(%rbp),%rdi
mov    0x2e27(%rip),%rax
mov    (%rax),%esi
call   1080 <access@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     11d2 <_bkp_logfile+0x52>
movl   $0xffffffff,-0x4(%rbp)
jmp    12f3 <_bkp_logfile+0x173>
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x20(%rbp)
lea    0xe1b(%rip),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
add    %ecx,%eax
cltq
add    $0x1,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1219 <_bkp_logfile+0x99>
movl   $0xffffffff,-0x4(%rbp)
jmp    12f3 <_bkp_logfile+0x173>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xded(%rip),%rsi
call   10a0 <sprintf@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x38(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
lea    0xdc2(%rip),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
lea    0xd90(%rip),%rdi
call   1050 <strlen@plt>
mov    -0x28(%rbp),%rdi
mov    %eax,%esi
add    $0x1,%esi
call   1070 <_get_current_date_string@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    12d4 <_bkp_logfile+0x154>
mov    -0x18(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x48(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x40(%rbp)
lea    0xd5d(%rip),%rdi
call   1050 <strlen@plt>
mov    -0x40(%rbp),%rdi
cltq
add    %rax,%rdi
lea    0xd4a(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1090 <rename@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_bkp_logfile>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %rdi,%rdi
je     11a3 <_bkp_logfile+0x23>
mov    %rdi,%rbx
mov    0x2e41(%rip),%rax
mov    (%rax),%esi
call   1080 <access@plt>
test   %rax,%rax
je     11b4 <_bkp_logfile+0x34>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %eax,%r14d
lea    0xe3a(%rip),%rdi
call   1050 <strlen@plt>
lea    (%r14,%rax,1),%edi
add    $0x1,%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     11a3 <_bkp_logfile+0x23>
mov    %rax,%r14
lea    0xe2f(%rip),%rsi
mov    %rax,%rdi
mov    %rbx,%rdx
call   10a0 <sprintf@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
movslq %eax,%r12
add    %r14,%r12
lea    0xe11(%rip),%rdi
call   1050 <strlen@plt>
movslq %eax,%r15
add    %r12,%r15
lea    0xde9(%rip),%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%esi
mov    %r15,%rdi
call   1070 <_get_current_date_string@plt>
test   %rax,%rax
jne    125b <_bkp_logfile+0xdb>
mov    %rbx,%rdi
call   1050 <strlen@plt>
cltq
mov    %r14,%r15
add    %rax,%r15
lea    0xdd3(%rip),%rdi
call   1050 <strlen@plt>
movslq %eax,%rdi
add    %r15,%rdi
lea    0xdc3(%rip),%rsi
call   1040 <strcpy@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1090 <rename@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1030 <free@plt>
mov    %ebx,%eax
jmp    11a8 <_bkp_logfile+0x28>

LLVM IR (-O0):
@F_OK = global i32 0
@.str = [21 x i8] c".yyyy-mm-dd HH:ii:ss\00"
@.str.1 = [4 x i8] c"%s.\00"
@.str.2 = [2 x i8] c".\00"
@.str.3 = [20 x i8] c"yyyy-mm-dd HH:ii:ss\00"
@.str.4 = [20 x i8] c"0000-00-00 00:00:00\00"
define i32 @_bkp_logfile(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %3
store i8* null, i8** %4
store i32 0, i32* %5
%6 = load i8*, i8** %3
%7 = icmp ne i8* %6, null
br i1 %7, label %8, label %13
8: ; preds = %1
%9 = load i8*, i8** %3
%10 = load i32, i32* @F_OK
%11 = call i64 @access(i8* %9, i32 %10)
%12 = icmp ne i64 0, %11
br i1 %12, label %13, label %14
13: ; preds = %8, %1
store i32 -1, i32* %2
br label %60
14: ; preds = %8
%15 = load i8*, i8** %3
%16 = call i32 @strlen(i8* %15)
%17 = call i32 @strlen(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%18 = add nsw i32 %16, %17
%19 = sext i32 %18 to i64
%20 = add i64 %19, 1
%21 = trunc i64 %20 to i32
%22 = call i64 @malloc(i32 %21)
%23 = inttoptr i64 %22 to i8*
store i8* %23, i8** %4
%24 = load i8*, i8** %4
%25 = icmp eq i8* %24, null
br i1 %25, label %26, label %27
26: ; preds = %14
store i32 -1, i32* %2
br label %60
27: ; preds = %14
%28 = load i8*, i8** %4
%29 = load i8*, i8** %3
%30 = call i32 @sprintf(i8* %28, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %29)
%31 = load i8*, i8** %4
%32 = load i8*, i8** %3
%33 = call i32 @strlen(i8* %32)
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %31, i64 %34
%36 = call i32 @strlen(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %35, i64 %37
%39 = call i32 @strlen(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
%40 = add nsw i32 %39, 1
%41 = call i32* @_get_current_date_string(i8* %38, i32 %40)
%42 = icmp eq i32* null, %41
br i1 %42, label %43, label %53
43: ; preds = %27
%44 = load i8*, i8** %4
%45 = load i8*, i8** %3
%46 = call i32 @strlen(i8* %45)
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i8, i8* %44, i64 %47
%49 = call i32 @strlen(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i8, i8* %48, i64 %50
%52 = call i32 @strcpy(i8* %51, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
br label %53
53: ; preds = %43, %27
%54 = load i8*, i8** %3
%55 = load i8*, i8** %4
%56 = call i32 @rename(i8* %54, i8* %55)
store i32 %56, i32* %5
%57 = load i8*, i8** %4
%58 = call i32 @free(i8* %57)
%59 = load i32, i32* %5
store i32 %59, i32* %2
br label %60
60: ; preds = %53, %26, %13
%61 = load i32, i32* %2
ret i32 %61
}

LLVM IR (-O2):
@F_OK = global i32 0
@.str = [21 x i8] c".yyyy-mm-dd HH:ii:ss\00"
@.str.1 = [4 x i8] c"%s.\00"
@.str.2 = [2 x i8] c".\00"
@.str.3 = [20 x i8] c"yyyy-mm-dd HH:ii:ss\00"
@.str.4 = [20 x i8] c"0000-00-00 00:00:00\00"
define i32 @_bkp_logfile(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %38, label %3
3: ; preds = %1
%4 = load i32, i32* @F_OK
%5 = tail call i64 @access(i8* %0, i32 %4)
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %38
7: ; preds = %3
%8 = tail call i32 @strlen(i8* %0)
%9 = tail call i32 @strlen(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%10 = add i32 %8, 1
%11 = add i32 %10, %9
%12 = tail call i64 @malloc(i32 %11)
%13 = inttoptr i64 %12 to i8*
%14 = icmp eq i64 %12, 0
br i1 %14, label %38, label %15
15: ; preds = %7
%16 = tail call i32 @sprintf(i8* %13, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%17 = tail call i32 @strlen(i8* %0)
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %13, i64 %18
%20 = tail call i32 @strlen(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %19, i64 %21
%23 = tail call i32 @strlen(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
%24 = add nsw i32 %23, 1
%25 = tail call i32* @_get_current_date_string(i8* %22, i32 %24)
%26 = icmp eq i32* %25, null
br i1 %26, label %27, label %35
27: ; preds = %15
%28 = tail call i32 @strlen(i8* %0)
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %13, i64 %29
%31 = tail call i32 @strlen(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %30, i64 %32
%34 = tail call i32 @strcpy(i8* %33, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
br label %35
35: ; preds = %27, %15
%36 = tail call i32 @rename(i8* %0, i8* %13)
%37 = tail call i32 @free(i8* %13)
br label %38
38: ; preds = %7, %1, %3, %35
%39 = phi i32 [ %36, %35 ], [ -1, %3 ], [ -1, %1 ], [ -1, %7 ]
ret i32 %39
}