#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 */
int /*<<< orphan*/ test_relative(char *, char *, char *);
void test_path_relative(void) {
  test_relative("/data/orandea/test/aaa", "/data/orandea/impl/bbb",
                "../../impl/bbb");
  test_relative("a/b", "a/b/c.txt", "c.txt");
  test_relative("", "", "");
  test_relative("", "aoeu", "aoeu");
  test_relative("aoeu", "", "..");
  test_relative("/", "/", "");
  test_relative("/var/lib", "/var", "..");
  test_relative("/var/lib", "/bin", "../../bin");
  test_relative("/var/lib", "/var/lib", "");
  test_relative("/var/lib", "/var/apache", "../apache");
  test_relative("/var/", "/var/lib", "lib");
  test_relative("/", "/var/lib", "var/lib");
}


x86 assembly (clang, -O0):
<test_path_relative>:
push   %rbp
mov    %rsp,%rbp
lea    0xee5(%rip),%rdi
lea    0xef5(%rip),%rsi
lea    0xf05(%rip),%rdx
call   1030 <test_relative@plt>
lea    0xf08(%rip),%rdi
lea    0xf05(%rip),%rsi
lea    0xf02(%rip),%rdx
call   1030 <test_relative@plt>
lea    0xf03(%rip),%rdx
mov    %rdx,%rdi
mov    %rdx,%rsi
call   1030 <test_relative@plt>
lea    0xef1(%rip),%rdi
lea    0xee3(%rip),%rdx
mov    %rdx,%rsi
call   1030 <test_relative@plt>
lea    0xed4(%rip),%rdi
lea    0xed4(%rip),%rsi
lea    0xecb(%rip),%rdx
call   1030 <test_relative@plt>
lea    0xef4(%rip),%rsi
lea    0xeba(%rip),%rdx
mov    %rsi,%rdi
call   1030 <test_relative@plt>
lea    0xeac(%rip),%rdi
lea    0xeae(%rip),%rsi
lea    0xe9b(%rip),%rdx
call   1030 <test_relative@plt>
lea    0xe92(%rip),%rdi
lea    0xe9e(%rip),%rsi
lea    0xe92(%rip),%rdx
call   1030 <test_relative@plt>
lea    0xe78(%rip),%rsi
lea    0xe70(%rip),%rdx
mov    %rsi,%rdi
call   1030 <test_relative@plt>
lea    0xe62(%rip),%rdi
lea    0xe73(%rip),%rsi
lea    0xe78(%rip),%rdx
call   1030 <test_relative@plt>
lea    0xe76(%rip),%rdi
lea    0xe41(%rip),%rsi
lea    0xe3f(%rip),%rdx
call   1030 <test_relative@plt>
lea    0xe60(%rip),%rdi
lea    0xe27(%rip),%rsi
lea    0xe21(%rip),%rdx
call   1030 <test_relative@plt>
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_path_relative>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
lea    0xee1(%rip),%rdi
lea    0xef1(%rip),%rsi
lea    0xf01(%rip),%rdx
call   1030 <test_relative@plt>
lea    0xf04(%rip),%rdi
lea    0xf01(%rip),%rsi
lea    0xefe(%rip),%rdx
call   1030 <test_relative@plt>
lea    0xeff(%rip),%r15
mov    %r15,%rdi
mov    %r15,%rsi
mov    %r15,%rdx
call   1030 <test_relative@plt>
lea    0xee3(%rip),%rbx
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %rbx,%rdx
call   1030 <test_relative@plt>
lea    0xed3(%rip),%r12
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1030 <test_relative@plt>
lea    0xef3(%rip),%r14
mov    %r14,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1030 <test_relative@plt>
lea    0xeac(%rip),%rbx
lea    0xeae(%rip),%rsi
mov    %rbx,%rdi
mov    %r12,%rdx
call   1030 <test_relative@plt>
lea    0xea6(%rip),%rsi
lea    0xe9a(%rip),%rdx
mov    %rbx,%rdi
call   1030 <test_relative@plt>
mov    %rbx,%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1030 <test_relative@plt>
lea    0xe87(%rip),%rsi
lea    0xe8c(%rip),%rdx
mov    %rbx,%rdi
call   1030 <test_relative@plt>
lea    0xe87(%rip),%rdi
lea    0xe57(%rip),%rdx
mov    %rbx,%rsi
call   1030 <test_relative@plt>
lea    0xe44(%rip),%rdx
mov    %r14,%rdi
mov    %rbx,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <test_relative@plt>

