#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 */
int /*<<< orphan*/ die(char *);
char *malloc_or_die(scalar_t__);
int /*<<< orphan*/ sprintf(char *, char *, char const *, char const *);
scalar_t__ strlen(char const *);
char *tracecmd_find_tracing_dir();
char *tracecmd_get_tracing_file(const char *name) {
  static const char *tracing;
  char *file;
  if (!tracing) {
    tracing = tracecmd_find_tracing_dir();
    if (!tracing)
      die("Can't find tracing dir");
  }
  file = malloc_or_die(strlen(tracing) + strlen(name) + 2);
  if (!file)
    return NULL;
  sprintf(file, "%s/%s", tracing, name);
  return file;
}


x86 assembly (clang, -O0):
<tracecmd_get_tracing_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,0x2eec(%rip)
jne    1197 <tracecmd_get_tracing_file+0x47>
mov    $0x0,%al
call   1060 <tracecmd_find_tracing_dir@plt>
mov    %rax,0x2ed8(%rip)
cmpq   $0x0,0x2ed0(%rip)
jne    1192 <tracecmd_get_tracing_file+0x42>
lea    0xe73(%rip),%rdi
call   1050 <die@plt>
jmp    1197 <tracecmd_get_tracing_file+0x47>
mov    0x2eb2(%rip),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x20(%rbp),%rdi
add    %rax,%rdi
add    $0x2,%rdi
call   1040 <malloc_or_die@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11dc <tracecmd_get_tracing_file+0x8c>
movq   $0x0,-0x8(%rbp)
jmp    11ff <tracecmd_get_tracing_file+0xaf>
mov    -0x18(%rbp),%rdi
mov    0x2e69(%rip),%rdx
mov    -0x10(%rbp),%rcx
lea    0xe25(%rip),%rsi
call   1070 <sprintf@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tracecmd_get_tracing_file>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    0x2ef2(%rip),%rdi
test   %rdi,%rdi
jne    118c <tracecmd_get_tracing_file+0x3c>
xor    %eax,%eax
call   1060 <tracecmd_find_tracing_dir@plt>
mov    %rax,%rdi
mov    %rax,0x2edc(%rip)
test   %rax,%rax
jne    118c <tracecmd_get_tracing_file+0x3c>
lea    0xe80(%rip),%rdi
call   1050 <die@plt>
mov    0x2ec4(%rip),%rdi
call   1030 <strlen@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1030 <strlen@plt>
lea    (%rbx,%rax,1),%rdi
add    $0x2,%rdi
call   1040 <malloc_or_die@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11ca <tracecmd_get_tracing_file+0x7a>
mov    0x2e98(%rip),%rdx
lea    0xe58(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rcx
call   1070 <sprintf@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@tracecmd_get_tracing_file.tracing = internal global i8* null
@.str = [23 x i8] c"Can't find tracing dir\00"
@.str.1 = [6 x i8] c"%s/%s\00"
define i8* @tracecmd_get_tracing_file(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %3
%5 = load i8*, i8** @tracecmd_get_tracing_file.tracing
%6 = icmp ne i8* %5, null
br i1 %6, label %14, label %7
7: ; preds = %1
%8 = call i8* (...) @tracecmd_find_tracing_dir()
store i8* %8, i8** @tracecmd_get_tracing_file.tracing
%9 = load i8*, i8** @tracecmd_get_tracing_file.tracing
%10 = icmp ne i8* %9, null
br i1 %10, label %13, label %11
11: ; preds = %7
%12 = call i32 @die(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %11, %7
br label %14
14: ; preds = %13, %1
%15 = load i8*, i8** @tracecmd_get_tracing_file.tracing
%16 = call i64 @strlen(i8* %15)
%17 = load i8*, i8** %3
%18 = call i64 @strlen(i8* %17)
%19 = add nsw i64 %16, %18
%20 = add nsw i64 %19, 2
%21 = call i8* @malloc_or_die(i64 %20)
store i8* %21, i8** %4
%22 = load i8*, i8** %4
%23 = icmp ne i8* %22, null
br i1 %23, label %25, label %24
24: ; preds = %14
store i8* null, i8** %2
br label %31
25: ; preds = %14
%26 = load i8*, i8** %4
%27 = load i8*, i8** @tracecmd_get_tracing_file.tracing
%28 = load i8*, i8** %3
%29 = call i32 @sprintf(i8* %26, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %27, i8* %28)
%30 = load i8*, i8** %4
store i8* %30, i8** %2
br label %31
31: ; preds = %25, %24
%32 = load i8*, i8** %2
ret i8* %32
}

LLVM IR (-O2):
@tracecmd_get_tracing_file.tracing = internal unnamed_addr global i8* null
@.str = [23 x i8] c"Can't find tracing dir\00"
@.str.1 = [6 x i8] c"%s/%s\00"
define i8* @tracecmd_get_tracing_file(i8* %0) {
%2 = load i8*, i8** @tracecmd_get_tracing_file.tracing
%3 = icmp eq i8* %2, null
br i1 %3, label %4, label %10
4: ; preds = %1
%5 = tail call i8* (...) @tracecmd_find_tracing_dir()
store i8* %5, i8** @tracecmd_get_tracing_file.tracing
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %10
7: ; preds = %4
%8 = tail call i32 @die(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%9 = load i8*, i8** @tracecmd_get_tracing_file.tracing
br label %10
10: ; preds = %4, %7, %1
%11 = phi i8* [ %5, %4 ], [ %9, %7 ], [ %2, %1 ]
%12 = tail call i64 @strlen(i8* dereferenceable(1) %11)
%13 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%14 = add i64 %12, 2
%15 = add i64 %14, %13
%16 = tail call i8* @malloc_or_die(i64 %15)
%17 = icmp eq i8* %16, null
br i1 %17, label %21, label %18
18: ; preds = %10
%19 = load i8*, i8** @tracecmd_get_tracing_file.tracing
%20 = tail call i32 @sprintf(i8* %16, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %19, i8* %0)
br label %21
21: ; preds = %10, %18
ret i8* %16
}