#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 */
char *currdatetime();
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ strcpy(char *, char const *);
int strlen(char const *);
char *getname(const char *pathtofile, const char *ext) {
  char *timestamp = currdatetime();
  int size = (strlen(pathtofile) + strlen(ext) + strlen(timestamp) + 1);
  char *filename = (char *)malloc(sizeof(char) * size);
  if (filename == NULL) {
    return NULL;
  }
  memset(filename, 0, size);
  strcpy(filename, pathtofile);
  strcpy(filename + strlen(pathtofile), timestamp);
  strcpy(filename + strlen(pathtofile) + strlen(timestamp), ext);
  free(timestamp);
  timestamp = NULL;
  return filename;
}


x86 assembly (clang, -O0):
<getname>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    $0x0,%al
call   1080 <currdatetime@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x38(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x34(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x34(%rbp),%eax
add    %ecx,%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
movslq -0x24(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11db <getname+0x7b>
movq   $0x0,-0x8(%rbp)
jmp    126e <getname+0x10e>
mov    -0x30(%rbp),%rdi
mov    -0x24(%rbp),%edx
xor    %esi,%esi
call   1060 <memset@plt>
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x50(%rbp),%rdi
cltq
add    %rax,%rdi
mov    -0x20(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x30(%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)
mov    -0x20(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x40(%rbp),%rdi
cltq
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x20(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getname>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r12
xor    %r13d,%r13d
xor    %eax,%eax
call   1080 <currdatetime@plt>
mov    %rax,%r15
mov    %r12,%rdi
call   1050 <strlen@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %eax,%ebp
mov    %r15,%rdi
call   1050 <strlen@plt>
add    %ebx,%ebp
add    %eax,%ebp
add    $0x1,%ebp
mov    %ebp,%edi
call   1070 <malloc@plt>
test   %rax,%rax
je     120c <getname+0xac>
mov    %rax,%rbx
mov    %rax,%rdi
xor    %esi,%esi
mov    %ebp,%edx
call   1060 <memset@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1040 <strcpy@plt>
mov    %r12,%rdi
call   1050 <strlen@plt>
movslq %eax,%rdi
add    %rbx,%rdi
mov    %r15,%rsi
call   1040 <strcpy@plt>
mov    %r12,%rdi
call   1050 <strlen@plt>
movslq %eax,%rbp
add    %rbx,%rbp
mov    %r15,%rdi
call   1050 <strlen@plt>
movslq %eax,%rdi
add    %rbp,%rdi
mov    %r14,%rsi
call   1040 <strcpy@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %rbx,%r13
mov    %r13,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @getname(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%9 = call i8* (...) @currdatetime()
store i8* %9, i8** %6
%10 = load i8*, i8** %4
%11 = call i32 @strlen(i8* %10)
%12 = load i8*, i8** %5
%13 = call i32 @strlen(i8* %12)
%14 = add nsw i32 %11, %13
%15 = load i8*, i8** %6
%16 = call i32 @strlen(i8* %15)
%17 = add nsw i32 %14, %16
%18 = add nsw i32 %17, 1
store i32 %18, i32* %7
%19 = load i32, i32* %7
%20 = sext i32 %19 to i64
%21 = mul i64 1, %20
%22 = trunc i64 %21 to i32
%23 = call i64 @malloc(i32 %22)
%24 = inttoptr i64 %23 to i8*
store i8* %24, i8** %8
%25 = load i8*, i8** %8
%26 = icmp eq i8* %25, null
br i1 %26, label %27, label %28
27: ; preds = %2
store i8* null, i8** %3
br label %56
28: ; preds = %2
%29 = load i8*, i8** %8
%30 = load i32, i32* %7
%31 = call i32 @memset(i8* %29, i32 0, i32 %30)
%32 = load i8*, i8** %8
%33 = load i8*, i8** %4
%34 = call i32 @strcpy(i8* %32, i8* %33)
%35 = load i8*, i8** %8
%36 = load i8*, i8** %4
%37 = call i32 @strlen(i8* %36)
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %35, i64 %38
%40 = load i8*, i8** %6
%41 = call i32 @strcpy(i8* %39, i8* %40)
%42 = load i8*, i8** %8
%43 = load i8*, i8** %4
%44 = call i32 @strlen(i8* %43)
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8, i8* %42, i64 %45
%47 = load i8*, i8** %6
%48 = call i32 @strlen(i8* %47)
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i8, i8* %46, i64 %49
%51 = load i8*, i8** %5
%52 = call i32 @strcpy(i8* %50, i8* %51)
%53 = load i8*, i8** %6
%54 = call i32 @free(i8* %53)
store i8* null, i8** %6
%55 = load i8*, i8** %8
store i8* %55, i8** %3
br label %56
56: ; preds = %28, %27
%57 = load i8*, i8** %3
ret i8* %57
}

LLVM IR (-O2):
define i8* @getname(i8* %0, i8* %1) {
%3 = tail call i8* (...) @currdatetime()
%4 = tail call i32 @strlen(i8* %0)
%5 = tail call i32 @strlen(i8* %1)
%6 = tail call i32 @strlen(i8* %3)
%7 = add i32 %4, 1
%8 = add i32 %7, %5
%9 = add i32 %8, %6
%10 = tail call i64 @malloc(i32 %9)
%11 = inttoptr i64 %10 to i8*
%12 = icmp eq i64 %10, 0
br i1 %12, label %28, label %13
13: ; preds = %2
%14 = tail call i32 @memset(i8* %11, i32 0, i32 %9)
%15 = tail call i32 @strcpy(i8* %11, i8* %0)
%16 = tail call i32 @strlen(i8* %0)
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %11, i64 %17
%19 = tail call i32 @strcpy(i8* %18, i8* %3)
%20 = tail call i32 @strlen(i8* %0)
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %11, i64 %21
%23 = tail call i32 @strlen(i8* %3)
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %22, i64 %24
%26 = tail call i32 @strcpy(i8* %25, i8* %1)
%27 = tail call i32 @free(i8* %3)
br label %28
28: ; preds = %2, %13
%29 = phi i8* [ %11, %13 ], [ null, %2 ]
ret i8* %29
}