#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 /*<<< orphan*/ target;

/* Variables and functions */
scalar_t__ EEXIST;
scalar_t__ ENOENT;
int PATH_MAX;
int /*<<< orphan*/ S_IRWXU;
scalar_t__ __readlink(char const *, char *, int);
scalar_t__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *, ...);
scalar_t__ mkdir(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char const *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcmp(char *, char const *);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ strncmp(char const *, char *, int /*<<< orphan*/);
scalar_t__ symlink(char const *, char const *);
scalar_t__ unlink(char const *);
int register_path(const char *linkname, const char *path) {
  char target[PATH_MAX];
  if (path[0] != '/') {
    fprintf(stderr,
            "File %s: absolute path expected; won't "
            "register relative path.",
            path);
    return -1;
  }
  if (!strncmp(path,
               "/var/run/drbd"
               "/",
               strlen("/var/run/drbd"
                      "/")))
    return -1;
  if (__readlink(linkname, target, sizeof(target)) >= 0 &&
      !strcmp(target, path))
    return 0;
  if (unlink(linkname) != 0 && errno != ENOENT) {
    perror(linkname);
    return -1;
  }
  if (mkdir("/var/run/drbd", S_IRWXU) != 0 && errno != EEXIST) {
    perror("/var/run/drbd");
    return -1;
  }
  if (symlink(path, linkname) != 0) {
    fprintf(stderr, "symlink(%s, %s): %m\n", path, linkname);
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<register_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    0x2e49(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x40(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
je     120e <register_path+0x7e>
mov    0x2de1(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xe0c(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x2c(%rbp)
jmp    138e <register_path+0x1fe>
mov    -0x18(%rbp),%rax
mov    %rax,-0x48(%rbp)
lea    0xe22(%rip),%rdi
call   1060 <strlen@plt>
mov    -0x48(%rbp),%rdi
mov    %eax,%edx
lea    0xe10(%rip),%rsi
call   1040 <strncmp@plt>
cmp    $0x0,%eax
jne    1250 <register_path+0xc0>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x2c(%rbp)
jmp    138e <register_path+0x1fe>
mov    -0x38(%rbp),%rsi
mov    -0x40(%rbp),%rax
mov    -0x10(%rbp),%rdi
mov    %eax,%edx
call   1070 <__readlink@plt>
cmp    $0x0,%rax
jl     1296 <register_path+0x106>
mov    -0x38(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%eax
jne    1296 <register_path+0x106>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x2c(%rbp)
jmp    138e <register_path+0x1fe>
mov    -0x10(%rbp),%rdi
call   1030 <unlink@plt>
cmp    $0x0,%rax
je     12df <register_path+0x14f>
mov    0x2d10(%rip),%rax
mov    (%rax),%rax
mov    0x2cf6(%rip),%rcx
cmp    (%rcx),%rax
je     12df <register_path+0x14f>
mov    -0x10(%rbp),%rdi
call   10b0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x2c(%rbp)
jmp    138e <register_path+0x1fe>
mov    0x2cfa(%rip),%rax
mov    (%rax),%esi
lea    0xd5f(%rip),%rdi
call   1050 <mkdir@plt>
cmp    $0x0,%rax
je     1337 <register_path+0x1a7>
mov    0x2cbb(%rip),%rax
mov    (%rax),%rax
mov    0x2cc1(%rip),%rcx
cmp    (%rcx),%rax
je     1337 <register_path+0x1a7>
lea    0xd2f(%rip),%rdi
call   10b0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x2c(%rbp)
jmp    138e <register_path+0x1fe>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1080 <symlink@plt>
cmp    $0x0,%rax
je     1380 <register_path+0x1f0>
mov    0x2c73(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xcf6(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x2c(%rbp)
jmp    138e <register_path+0x1fe>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x2c(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<register_path>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r12
mov    0x2e48(%rip),%rax
mov    (%rax),%r13d
mov    %rsp,%rbx
lea    0xf(%r13),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
cmpb   $0x2f,(%rsi)
jne    129e <register_path+0x10e>
mov    %rdi,%r15
lea    0xe70(%rip),%r14
mov    %r14,%rdi
call   1060 <strlen@plt>
mov    %r12,%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   1040 <strncmp@plt>
mov    $0xffffffff,%r14d
test   %eax,%eax
je     12c3 <register_path+0x133>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r13d,%edx
call   1070 <__readlink@plt>
test   %rax,%rax
js     1218 <register_path+0x88>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1090 <strcmp@plt>
test   %eax,%eax
je     12c0 <register_path+0x130>
mov    %r15,%rdi
call   1030 <unlink@plt>
test   %rax,%rax
je     123f <register_path+0xaf>
mov    0x2d94(%rip),%rax
mov    (%rax),%rax
mov    0x2d7a(%rip),%rcx
cmp    (%rcx),%rax
jne    12d5 <register_path+0x145>
mov    0x2d9a(%rip),%rax
mov    (%rax),%esi
lea    0xdff(%rip),%rdi
call   1050 <mkdir@plt>
test   %rax,%rax
je     126f <register_path+0xdf>
mov    0x2d60(%rip),%rax
mov    (%rax),%rax
mov    0x2d66(%rip),%rcx
cmp    (%rcx),%rax
jne    12df <register_path+0x14f>
mov    %r12,%rdi
mov    %r15,%rsi
call   1080 <symlink@plt>
test   %rax,%rax
je     12c0 <register_path+0x130>
mov    0x2d42(%rip),%rax
mov    (%rax),%edi
lea    0xdcd(%rip),%rsi
mov    %r12,%rdx
mov    %r15,%rcx
xor    %eax,%eax
call   10a0 <fprintf@plt>
jmp    12c3 <register_path+0x133>
mov    0x2d23(%rip),%rax
mov    (%rax),%edi
lea    0xd52(%rip),%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    $0xffffffff,%r14d
jmp    12c3 <register_path+0x133>
xor    %r14d,%r14d
mov    %r14d,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r15,%rdi
call   10b0 <perror@plt>
jmp    12c3 <register_path+0x133>
lea    0xd68(%rip),%rdi
call   10b0 <perror@plt>
jmp    12c3 <register_path+0x133>

LLVM IR (-O0):
@PATH_MAX = global i32 0
@stderr = global i32 0
@.str = [63 x i8] c"File %s: absolute path expected; won't register relative path.\00"
@.str.1 = [15 x i8] c"/var/run/drbd/\00"
@errno = global i64 0
@ENOENT = global i64 0
@.str.2 = [14 x i8] c"/var/run/drbd\00"
@S_IRWXU = global i32 0
@EEXIST = global i64 0
@.str.3 = [21 x i8] c"symlink(%s, %s): %m\0A\00"
define i32 @register_path(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%9 = load i32, i32* @PATH_MAX
%10 = zext i32 %9 to i64
%11 = call i8* @llvm.stacksave()
store i8* %11, i8** %6
%12 = alloca i8, i64 %10
store i64 %10, i64* %7
%13 = load i8*, i8** %5
%14 = getelementptr inbounds i8, i8* %13, i64 0
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp ne i32 %16, 47
br i1 %17, label %18, label %22
18: ; preds = %2
%19 = load i32, i32* @stderr
%20 = load i8*, i8** %5
%21 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str, i64 0, i64 0), i8* %20)
store i32 -1, i32* %3
store i32 1, i32* %8
br label %70
22: ; preds = %2
%23 = load i8*, i8** %5
%24 = call i32 @strlen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%25 = call i32 @strncmp(i8* %23, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %24)
%26 = icmp ne i32 %25, 0
br i1 %26, label %28, label %27
27: ; preds = %22
store i32 -1, i32* %3
store i32 1, i32* %8
br label %70
28: ; preds = %22
%29 = load i8*, i8** %4
%30 = trunc i64 %10 to i32
%31 = call i64 @__readlink(i8* %29, i8* %12, i32 %30)
%32 = icmp sge i64 %31, 0
br i1 %32, label %33, label %38
33: ; preds = %28
%34 = load i8*, i8** %5
%35 = call i32 @strcmp(i8* %12, i8* %34)
%36 = icmp ne i32 %35, 0
br i1 %36, label %38, label %37
37: ; preds = %33
store i32 0, i32* %3
store i32 1, i32* %8
br label %70
38: ; preds = %33, %28
%39 = load i8*, i8** %4
%40 = call i64 @unlink(i8* %39)
%41 = icmp ne i64 %40, 0
br i1 %41, label %42, label %49
42: ; preds = %38
%43 = load i64, i64* @errno
%44 = load i64, i64* @ENOENT
%45 = icmp ne i64 %43, %44
br i1 %45, label %46, label %49
46: ; preds = %42
%47 = load i8*, i8** %4
%48 = call i32 @perror(i8* %47)
store i32 -1, i32* %3
store i32 1, i32* %8
br label %70
49: ; preds = %42, %38
%50 = load i32, i32* @S_IRWXU
%51 = call i64 @mkdir(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %50)
%52 = icmp ne i64 %51, 0
br i1 %52, label %53, label %59
53: ; preds = %49
%54 = load i64, i64* @errno
%55 = load i64, i64* @EEXIST
%56 = icmp ne i64 %54, %55
br i1 %56, label %57, label %59
57: ; preds = %53
%58 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %3
store i32 1, i32* %8
br label %70
59: ; preds = %53, %49
%60 = load i8*, i8** %5
%61 = load i8*, i8** %4
%62 = call i64 @symlink(i8* %60, i8* %61)
%63 = icmp ne i64 %62, 0
br i1 %63, label %64, label %69
64: ; preds = %59
%65 = load i32, i32* @stderr
%66 = load i8*, i8** %5
%67 = load i8*, i8** %4
%68 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %65, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i8* %66, i8* %67)
store i32 -1, i32* %3
store i32 1, i32* %8
br label %70
69: ; preds = %59
store i32 0, i32* %3
store i32 1, i32* %8
br label %70
70: ; preds = %69, %64, %57, %46, %37, %27, %18
%71 = load i8*, i8** %6
%72 = load i32, i32* %3
ret i32 %72
}

LLVM IR (-O2):
@PATH_MAX = global i32 0
@stderr = global i32 0
@.str = [63 x i8] c"File %s: absolute path expected; won't register relative path.\00"
@.str.1 = [15 x i8] c"/var/run/drbd/\00"
@errno = global i64 0
@ENOENT = global i64 0
@.str.2 = [14 x i8] c"/var/run/drbd\00"
@S_IRWXU = global i32 0
@EEXIST = global i64 0
@.str.3 = [21 x i8] c"symlink(%s, %s): %m\0A\00"
define i32 @register_path(i8* %0, i8* %1) {
%3 = load i32, i32* @PATH_MAX
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = load i8, i8* %1
%7 = icmp eq i8 %6, 47
br i1 %7, label %11, label %8
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str, i64 0, i64 0), i8* %1)
br label %46
11: ; preds = %2
%12 = tail call i32 @strlen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%13 = tail call i32 @strncmp(i8* %1, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %12)
%14 = icmp eq i32 %13, 0
br i1 %14, label %46, label %15
15: ; preds = %11
%16 = call i64 @__readlink(i8* %0, i8* %5, i32 %3)
%17 = icmp sgt i64 %16, -1
br i1 %17, label %18, label %21
18: ; preds = %15
%19 = call i32 @strcmp(i8* %5, i8* %1)
%20 = icmp eq i32 %19, 0
br i1 %20, label %46, label %21
21: ; preds = %18, %15
%22 = call i64 @unlink(i8* %0)
%23 = icmp eq i64 %22, 0
br i1 %23, label %30, label %24
24: ; preds = %21
%25 = load i64, i64* @errno
%26 = load i64, i64* @ENOENT
%27 = icmp eq i64 %25, %26
br i1 %27, label %30, label %28
28: ; preds = %24
%29 = call i32 @perror(i8* %0)
br label %46
30: ; preds = %24, %21
%31 = load i32, i32* @S_IRWXU
%32 = call i64 @mkdir(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %31)
%33 = icmp eq i64 %32, 0
br i1 %33, label %40, label %34
34: ; preds = %30
%35 = load i64, i64* @errno
%36 = load i64, i64* @EEXIST
%37 = icmp eq i64 %35, %36
br i1 %37, label %40, label %38
38: ; preds = %34
%39 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
br label %46
40: ; preds = %34, %30
%41 = call i64 @symlink(i8* %1, i8* %0)
%42 = icmp eq i64 %41, 0
br i1 %42, label %46, label %43
43: ; preds = %40
%44 = load i32, i32* @stderr
%45 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %44, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i8* %1, i8* %0)
br label %46
46: ; preds = %40, %18, %11, %43, %38, %28, %8
%47 = phi i32 [ -1, %8 ], [ -1, %28 ], [ -1, %38 ], [ -1, %43 ], [ -1, %11 ], [ 0, %18 ], [ 0, %40 ]
ret i32 %47
}