#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 */
char *dirname(char const *);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fatal(int /*<<< orphan*/, char *, char const *, char const *,
                         ...);
int /*<<< orphan*/ fcp(char const *, char const *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ fsymlink(char const *, char const *);
int /*<<< orphan*/ fut(char const *, char const *);
scalar_t__ isdir(char const *);
scalar_t__ isreg(char const *);
scalar_t__ issym(char const *);
scalar_t__ link(char const *, char const *);
int /*<<< orphan*/ mkdirp(char *);
scalar_t__ samefs(char const *, char *);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int /*<<< orphan*/ unlink(char const *);
extern void fmove(const char *src, const char *dst, int *succ) {
  if (isdir(src))
    fatal(0, "in fmove() src=\"%s\" dst=\"%s\": src must not be a directory",
          src, dst);
  if (isdir(dst))
    fatal(0, "in fmove() src=\"%s\" dst=\"%s\": dst must not be a directory",
          src, dst);
  if (!(issym(src) || isreg(src))) {
    if (succ)
      *succ = 0;
    return;
  }
  if (isreg(dst) || issym(dst))
    unlink(dst);
  char *dstdir = dirname(dst);
  mkdirp(dstdir);
  if (issym(src)) {
    fsymlink(src, dst);
  } else if (isreg(src)) {
    if (samefs(src, dstdir)) {
      if (link(src, dst))
        fatal(0, "in fmove(): link(%s,%s) failed: %s", src, dst,
              strerror(errno));
    } else {
      if (!fcp(src, dst))
        fatal(0, "in fmove(): fcp(%s,%s) failed", src, dst);
      fut(src, dst);
    }
  }
  free(dstdir);
}


x86 assembly (clang, -O0):
<fmove>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1090 <isdir@plt>
cmp    $0x0,%rax
je     121f <fmove+0x3f>
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
xor    %edi,%edi
lea    0xde8(%rip),%rsi
mov    $0x0,%al
call   1100 <fatal@plt>
mov    -0x10(%rbp),%rdi
call   1090 <isdir@plt>
cmp    $0x0,%rax
je     124a <fmove+0x6a>
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
xor    %edi,%edi
lea    0xdf7(%rip),%rsi
mov    $0x0,%al
call   1100 <fatal@plt>
mov    -0x8(%rbp),%rdi
call   10c0 <issym@plt>
cmp    $0x0,%rax
jne    128a <fmove+0xaa>
mov    -0x8(%rbp),%rdi
call   1080 <isreg@plt>
cmp    $0x0,%rax
jne    128a <fmove+0xaa>
cmpq   $0x0,-0x18(%rbp)
je     1285 <fmove+0xa5>
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
jmp    13c1 <fmove+0x1e1>
mov    -0x10(%rbp),%rdi
call   1080 <isreg@plt>
cmp    $0x0,%rax
jne    12b0 <fmove+0xd0>
mov    -0x10(%rbp),%rdi
call   10c0 <issym@plt>
cmp    $0x0,%rax
je     12b9 <fmove+0xd9>
mov    -0x10(%rbp),%rdi
call   1040 <unlink@plt>
mov    -0x10(%rbp),%rdi
call   1060 <dirname@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1070 <mkdirp@plt>
mov    -0x8(%rbp),%rdi
call   10c0 <issym@plt>
cmp    $0x0,%rax
je     12f4 <fmove+0x114>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   10b0 <fsymlink@plt>
jmp    13b8 <fmove+0x1d8>
mov    -0x8(%rbp),%rdi
call   1080 <isreg@plt>
cmp    $0x0,%rax
je     13b3 <fmove+0x1d3>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   10d0 <samefs@plt>
cmp    $0x0,%rax
je     1373 <fmove+0x193>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   10e0 <link@plt>
cmp    $0x0,%rax
je     136e <fmove+0x18e>
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    0x2c94(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
mov    -0x30(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    %eax,%r8d
xor    %edi,%edi
lea    0xd0d(%rip),%rsi
mov    $0x0,%al
call   1100 <fatal@plt>
jmp    13ae <fmove+0x1ce>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   10a0 <fcp@plt>
cmp    $0x0,%eax
jne    13a1 <fmove+0x1c1>
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
xor    %edi,%edi
lea    0xcfd(%rip),%rsi
mov    $0x0,%al
call   1100 <fatal@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <fut@plt>
jmp    13b3 <fmove+0x1d3>
jmp    13b8 <fmove+0x1d8>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fmove>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%rbx
call   1090 <isdir@plt>
test   %rax,%rax
je     120e <fmove+0x2e>
lea    0xe01(%rip),%rsi
xor    %edi,%edi
mov    %rbx,%rdx
mov    %r14,%rcx
xor    %eax,%eax
call   1100 <fatal@plt>
mov    %r14,%rdi
call   1090 <isdir@plt>
test   %rax,%rax
je     1231 <fmove+0x51>
lea    0xe18(%rip),%rsi
xor    %edi,%edi
mov    %rbx,%rdx
mov    %r14,%rcx
xor    %eax,%eax
call   1100 <fatal@plt>
mov    %rbx,%rdi
call   10c0 <issym@plt>
test   %rax,%rax
jne    124f <fmove+0x6f>
mov    %rbx,%rdi
call   1080 <isreg@plt>
test   %rax,%rax
je     12ff <fmove+0x11f>
mov    %r14,%rdi
call   1080 <isreg@plt>
test   %rax,%rax
jne    1269 <fmove+0x89>
mov    %r14,%rdi
call   10c0 <issym@plt>
test   %rax,%rax
je     1271 <fmove+0x91>
mov    %r14,%rdi
call   1040 <unlink@plt>
mov    %r14,%rdi
call   1060 <dirname@plt>
mov    %rax,%r15
mov    %rax,%rdi
call   1070 <mkdirp@plt>
mov    %rbx,%rdi
call   10c0 <issym@plt>
test   %rax,%rax
je     12a9 <fmove+0xc9>
mov    %rbx,%rdi
mov    %r14,%rsi
call   10b0 <fsymlink@plt>
mov    %r15,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <free@plt>
mov    %rbx,%rdi
call   1080 <isreg@plt>
test   %rax,%rax
je     129c <fmove+0xbc>
mov    %rbx,%rdi
mov    %r15,%rsi
call   10d0 <samefs@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
test   %rax,%rax
je     1311 <fmove+0x131>
call   10e0 <link@plt>
test   %rax,%rax
je     129c <fmove+0xbc>
mov    0x2d03(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
lea    0xd89(%rip),%rsi
xor    %edi,%edi
mov    %rbx,%rdx
mov    %r14,%rcx
mov    %eax,%r8d
xor    %eax,%eax
call   1100 <fatal@plt>
jmp    129c <fmove+0xbc>
test   %r15,%r15
je     130b <fmove+0x12b>
movl   $0x0,(%r15)
pop    %rbx
pop    %r14
pop    %r15
ret
call   10a0 <fcp@plt>
test   %eax,%eax
jne    1330 <fmove+0x150>
lea    0xd76(%rip),%rsi
xor    %edi,%edi
mov    %rbx,%rdx
mov    %r14,%rcx
xor    %eax,%eax
call   1100 <fatal@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <fut@plt>
jmp    129c <fmove+0xbc>

LLVM IR (-O0):
@.str = [58 x i8] c"in fmove() src=\22%s\22 dst=\22%s\22: src must not be a directory\00"
@.str.1 = [58 x i8] c"in fmove() src=\22%s\22 dst=\22%s\22: dst must not be a directory\00"
@.str.2 = [35 x i8] c"in fmove(): link(%s,%s) failed: %s\00"
@errno = global i32 0
@.str.3 = [30 x i8] c"in fmove(): fcp(%s,%s) failed\00"
define void @fmove(i8* %0, i8* %1, i32* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32* %2, i32** %6
%8 = load i8*, i8** %4
%9 = call i64 @isdir(i8* %8)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %15
11: ; preds = %3
%12 = load i8*, i8** %4
%13 = load i8*, i8** %5
%14 = call i32 (i32, i8*, i8*, i8*, ...) @fatal(i32 0, i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str, i64 0, i64 0), i8* %12, i8* %13)
br label %15
15: ; preds = %11, %3
%16 = load i8*, i8** %5
%17 = call i64 @isdir(i8* %16)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %23
19: ; preds = %15
%20 = load i8*, i8** %4
%21 = load i8*, i8** %5
%22 = call i32 (i32, i8*, i8*, i8*, ...) @fatal(i32 0, i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.1, i64 0, i64 0), i8* %20, i8* %21)
br label %23
23: ; preds = %19, %15
%24 = load i8*, i8** %4
%25 = call i64 @issym(i8* %24)
%26 = icmp ne i64 %25, 0
br i1 %26, label %37, label %27
27: ; preds = %23
%28 = load i8*, i8** %4
%29 = call i64 @isreg(i8* %28)
%30 = icmp ne i64 %29, 0
br i1 %30, label %37, label %31
31: ; preds = %27
%32 = load i32*, i32** %6
%33 = icmp ne i32* %32, null
br i1 %33, label %34, label %36
34: ; preds = %31
%35 = load i32*, i32** %6
store i32 0, i32* %35
br label %36
36: ; preds = %34, %31
br label %99
37: ; preds = %27, %23
%38 = load i8*, i8** %5
%39 = call i64 @isreg(i8* %38)
%40 = icmp ne i64 %39, 0
br i1 %40, label %45, label %41
41: ; preds = %37
%42 = load i8*, i8** %5
%43 = call i64 @issym(i8* %42)
%44 = icmp ne i64 %43, 0
br i1 %44, label %45, label %48
45: ; preds = %41, %37
%46 = load i8*, i8** %5
%47 = call i32 @unlink(i8* %46)
br label %48
48: ; preds = %45, %41
%49 = load i8*, i8** %5
%50 = call i8* @dirname(i8* %49)
store i8* %50, i8** %7
%51 = load i8*, i8** %7
%52 = call i32 @mkdirp(i8* %51)
%53 = load i8*, i8** %4
%54 = call i64 @issym(i8* %53)
%55 = icmp ne i64 %54, 0
br i1 %55, label %56, label %60
56: ; preds = %48
%57 = load i8*, i8** %4
%58 = load i8*, i8** %5
%59 = call i32 @fsymlink(i8* %57, i8* %58)
br label %96
60: ; preds = %48
%61 = load i8*, i8** %4
%62 = call i64 @isreg(i8* %61)
%63 = icmp ne i64 %62, 0
br i1 %63, label %64, label %95
64: ; preds = %60
%65 = load i8*, i8** %4
%66 = load i8*, i8** %7
%67 = call i64 @samefs(i8* %65, i8* %66)
%68 = icmp ne i64 %67, 0
br i1 %68, label %69, label %81
69: ; preds = %64
%70 = load i8*, i8** %4
%71 = load i8*, i8** %5
%72 = call i64 @link(i8* %70, i8* %71)
%73 = icmp ne i64 %72, 0
br i1 %73, label %74, label %80
74: ; preds = %69
%75 = load i8*, i8** %4
%76 = load i8*, i8** %5
%77 = load i32, i32* @errno
%78 = call i32 @strerror(i32 %77)
%79 = call i32 (i32, i8*, i8*, i8*, ...) @fatal(i32 0, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i8* %75, i8* %76, i32 %78)
br label %80
80: ; preds = %74, %69
br label %94
81: ; preds = %64
%82 = load i8*, i8** %4
%83 = load i8*, i8** %5
%84 = call i32 @fcp(i8* %82, i8* %83)
%85 = icmp ne i32 %84, 0
br i1 %85, label %90, label %86
86: ; preds = %81
%87 = load i8*, i8** %4
%88 = load i8*, i8** %5
%89 = call i32 (i32, i8*, i8*, i8*, ...) @fatal(i32 0, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i8* %87, i8* %88)
br label %90
90: ; preds = %86, %81
%91 = load i8*, i8** %4
%92 = load i8*, i8** %5
%93 = call i32 @fut(i8* %91, i8* %92)
br label %94
94: ; preds = %90, %80
br label %95
95: ; preds = %94, %60
br label %96
96: ; preds = %95, %56
%97 = load i8*, i8** %7
%98 = call i32 @free(i8* %97)
br label %99
99: ; preds = %96, %36
ret void
}

LLVM IR (-O2):
@.str = [58 x i8] c"in fmove() src=\22%s\22 dst=\22%s\22: src must not be a directory\00"
@.str.1 = [58 x i8] c"in fmove() src=\22%s\22 dst=\22%s\22: dst must not be a directory\00"
@.str.2 = [35 x i8] c"in fmove(): link(%s,%s) failed: %s\00"
@errno = global i32 0
@.str.3 = [30 x i8] c"in fmove(): fcp(%s,%s) failed\00"
define void @fmove(i8* %0, i8* %1, i32* writeonly %2) {
%4 = tail call i64 @isdir(i8* %0)
%5 = icmp eq i64 %4, 0
br i1 %5, label %8, label %6
6: ; preds = %3
%7 = tail call i32 (i32, i8*, i8*, i8*, ...) @fatal(i32 0, i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %1)
br label %8
8: ; preds = %6, %3
%9 = tail call i64 @isdir(i8* %1)
%10 = icmp eq i64 %9, 0
br i1 %10, label %13, label %11
11: ; preds = %8
%12 = tail call i32 (i32, i8*, i8*, i8*, ...) @fatal(i32 0, i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %1)
br label %13
13: ; preds = %11, %8
%14 = tail call i64 @issym(i8* %0)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %22
16: ; preds = %13
%17 = tail call i64 @isreg(i8* %0)
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %16
%20 = icmp eq i32* %2, null
br i1 %20, label %59, label %21
21: ; preds = %19
store i32 0, i32* %2
br label %59
22: ; preds = %16, %13
%23 = tail call i64 @isreg(i8* %1)
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %22
%26 = tail call i64 @issym(i8* %1)
%27 = icmp eq i64 %26, 0
br i1 %27, label %30, label %28
28: ; preds = %25, %22
%29 = tail call i32 @unlink(i8* %1)
br label %30
30: ; preds = %28, %25
%31 = tail call i8* @dirname(i8* %1)
%32 = tail call i32 @mkdirp(i8* %31)
%33 = tail call i64 @issym(i8* %0)
%34 = icmp eq i64 %33, 0
br i1 %34, label %37, label %35
35: ; preds = %30
%36 = tail call i32 @fsymlink(i8* %0, i8* %1)
br label %57
37: ; preds = %30
%38 = tail call i64 @isreg(i8* %0)
%39 = icmp eq i64 %38, 0
br i1 %39, label %57, label %40
40: ; preds = %37
%41 = tail call i64 @samefs(i8* %0, i8* %31)
%42 = icmp eq i64 %41, 0
br i1 %42, label %50, label %43
43: ; preds = %40
%44 = tail call i64 @link(i8* %0, i8* %1)
%45 = icmp eq i64 %44, 0
br i1 %45, label %57, label %46
46: ; preds = %43
%47 = load i32, i32* @errno
%48 = tail call i32 @strerror(i32 %47)
%49 = tail call i32 (i32, i8*, i8*, i8*, ...) @fatal(i32 0, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i8* %0, i8* %1, i32 %48)
br label %57
50: ; preds = %40
%51 = tail call i32 @fcp(i8* %0, i8* %1)
%52 = icmp eq i32 %51, 0
br i1 %52, label %53, label %55
53: ; preds = %50
%54 = tail call i32 (i32, i8*, i8*, i8*, ...) @fatal(i32 0, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i8* %0, i8* %1)
br label %55
55: ; preds = %53, %50
%56 = tail call i32 @fut(i8* %0, i8* %1)
br label %57
57: ; preds = %37, %43, %46, %55, %35
%58 = tail call i32 @free(i8* %31)
br label %59
59: ; preds = %19, %21, %57
ret void
}