#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 PATH_MAX;
scalar_t__ S_IFDIR;
char *basename(char *);
scalar_t__ path_type(char *);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char const *);
void cp_target_add_basename(const char *src, char *dst) {
  char bname_buf[PATH_MAX];
  char *bname;
  if (path_type(dst) == S_IFDIR) {
    strcpy(bname_buf, src);
    bname = basename(bname_buf);
    strcat(dst, "/");
    strcat(dst, bname);
  }
}


x86 assembly (clang, -O0):
<cp_target_add_basename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e99(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <path_type@plt>
mov    0x2e44(%rip),%rcx
cmp    (%rcx),%rax
jne    11cc <cp_target_add_basename+0x8c>
mov    -0x30(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x30(%rbp),%rdi
call   1040 <basename@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe46(%rip),%rsi
call   1050 <strcat@plt>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1050 <strcat@plt>
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cp_target_add_basename>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%r14
mov    0x2e99(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rsi,%rdi
call   1060 <path_type@plt>
mov    0x2e57(%rip),%rcx
cmp    (%rcx),%rax
jne    11ae <cp_target_add_basename+0x6e>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
call   1040 <basename@plt>
mov    %rax,%rbx
lea    0xe65(%rip),%rsi
mov    %r15,%rdi
call   1050 <strcat@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1050 <strcat@plt>
lea    -0x18(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@PATH_MAX = global i32 0
@S_IFDIR = global i64 0
@.str = [2 x i8] c"/\00"
define void @cp_target_add_basename(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%8 = load i32, i32* @PATH_MAX
%9 = zext i32 %8 to i64
%10 = call i8* @llvm.stacksave()
store i8* %10, i8** %5
%11 = alloca i8, i64 %9
store i64 %9, i64* %6
%12 = load i8*, i8** %4
%13 = call i64 @path_type(i8* %12)
%14 = load i64, i64* @S_IFDIR
%15 = icmp eq i64 %13, %14
br i1 %15, label %16, label %25
16: ; preds = %2
%17 = load i8*, i8** %3
%18 = call i32 @strcpy(i8* %11, i8* %17)
%19 = call i8* @basename(i8* %11)
store i8* %19, i8** %7
%20 = load i8*, i8** %4
%21 = call i32 @strcat(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%22 = load i8*, i8** %4
%23 = load i8*, i8** %7
%24 = call i32 @strcat(i8* %22, i8* %23)
br label %25
25: ; preds = %16, %2
%26 = load i8*, i8** %5
ret void
}

LLVM IR (-O2):
@PATH_MAX = global i32 0
@S_IFDIR = global i64 0
@.str = [2 x i8] c"/\00"
define void @cp_target_add_basename(i8* %0, i8* %1) {
%3 = load i32, i32* @PATH_MAX
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = tail call i64 @path_type(i8* %1)
%7 = load i64, i64* @S_IFDIR
%8 = icmp eq i64 %6, %7
br i1 %8, label %9, label %14
9: ; preds = %2
%10 = call i32 @strcpy(i8* %5, i8* %0)
%11 = call i8* @basename(i8* %5)
%12 = call i32 @strcat(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @strcat(i8* %1, i8* %11)
br label %14
14: ; preds = %9, %2
ret void
}