#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 */
typedef int /*<<< orphan*/ timestring;
typedef int /*<<< orphan*/ time_t;

/* Variables and functions */
scalar_t__ ENOENT;
int /*<<< orphan*/ F_OK;
int /*<<< orphan*/ LOG_DEBUG;
int /*<<< orphan*/ LOG_ERR;
scalar_t__ access(char *, int /*<<< orphan*/);
scalar_t__ errno;
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ localtime(int /*<<< orphan*/ *);
char *malloc(scalar_t__);
int /*<<< orphan*/ rename(char *, char *);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ strftime(char *, int, char *, int /*<<< orphan*/);
scalar_t__ strlen(char *);
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
void save_dumpfile(char *fname) {
  char *s;
  char timestring[16];
  time_t tmptime = time(NULL);
  if (access(fname, F_OK) == 0) {
    syslog(LOG_DEBUG, "found old dumpfile (%s)", fname);
    s = malloc(strlen(fname) + 22);
    strcpy(s, fname);
    strcat(s, ".saved.");
    strftime(timestring, sizeof(timestring), "%Y%m%d%H%M%S",
             localtime(&tmptime));
    strcat(s, timestring);
    rename(fname, s);
    free(s);
  } else {
    if (errno != ENOENT) {
      syslog(LOG_ERR, "error accessing dumpfile: %m");
    } else {
      syslog(LOG_DEBUG, "no old dumpfile (%s) exists", fname);
    }
  }
}


