#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 *basename(char *);
char *getcwd(char *, int);
int /*<<< orphan*/ printf(char *, char *);
int main() {
  printf("%s\n", "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                 "outputs/2022-01-22/02-19-57/repos/zhangrxiang/learn-c/refs/"
                 "heads/master/linux/libgen/basename.c");
  printf("%s\n",
         basename("/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                  "outputs/2022-01-22/02-19-57/repos/zhangrxiang/learn-c/refs/"
                  "heads/master/linux/libgen/basename.c"));
  char path[100] = {0};
  char *cwd = getcwd(path, sizeof(path));
  printf("%s\n", cwd);
  printf("%s\n", basename(cwd));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xea7(%rip),%rdi
lea    0xea4(%rip),%rsi
call   1030 <printf@plt>
lea    0xe98(%rip),%rdi
call   1060 <basename@plt>
mov    %rax,%rsi
lea    0xe85(%rip),%rdi
call   1030 <printf@plt>
lea    -0x70(%rbp),%rdi
xor    %esi,%esi
mov    $0x64,%edx
call   1040 <memset@plt>
lea    -0x70(%rbp),%rdi
mov    $0x64,%esi
call   1050 <getcwd@plt>
mov    %rax,-0x78(%rbp)
mov    -0x78(%rbp),%rsi
lea    0xe53(%rip),%rdi
call   1030 <printf@plt>
mov    -0x78(%rbp),%rdi
call   1060 <basename@plt>
mov    %rax,%rsi
lea    0xe3b(%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),%r14
lea    0xebf(%rip),%rbx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
mov    %rbx,%rdi
call   1050 <basename@plt>
mov    %r14,%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,%rdi
mov    $0x64,%esi
call   1040 <getcwd@plt>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %rax,%rsi
call   1030 <printf@plt>
mov    %rbx,%rdi
call   1050 <basename@plt>
mov    %r14,%rdi
mov    %rax,%rsi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%s\0A\00"
@.str.1 = [152 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/zhangrxiang/learn-c/refs/heads/master/linux/libgen/basename.c\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [100 x i8]
%3 = alloca i8*
store i32 0, i32* %1
%4 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([152 x i8], [152 x i8]* @.str.1, i64 0, i64 0))
%5 = call i8* @basename(i8* getelementptr inbounds ([152 x i8], [152 x i8]* @.str.1, i64 0, i64 0))
%6 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, 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 ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = load i8*, i8** %3
%13 = call i8* @basename(i8* %12)
%14 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %13)
ret i32 0
}

LLVM IR (-O2):
@.str = [4 x i8] c"%s\0A\00"
@.str.1 = [152 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/zhangrxiang/learn-c/refs/heads/master/linux/libgen/basename.c\00"
define i32 @main() {
%1 = alloca [100 x i8]
%2 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([152 x i8], [152 x i8]* @.str.1, i64 0, i64 0))
%3 = tail call i8* @basename(i8* getelementptr inbounds ([152 x i8], [152 x i8]* @.str.1, i64 0, i64 0))
%4 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %3)
%5 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%6 = call i8* @getcwd(i8* %5, i32 100)
%7 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = call i8* @basename(i8* %6)
%9 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %8)
ret i32 0
}