#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*/ EINVAL;
int /*<<< orphan*/ errno;
int link(char const *, char const *);
int linkat(int olddirfd, const char *oldpath, int newdirfd, const char *newpath,
           int flags) {
  int result;
  if ((oldpath[0] == '/') && (newpath[0] == '/')) {
    result = link(oldpath, newpath);
  } else {
    errno = EINVAL;
    result = -1;
  }
  return result;
}


x86 assembly (clang, -O0):
<linkat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    115f <linkat+0x4f>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    115f <linkat+0x4f>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <link@plt>
mov    %eax,-0x28(%rbp)
jmp    1178 <linkat+0x68>
mov    0x2e72(%rip),%rax
mov    (%rax),%ecx
mov    0x2e71(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x28(%rbp)
mov    -0x28(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<linkat>:
cmpb   $0x2f,(%rsi)
jne    1125 <linkat+0x15>
cmpb   $0x2f,(%rcx)
jne    1125 <linkat+0x15>
mov    %rsi,%rdi
mov    %rcx,%rsi
jmp    1030 <link@plt>
mov    0x2eac(%rip),%rax
mov    (%rax),%eax
mov    0x2eab(%rip),%rcx
mov    %eax,(%rcx)
mov    $0xffffffff,%eax
ret

LLVM IR (-O0):
@EINVAL = global i32 0
@errno = global i32 0
define i32 @linkat(i32 %0, i8* %1, i32 %2, i8* %3, i32 %4) {
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
store i32 %0, i32* %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i8* %3, i8** %9
store i32 %4, i32* %10
%12 = load i8*, i8** %7
%13 = getelementptr inbounds i8, i8* %12, i64 0
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp eq i32 %15, 47
br i1 %16, label %17, label %27
17: ; preds = %5
%18 = load i8*, i8** %9
%19 = getelementptr inbounds i8, i8* %18, i64 0
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp eq i32 %21, 47
br i1 %22, label %23, label %27
23: ; preds = %17
%24 = load i8*, i8** %7
%25 = load i8*, i8** %9
%26 = call i32 @link(i8* %24, i8* %25)
store i32 %26, i32* %11
br label %29
27: ; preds = %17, %5
%28 = load i32, i32* @EINVAL
store i32 %28, i32* @errno
store i32 -1, i32* %11
br label %29
29: ; preds = %27, %23
%30 = load i32, i32* %11
ret i32 %30
}

LLVM IR (-O2):
@EINVAL = global i32 0
@errno = global i32 0
define i32 @linkat(i32 %0, i8* %1, i32 %2, i8* %3, i32 %4) {
%6 = load i8, i8* %1
%7 = icmp eq i8 %6, 47
br i1 %7, label %8, label %13
8: ; preds = %5
%9 = load i8, i8* %3
%10 = icmp eq i8 %9, 47
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = tail call i32 @link(i8* %1, i8* %3)
br label %15
13: ; preds = %8, %5
%14 = load i32, i32* @EINVAL
store i32 %14, i32* @errno
br label %15
15: ; preds = %13, %11
%16 = phi i32 [ %12, %11 ], [ -1, %13 ]
ret i32 %16
}