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

/* Variables and functions */
scalar_t__ calloc(size_t const, int);
struct tm *localtime(int /*<<< orphan*/ const *);
int /*<<< orphan*/ snprintf(char *, size_t const, char *, char const *,
                            char const *, int, int, int /*<<< orphan*/);
int strlen(char const *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
char *construct_output_root(const char *output_location,
                            const char *output_name) {
  if (!output_location || strlen(output_location) == 0)
    return 0;
  const size_t len = 10 + strlen(output_location) + strlen(output_name);
  char *output_root = (char *)calloc(len, sizeof(char));
  const time_t unix_time = time(NULL);
  struct tm *timeinfo = localtime(&unix_time);
  snprintf(output_root, len, "%s/%s_%.2d%.2d%.2d", output_location, output_name,
           timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec);
  return output_root;
}


x86 assembly (clang, -O0):
<construct_output_root>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     117d <construct_output_root+0x2d>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x0,%eax
jne    118a <construct_output_root+0x3a>
movq   $0x0,-0x8(%rbp)
jmp    121c <construct_output_root+0xcc>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
add    $0xa,%eax
mov    %eax,-0x3c(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x3c(%rbp),%eax
add    %ecx,%eax
cltq
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,-0x28(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1070 <time@plt>
mov    %eax,-0x2c(%rbp)
lea    -0x2c(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%r8
mov    -0x38(%rbp),%rax
mov    (%rax),%r9d
mov    -0x38(%rbp),%rax
mov    0x4(%rax),%r10d
mov    -0x38(%rbp),%rax
mov    0x8(%rax),%eax
lea    0xdf9(%rip),%rdx
mov    %r10d,(%rsp)
mov    %eax,0x8(%rsp)
call   1050 <snprintf@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<construct_output_root>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %rdi,%rdi
je     11d8 <construct_output_root+0x88>
mov    %rsi,%r14
mov    %rdi,%rbx
call   1040 <strlen@plt>
test   %eax,%eax
je     11d8 <construct_output_root+0x88>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %eax,%r15d
mov    %r14,%rdi
call   1040 <strlen@plt>
add    %r15d,%eax
add    $0xa,%eax
movslq %eax,%r12
mov    %r12,%rdi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,%r15
xor    %edi,%edi
call   1070 <time@plt>
mov    %eax,0x4(%rsp)
lea    0x4(%rsp),%rdi
call   1030 <localtime@plt>
mov    (%rax),%r9d
mov    0x4(%rax),%r10d
mov    0x8(%rax),%eax
lea    0xe42(%rip),%rdx
mov    %r15,%rdi
mov    %r12,%rsi
mov    %rbx,%rcx
mov    %r14,%r8
push   %rax
push   %r10
call   1050 <snprintf@plt>
add    $0x10,%rsp
jmp    11db <construct_output_root+0x8b>
xor    %r15d,%r15d
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 = [19 x i8] c"%s/%s_%.2d%.2d%.2d\00"
define i8* @construct_output_root(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i32
%9 = alloca %struct.tm*
store i8* %0, i8** %4
store i8* %1, i8** %5
%10 = load i8*, i8** %4
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %16
12: ; preds = %2
%13 = load i8*, i8** %4
%14 = call i32 @strlen(i8* %13)
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %12, %2
store i8* null, i8** %3
br label %45
17: ; preds = %12
%18 = load i8*, i8** %4
%19 = call i32 @strlen(i8* %18)
%20 = add nsw i32 10, %19
%21 = load i8*, i8** %5
%22 = call i32 @strlen(i8* %21)
%23 = add nsw i32 %20, %22
%24 = sext i32 %23 to i64
store i64 %24, i64* %6
%25 = load i64, i64* %6
%26 = call i64 @calloc(i64 %25, i32 1)
%27 = inttoptr i64 %26 to i8*
store i8* %27, i8** %7
%28 = call i32 @time(i32* null)
store i32 %28, i32* %8
%29 = call %struct.tm* @localtime(i32* %8)
store %struct.tm* %29, %struct.tm** %9
%30 = load i8*, i8** %7
%31 = load i64, i64* %6
%32 = load i8*, i8** %4
%33 = load i8*, i8** %5
%34 = load %struct.tm*, %struct.tm** %9
%35 = getelementptr inbounds %struct.tm, %struct.tm* %34, i32 0, i32 0
%36 = load i32, i32* %35
%37 = load %struct.tm*, %struct.tm** %9
%38 = getelementptr inbounds %struct.tm, %struct.tm* %37, i32 0, i32 1
%39 = load i32, i32* %38
%40 = load %struct.tm*, %struct.tm** %9
%41 = getelementptr inbounds %struct.tm, %struct.tm* %40, i32 0, i32 2
%42 = load i32, i32* %41
%43 = call i32 @snprintf(i8* %30, i64 %31, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %32, i8* %33, i32 %36, i32 %39, i32 %42)
%44 = load i8*, i8** %7
store i8* %44, i8** %3
br label %45
45: ; preds = %17, %16
%46 = load i8*, i8** %3
ret i8* %46
}

LLVM IR (-O2):
%struct.tm = type { i32, i32, i32 }
@.str = [19 x i8] c"%s/%s_%.2d%.2d%.2d\00"
define i8* @construct_output_root(i8* %0, i8* %1) {
%3 = alloca i32
%4 = icmp eq i8* %0, null
br i1 %4, label %26, label %5
5: ; preds = %2
%6 = tail call i32 @strlen(i8* %0)
%7 = icmp eq i32 %6, 0
br i1 %7, label %26, label %8
8: ; preds = %5
%9 = tail call i32 @strlen(i8* %0)
%10 = add nsw i32 %9, 10
%11 = tail call i32 @strlen(i8* %1)
%12 = add nsw i32 %10, %11
%13 = sext i32 %12 to i64
%14 = tail call i64 @calloc(i64 %13, i32 1)
%15 = inttoptr i64 %14 to i8*
%16 = bitcast i32* %3 to i8*
%17 = tail call i32 @time(i32* null)
store i32 %17, i32* %3
%18 = call %struct.tm* @localtime(i32* %3)
%19 = getelementptr inbounds %struct.tm, %struct.tm* %18, i64 0, i32 0
%20 = load i32, i32* %19
%21 = getelementptr inbounds %struct.tm, %struct.tm* %18, i64 0, i32 1
%22 = load i32, i32* %21
%23 = getelementptr inbounds %struct.tm, %struct.tm* %18, i64 0, i32 2
%24 = load i32, i32* %23
%25 = call i32 @snprintf(i8* %15, i64 %13, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %1, i32 %20, i32 %22, i32 %24)
br label %26
26: ; preds = %2, %5, %8
%27 = phi i8* [ %15, %8 ], [ null, %5 ], [ null, %2 ]
ret i8* %27
}