#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 *, char *);
char *strdup(char *);
int main(int argc, char *argv[]) {
  char *path = "/var/www/text/unkown/index.html";
  char *dir = strdup(path);
  char *base = strdup(path);
  printf("dir = %s, base = %s\n", dirname(dir), basename(base));
  printf("dir = %s\nbase = %s\n", dir, base);
  free(dir);
  free(base);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe93(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1070 <strdup@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1070 <strdup@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <dirname@plt>
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
call   1060 <basename@plt>
mov    -0x30(%rbp),%rsi
mov    %rax,%rdx
lea    0xe71(%rip),%rdi
call   1040 <printf@plt>
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
lea    0xe72(%rip),%rdi
call   1040 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
lea    0xea4(%rip),%r14
mov    %r14,%rdi
call   1070 <strdup@plt>
mov    %rax,%r15
mov    %r14,%rdi
call   1070 <strdup@plt>
mov    %rax,%rbx
mov    %r15,%rdi
call   1050 <dirname@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1060 <basename@plt>
lea    0xe94(%rip),%rdi
mov    %r14,%rsi
mov    %rax,%rdx
call   1040 <printf@plt>
lea    0xe97(%rip),%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1040 <printf@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [32 x i8] c"/var/www/text/unkown/index.html\00"
@.str.1 = [21 x i8] c"dir = %s, base = %s\0A\00"
@.str.2 = [20 x i8] c"dir = %s\0Abase = %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8** %6
%9 = load i8*, i8** %6
%10 = call i8* @strdup(i8* %9)
store i8* %10, i8** %7
%11 = load i8*, i8** %6
%12 = call i8* @strdup(i8* %11)
store i8* %12, i8** %8
%13 = load i8*, i8** %7
%14 = call i8* @dirname(i8* %13)
%15 = load i8*, i8** %8
%16 = call i8* @basename(i8* %15)
%17 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %14, i8* %16)
%18 = load i8*, i8** %7
%19 = load i8*, i8** %8
%20 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %18, i8* %19)
%21 = load i8*, i8** %7
%22 = call i32 @free(i8* %21)
%23 = load i8*, i8** %8
%24 = call i32 @free(i8* %23)
ret i32 0
}

LLVM IR (-O2):
@.str = [32 x i8] c"/var/www/text/unkown/index.html\00"
@.str.1 = [21 x i8] c"dir = %s, base = %s\0A\00"
@.str.2 = [20 x i8] c"dir = %s\0Abase = %s\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call dereferenceable_or_null(32) i8* @strdup(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%4 = tail call dereferenceable_or_null(32) i8* @strdup(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%5 = tail call i8* @dirname(i8* %3)
%6 = tail call i8* @basename(i8* %4)
%7 = tail call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %5, i8* %6)
%8 = tail call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %3, i8* %4)
%9 = tail call i32 @free(i8* %3)
%10 = tail call i32 @free(i8* %4)
ret i32 0
}