#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 timespec {
  int /*<<< orphan*/ tv_nsec;
  int /*<<< orphan*/ tv_sec;
};

/* Variables and functions */
int /*<<< orphan*/ CLOCK_REALTIME;
int FILENAME_MAX;
int /*<<< orphan*/ clock_gettime(int /*<<< orphan*/, struct timespec *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *);
char *malloc(int);
int /*<<< orphan*/ mkdirp(char *);
int /*<<< orphan*/ snprintf(char *, int, char *, char *, char *, ...);
int /*<<< orphan*/ stdout;
char *gen_tmp_filename(char *dir, char *dirname, char *fname) {
  char *file_cache_path = malloc(FILENAME_MAX);
  char file_cache_dir[FILENAME_MAX];
  struct timespec now_time;
  clock_gettime(CLOCK_REALTIME, &now_time);
  snprintf(file_cache_dir, FILENAME_MAX, "%s/%ld.%09ld/%s", dir,
           now_time.tv_sec, now_time.tv_nsec, dirname);
  snprintf(file_cache_path, FILENAME_MAX, "%s/%s", file_cache_dir, fname);
  mkdirp(file_cache_dir);
  fprintf(stdout, "file_cache_path (%p) is %s\n", file_cache_path,
          file_cache_path);
  fprintf(stdout, "file_cache_dir (%p) is %s\n", file_cache_dir,
          file_cache_dir);
  return file_cache_path;
}


