#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 */
char *getTmpPath();
int /*<<< orphan*/ safe_free(char *);
char *strdup_together(char *, char const *);
char *strrchr(char const *, char);
char *strdup_tmp_path(const char *s) {
  char *tmp, *p, *fullname;
  if (s == NULL)
    return NULL;
  tmp = getTmpPath();
  p = strrchr(s, '/');
  if (!p)
    fullname = strdup_together(tmp, s);
  else
    fullname = strdup_together(tmp, p + 1);
  safe_free(tmp);
  return fullname;
}


x86 assembly (clang, -O0):
<strdup_tmp_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1164 <strdup_tmp_path+0x24>
movq   $0x0,-0x8(%rbp)
jmp    11c8 <strdup_tmp_path+0x88>
mov    $0x0,%al
call   1030 <getTmpPath@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11a2 <strdup_tmp_path+0x62>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <strdup_together@plt>
mov    %rax,-0x28(%rbp)
jmp    11b7 <strdup_tmp_path+0x77>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
add    $0x1,%rsi
call   1060 <strdup_together@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <safe_free@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strdup_tmp_path>:
test   %rdi,%rdi
je     118c <strdup_tmp_path+0x4c>
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
xor    %eax,%eax
call   1030 <getTmpPath@plt>
mov    %rax,%r14
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
lea    0x1(%rax),%rsi
test   %rax,%rax
cmove  %rbx,%rsi
mov    %r14,%rdi
call   1060 <strdup_together@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1050 <safe_free@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
xor    %eax,%eax
ret

LLVM IR (-O0):
define i8* @strdup_tmp_path(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %10
9: ; preds = %1
store i8* null, i8** %2
br label %29
10: ; preds = %1
%11 = call i8* (...) @getTmpPath()
store i8* %11, i8** %4
%12 = load i8*, i8** %3
%13 = call i8* @strrchr(i8* %12, i8 signext 47)
store i8* %13, i8** %5
%14 = load i8*, i8** %5
%15 = icmp ne i8* %14, null
br i1 %15, label %20, label %16
16: ; preds = %10
%17 = load i8*, i8** %4
%18 = load i8*, i8** %3
%19 = call i8* @strdup_together(i8* %17, i8* %18)
store i8* %19, i8** %6
br label %25
20: ; preds = %10
%21 = load i8*, i8** %4
%22 = load i8*, i8** %5
%23 = getelementptr inbounds i8, i8* %22, i64 1
%24 = call i8* @strdup_together(i8* %21, i8* %23)
store i8* %24, i8** %6
br label %25
25: ; preds = %20, %16
%26 = load i8*, i8** %4
%27 = call i32 @safe_free(i8* %26)
%28 = load i8*, i8** %6
store i8* %28, i8** %2
br label %29
29: ; preds = %25, %9
%30 = load i8*, i8** %2
ret i8* %30
}

LLVM IR (-O2):
define i8* @strdup_tmp_path(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %11, label %3
3: ; preds = %1
%4 = tail call i8* (...) @getTmpPath()
%5 = tail call i8* @strrchr(i8* %0, i8 signext 47)
%6 = icmp eq i8* %5, null
%7 = getelementptr inbounds i8, i8* %5, i64 1
%8 = select i1 %6, i8* %0, i8* %7
%9 = tail call i8* @strdup_together(i8* %4, i8* %8)
%10 = tail call i32 @safe_free(i8* %4)
br label %11
11: ; preds = %1, %3
%12 = phi i8* [ %9, %3 ], [ null, %1 ]
ret i8* %12
}