#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 *basename(char *);
char *dirname(char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ printf(char *, ...);
char *strdup(char *);
void dirname_basename(char *filename) {
  printf("     original: %s\n", filename);
  char *copyForDir = strdup(filename);
  char *dir = dirname(copyForDir);
  printf("      dirname: %s\n", dir);
  char *copyForBase = strdup(filename);
  char *base = basename(copyForBase);
  printf("     basename: %s\n", base);
  printf("reconstructed: %s/%s\n", dir, base);
  free(copyForDir);
  free(copyForBase);
  printf("\n");
}


x86 assembly (clang, -O0):
<dirname_basename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xe99(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
call   1070 <strdup@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <dirname@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
lea    0xe80(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
call   1070 <strdup@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1060 <basename@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rsi
lea    0xe67(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%rdx
lea    0xe64(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
lea    0xe42(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dirname_basename>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
lea    0xe8e(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1080 <strdup@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   1060 <dirname@plt>
mov    %rax,%r15
lea    0xe7a(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1080 <strdup@plt>
mov    %rax,%r12
mov    %rax,%rdi
call   1070 <basename@plt>
mov    %rax,%rbx
lea    0xe66(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe68(%rip),%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    $0xa,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1040 <putchar@plt>

LLVM IR (-O0):
@.str = [19 x i8] c" original: %s\0A\00"
@.str.1 = [19 x i8] c" dirname: %s\0A\00"
@.str.2 = [19 x i8] c" basename: %s\0A\00"
@.str.3 = [22 x i8] c"reconstructed: %s/%s\0A\00"
@.str.4 = [2 x i8] c"\0A\00"
define void @dirname_basename(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
store i8* %0, i8** %2
%7 = load i8*, i8** %2
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = load i8*, i8** %2
%10 = call i8* @strdup(i8* %9)
store i8* %10, i8** %3
%11 = load i8*, i8** %3
%12 = call i8* @dirname(i8* %11)
store i8* %12, i8** %4
%13 = load i8*, i8** %4
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %13)
%15 = load i8*, i8** %2
%16 = call i8* @strdup(i8* %15)
store i8* %16, i8** %5
%17 = load i8*, i8** %5
%18 = call i8* @basename(i8* %17)
store i8* %18, i8** %6
%19 = load i8*, i8** %6
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %19)
%21 = load i8*, i8** %4
%22 = load i8*, i8** %6
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i8* %21, i8* %22)
%24 = load i8*, i8** %3
%25 = call i32 @free(i8* %24)
%26 = load i8*, i8** %5
%27 = call i32 @free(i8* %26)
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [19 x i8] c" original: %s\0A\00"
@.str.1 = [19 x i8] c" dirname: %s\0A\00"
@.str.2 = [19 x i8] c" basename: %s\0A\00"
@.str.3 = [22 x i8] c"reconstructed: %s/%s\0A\00"
define void @dirname_basename(i8* %0) {
%2 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %0)
%3 = tail call i8* @strdup(i8* %0)
%4 = tail call i8* @dirname(i8* %3)
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %4)
%6 = tail call i8* @strdup(i8* %0)
%7 = tail call i8* @basename(i8* %6)
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %7)
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i8* %4, i8* %7)
%10 = tail call i32 @free(i8* %3)
%11 = tail call i32 @free(i8* %6)
%12 = tail call i32 @putchar(i32 10)
ret void
}