#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 */
struct timezone {
  int dummy;
};
struct timeval {
  scalar_t__ tv_usec;
  scalar_t__ tv_sec;
};

/* Variables and functions */
int /*<<< orphan*/ MAXHOSTNAMELEN;
int asprintf(char **, char *, unsigned long, unsigned long, char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ gethostname(char *, int /*<<< orphan*/);
int /*<<< orphan*/ gettimeofday(struct timeval *, struct timezone *);
scalar_t__ malloc(int /*<<< orphan*/);
char *smf_core_get_maildir_filename(void) {
  char *filename;
  char *hostname = NULL;
  struct timeval starttime;
  gettimeofday(&starttime, (struct timezone *)0);
  hostname = (char *)malloc(MAXHOSTNAMELEN);
  gethostname(hostname, MAXHOSTNAMELEN);
  if (asprintf(&filename, "%lu.V%lu.%s", (unsigned long)starttime.tv_sec,
               (unsigned long)starttime.tv_usec, hostname) == -1) {
    free(hostname);
    return NULL;
  }
  free(hostname);
  return filename;
}


x86 assembly (clang, -O0):
<smf_core_get_maildir_filename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movq   $0x0,-0x18(%rbp)
lea    -0x28(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
mov    0x2e74(%rip),%rax
mov    (%rax),%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2e5e(%rip),%rax
mov    (%rax),%esi
call   1070 <gethostname@plt>
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    -0x18(%rbp),%r8
lea    -0x10(%rbp),%rdi
lea    0xe58(%rip),%rsi
call   1060 <asprintf@plt>
cmp    $0xffffffff,%eax
jne    11cc <smf_core_get_maildir_filename+0x7c>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    11dd <smf_core_get_maildir_filename+0x8d>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<smf_core_get_maildir_filename>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
xor    %r14d,%r14d
lea    0x10(%rsp),%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
mov    0x2e7a(%rip),%rbp
mov    0x0(%rbp),%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
mov    0x0(%rbp),%esi
mov    %rax,%rdi
call   1070 <gethostname@plt>
mov    0x10(%rsp),%rcx
mov    0x18(%rsp),%rdx
lea    0xe6b(%rip),%rsi
lea    0x8(%rsp),%rdi
mov    %rbx,%r8
call   1060 <asprintf@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <free@plt>
cmp    $0xffffffff,%ebp
je     11b6 <smf_core_get_maildir_filename+0x66>
mov    0x8(%rsp),%r14
mov    %r14,%rax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { i64, i64 }
%struct.timezone = type { i32 }
@MAXHOSTNAMELEN = global i32 0
@.str = [12 x i8] c"%lu.V%lu.%s\00"
define i8* @smf_core_get_maildir_filename() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca %struct.timeval
store i8* null, i8** %3
%5 = call i32 @gettimeofday(%struct.timeval* %4, %struct.timezone* null)
%6 = load i32, i32* @MAXHOSTNAMELEN
%7 = call i64 @malloc(i32 %6)
%8 = inttoptr i64 %7 to i8*
store i8* %8, i8** %3
%9 = load i8*, i8** %3
%10 = load i32, i32* @MAXHOSTNAMELEN
%11 = call i32 @gethostname(i8* %9, i32 %10)
%12 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 1
%13 = load i64, i64* %12
%14 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 0
%15 = load i64, i64* %14
%16 = load i8*, i8** %3
%17 = call i32 @asprintf(i8** %2, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i64 %13, i64 %15, i8* %16)
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %22
19: ; preds = %0
%20 = load i8*, i8** %3
%21 = call i32 @free(i8* %20)
store i8* null, i8** %1
br label %26
22: ; preds = %0
%23 = load i8*, i8** %3
%24 = call i32 @free(i8* %23)
%25 = load i8*, i8** %2
store i8* %25, i8** %1
br label %26
26: ; preds = %22, %19
%27 = load i8*, i8** %1
ret i8* %27
}

LLVM IR (-O2):
%struct.timeval = type { i64, i64 }
%struct.timezone = type { i32 }
@MAXHOSTNAMELEN = global i32 0
@.str = [12 x i8] c"%lu.V%lu.%s\00"
define i8* @smf_core_get_maildir_filename() {
%1 = alloca i8*
%2 = alloca %struct.timeval
%3 = bitcast i8** %1 to i8*
%4 = bitcast %struct.timeval* %2 to i8*
%5 = call i32 @gettimeofday(%struct.timeval* %2, %struct.timezone* null)
%6 = load i32, i32* @MAXHOSTNAMELEN
%7 = tail call i64 @malloc(i32 %6)
%8 = inttoptr i64 %7 to i8*
%9 = load i32, i32* @MAXHOSTNAMELEN
%10 = tail call i32 @gethostname(i8* %8, i32 %9)
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 1
%12 = load i64, i64* %11
%13 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 0
%14 = load i64, i64* %13
%15 = call i32 @asprintf(i8** %1, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i64 %12, i64 %14, i8* %8)
%16 = icmp eq i32 %15, -1
%17 = call i32 @free(i8* %8)
%18 = load i8*, i8** %1
%19 = select i1 %16, i8* null, i8* %18
ret i8* %19
}