#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 */
typedef int /*<<< orphan*/ path;

/* Variables and functions */
char *dirname(char *);
char *getcwd(char *, int);
int /*<<< orphan*/ printf(char *, char *);
int main() {
  char *name = dirname(".");
  printf("%s\n", name);
  char path[100] = {0};
  char *cwd = getcwd(path, sizeof(path));
  printf("cwd:  %s\n", cwd);
  printf("path: %s\n", path);
  printf("dirname(cwd):  %s\n", dirname(cwd));
  printf("dirname(path): %s\n", dirname(path));
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
lea    0xeae(%rip),%rdi
call   1040 <dirname@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xebf(%rip),%rdi
call   1030 <printf@plt>
lea    -0x70(%rbp),%rdi
xor    %esi,%esi
mov    $0x64,%edx
call   1050 <memset@plt>
lea    -0x70(%rbp),%rdi
mov    $0x64,%esi
call   1060 <getcwd@plt>
mov    %rax,-0x78(%rbp)
mov    -0x78(%rbp),%rsi
lea    0xe6a(%rip),%rdi
call   1030 <printf@plt>
lea    -0x70(%rbp),%rsi
lea    0xe64(%rip),%rdi
call   1030 <printf@plt>
mov    -0x78(%rbp),%rdi
call   1040 <dirname@plt>
mov    %rax,%rsi
lea    0xe56(%rip),%rdi
call   1030 <printf@plt>
lea    -0x70(%rbp),%rdi
call   1040 <dirname@plt>
mov    %rax,%rsi
lea    0xe51(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x68,%rsp
lea    0xec2(%rip),%rdi
call   1040 <dirname@plt>
lea    0xedb(%rip),%rdi
mov    %rax,%rsi
call   1030 <printf@plt>
xorps  %xmm0,%xmm0
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
movl   $0x0,0x60(%rsp)
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x64,%esi
call   1050 <getcwd@plt>
mov    %rax,%rbx
lea    0xe6e(%rip),%rdi
mov    %rax,%rsi
call   1030 <printf@plt>
lea    0xe69(%rip),%rdi
mov    %r14,%rsi
call   1030 <printf@plt>
mov    %rbx,%rdi
call   1040 <dirname@plt>
lea    0xe5c(%rip),%rdi
mov    %rax,%rsi
call   1030 <printf@plt>
mov    %r14,%rdi
call   1040 <dirname@plt>
lea    0xe58(%rip),%rdi
mov    %rax,%rsi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [2 x i8] c".\00"
@.str.1 = [4 x i8] c"%s\0A\00"
@.str.2 = [10 x i8] c"cwd: %s\0A\00"
@.str.3 = [10 x i8] c"path: %s\0A\00"
@.str.4 = [19 x i8] c"dirname(cwd): %s\0A\00"
@.str.5 = [19 x i8] c"dirname(path): %s\0A\00"
define i32 @main() {
%1 = alloca i8*
%2 = alloca [100 x i8]
%3 = alloca i8*
%4 = call i8* @dirname(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %4, i8** %1
%5 = load i8*, i8** %1
%6 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %5)
%7 = bitcast [100 x i8]* %2 to i8*
%8 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%9 = call i8* @getcwd(i8* %8, i32 100)
store i8* %9, i8** %3
%10 = load i8*, i8** %3
%11 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %10)
%12 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%13 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* %12)
%14 = load i8*, i8** %3
%15 = call i8* @dirname(i8* %14)
%16 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8* %15)
%17 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%18 = call i8* @dirname(i8* %17)
%19 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i8* %18)
ret i32 0
}

LLVM IR (-O2):
@.str = [2 x i8] c".\00"
@.str.1 = [4 x i8] c"%s\0A\00"
@.str.2 = [10 x i8] c"cwd: %s\0A\00"
@.str.3 = [10 x i8] c"path: %s\0A\00"
@.str.4 = [19 x i8] c"dirname(cwd): %s\0A\00"
@.str.5 = [19 x i8] c"dirname(path): %s\0A\00"
define i32 @main() {
%1 = alloca [100 x i8]
%2 = tail call i8* @dirname(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%3 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %2)
%4 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%5 = call i8* @getcwd(i8* %4, i32 100)
%6 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %5)
%7 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* %4)
%8 = call i8* @dirname(i8* %5)
%9 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8* %8)
%10 = call i8* @dirname(i8* %4)
%11 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i8* %10)
ret i32 0
}