#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 */
scalar_t__ mx_file_exists(int, char const *);
scalar_t__ mx_file_is_directory(int, char const *);
int mx_pathname_to_ino(int, char const *);
int /*<<< orphan*/ mx_write_link(int, int, char const *);
int /*<<< orphan*/ printf(char *);
int mx_link(int device, const char *path1, const char *path2) {
  if (!mx_file_exists(device, path1))
    return -1;
  if (mx_file_is_directory(device, path1)) {
    printf("ln: warning: %s is a directory. This option will be removed.\n");
  }
  if (mx_file_exists(device, path2)) {
    return -1;
  }
  int ino = mx_pathname_to_ino(device, path1);
  mx_write_link(device, ino, path2);
  return 0;
}


x86 assembly (clang, -O0):
<mx_link>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1060 <mx_file_exists@plt>
cmp    $0x0,%rax
jne    1185 <mx_link+0x35>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ee <mx_link+0x9e>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1070 <mx_file_is_directory@plt>
cmp    $0x0,%rax
je     11a7 <mx_link+0x57>
lea    0xe5e(%rip),%rdi
call   1050 <printf@plt>
mov    -0x8(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1060 <mx_file_exists@plt>
cmp    $0x0,%rax
je     11c9 <mx_link+0x79>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ee <mx_link+0x9e>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1040 <mx_pathname_to_ino@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x1c(%rbp),%esi
mov    -0x18(%rbp),%rdx
call   1030 <mx_write_link@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mx_link>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %edi,%ebp
call   1060 <mx_file_exists@plt>
mov    $0xffffffff,%r15d
test   %rax,%rax
je     11b2 <mx_link+0x62>
mov    %ebp,%edi
mov    %rbx,%rsi
call   1070 <mx_file_is_directory@plt>
test   %rax,%rax
je     118a <mx_link+0x3a>
lea    0xe7b(%rip),%rdi
call   1050 <printf@plt>
mov    %ebp,%edi
mov    %r14,%rsi
call   1060 <mx_file_exists@plt>
test   %rax,%rax
jne    11b2 <mx_link+0x62>
mov    %ebp,%edi
mov    %rbx,%rsi
call   1040 <mx_pathname_to_ino@plt>
mov    %ebp,%edi
mov    %eax,%esi
mov    %r14,%rdx
call   1030 <mx_write_link@plt>
xor    %r15d,%r15d
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [62 x i8] c"ln: warning: %s is a directory. This option will be removed.\0A\00"
define i32 @mx_link(i32 %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
store i32 %0, i32* %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%9 = load i32, i32* %5
%10 = load i8*, i8** %6
%11 = call i64 @mx_file_exists(i32 %9, i8* %10)
%12 = icmp ne i64 %11, 0
br i1 %12, label %14, label %13
13: ; preds = %3
store i32 -1, i32* %4
br label %35
14: ; preds = %3
%15 = load i32, i32* %5
%16 = load i8*, i8** %6
%17 = call i64 @mx_file_is_directory(i32 %15, i8* %16)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %14
%20 = call i32 @printf(i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str, i64 0, i64 0))
br label %21
21: ; preds = %19, %14
%22 = load i32, i32* %5
%23 = load i8*, i8** %7
%24 = call i64 @mx_file_exists(i32 %22, i8* %23)
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %21
store i32 -1, i32* %4
br label %35
27: ; preds = %21
%28 = load i32, i32* %5
%29 = load i8*, i8** %6
%30 = call i32 @mx_pathname_to_ino(i32 %28, i8* %29)
store i32 %30, i32* %8
%31 = load i32, i32* %5
%32 = load i32, i32* %8
%33 = load i8*, i8** %7
%34 = call i32 @mx_write_link(i32 %31, i32 %32, i8* %33)
store i32 0, i32* %4
br label %35
35: ; preds = %27, %26, %13
%36 = load i32, i32* %4
ret i32 %36
}

LLVM IR (-O2):
@.str = [62 x i8] c"ln: warning: %s is a directory. This option will be removed.\0A\00"
define i32 @mx_link(i32 %0, i8* %1, i8* %2) {
%4 = tail call i64 @mx_file_exists(i32 %0, i8* %1)
%5 = icmp eq i64 %4, 0
br i1 %5, label %17, label %6
6: ; preds = %3
%7 = tail call i64 @mx_file_is_directory(i32 %0, i8* %1)
%8 = icmp eq i64 %7, 0
br i1 %8, label %11, label %9
9: ; preds = %6
%10 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([62 x i8], [62 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %9, %6
%12 = tail call i64 @mx_file_exists(i32 %0, i8* %2)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %11
%15 = tail call i32 @mx_pathname_to_ino(i32 %0, i8* %1)
%16 = tail call i32 @mx_write_link(i32 %0, i32 %15, i8* %2)
br label %17
17: ; preds = %11, %3, %14
%18 = phi i32 [ 0, %14 ], [ -1, %3 ], [ -1, %11 ]
ret i32 %18
}