#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 _POSIX_PATH_MAX;
int /*<<< orphan*/ assert(int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
int make_relative_path(char *, char *, char *, int);
char *xstrdup(char *);
char *relative_path(char *from, char *to) {
  char *from_copy;
  char *to_copy;
  char buffer[_POSIX_PATH_MAX];
  int retval;
  assert(from != NULL);
  assert(to != NULL);
  from_copy = xstrdup(from);
  to_copy = xstrdup(to);
  retval = make_relative_path(from_copy, to_copy, buffer, _POSIX_PATH_MAX);
  free(to_copy);
  free(from_copy);
  return retval == 0 ? xstrdup(buffer) : NULL;
}


x86 assembly (clang, -O0):
<relative_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2ea1(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x8(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
cmpq   $0x0,-0x10(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x8(%rbp),%rdi
call   1050 <xstrdup@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <xstrdup@plt>
mov    -0x40(%rbp),%rdx
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    0x2e2b(%rip),%rax
mov    (%rax),%ecx
call   1030 <make_relative_path@plt>
mov    %eax,-0x34(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <free@plt>
mov    -0x18(%rbp),%rdi
call   1040 <free@plt>
cmpl   $0x0,-0x34(%rbp)
jne    1205 <relative_path+0xc5>
mov    -0x40(%rbp),%rdi
call   1050 <xstrdup@plt>
mov    %rax,-0x48(%rbp)
jmp    1210 <relative_path+0xd0>
xor    %eax,%eax
mov    %rax,-0x48(%rbp)
jmp    1210 <relative_path+0xd0>
mov    -0x48(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<relative_path>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
mov    0x2e9d(%rip),%r13
mov    0x0(%r13),%eax
mov    %rsp,%r12
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
xor    %edi,%edi
test   %r15,%r15
setne  %dil
call   1060 <assert@plt>
xor    %edi,%edi
test   %r14,%r14
setne  %dil
call   1060 <assert@plt>
mov    %r15,%rdi
call   1050 <xstrdup@plt>
mov    %rax,%r15
mov    %r14,%rdi
call   1050 <xstrdup@plt>
mov    %rax,%rbx
mov    0x0(%r13),%ecx
mov    %r15,%rdi
mov    %rax,%rsi
mov    %r12,%rdx
call   1030 <make_relative_path@plt>
mov    %eax,%r14d
mov    %rbx,%rdi
call   1040 <free@plt>
mov    %r15,%rdi
call   1040 <free@plt>
test   %r14d,%r14d
je     11d0 <relative_path+0x90>
xor    %eax,%eax
jmp    11d8 <relative_path+0x98>
mov    %r12,%rdi
call   1050 <xstrdup@plt>
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@_POSIX_PATH_MAX = global i32 0
define i8* @relative_path(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%10 = load i32, i32* @_POSIX_PATH_MAX
%11 = zext i32 %10 to i64
%12 = call i8* @llvm.stacksave()
store i8* %12, i8** %7
%13 = alloca i8, i64 %11
store i64 %11, i64* %8
%14 = load i8*, i8** %3
%15 = icmp ne i8* %14, null
%16 = zext i1 %15 to i32
%17 = call i32 @assert(i32 %16)
%18 = load i8*, i8** %4
%19 = icmp ne i8* %18, null
%20 = zext i1 %19 to i32
%21 = call i32 @assert(i32 %20)
%22 = load i8*, i8** %3
%23 = call i8* @xstrdup(i8* %22)
store i8* %23, i8** %5
%24 = load i8*, i8** %4
%25 = call i8* @xstrdup(i8* %24)
store i8* %25, i8** %6
%26 = load i8*, i8** %5
%27 = load i8*, i8** %6
%28 = load i32, i32* @_POSIX_PATH_MAX
%29 = call i32 @make_relative_path(i8* %26, i8* %27, i8* %13, i32 %28)
store i32 %29, i32* %9
%30 = load i8*, i8** %6
%31 = call i32 @free(i8* %30)
%32 = load i8*, i8** %5
%33 = call i32 @free(i8* %32)
%34 = load i32, i32* %9
%35 = icmp eq i32 %34, 0
br i1 %35, label %36, label %38
36: ; preds = %2
%37 = call i8* @xstrdup(i8* %13)
br label %39
38: ; preds = %2
br label %39
39: ; preds = %38, %36
%40 = phi i8* [ %37, %36 ], [ null, %38 ]
%41 = load i8*, i8** %7
ret i8* %40
}

LLVM IR (-O2):
@_POSIX_PATH_MAX = global i32 0
define i8* @relative_path(i8* %0, i8* %1) {
%3 = load i32, i32* @_POSIX_PATH_MAX
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = icmp ne i8* %0, null
%7 = zext i1 %6 to i32
%8 = tail call i32 @assert(i32 %7)
%9 = icmp ne i8* %1, null
%10 = zext i1 %9 to i32
%11 = tail call i32 @assert(i32 %10)
%12 = tail call i8* @xstrdup(i8* %0)
%13 = tail call i8* @xstrdup(i8* %1)
%14 = load i32, i32* @_POSIX_PATH_MAX
%15 = call i32 @make_relative_path(i8* %12, i8* %13, i8* %5, i32 %14)
%16 = call i32 @free(i8* %13)
%17 = call i32 @free(i8* %12)
%18 = icmp eq i32 %15, 0
br i1 %18, label %19, label %21
19: ; preds = %2
%20 = call i8* @xstrdup(i8* %5)
br label %21
21: ; preds = %2, %19
%22 = phi i8* [ %20, %19 ], [ null, %2 ]
ret i8* %22
}