#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*/ get_dev_and_path(char *, short *, short *, char *);
int mx_link(short, char *, char *);
int /*<<< orphan*/ relpath_to_abspath(char const *, char *);
int /*<<< orphan*/ splitpath(char *, char *, char *);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char const *, int);
int u_link(const char *path, const char *path2) {
  char localpath[256], abspath[256];
  short device, fs;
  char localpath2[256], abspath2[256];
  short device2, fs2;
  char dir2[256], base2[256], localdir2[256];
  if (*path != '/')
    relpath_to_abspath(path, abspath);
  else
    strncpy(abspath, path, 256);
  get_dev_and_path(abspath, &device, &fs, (char *)&localpath);
  if (*path2 != '/')
    relpath_to_abspath(path2, abspath2);
  else
    strncpy(abspath2, path2, 256);
  splitpath(abspath2, dir2, base2);
  get_dev_and_path(dir2, &device2, &fs2, (char *)&localdir2);
  if (device != device2)
    return -1;
  if (fs != 1)
    return -1;
  strncpy(localpath2, localdir2, 256);
  int len = strlen(localpath2);
  if (len == 1)
    len = 0;
  localpath2[len] = '/';
  strncpy(localpath2 + len + 1, base2, 256);
  return mx_link(device, localpath, localpath2);
}


