#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*/ pathp;

/* Variables and functions */
int /*<<< orphan*/ die(char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ get_dir(char *);
int strlcat(char *, char *, int);
char *timestamp(char *);
void get_filename(char *path, char *name) {
  char *pathp[100];
  char *namep;
  namep = (name) ?: timestamp("%Y-%m-%d");
  *pathp = path;
  get_dir(path);
  if (strlcat(*pathp, namep, sizeof(pathp)) >= sizeof(pathp))
    die("Unable to add file name to path.");
  else
    path = *pathp;
  if (name == NULL)
    free(namep);
}


x86 assembly (clang, -O0):
<get_filename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x350,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x340(%rbp)
cmp    $0x0,%rax
je     118b <get_filename+0x3b>
mov    -0x340(%rbp),%rax
mov    %rax,-0x348(%rbp)
jmp    119e <get_filename+0x4e>
lea    0xe6e(%rip),%rdi
call   1060 <timestamp@plt>
mov    %rax,-0x348(%rbp)
mov    -0x348(%rbp),%rax
mov    %rax,-0x338(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x330(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <get_dir@plt>
mov    -0x330(%rbp),%rdi
mov    -0x338(%rbp),%rsi
mov    $0x320,%edx
call   1050 <strlcat@plt>
cltq
cmp    $0x320,%rax
jb     11f7 <get_filename+0xa7>
lea    0xe1c(%rip),%rdi
call   1070 <die@plt>
jmp    1202 <get_filename+0xb2>
mov    -0x330(%rbp),%rax
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1219 <get_filename+0xc9>
mov    -0x338(%rbp),%rdi
call   1030 <free@plt>
add    $0x350,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_filename>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r15
mov    %rdi,%rbx
mov    %rsi,%r14
test   %rsi,%rsi
jne    1172 <get_filename+0x22>
lea    0xe96(%rip),%rdi
call   1060 <timestamp@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1040 <get_dir@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x320,%edx
call   1050 <strlcat@plt>
cmp    $0x320,%eax
jb     119d <get_filename+0x4d>
lea    0xe71(%rip),%rdi
call   1070 <die@plt>
test   %r15,%r15
je     11a8 <get_filename+0x58>
pop    %rbx
pop    %r14
pop    %r15
ret
mov    %r14,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <free@plt>

LLVM IR (-O0):
@.str = [9 x i8] c"%Y-%m-%d\00"
@.str.1 = [33 x i8] c"Unable to add file name to path.\00"
define void @get_filename(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca [100 x i8*]
%6 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%7 = load i8*, i8** %4
%8 = icmp ne i8* %7, null
br i1 %8, label %9, label %10
9: ; preds = %2
br label %12
10: ; preds = %2
%11 = call i8* @timestamp(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %10, %9
%13 = phi i8* [ %7, %9 ], [ %11, %10 ]
store i8* %13, i8** %6
%14 = load i8*, i8** %3
%15 = getelementptr inbounds [100 x i8*], [100 x i8*]* %5, i64 0, i64 0
store i8* %14, i8** %15
%16 = load i8*, i8** %3
%17 = call i32 @get_dir(i8* %16)
%18 = getelementptr inbounds [100 x i8*], [100 x i8*]* %5, i64 0, i64 0
%19 = load i8*, i8** %18
%20 = load i8*, i8** %6
%21 = call i32 @strlcat(i8* %19, i8* %20, i32 800)
%22 = sext i32 %21 to i64
%23 = icmp uge i64 %22, 800
br i1 %23, label %24, label %26
24: ; preds = %12
%25 = call i32 @die(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
br label %29
26: ; preds = %12
%27 = getelementptr inbounds [100 x i8*], [100 x i8*]* %5, i64 0, i64 0
%28 = load i8*, i8** %27
store i8* %28, i8** %3
br label %29
29: ; preds = %26, %24
%30 = load i8*, i8** %4
%31 = icmp eq i8* %30, null
br i1 %31, label %32, label %35
32: ; preds = %29
%33 = load i8*, i8** %6
%34 = call i32 @free(i8* %33)
br label %35
35: ; preds = %32, %29
ret void
}

LLVM IR (-O2):
@.str = [9 x i8] c"%Y-%m-%d\00"
@.str.1 = [33 x i8] c"Unable to add file name to path.\00"
define void @get_filename(i8* %0, i8* %1) {
%3 = icmp eq i8* %1, null
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i8* @timestamp(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
br label %6
6: ; preds = %2, %4
%7 = phi i8* [ %5, %4 ], [ %1, %2 ]
%8 = tail call i32 @get_dir(i8* %0)
%9 = tail call i32 @strlcat(i8* %0, i8* %7, i32 800)
%10 = icmp ugt i32 %9, 799
br i1 %10, label %11, label %13
11: ; preds = %6
%12 = tail call i32 @die(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
br label %13
13: ; preds = %6, %11
br i1 %3, label %14, label %16
14: ; preds = %13
%15 = tail call i32 @free(i8* %7)
br label %16
16: ; preds = %14, %13
ret void
}