#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;
};

/* Variables and functions */
struct tm *localtime(int /*<<< orphan*/ *);
scalar_t__ malloc(int);
int /*<<< orphan*/ sprintf(char *, char *, char *, int, int, int,
                           int /*<<< orphan*/, char *);
int strlen(char *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
char *get_file_name(char *prefix, char *suffix) {
  char *name;
  int prelen, suflen, sumlen;
  time_t current;
  struct tm *date;
  prelen = strlen((prefix == NULL) ? "" : prefix);
  suflen = strlen((suffix == NULL) ? "tmp" : suffix);
  sumlen = prelen + suflen + 24;
  name = (char *)malloc(sumlen * sizeof(char));
  time(&current);
  date = localtime(&current);
  sprintf(name, "%s-%04d-%02d-%02d-%ld.%s", (prefix == NULL) ? "" : prefix,
          date->tm_year + 1900, date->tm_mon + 1, date->tm_mday, current,
          (suffix == NULL) ? "tmp" : suffix);
  return name;
}


x86 assembly (clang, -O0):
<get_file_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    117e <get_file_name+0x2e>
lea    0xe8e(%rip),%rax
mov    %rax,-0x38(%rbp)
jmp    1186 <get_file_name+0x36>
mov    -0x8(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x1c(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11ad <get_file_name+0x5d>
lea    0xe5c(%rip),%rax
mov    %rax,-0x40(%rbp)
jmp    11b5 <get_file_name+0x65>
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
add    -0x20(%rbp),%eax
add    $0x18,%eax
mov    %eax,-0x24(%rbp)
movslq -0x24(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
lea    -0x28(%rbp),%rdi
call   1050 <time@plt>
lea    -0x28(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1219 <get_file_name+0xc9>
lea    0xdf3(%rip),%rax
mov    %rax,-0x50(%rbp)
jmp    1221 <get_file_name+0xd1>
mov    -0x8(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x30(%rbp),%rax
mov    (%rax),%eax
add    $0x76c,%eax
mov    %eax,-0x60(%rbp)
mov    -0x30(%rbp),%rax
mov    0x4(%rax),%eax
add    $0x1,%eax
mov    %eax,-0x5c(%rbp)
mov    -0x30(%rbp),%rax
mov    0x8(%rax),%eax
mov    %eax,-0x58(%rbp)
mov    -0x28(%rbp),%eax
mov    %eax,-0x54(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    126f <get_file_name+0x11f>
lea    0xd9a(%rip),%rax
mov    %rax,-0x70(%rbp)
jmp    1277 <get_file_name+0x127>
mov    -0x10(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    -0x54(%rbp),%r10d
mov    -0x58(%rbp),%r9d
mov    -0x5c(%rbp),%r8d
mov    -0x60(%rbp),%ecx
mov    -0x68(%rbp),%rdx
mov    -0x48(%rbp),%rdi
mov    -0x70(%rbp),%rax
lea    0xd6b(%rip),%rsi
mov    %r10d,(%rsp)
mov    %rax,0x8(%rsp)
call   1070 <sprintf@plt>
mov    -0x18(%rbp),%rax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_file_name>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
test   %rdi,%rdi
lea    0xe9e(%rip),%r14
cmovne %rdi,%r14
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %eax,%r15d
test   %rbx,%rbx
lea    0xe82(%rip),%r12
cmovne %rbx,%r12
mov    %r12,%rdi
call   1040 <strlen@plt>
lea    (%r15,%rax,1),%edi
add    $0x18,%edi
call   1060 <malloc@plt>
mov    %rax,%r15
lea    0x4(%rsp),%rbx
mov    %rbx,%rdi
call   1050 <time@plt>
mov    %rbx,%rdi
call   1030 <localtime@plt>
mov    $0x76c,%ecx
add    (%rax),%ecx
mov    0x4(%rax),%r8d
mov    0x8(%rax),%r9d
add    $0x1,%r8d
mov    0x4(%rsp),%eax
lea    0xe38(%rip),%rsi
mov    %r15,%rdi
mov    %r14,%rdx
push   %r12
push   %rax
call   1070 <sprintf@plt>
add    $0x10,%rsp
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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