#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 */
typedef int ssize_t;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int PATH_MAX;
int _cp_error(char const *, int);
int readlink(char const *, char *, int);
scalar_t__ symlink(char *, char const *);
int _cp_single_symlink(char const *src, char const *dst) {
  char buf[PATH_MAX];
  ssize_t len;
  if ((len = readlink(src, buf, sizeof(buf) - 1)) == -1)
    return _cp_error(src, 1);
  buf[len] = '\0';
  if (symlink(buf, dst) != 0)
    return _cp_error(dst, 1);
  return 0;
}


x86 assembly (clang, -O0):
<_cp_single_symlink>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    0x2ea9(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rsi
sub    %rcx,%rsi
mov    %rsi,-0x38(%rbp)
mov    %rsi,%rsp
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
sub    $0x1,%rax
mov    %eax,%edx
call   1030 <readlink@plt>
mov    %eax,-0x2c(%rbp)
cmp    $0xffffffff,%eax
jne    11a4 <_cp_single_symlink+0x74>
mov    -0x10(%rbp),%rdi
mov    $0x1,%esi
call   1050 <_cp_error@plt>
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x30(%rbp)
jmp    11ee <_cp_single_symlink+0xbe>
mov    -0x38(%rbp),%rdi
movslq -0x2c(%rbp),%rax
movb   $0x0,(%rdi,%rax,1)
mov    -0x18(%rbp),%rsi
call   1040 <symlink@plt>
cmp    $0x0,%rax
je     11e0 <_cp_single_symlink+0xb0>
mov    -0x18(%rbp),%rdi
mov    $0x1,%esi
call   1050 <_cp_error@plt>
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x30(%rbp)
jmp    11ee <_cp_single_symlink+0xbe>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x30(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_cp_single_symlink>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
mov    0x2ea9(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rbx
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
sub    %rcx,%rbx
mov    %rbx,%rsp
lea    -0x1(%rax),%edx
mov    %rbx,%rsi
call   1030 <readlink@plt>
cmp    $0xffffffff,%eax
je     1192 <_cp_single_symlink+0x62>
cltq
movb   $0x0,(%rbx,%rax,1)
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <symlink@plt>
test   %rax,%rax
je     11a9 <_cp_single_symlink+0x79>
mov    %r14,%rdi
mov    $0x1,%esi
call   1050 <_cp_error@plt>
jmp    11ab <_cp_single_symlink+0x7b>
mov    %r15,%rdi
mov    $0x1,%esi
lea    -0x18(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <_cp_error@plt>
xor    %eax,%eax
lea    -0x18(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@PATH_MAX = global i32 0
define i32 @_cp_single_symlink(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%10 = load i32, i32* @PATH_MAX
%11 = zext i32 %10 to i64
%12 = call i8* @llvm.stacksave()
store i8* %12, i8** %6
%13 = alloca i8, i64 %11
store i64 %11, i64* %7
%14 = load i8*, i8** %4
%15 = sub i64 %11, 1
%16 = trunc i64 %15 to i32
%17 = call i32 @readlink(i8* %14, i8* %13, i32 %16)
store i32 %17, i32* %8
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %22
19: ; preds = %2
%20 = load i8*, i8** %4
%21 = call i32 @_cp_error(i8* %20, i32 1)
store i32 %21, i32* %3
store i32 1, i32* %9
br label %33
22: ; preds = %2
%23 = load i32, i32* %8
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %13, i64 %24
store i8 0, i8* %25
%26 = load i8*, i8** %5
%27 = call i64 @symlink(i8* %13, i8* %26)
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %22
%30 = load i8*, i8** %5
%31 = call i32 @_cp_error(i8* %30, i32 1)
store i32 %31, i32* %3
store i32 1, i32* %9
br label %33
32: ; preds = %22
store i32 0, i32* %3
store i32 1, i32* %9
br label %33
33: ; preds = %32, %29, %19
%34 = load i8*, i8** %6
%35 = load i32, i32* %3
ret i32 %35
}

LLVM IR (-O2):
@PATH_MAX = global i32 0
define i32 @_cp_single_symlink(i8* %0, i8* %1) {
%3 = load i32, i32* @PATH_MAX
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = add i32 %3, -1
%7 = call i32 @readlink(i8* %0, i8* %5, i32 %6)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = tail call i32 @_cp_error(i8* %0, i32 1)
br label %18
11: ; preds = %2
%12 = sext i32 %7 to i64
%13 = getelementptr inbounds i8, i8* %5, i64 %12
store i8 0, i8* %13
%14 = call i64 @symlink(i8* %5, i8* %1)
%15 = icmp eq i64 %14, 0
br i1 %15, label %18, label %16
16: ; preds = %11
%17 = call i32 @_cp_error(i8* %1, i32 1)
br label %18
18: ; preds = %11, %16, %9
%19 = phi i32 [ %10, %9 ], [ %17, %16 ], [ 0, %11 ]
ret i32 %19
}