#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 _mv_error(char const *, int);
int readlink(char const *, char *, int);
scalar_t__ symlink(char *, char const *);
scalar_t__ unlink(char const *);
int _mv_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 _mv_error(src, 1);
  buf[len] = '\0';
  if (symlink(buf, dst) != 0)
    return _mv_error(dst, 1);
  if (unlink(src) != 0)
    _mv_error(src, 0);
  return 0;
}


x86 assembly (clang, -O0):
<_mv_single_symlink>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    0x2e99(%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   1040 <readlink@plt>
mov    %eax,-0x2c(%rbp)
cmp    $0xffffffff,%eax
jne    11b4 <_mv_single_symlink+0x74>
mov    -0x10(%rbp),%rdi
mov    $0x1,%esi
call   1060 <_mv_error@plt>
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x30(%rbp)
jmp    121c <_mv_single_symlink+0xdc>
mov    -0x38(%rbp),%rdi
movslq -0x2c(%rbp),%rax
movb   $0x0,(%rdi,%rax,1)
mov    -0x18(%rbp),%rsi
call   1050 <symlink@plt>
cmp    $0x0,%rax
je     11f0 <_mv_single_symlink+0xb0>
mov    -0x18(%rbp),%rdi
mov    $0x1,%esi
call   1060 <_mv_error@plt>
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x30(%rbp)
jmp    121c <_mv_single_symlink+0xdc>
mov    -0x10(%rbp),%rdi
call   1030 <unlink@plt>
cmp    $0x0,%rax
je     120e <_mv_single_symlink+0xce>
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
call   1060 <_mv_error@plt>
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):
<_mv_single_symlink>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
mov    0x2e99(%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   1040 <readlink@plt>
cmp    $0xffffffff,%eax
je     11a4 <_mv_single_symlink+0x64>
cltq
movb   $0x0,(%rbx,%rax,1)
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <symlink@plt>
test   %rax,%rax
je     11bb <_mv_single_symlink+0x7b>
mov    %r14,%rdi
mov    $0x1,%esi
call   1060 <_mv_error@plt>
mov    %eax,%ebx
jmp    11d4 <_mv_single_symlink+0x94>
mov    %r15,%rdi
mov    $0x1,%esi
lea    -0x18(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <_mv_error@plt>
mov    %r15,%rdi
call   1030 <unlink@plt>
xor    %ebx,%ebx
test   %rax,%rax
je     11d4 <_mv_single_symlink+0x94>
mov    %r15,%rdi
xor    %esi,%esi
call   1060 <_mv_error@plt>
mov    %ebx,%eax
lea    -0x18(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@PATH_MAX = global i32 0
define i32 @_mv_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 @_mv_error(i8* %20, i32 1)
store i32 %21, i32* %3
store i32 1, i32* %9
br label %40
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 @_mv_error(i8* %30, i32 1)
store i32 %31, i32* %3
store i32 1, i32* %9
br label %40
32: ; preds = %22
%33 = load i8*, i8** %4
%34 = call i64 @unlink(i8* %33)
%35 = icmp ne i64 %34, 0
br i1 %35, label %36, label %39
36: ; preds = %32
%37 = load i8*, i8** %4
%38 = call i32 @_mv_error(i8* %37, i32 0)
br label %39
39: ; preds = %36, %32
store i32 0, i32* %3
store i32 1, i32* %9
br label %40
40: ; preds = %39, %29, %19
%41 = load i8*, i8** %6
%42 = load i32, i32* %3
ret i32 %42
}

LLVM IR (-O2):
@PATH_MAX = global i32 0
define i32 @_mv_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 @_mv_error(i8* %0, i32 1)
br label %23
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 @_mv_error(i8* %1, i32 1)
br label %23
18: ; preds = %11
%19 = call i64 @unlink(i8* %0)
%20 = icmp eq i64 %19, 0
br i1 %20, label %23, label %21
21: ; preds = %18
%22 = call i32 @_mv_error(i8* %0, i32 0)
br label %23
23: ; preds = %18, %21, %16, %9
%24 = phi i32 [ %10, %9 ], [ %17, %16 ], [ 0, %21 ], [ 0, %18 ]
ret i32 %24
}