x86 assembly (clang, -O0):
<save_dumpfile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1070 <time@plt>
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2de5(%rip),%rax
mov    (%rax),%esi
call   10b0 <access@plt>
cmp    $0x0,%rax
jne    1285 <save_dumpfile+0xd5>
mov    0x2ded(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe08(%rip),%rsi
mov    $0x0,%al
call   1090 <syslog@plt>
mov    -0x8(%rbp),%rdi
call   1060 <strlen@plt>
mov    %rax,%rdi
add    $0x16,%rdi
call   1080 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1050 <strcpy@plt>
mov    -0x10(%rbp),%rdi
lea    0xde8(%rip),%rsi
call   10d0 <strcat@plt>
lea    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
lea    -0x24(%rbp),%rdi
call   1040 <localtime@plt>
mov    -0x30(%rbp),%rdi
mov    %eax,%ecx
mov    $0x10,%esi
lea    0xdc8(%rip),%rdx
call   10a0 <strftime@plt>
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   10d0 <strcat@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   10c0 <rename@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
jmp    12db <save_dumpfile+0x12b>
mov    0x2d54(%rip),%rax
mov    (%rax),%rax
mov    0x2d32(%rip),%rcx
cmp    (%rcx),%rax
je     12bb <save_dumpfile+0x10b>
mov    0x2d1a(%rip),%rax
mov    (%rax),%edi
lea    0xd7e(%rip),%rsi
mov    $0x0,%al
call   1090 <syslog@plt>
jmp    12d6 <save_dumpfile+0x126>
mov    0x2d16(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xd7b(%rip),%rsi
mov    $0x0,%al
call   1090 <syslog@plt>
jmp    12db <save_dumpfile+0x12b>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<save_dumpfile>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %rdi,%r14
xor    %edi,%edi
call   1070 <time@plt>
mov    %eax,0xc(%rsp)
mov    0x2dea(%rip),%rax
mov    (%rax),%esi
mov    %r14,%rdi
call   10b0 <access@plt>
test   %rax,%rax
je     121a <save_dumpfile+0x6a>
mov    0x2dfc(%rip),%rax
mov    (%rax),%rax
mov    0x2dda(%rip),%rcx
cmp    (%rcx),%rax
jne    12af <save_dumpfile+0xff>
mov    0x2dda(%rip),%rax
mov    (%rax),%edi
lea    0xe43(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
jmp    1090 <syslog@plt>
mov    0x2db7(%rip),%rax
mov    (%rax),%edi
lea    0xdd6(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1090 <syslog@plt>
mov    %r14,%rdi
call   1060 <strlen@plt>
lea    0x16(%rax),%rdi
call   1080 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1050 <strcpy@plt>
lea    0xdbe(%rip),%rsi
mov    %rbx,%rdi
call   10d0 <strcat@plt>
lea    0xc(%rsp),%rdi
call   1040 <localtime@plt>
lea    0xdad(%rip),%rdx
lea    0x10(%rsp),%r15
mov    %r15,%rdi
mov    $0x10,%esi
mov    %eax,%ecx
call   10a0 <strftime@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   10d0 <strcat@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   10c0 <rename@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2d0a(%rip),%rax
mov    (%rax),%edi
lea    0xd6e(%rip),%rsi
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
jmp    1090 <syslog@plt>

LLVM IR (-O0):
@F_OK = global i32 0
@LOG_DEBUG = global i32 0
@.str = [24 x i8] c"found old dumpfile (%s)\00"
@.str.1 = [8 x i8] c".saved.\00"
@.str.2 = [13 x i8] c"%Y%m%d%H%M%S\00"
@errno = global i64 0
@ENOENT = global i64 0
@LOG_ERR = global i32 0
@.str.3 = [29 x i8] c"error accessing dumpfile: %m\00"
@.str.4 = [28 x i8] c"no old dumpfile (%s) exists\00"
define void @save_dumpfile(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca [16 x i8]
%5 = alloca i32
store i8* %0, i8** %2
%6 = call i32 @time(i32* null)
store i32 %6, i32* %5
%7 = load i8*, i8** %2
%8 = load i32, i32* @F_OK
%9 = call i64 @access(i8* %7, i32 %8)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %35
11: ; preds = %1
%12 = load i32, i32* @LOG_DEBUG
%13 = load i8*, i8** %2
%14 = call i32 (i32, i8*, ...) @syslog(i32 %12, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = load i8*, i8** %2
%16 = call i64 @strlen(i8* %15)
%17 = add nsw i64 %16, 22
%18 = call i8* @malloc(i64 %17)
store i8* %18, i8** %3
%19 = load i8*, i8** %3
%20 = load i8*, i8** %2
%21 = call i32 @strcpy(i8* %19, i8* %20)
%22 = load i8*, i8** %3
%23 = call i32 @strcat(i8* %22, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%24 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%25 = call i32 @localtime(i32* %5)
%26 = call i32 @strftime(i8* %24, i32 16, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %25)
%27 = load i8*, i8** %3
%28 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%29 = call i32 @strcat(i8* %27, i8* %28)
%30 = load i8*, i8** %2
%31 = load i8*, i8** %3
%32 = call i32 @rename(i8* %30, i8* %31)
%33 = load i8*, i8** %3
%34 = call i32 @free(i8* %33)
br label %47
35: ; preds = %1
%36 = load i64, i64* @errno
%37 = load i64, i64* @ENOENT
%38 = icmp ne i64 %36, %37
br i1 %38, label %39, label %42
39: ; preds = %35
%40 = load i32, i32* @LOG_ERR
%41 = call i32 (i32, i8*, ...) @syslog(i32 %40, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0))
br label %46
42: ; preds = %35
%43 = load i32, i32* @LOG_DEBUG
%44 = load i8*, i8** %2
%45 = call i32 (i32, i8*, ...) @syslog(i32 %43, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), i8* %44)
br label %46
46: ; preds = %42, %39
br label %47
47: ; preds = %46, %11
ret void
}

LLVM IR (-O2):
@F_OK = global i32 0
@LOG_DEBUG = global i32 0
@.str = [24 x i8] c"found old dumpfile (%s)\00"
@.str.1 = [8 x i8] c".saved.\00"
@.str.2 = [13 x i8] c"%Y%m%d%H%M%S\00"
@errno = global i64 0
@ENOENT = global i64 0
@LOG_ERR = global i32 0
@.str.3 = [29 x i8] c"error accessing dumpfile: %m\00"
@.str.4 = [28 x i8] c"no old dumpfile (%s) exists\00"
define void @save_dumpfile(i8* %0) {
%2 = alloca [16 x i8]
%3 = alloca i32
%4 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%5 = bitcast i32* %3 to i8*
%6 = tail call i32 @time(i32* null)
store i32 %6, i32* %3
%7 = load i32, i32* @F_OK
%8 = tail call i64 @access(i8* %0, i32 %7)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %23
10: ; preds = %1
%11 = load i32, i32* @LOG_DEBUG
%12 = tail call i32 (i32, i8*, ...) @syslog(i32 %11, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %0)
%13 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%14 = add nsw i64 %13, 22
%15 = tail call i8* @malloc(i64 %14)
%16 = tail call i32 @strcpy(i8* %15, i8* %0)
%17 = tail call i32 @strcat(i8* %15, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%18 = call i32 @localtime(i32* %3)
%19 = call i32 @strftime(i8* %4, i32 16, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %18)
%20 = call i32 @strcat(i8* %15, i8* %4)
%21 = call i32 @rename(i8* %0, i8* %15)
%22 = call i32 @free(i8* %15)
br label %33
23: ; preds = %1
%24 = load i64, i64* @errno
%25 = load i64, i64* @ENOENT
%26 = icmp eq i64 %24, %25
br i1 %26, label %30, label %27
27: ; preds = %23
%28 = load i32, i32* @LOG_ERR
%29 = tail call i32 (i32, i8*, ...) @syslog(i32 %28, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0))
br label %33
30: ; preds = %23
%31 = load i32, i32* @LOG_DEBUG
%32 = tail call i32 (i32, i8*, ...) @syslog(i32 %31, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), i8* %0)
br label %33
33: ; preds = %27, %30, %10
ret void
}