void test_parent_dir(void) {
  const char *buf;
  buf = make_rel_path("/", "/home/");
  do {
    seatest_assert_string_equal("..", buf, __FUNCTION__, 62);
  } while (0);
  buf = make_rel_path("/", "/home/user/");
  do {
    seatest_assert_string_equal("../..", buf, __FUNCTION__, 65);
  } while (0);
  buf = make_rel_path("/", "/home/////user/dir/");
  do {
    seatest_assert_string_equal("../../..", buf, __FUNCTION__, 68);
  } while (0);
}


x86 assembly (clang, -O0):
<test_parent_dir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xed6(%rip),%rdi
lea    0xeca(%rip),%rsi
mov    $0x0,%al
call   1030 <make_rel_path@plt>
cltq
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xeef(%rip),%rdi
lea    0xeb2(%rip),%rdx
mov    $0x3e,%ecx
mov    $0x0,%al
call   1040 <seatest_assert_string_equal@plt>
lea    0xe9d(%rip),%rdi
lea    0xea8(%rip),%rsi
mov    $0x0,%al
call   1030 <make_rel_path@plt>
cltq
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xeb3(%rip),%rdi
lea    0xe79(%rip),%rdx
mov    $0x41,%ecx
mov    $0x0,%al
call   1040 <seatest_assert_string_equal@plt>
lea    0xe64(%rip),%rdi
lea    0xe7b(%rip),%rsi
mov    $0x0,%al
call   1030 <make_rel_path@plt>
cltq
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xe77(%rip),%rdi
lea    0xe40(%rip),%rdx
mov    $0x44,%ecx
mov    $0x0,%al
call   1040 <seatest_assert_string_equal@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_parent_dir>:
push   %r14
push   %rbx
push   %rax
lea    0xeda(%rip),%r14
lea    0xece(%rip),%rsi
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <make_rel_path@plt>
movslq %eax,%rsi
lea    0xef7(%rip),%rdi
lea    0xeba(%rip),%rbx
mov    %rbx,%rdx
mov    $0x3e,%ecx
xor    %eax,%eax
call   1040 <seatest_assert_string_equal@plt>
lea    0xeb4(%rip),%rsi
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <make_rel_path@plt>
movslq %eax,%rsi
lea    0xec3(%rip),%rdi
mov    %rbx,%rdx
mov    $0x41,%ecx
xor    %eax,%eax
call   1040 <seatest_assert_string_equal@plt>
lea    0xe96(%rip),%rsi
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <make_rel_path@plt>
movslq %eax,%rsi
lea    0xe96(%rip),%rdi
mov    %rbx,%rdx
mov    $0x44,%ecx
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <seatest_assert_string_equal@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"/\00"
@.str.1 = [7 x i8] c"/home/\00"
@.str.2 = [3 x i8] c"..\00"
@__FUNCTION__.test_parent_dir = [16 x i8] c"test_parent_dir\00"
@.str.3 = [12 x i8] c"/home/user/\00"
@.str.4 = [6 x i8] c"../..\00"
@.str.5 = [20 x i8] c"/home/////user/dir/\00"
@.str.6 = [9 x i8] c"../../..\00"
define void @test_parent_dir() {
%1 = alloca i8*
%2 = call i32 (i8*, i8*, ...) bitcast (i32 (...)* @make_rel_path to i32 (i8*, i8*, ...)*)(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%3 = sext i32 %2 to i64
%4 = inttoptr i64 %3 to i8*
store i8* %4, i8** %1
br label %5
5: ; preds = %0
%6 = load i8*, i8** %1
%7 = call i32 (i8*, i8*, i8*, i32, ...) bitcast (i32 (...)* @seatest_assert_string_equal to i32 (i8*, i8*, i8*, i32, ...)*)(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %6, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @__FUNCTION__.test_parent_dir, i64 0, i64 0), i32 62)
br label %8
8: ; preds = %5
%9 = call i32 (i8*, i8*, ...) bitcast (i32 (...)* @make_rel_path to i32 (i8*, i8*, ...)*)(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
%10 = sext i32 %9 to i64
%11 = inttoptr i64 %10 to i8*
store i8* %11, i8** %1
br label %12
12: ; preds = %8
%13 = load i8*, i8** %1
%14 = call i32 (i8*, i8*, i8*, i32, ...) bitcast (i32 (...)* @seatest_assert_string_equal to i32 (i8*, i8*, i8*, i32, ...)*)(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* %13, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @__FUNCTION__.test_parent_dir, i64 0, i64 0), i32 65)
br label %15
15: ; preds = %12
%16 = call i32 (i8*, i8*, ...) bitcast (i32 (...)* @make_rel_path to i32 (i8*, i8*, ...)*)(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0))
%17 = sext i32 %16 to i64
%18 = inttoptr i64 %17 to i8*
store i8* %18, i8** %1
br label %19
19: ; preds = %15
%20 = load i8*, i8** %1
%21 = call i32 (i8*, i8*, i8*, i32, ...) bitcast (i32 (...)* @seatest_assert_string_equal to i32 (i8*, i8*, i8*, i32, ...)*)(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i8* %20, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @__FUNCTION__.test_parent_dir, i64 0, i64 0), i32 68)
br label %22
22: ; preds = %19
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"/\00"
@.str.1 = [7 x i8] c"/home/\00"
@.str.2 = [3 x i8] c"..\00"
@__FUNCTION__.test_parent_dir = [16 x i8] c"test_parent_dir\00"
@.str.3 = [12 x i8] c"/home/user/\00"
@.str.4 = [6 x i8] c"../..\00"
@.str.5 = [20 x i8] c"/home/////user/dir/\00"
@.str.6 = [9 x i8] c"../../..\00"
define void @test_parent_dir() {
%1 = tail call i32 (i8*, i8*, ...) bitcast (i32 (...)* @make_rel_path to i32 (i8*, i8*, ...)*)(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%2 = sext i32 %1 to i64
%3 = inttoptr i64 %2 to i8*
%4 = tail call i32 (i8*, i8*, i8*, i32, ...) bitcast (i32 (...)* @seatest_assert_string_equal to i32 (i8*, i8*, i8*, i32, ...)*)(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %3, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @__FUNCTION__.test_parent_dir, i64 0, i64 0), i32 62)
%5 = tail call i32 (i8*, i8*, ...) bitcast (i32 (...)* @make_rel_path to i32 (i8*, i8*, ...)*)(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
%6 = sext i32 %5 to i64
%7 = inttoptr i64 %6 to i8*
%8 = tail call i32 (i8*, i8*, i8*, i32, ...) bitcast (i32 (...)* @seatest_assert_string_equal to i32 (i8*, i8*, i8*, i32, ...)*)(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* %7, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @__FUNCTION__.test_parent_dir, i64 0, i64 0), i32 65)
%9 = tail call i32 (i8*, i8*, ...) bitcast (i32 (...)* @make_rel_path to i32 (i8*, i8*, ...)*)(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0))
%10 = sext i32 %9 to i64
%11 = inttoptr i64 %10 to i8*
%12 = tail call i32 (i8*, i8*, i8*, i32, ...) bitcast (i32 (...)* @seatest_assert_string_equal to i32 (i8*, i8*, i8*, i32, ...)*)(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i8* %11, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @__FUNCTION__.test_parent_dir, i64 0, i64 0), i32 68)
ret void
}