LLVM IR (-O0):
@.str = [23 x i8] c"/data/orandea/test/aaa\00"
@.str.1 = [23 x i8] c"/data/orandea/impl/bbb\00"
@.str.2 = [15 x i8] c"../../impl/bbb\00"
@.str.3 = [4 x i8] c"a/b\00"
@.str.4 = [10 x i8] c"a/b/c.txt\00"
@.str.5 = [6 x i8] c"c.txt\00"
@.str.6 = [1 x i8] zeroinitializer
@.str.7 = [5 x i8] c"aoeu\00"
@.str.8 = [3 x i8] c"..\00"
@.str.9 = [2 x i8] c"/\00"
@.str.10 = [9 x i8] c"/var/lib\00"
@.str.11 = [5 x i8] c"/var\00"
@.str.12 = [5 x i8] c"/bin\00"
@.str.13 = [10 x i8] c"../../bin\00"
@.str.14 = [12 x i8] c"/var/apache\00"
@.str.15 = [10 x i8] c"../apache\00"
@.str.16 = [6 x i8] c"/var/\00"
@.str.17 = [4 x i8] c"lib\00"
@.str.18 = [8 x i8] c"var/lib\00"
define void @test_path_relative() {
%1 = call i32 @test_relative(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%2 = call i32 @test_relative(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
%3 = call i32 @test_relative(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.6, i64 0, i64 0))
%4 = call i32 @test_relative(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
%5 = call i32 @test_relative(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0))
%6 = call i32 @test_relative(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.6, i64 0, i64 0))
%7 = call i32 @test_relative(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0))
%8 = call i32 @test_relative(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.12, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.13, i64 0, i64 0))
%9 = call i32 @test_relative(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.6, i64 0, i64 0))
%10 = call i32 @test_relative(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.14, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.15, i64 0, i64 0))
%11 = call i32 @test_relative(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.16, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.17, i64 0, i64 0))
%12 = call i32 @test_relative(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.18, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [23 x i8] c"/data/orandea/test/aaa\00"
@.str.1 = [23 x i8] c"/data/orandea/impl/bbb\00"
@.str.2 = [15 x i8] c"../../impl/bbb\00"
@.str.3 = [4 x i8] c"a/b\00"
@.str.4 = [10 x i8] c"a/b/c.txt\00"
@.str.5 = [6 x i8] c"c.txt\00"
@.str.6 = [1 x i8] zeroinitializer
@.str.7 = [5 x i8] c"aoeu\00"
@.str.8 = [3 x i8] c"..\00"
@.str.9 = [2 x i8] c"/\00"
@.str.10 = [9 x i8] c"/var/lib\00"
@.str.11 = [5 x i8] c"/var\00"
@.str.12 = [5 x i8] c"/bin\00"
@.str.13 = [10 x i8] c"../../bin\00"
@.str.14 = [12 x i8] c"/var/apache\00"
@.str.15 = [10 x i8] c"../apache\00"
@.str.16 = [6 x i8] c"/var/\00"
@.str.17 = [4 x i8] c"lib\00"
@.str.18 = [8 x i8] c"var/lib\00"
define void @test_path_relative() {
%1 = tail call i32 @test_relative(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%2 = tail call i32 @test_relative(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
%3 = tail call i32 @test_relative(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.6, i64 0, i64 0))
%4 = tail call i32 @test_relative(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
%5 = tail call i32 @test_relative(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0))
%6 = tail call i32 @test_relative(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.6, i64 0, i64 0))
%7 = tail call i32 @test_relative(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0))
%8 = tail call i32 @test_relative(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.12, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.13, i64 0, i64 0))
%9 = tail call i32 @test_relative(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.6, i64 0, i64 0))
%10 = tail call i32 @test_relative(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.14, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.15, i64 0, i64 0))
%11 = tail call i32 @test_relative(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.16, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.17, i64 0, i64 0))
%12 = tail call i32 @test_relative(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.18, i64 0, i64 0))
ret void
}