#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*/ free(char *);
char *malloc(scalar_t__);
int /*<<< orphan*/ sprintf(char *, char *, char const *, char const *);
scalar_t__ strlen(char const *);
void setddup(char **old, const char *dir, const char *name) {
  free(*old);
  *old = malloc(strlen(dir) + strlen(name) + 2);
  if (*old)
    sprintf(*old, "%s/%s", dir, name);
}


x86 assembly (clang, -O0):
<setddup>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x20(%rbp),%rdi
add    %rax,%rdi
add    $0x2,%rdi
call   1050 <malloc@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
cmpq   $0x0,(%rax)
je     11b9 <setddup+0x79>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xe4c(%rip),%rsi
call   1060 <sprintf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setddup>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
mov    (%rdi),%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1040 <strlen@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1040 <strlen@plt>
lea    (%rbx,%rax,1),%rdi
add    $0x2,%rdi
call   1050 <malloc@plt>
mov    %rax,(%r12)
test   %rax,%rax
je     11a2 <setddup+0x62>
lea    0xe77(%rip),%rsi
mov    %rax,%rdi
mov    %r15,%rdx
mov    %r14,%rcx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1060 <sprintf@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%s/%s\00"
define void @setddup(i8** %0, i8* %1, i8* %2) {
%4 = alloca i8**
%5 = alloca i8*
%6 = alloca i8*
store i8** %0, i8*** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%7 = load i8**, i8*** %4
%8 = load i8*, i8** %7
%9 = call i32 @free(i8* %8)
%10 = load i8*, i8** %5
%11 = call i64 @strlen(i8* %10)
%12 = load i8*, i8** %6
%13 = call i64 @strlen(i8* %12)
%14 = add nsw i64 %11, %13
%15 = add nsw i64 %14, 2
%16 = call i8* @malloc(i64 %15)
%17 = load i8**, i8*** %4
store i8* %16, i8** %17
%18 = load i8**, i8*** %4
%19 = load i8*, i8** %18
%20 = icmp ne i8* %19, null
br i1 %20, label %21, label %27
21: ; preds = %3
%22 = load i8**, i8*** %4
%23 = load i8*, i8** %22
%24 = load i8*, i8** %5
%25 = load i8*, i8** %6
%26 = call i32 @sprintf(i8* %23, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %24, i8* %25)
br label %27
27: ; preds = %21, %3
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c"%s/%s\00"
define void @setddup(i8** nocapture %0, i8* %1, i8* %2) {
%4 = load i8*, i8** %0
%5 = tail call i32 @free(i8* %4)
%6 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%7 = tail call i64 @strlen(i8* dereferenceable(1) %2)
%8 = add i64 %6, 2
%9 = add i64 %8, %7
%10 = tail call i8* @malloc(i64 %9)
store i8* %10, i8** %0
%11 = icmp eq i8* %10, null
br i1 %11, label %14, label %12
12: ; preds = %3
%13 = tail call i32 @sprintf(i8* %10, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %1, i8* %2)
br label %14
14: ; preds = %12, %3
ret void
}