#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*/ time_t;
struct tm {
  int tm_year;
  int tm_mon;
  int tm_mday;
  int /*<<< orphan*/ tm_sec;
  int /*<<< orphan*/ tm_min;
  int /*<<< orphan*/ tm_hour;
};

/* Variables and functions */
struct tm *localtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ rename(char const *, char *);
int /*<<< orphan*/ snprintf(char *, int, char *, ...);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
void rename_logfile(const char *fname) {
  time_t now = time(NULL);
  struct tm *r = localtime(&now);
  char postfix[100];
  char newname[4096 + 255];
  snprintf(postfix, 99, "%4d%02d%02d%02d%02d%02d", r->tm_year + 1900,
           r->tm_mon + 1, r->tm_mday, r->tm_hour, r->tm_min, r->tm_sec);
  snprintf(newname, 4096 + 255 - 1, "%s.%s", fname, postfix);
  rename(fname, newname);
}


x86 assembly (clang, -O0):
<rename_logfile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x11a0,%rsp
mov    %rdi,-0x8(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1050 <time@plt>
mov    %eax,-0xc(%rbp)
lea    -0xc(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x18(%rbp)
lea    -0x80(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
add    $0x76c,%ecx
mov    -0x18(%rbp),%rax
mov    0x4(%rax),%r8d
add    $0x1,%r8d
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%r9d
mov    -0x18(%rbp),%rax
mov    0x14(%rax),%r11d
mov    -0x18(%rbp),%rax
mov    0x10(%rax),%r10d
mov    -0x18(%rbp),%rax
mov    0xc(%rax),%eax
mov    $0x63,%esi
lea    0xe51(%rip),%rdx
mov    %r11d,(%rsp)
mov    %r10d,0x8(%rsp)
mov    %eax,0x10(%rsp)
mov    $0x0,%al
call   1040 <snprintf@plt>
lea    -0x1180(%rbp),%rdi
mov    -0x8(%rbp),%rcx
lea    -0x80(%rbp),%r8
mov    $0x10fe,%esi
lea    0xe3a(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
mov    -0x8(%rbp),%rdi
lea    -0x1180(%rbp),%rsi
call   1060 <rename@plt>
add    $0x11a0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rename_logfile>:
push   %r15
push   %r14
push   %rbx
sub    $0x1180,%rsp
mov    %rdi,%r15
xor    %edi,%edi
call   1050 <time@plt>
mov    %eax,0xc(%rsp)
lea    0xc(%rsp),%rdi
call   1030 <localtime@plt>
mov    $0x76c,%ecx
add    (%rax),%ecx
mov    0x4(%rax),%r8d
mov    0x8(%rax),%r9d
add    $0x1,%r8d
mov    0x14(%rax),%r10d
mov    0x10(%rax),%r11d
mov    0xc(%rax),%ebx
sub    $0x8,%rsp
lea    0xe73(%rip),%rdx
lea    0x18(%rsp),%r14
mov    %r14,%rdi
mov    $0x63,%esi
xor    %eax,%eax
push   %rbx
push   %r11
push   %r10
call   1040 <snprintf@plt>
add    $0x20,%rsp
lea    0xe67(%rip),%rdx
lea    0x80(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x10fe,%esi
mov    %r15,%rcx
mov    %r14,%r8
xor    %eax,%eax
call   1040 <snprintf@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1060 <rename@plt>
add    $0x1180,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.tm = type { i32, i32, i32, i32, i32, i32 }
@.str = [24 x i8] c"%4d%02d%02d%02d%02d%02d\00"
@.str.1 = [6 x i8] c"%s.%s\00"
define void @rename_logfile(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca %struct.tm*
%5 = alloca [100 x i8]
%6 = alloca [4351 x i8]
store i8* %0, i8** %2
%7 = call i32 @time(i32* null)
store i32 %7, i32* %3
%8 = call %struct.tm* @localtime(i32* %3)
store %struct.tm* %8, %struct.tm** %4
%9 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%10 = load %struct.tm*, %struct.tm** %4
%11 = getelementptr inbounds %struct.tm, %struct.tm* %10, i32 0, i32 0
%12 = load i32, i32* %11
%13 = add nsw i32 %12, 1900
%14 = load %struct.tm*, %struct.tm** %4
%15 = getelementptr inbounds %struct.tm, %struct.tm* %14, i32 0, i32 1
%16 = load i32, i32* %15
%17 = add nsw i32 %16, 1
%18 = load %struct.tm*, %struct.tm** %4
%19 = getelementptr inbounds %struct.tm, %struct.tm* %18, i32 0, i32 2
%20 = load i32, i32* %19
%21 = load %struct.tm*, %struct.tm** %4
%22 = getelementptr inbounds %struct.tm, %struct.tm* %21, i32 0, i32 5
%23 = load i32, i32* %22
%24 = load %struct.tm*, %struct.tm** %4
%25 = getelementptr inbounds %struct.tm, %struct.tm* %24, i32 0, i32 4
%26 = load i32, i32* %25
%27 = load %struct.tm*, %struct.tm** %4
%28 = getelementptr inbounds %struct.tm, %struct.tm* %27, i32 0, i32 3
%29 = load i32, i32* %28
%30 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %9, i32 99, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %13, i32 %17, i32 %20, i32 %23, i32 %26, i32 %29)
%31 = getelementptr inbounds [4351 x i8], [4351 x i8]* %6, i64 0, i64 0
%32 = load i8*, i8** %2
%33 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%34 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %31, i32 4350, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %32, i8* %33)
%35 = load i8*, i8** %2
%36 = getelementptr inbounds [4351 x i8], [4351 x i8]* %6, i64 0, i64 0
%37 = call i32 @rename(i8* %35, i8* %36)
ret void
}

LLVM IR (-O2):
%struct.tm = type { i32, i32, i32, i32, i32, i32 }
@.str = [24 x i8] c"%4d%02d%02d%02d%02d%02d\00"
@.str.1 = [6 x i8] c"%s.%s\00"
define void @rename_logfile(i8* %0) {
%2 = alloca i32
%3 = alloca [100 x i8]
%4 = alloca [4351 x i8]
%5 = bitcast i32* %2 to i8*
%6 = tail call i32 @time(i32* null)
store i32 %6, i32* %2
%7 = call %struct.tm* @localtime(i32* %2)
%8 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%9 = getelementptr inbounds [4351 x i8], [4351 x i8]* %4, i64 0, i64 0
%10 = getelementptr inbounds %struct.tm, %struct.tm* %7, i64 0, i32 0
%11 = load i32, i32* %10
%12 = add nsw i32 %11, 1900
%13 = getelementptr inbounds %struct.tm, %struct.tm* %7, i64 0, i32 1
%14 = load i32, i32* %13
%15 = add nsw i32 %14, 1
%16 = getelementptr inbounds %struct.tm, %struct.tm* %7, i64 0, i32 2
%17 = load i32, i32* %16
%18 = getelementptr inbounds %struct.tm, %struct.tm* %7, i64 0, i32 5
%19 = load i32, i32* %18
%20 = getelementptr inbounds %struct.tm, %struct.tm* %7, i64 0, i32 4
%21 = load i32, i32* %20
%22 = getelementptr inbounds %struct.tm, %struct.tm* %7, i64 0, i32 3
%23 = load i32, i32* %22
%24 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %8, i32 99, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %12, i32 %15, i32 %17, i32 %19, i32 %21, i32 %23)
%25 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %9, i32 4350, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %8)
%26 = call i32 @rename(i8* %0, i8* %9)
ret void
}