x86 assembly (clang, -O0):
<u_link>:
push   %rbp
mov    %rsp,%rbp
sub    $0x750,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
je     1198 <u_link+0x38>
mov    -0x10(%rbp),%rdi
lea    -0x220(%rbp),%rsi
call   1040 <relpath_to_abspath@plt>
jmp    11ad <u_link+0x4d>
lea    -0x220(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x100,%edx
call   1030 <strncpy@plt>
lea    -0x220(%rbp),%rdi
lea    -0x120(%rbp),%rcx
lea    -0x222(%rbp),%rsi
lea    -0x224(%rbp),%rdx
call   1060 <get_dev_and_path@plt>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
je     11f3 <u_link+0x93>
mov    -0x18(%rbp),%rdi
lea    -0x430(%rbp),%rsi
call   1040 <relpath_to_abspath@plt>
jmp    1208 <u_link+0xa8>
lea    -0x430(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0x100,%edx
call   1030 <strncpy@plt>
lea    -0x430(%rbp),%rdi
lea    -0x540(%rbp),%rsi
lea    -0x640(%rbp),%rdx
call   1080 <splitpath@plt>
lea    -0x540(%rbp),%rdi
lea    -0x740(%rbp),%rcx
lea    -0x432(%rbp),%rsi
lea    -0x434(%rbp),%rdx
call   1060 <get_dev_and_path@plt>
movswl -0x222(%rbp),%eax
movswl -0x432(%rbp),%ecx
cmp    %ecx,%eax
je     1265 <u_link+0x105>
movl   $0xffffffff,-0x4(%rbp)
jmp    1317 <u_link+0x1b7>
movswl -0x224(%rbp),%eax
cmp    $0x1,%eax
je     1281 <u_link+0x121>
movl   $0xffffffff,-0x4(%rbp)
jmp    1317 <u_link+0x1b7>
lea    -0x330(%rbp),%rdi
lea    -0x740(%rbp),%rsi
mov    $0x100,%edx
call   1030 <strncpy@plt>
lea    -0x330(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x744(%rbp)
cmpl   $0x1,-0x744(%rbp)
jne    12c2 <u_link+0x162>
movl   $0x0,-0x744(%rbp)
movslq -0x744(%rbp),%rax
movb   $0x2f,-0x330(%rbp,%rax,1)
2f
lea    -0x330(%rbp),%rdi
movslq -0x744(%rbp),%rax
add    %rax,%rdi
add    $0x1,%rdi
lea    -0x640(%rbp),%rsi
mov    $0x100,%edx
call   1030 <strncpy@plt>
mov    -0x222(%rbp),%ax
lea    -0x120(%rbp),%rsi
lea    -0x330(%rbp),%rdx
movswl %ax,%edi
call   1070 <mx_link@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x750,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<u_link>:
push   %rbx
sub    $0x710,%rsp
mov    %rsi,%rbx
mov    %rdi,%rax
cmpb   $0x2f,(%rdi)
jne    118a <u_link+0x2a>
lea    0x210(%rsp),%rdi
mov    %rax,%rsi
mov    $0x100,%edx
call   1030 <strncpy@plt>
jmp    119a <u_link+0x3a>
lea    0x210(%rsp),%rsi
mov    %rax,%rdi
call   1040 <relpath_to_abspath@plt>
lea    0x210(%rsp),%rdi
lea    0x8(%rsp),%rsi
lea    0xc(%rsp),%rdx
lea    0x510(%rsp),%rcx
call   1060 <get_dev_and_path@plt>
cmpb   $0x2f,(%rbx)
jne    11d2 <u_link+0x72>
lea    0x10(%rsp),%rdi
mov    %rbx,%rsi
mov    $0x100,%edx
call   1030 <strncpy@plt>
jmp    11df <u_link+0x7f>
lea    0x10(%rsp),%rsi
mov    %rbx,%rdi
call   1040 <relpath_to_abspath@plt>
lea    0x10(%rsp),%rdi
lea    0x610(%rsp),%rbx
lea    0x410(%rsp),%rdx
mov    %rbx,%rsi
call   1080 <splitpath@plt>
lea    0xa(%rsp),%rsi
lea    0xe(%rsp),%rdx
lea    0x310(%rsp),%rcx
mov    %rbx,%rdi
call   1060 <get_dev_and_path@plt>
movzwl 0x8(%rsp),%ecx
mov    $0xffffffff,%eax
cmp    0xa(%rsp),%cx
jne    1299 <u_link+0x139>
cmpw   $0x1,0xc(%rsp)
jne    1299 <u_link+0x139>
lea    0x110(%rsp),%rbx
lea    0x310(%rsp),%rsi
mov    %rbx,%rdi
mov    $0x100,%edx
call   1030 <strncpy@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
xor    %ecx,%ecx
cmp    $0x1,%eax
cmovne %eax,%ecx
movslq %ecx,%rax
movb   $0x2f,0x110(%rsp,%rax,1)
2f
lea    (%rsp,%rax,1),%rdi
add    $0x111,%rdi
lea    0x410(%rsp),%rsi
mov    $0x100,%edx
call   1030 <strncpy@plt>
movswl 0x8(%rsp),%edi
lea    0x510(%rsp),%rsi
mov    %rbx,%rdx
call   1070 <mx_link@plt>
add    $0x710,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i32 @u_link(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca [256 x i8]
%7 = alloca [256 x i8]
%8 = alloca i16
%9 = alloca i16
%10 = alloca [256 x i8]
%11 = alloca [256 x i8]
%12 = alloca i16
%13 = alloca i16
%14 = alloca [256 x i8]
%15 = alloca [256 x i8]
%16 = alloca [256 x i8]
%17 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%18 = load i8*, i8** %4
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp ne i32 %20, 47
br i1 %21, label %22, label %26
22: ; preds = %2
%23 = load i8*, i8** %4
%24 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%25 = call i32 @relpath_to_abspath(i8* %23, i8* %24)
br label %30
26: ; preds = %2
%27 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%28 = load i8*, i8** %4
%29 = call i32 @strncpy(i8* %27, i8* %28, i32 256)
br label %30
30: ; preds = %26, %22
%31 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%32 = bitcast [256 x i8]* %6 to i8*
%33 = call i32 @get_dev_and_path(i8* %31, i16* %8, i16* %9, i8* %32)
%34 = load i8*, i8** %5
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = icmp ne i32 %36, 47
br i1 %37, label %38, label %42
38: ; preds = %30
%39 = load i8*, i8** %5
%40 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%41 = call i32 @relpath_to_abspath(i8* %39, i8* %40)
br label %46
42: ; preds = %30
%43 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%44 = load i8*, i8** %5
%45 = call i32 @strncpy(i8* %43, i8* %44, i32 256)
br label %46
46: ; preds = %42, %38
%47 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%48 = getelementptr inbounds [256 x i8], [256 x i8]* %14, i64 0, i64 0
%49 = getelementptr inbounds [256 x i8], [256 x i8]* %15, i64 0, i64 0
%50 = call i32 @splitpath(i8* %47, i8* %48, i8* %49)
%51 = getelementptr inbounds [256 x i8], [256 x i8]* %14, i64 0, i64 0
%52 = bitcast [256 x i8]* %16 to i8*
%53 = call i32 @get_dev_and_path(i8* %51, i16* %12, i16* %13, i8* %52)
%54 = load i16, i16* %8
%55 = sext i16 %54 to i32
%56 = load i16, i16* %12
%57 = sext i16 %56 to i32
%58 = icmp ne i32 %55, %57
br i1 %58, label %59, label %60
59: ; preds = %46
store i32 -1, i32* %3
br label %89
60: ; preds = %46
%61 = load i16, i16* %9
%62 = sext i16 %61 to i32
%63 = icmp ne i32 %62, 1
br i1 %63, label %64, label %65
64: ; preds = %60
store i32 -1, i32* %3
br label %89
65: ; preds = %60
%66 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%67 = getelementptr inbounds [256 x i8], [256 x i8]* %16, i64 0, i64 0
%68 = call i32 @strncpy(i8* %66, i8* %67, i32 256)
%69 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%70 = call i32 @strlen(i8* %69)
store i32 %70, i32* %17
%71 = load i32, i32* %17
%72 = icmp eq i32 %71, 1
br i1 %72, label %73, label %74
73: ; preds = %65
store i32 0, i32* %17
br label %74
74: ; preds = %73, %65
%75 = load i32, i32* %17
%76 = sext i32 %75 to i64
%77 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 %76
store i8 47, i8* %77
%78 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%79 = load i32, i32* %17
%80 = sext i32 %79 to i64
%81 = getelementptr inbounds i8, i8* %78, i64 %80
%82 = getelementptr inbounds i8, i8* %81, i64 1
%83 = getelementptr inbounds [256 x i8], [256 x i8]* %15, i64 0, i64 0
%84 = call i32 @strncpy(i8* %82, i8* %83, i32 256)
%85 = load i16, i16* %8
%86 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%87 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%88 = call i32 @mx_link(i16 signext %85, i8* %86, i8* %87)
store i32 %88, i32* %3
br label %89
89: ; preds = %74, %64, %59
%90 = load i32, i32* %3
ret i32 %90
}

LLVM IR (-O2):
define i32 @u_link(i8* %0, i8* %1) {
%3 = alloca [256 x i8]
%4 = alloca [256 x i8]
%5 = alloca i16
%6 = alloca i16
%7 = alloca [256 x i8]
%8 = alloca [256 x i8]
%9 = alloca i16
%10 = alloca i16
%11 = alloca [256 x i8]
%12 = alloca [256 x i8]
%13 = alloca [256 x i8]
%14 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%15 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%16 = bitcast i16* %5 to i8*
%17 = bitcast i16* %6 to i8*
%18 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%19 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%20 = bitcast i16* %9 to i8*
%21 = bitcast i16* %10 to i8*
%22 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%23 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%24 = getelementptr inbounds [256 x i8], [256 x i8]* %13, i64 0, i64 0
%25 = load i8, i8* %0
%26 = icmp eq i8 %25, 47
br i1 %26, label %29, label %27
27: ; preds = %2
%28 = call i32 @relpath_to_abspath(i8* %0, i8* %15)
br label %31
29: ; preds = %2
%30 = call i32 @strncpy(i8* %15, i8* %0, i32 256)
br label %31
31: ; preds = %29, %27
%32 = call i32 @get_dev_and_path(i8* %15, i16* %5, i16* %6, i8* %14)
%33 = load i8, i8* %1
%34 = icmp eq i8 %33, 47
br i1 %34, label %37, label %35
35: ; preds = %31
%36 = call i32 @relpath_to_abspath(i8* %1, i8* %19)
br label %39
37: ; preds = %31
%38 = call i32 @strncpy(i8* %19, i8* %1, i32 256)
br label %39
39: ; preds = %37, %35
%40 = call i32 @splitpath(i8* %19, i8* %22, i8* %23)
%41 = call i32 @get_dev_and_path(i8* %22, i16* %9, i16* %10, i8* %24)
%42 = load i16, i16* %5
%43 = load i16, i16* %9
%44 = icmp eq i16 %42, %43
%45 = load i16, i16* %6
%46 = icmp eq i16 %45, 1
%47 = select i1 %44, i1 %46, i1 false
br i1 %47, label %48, label %59
48: ; preds = %39
%49 = call i32 @strncpy(i8* %18, i8* %24, i32 256)
%50 = call i32 @strlen(i8* %18)
%51 = icmp eq i32 %50, 1
%52 = select i1 %51, i32 0, i32 %50
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 %53
store i8 47, i8* %54
%55 = getelementptr inbounds i8, i8* %54, i64 1
%56 = call i32 @strncpy(i8* %55, i8* %23, i32 256)
%57 = load i16, i16* %5
%58 = call i32 @mx_link(i16 signext %57, i8* %14, i8* %18)
br label %59
59: ; preds = %39, %48
%60 = phi i32 [ %58, %48 ], [ -1, %39 ]
ret i32 %60
}