#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 tm_hour;
  int tm_min;
  int /*<<< orphan*/ tm_sec;
};

/* Variables and functions */
char *getenv(char *);
struct tm *localtime(int /*<<< orphan*/ *);
scalar_t__ malloc(int);
int /*<<< orphan*/ sprintf(char *, char *, int, int, int, int, int,
                           int /*<<< orphan*/);
int /*<<< orphan*/ strcat(char *, char const *);
int strlen(char const *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
char *Get_File_Spec() {
  struct tm *local;
  time_t t;
  const char *user;
  char time_stmp[57];
  char *file_spec = 0;
  t = time(NULL);
  local = localtime(&t);
  sprintf(time_stmp, "%02d-%02d-%02d.%02d%02d%02d.", local->tm_year,
          (local->tm_mon + 1), local->tm_mday, local->tm_hour, local->tm_min,
          local->tm_sec);
  user = getenv("USER");
  if (user == NULL)
    user = "None";
  file_spec =
      (char *)malloc(sizeof(char) * (strlen(time_stmp) + strlen(user) + 1));
  file_spec[0] = '\0';
  strcat(file_spec, time_stmp);
  strcat(file_spec, user);
  return file_spec;
}


x86 assembly (clang, -O0):
<Get_File_Spec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movq   $0x0,-0x68(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1060 <time@plt>
mov    %eax,-0xc(%rbp)
lea    -0xc(%rbp),%rdi
call   1040 <localtime@plt>
mov    %rax,-0x8(%rbp)
lea    -0x60(%rbp),%rdi
mov    -0x8(%rbp),%rax
mov    (%rax),%edx
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%ecx
add    $0x1,%ecx
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%r8d
mov    -0x8(%rbp),%rax
mov    0xc(%rax),%r9d
mov    -0x8(%rbp),%rax
mov    0x10(%rax),%r10d
mov    -0x8(%rbp),%rax
mov    0x14(%rax),%eax
lea    0xe2a(%rip),%rsi
mov    %r10d,(%rsp)
mov    %eax,0x8(%rsp)
call   1090 <sprintf@plt>
lea    0xe33(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1209 <Get_File_Spec+0x99>
lea    0xe1d(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    -0x60(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x6c(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x6c(%rbp),%eax
add    %ecx,%eax
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x68(%rbp)
mov    -0x68(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x68(%rbp),%rdi
lea    -0x60(%rbp),%rsi
call   1080 <strcat@plt>
mov    -0x68(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1080 <strcat@plt>
mov    -0x68(%rbp),%rax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Get_File_Spec>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x58,%rsp
xor    %edi,%edi
call   1060 <time@plt>
mov    %eax,0xc(%rsp)
lea    0xc(%rsp),%rdi
call   1040 <localtime@plt>
mov    (%rax),%edx
mov    0x4(%rax),%ecx
add    $0x1,%ecx
mov    0x8(%rax),%r8d
mov    0xc(%rax),%r9d
mov    0x10(%rax),%ebx
mov    0x14(%rax),%eax
lea    0xe53(%rip),%rsi
lea    0x10(%rsp),%r14
mov    %r14,%rdi
push   %rax
push   %rbx
call   1090 <sprintf@plt>
add    $0x10,%rsp
lea    0xe56(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
lea    0xe4c(%rip),%r12
cmovne %rax,%r12
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %eax,%r15d
mov    %r12,%rdi
call   1050 <strlen@plt>
lea    (%r15,%rax,1),%edi
add    $0x1,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
movb   $0x0,(%rax)
mov    %rax,%rdi
mov    %r14,%rsi
call   1080 <strcat@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1080 <strcat@plt>
mov    %rbx,%rax
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.tm = type { i32, i32, i32, i32, i32, i32 }
@.str = [29 x i8] c"%02d-%02d-%02d.%02d%02d%02d.\00"
@.str.1 = [5 x i8] c"USER\00"
@.str.2 = [5 x i8] c"None\00"
define i8* @Get_File_Spec() {
%1 = alloca %struct.tm*
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [57 x i8]
%5 = alloca i8*
store i8* null, i8** %5
%6 = call i32 @time(i32* null)
store i32 %6, i32* %2
%7 = call %struct.tm* @localtime(i32* %2)
store %struct.tm* %7, %struct.tm** %1
%8 = getelementptr inbounds [57 x i8], [57 x i8]* %4, i64 0, i64 0
%9 = load %struct.tm*, %struct.tm** %1
%10 = getelementptr inbounds %struct.tm, %struct.tm* %9, i32 0, i32 0
%11 = load i32, i32* %10
%12 = load %struct.tm*, %struct.tm** %1
%13 = getelementptr inbounds %struct.tm, %struct.tm* %12, i32 0, i32 1
%14 = load i32, i32* %13
%15 = add nsw i32 %14, 1
%16 = load %struct.tm*, %struct.tm** %1
%17 = getelementptr inbounds %struct.tm, %struct.tm* %16, i32 0, i32 2
%18 = load i32, i32* %17
%19 = load %struct.tm*, %struct.tm** %1
%20 = getelementptr inbounds %struct.tm, %struct.tm* %19, i32 0, i32 3
%21 = load i32, i32* %20
%22 = load %struct.tm*, %struct.tm** %1
%23 = getelementptr inbounds %struct.tm, %struct.tm* %22, i32 0, i32 4
%24 = load i32, i32* %23
%25 = load %struct.tm*, %struct.tm** %1
%26 = getelementptr inbounds %struct.tm, %struct.tm* %25, i32 0, i32 5
%27 = load i32, i32* %26
%28 = call i32 @sprintf(i8* %8, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %11, i32 %15, i32 %18, i32 %21, i32 %24, i32 %27)
%29 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
store i8* %29, i8** %3
%30 = load i8*, i8** %3
%31 = icmp eq i8* %30, null
br i1 %31, label %32, label %33
32: ; preds = %0
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8** %3
br label %33
33: ; preds = %32, %0
%34 = getelementptr inbounds [57 x i8], [57 x i8]* %4, i64 0, i64 0
%35 = call i32 @strlen(i8* %34)
%36 = load i8*, i8** %3
%37 = call i32 @strlen(i8* %36)
%38 = add nsw i32 %35, %37
%39 = add nsw i32 %38, 1
%40 = sext i32 %39 to i64
%41 = mul i64 1, %40
%42 = trunc i64 %41 to i32
%43 = call i64 @malloc(i32 %42)
%44 = inttoptr i64 %43 to i8*
store i8* %44, i8** %5
%45 = load i8*, i8** %5
%46 = getelementptr inbounds i8, i8* %45, i64 0
store i8 0, i8* %46
%47 = load i8*, i8** %5
%48 = getelementptr inbounds [57 x i8], [57 x i8]* %4, i64 0, i64 0
%49 = call i32 @strcat(i8* %47, i8* %48)
%50 = load i8*, i8** %5
%51 = load i8*, i8** %3
%52 = call i32 @strcat(i8* %50, i8* %51)
%53 = load i8*, i8** %5
ret i8* %53
}

LLVM IR (-O2):
%struct.tm = type { i32, i32, i32, i32, i32, i32 }
@.str = [29 x i8] c"%02d-%02d-%02d.%02d%02d%02d.\00"
@.str.1 = [5 x i8] c"USER\00"
@.str.2 = [5 x i8] c"None\00"
define i8* @Get_File_Spec() {
%1 = alloca i32
%2 = alloca [57 x i8]
%3 = bitcast i32* %1 to i8*
%4 = getelementptr inbounds [57 x i8], [57 x i8]* %2, i64 0, i64 0
%5 = tail call i32 @time(i32* null)
store i32 %5, i32* %1
%6 = call %struct.tm* @localtime(i32* %1)
%7 = getelementptr inbounds %struct.tm, %struct.tm* %6, i64 0, i32 0
%8 = load i32, i32* %7
%9 = getelementptr inbounds %struct.tm, %struct.tm* %6, i64 0, i32 1
%10 = load i32, i32* %9
%11 = add nsw i32 %10, 1
%12 = getelementptr inbounds %struct.tm, %struct.tm* %6, i64 0, i32 2
%13 = load i32, i32* %12
%14 = getelementptr inbounds %struct.tm, %struct.tm* %6, i64 0, i32 3
%15 = load i32, i32* %14
%16 = getelementptr inbounds %struct.tm, %struct.tm* %6, i64 0, i32 4
%17 = load i32, i32* %16
%18 = getelementptr inbounds %struct.tm, %struct.tm* %6, i64 0, i32 5
%19 = load i32, i32* %18
%20 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %8, i32 %11, i32 %13, i32 %15, i32 %17, i32 %19)
%21 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%22 = icmp eq i8* %21, null
%23 = select i1 %22, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %21
%24 = call i32 @strlen(i8* %4)
%25 = call i32 @strlen(i8* %23)
%26 = add i32 %24, 1
%27 = add i32 %26, %25
%28 = call i64 @malloc(i32 %27)
%29 = inttoptr i64 %28 to i8*
store i8 0, i8* %29
%30 = call i32 @strcat(i8* %29, i8* %4)
%31 = call i32 @strcat(i8* %29, i8* %23)
ret i8* %29
}