x86 assembly (clang, -O0):
<gen_tmp_filename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    0x2e7d(%rip),%rax
mov    %rax,-0x48(%rbp)
mov    (%rax),%edi
call   1070 <malloc@plt>
mov    %rax,%rcx
mov    -0x48(%rbp),%rax
mov    %rcx,-0x20(%rbp)
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
mov    0x2e23(%rip),%rax
mov    (%rax),%edi
lea    -0x38(%rbp),%rsi
call   1030 <clock_gettime@plt>
mov    -0x40(%rbp),%rdi
mov    0x2e25(%rip),%rax
mov    (%rax),%esi
mov    -0x8(%rbp),%rcx
movslq -0x34(%rbp),%r8
mov    -0x38(%rbp),%r9d
mov    -0x10(%rbp),%rax
lea    0xe24(%rip),%rdx
sub    $0x10,%rsp
mov    %rax,(%rsp)
mov    $0x0,%al
call   1040 <snprintf@plt>
mov    -0x40(%rbp),%rcx
add    $0x10,%rsp
mov    -0x20(%rbp),%rdi
mov    0x2dea(%rip),%rax
mov    (%rax),%esi
mov    -0x18(%rbp),%r8
lea    0xe05(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
mov    -0x40(%rbp),%rdi
call   1050 <mkdirp@plt>
mov    0x2db6(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
mov    -0x20(%rbp),%rcx
lea    0xde3(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x40(%rbp),%rcx
mov    0x2d95(%rip),%rax
mov    (%rax),%edi
lea    0xde6(%rip),%rsi
mov    %rcx,%rdx
call   1060 <fprintf@plt>
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gen_tmp_filename>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,-0x38(%rbp)
mov    %rsi,%r12
mov    %rdi,%r13
mov    0x2e76(%rip),%rax
mov    (%rax),%r15d
mov    %r15d,%edi
call   1070 <malloc@plt>
mov    %rax,%r14
mov    %rsp,%rbx
add    $0xf,%r15
and    $0xfffffffffffffff0,%r15
sub    %r15,%rbx
mov    %rbx,%rsp
mov    0x2e38(%rip),%rax
mov    (%rax),%edi
lea    -0x30(%rbp),%rsi
call   1030 <clock_gettime@plt>
mov    0x2e3e(%rip),%r15
mov    (%r15),%esi
movslq -0x2c(%rbp),%r8
mov    -0x30(%rbp),%r9d
sub    $0x8,%rsp
lea    0xe40(%rip),%rdx
mov    %rbx,%rdi
mov    %r13,%rcx
xor    %eax,%eax
push   %r12
call   1040 <snprintf@plt>
add    $0x10,%rsp
mov    (%r15),%esi
lea    0xe33(%rip),%rdx
mov    %r14,%rdi
mov    %rbx,%rcx
mov    -0x38(%rbp),%r8
xor    %eax,%eax
call   1040 <snprintf@plt>
mov    %rbx,%rdi
call   1050 <mkdirp@plt>
mov    0x2ddb(%rip),%r15
mov    (%r15),%edi
lea    0xe0f(%rip),%rsi
mov    %r14,%rdx
mov    %r14,%rcx
call   1060 <fprintf@plt>
mov    (%r15),%edi
lea    0xe16(%rip),%rsi
mov    %rbx,%rdx
mov    %rbx,%rcx
call   1060 <fprintf@plt>
mov    %r14,%rax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.timespec = type { i32, i32 }
@FILENAME_MAX = global i32 0
@CLOCK_REALTIME = global i32 0
@.str = [16 x i8] c"%s/%ld.%09ld/%s\00"
@.str.1 = [6 x i8] c"%s/%s\00"
@stdout = global i32 0
@.str.2 = [28 x i8] c"file_cache_path (%p) is %s\0A\00"
@.str.3 = [27 x i8] c"file_cache_dir (%p) is %s\0A\00"
define i8* @gen_tmp_filename(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca %struct.timespec
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%11 = load i32, i32* @FILENAME_MAX
%12 = call i8* @malloc(i32 %11)
store i8* %12, i8** %7
%13 = load i32, i32* @FILENAME_MAX
%14 = zext i32 %13 to i64
%15 = call i8* @llvm.stacksave()
store i8* %15, i8** %8
%16 = alloca i8, i64 %14
store i64 %14, i64* %9
%17 = load i32, i32* @CLOCK_REALTIME
%18 = call i32 @clock_gettime(i32 %17, %struct.timespec* %10)
%19 = load i32, i32* @FILENAME_MAX
%20 = load i8*, i8** %4
%21 = getelementptr inbounds %struct.timespec, %struct.timespec* %10, i32 0, i32 1
%22 = load i32, i32* %21
%23 = sext i32 %22 to i64
%24 = inttoptr i64 %23 to i8*
%25 = getelementptr inbounds %struct.timespec, %struct.timespec* %10, i32 0, i32 0
%26 = load i32, i32* %25
%27 = load i8*, i8** %5
%28 = call i32 (i8*, i32, i8*, i8*, i8*, ...) @snprintf(i8* %16, i32 %19, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %20, i8* %24, i32 %26, i8* %27)
%29 = load i8*, i8** %7
%30 = load i32, i32* @FILENAME_MAX
%31 = load i8*, i8** %6
%32 = call i32 (i8*, i32, i8*, i8*, i8*, ...) @snprintf(i8* %29, i32 %30, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %16, i8* %31)
%33 = call i32 @mkdirp(i8* %16)
%34 = load i32, i32* @stdout
%35 = load i8*, i8** %7
%36 = load i8*, i8** %7
%37 = call i32 @fprintf(i32 %34, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i8* %35, i8* %36)
%38 = load i32, i32* @stdout
%39 = call i32 @fprintf(i32 %38, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i8* %16, i8* %16)
%40 = load i8*, i8** %7
%41 = load i8*, i8** %8
ret i8* %40
}

LLVM IR (-O2):
%struct.timespec = type { i32, i32 }
@FILENAME_MAX = global i32 0
@CLOCK_REALTIME = global i32 0
@.str = [16 x i8] c"%s/%ld.%09ld/%s\00"
@.str.1 = [6 x i8] c"%s/%s\00"
@stdout = global i32 0
@.str.2 = [28 x i8] c"file_cache_path (%p) is %s\0A\00"
@.str.3 = [27 x i8] c"file_cache_dir (%p) is %s\0A\00"
define i8* @gen_tmp_filename(i8* %0, i8* %1, i8* %2) {
%4 = alloca %struct.timespec
%5 = load i32, i32* @FILENAME_MAX
%6 = tail call i8* @malloc(i32 %5)
%7 = zext i32 %5 to i64
%8 = alloca i8, i64 %7
%9 = bitcast %struct.timespec* %4 to i8*
%10 = load i32, i32* @CLOCK_REALTIME
%11 = call i32 @clock_gettime(i32 %10, %struct.timespec* %4)
%12 = load i32, i32* @FILENAME_MAX
%13 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i64 0, i32 1
%14 = load i32, i32* %13
%15 = sext i32 %14 to i64
%16 = inttoptr i64 %15 to i8*
%17 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i64 0, i32 0
%18 = load i32, i32* %17
%19 = call i32 (i8*, i32, i8*, i8*, i8*, ...) @snprintf(i8* %8, i32 %12, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %16, i32 %18, i8* %1)
%20 = load i32, i32* @FILENAME_MAX
%21 = call i32 (i8*, i32, i8*, i8*, i8*, ...) @snprintf(i8* %6, i32 %20, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %8, i8* %2)
%22 = call i32 @mkdirp(i8* %8)
%23 = load i32, i32* @stdout
%24 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i8* %6, i8* %6)
%25 = load i32, i32* @stdout
%26 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i8* %8, i8* %8)
ret i8* %6
}