#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 */
scalar_t__ ENOENT;
int FILENAME_MAX;
int _symlink_exists(char *);
int /*<<< orphan*/ close(int);
scalar_t__ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int pmix_create_locked_wait(char *);
scalar_t__ pmix_leader_is_alive(char *);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int /*<<< orphan*/ stderr;
char *strerror(scalar_t__);
scalar_t__ unlink(char *);
void pmix_remove_leader_symlink(char *path) {
  int ret, is_symlink;
  ret = _symlink_exists(path);
  if (0 > ret) {
    fprintf(stderr, "FATAL error\n");
    exit(1);
  }
  if (0 == ret) {
    return;
  }
  char lockname[FILENAME_MAX];
  sprintf(lockname, "%s.lock", path);
  int fd = pmix_create_locked_wait(lockname);
  ret = _symlink_exists(path);
  if (0 > ret) {
    fprintf(stderr, "FATAL error\n");
    exit(1);
  }
  if (0 == ret) {
    goto exit;
  }
  if (pmix_leader_is_alive(path)) {
    goto exit;
  }
  if (unlink(path)) {
    if (ENOENT != errno) {
      fprintf(stderr, "unlink(%s): %s", path, strerror(errno));
      exit(1);
    }
  }
exit:
  close(fd);
}


x86 assembly (clang, -O0):
<pmix_remove_leader_symlink>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <_symlink_exists@plt>
mov    %eax,-0xc(%rbp)
xor    %eax,%eax
cmp    -0xc(%rbp),%eax
jle    11d4 <pmix_remove_leader_symlink+0x44>
mov    0x2e1e(%rip),%rax
mov    (%rax),%edi
lea    0xe3d(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
xor    %eax,%eax
cmp    -0xc(%rbp),%eax
jne    11e4 <pmix_remove_leader_symlink+0x54>
jmp    1317 <pmix_remove_leader_symlink+0x187>
mov    0x2dfd(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x30(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdx
lea    0xdf2(%rip),%rsi
call   1090 <sprintf@plt>
mov    -0x30(%rbp),%rdi
call   1040 <pmix_create_locked_wait@plt>
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <_symlink_exists@plt>
mov    %eax,-0xc(%rbp)
xor    %eax,%eax
cmp    -0xc(%rbp),%eax
jle    1264 <pmix_remove_leader_symlink+0xd4>
mov    0x2d8e(%rip),%rax
mov    (%rax),%edi
lea    0xdad(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
xor    %eax,%eax
cmp    -0xc(%rbp),%eax
jne    1274 <pmix_remove_leader_symlink+0xe4>
jmp    1308 <pmix_remove_leader_symlink+0x178>
mov    -0x8(%rbp),%rdi
call   1070 <pmix_leader_is_alive@plt>
cmp    $0x0,%rax
je     128c <pmix_remove_leader_symlink+0xfc>
jmp    1308 <pmix_remove_leader_symlink+0x178>
mov    -0x8(%rbp),%rdi
call   1030 <unlink@plt>
cmp    $0x0,%rax
je     1303 <pmix_remove_leader_symlink+0x173>
mov    0x2d1a(%rip),%rax
mov    (%rax),%rax
mov    0x2d20(%rip),%rcx
cmp    (%rcx),%rax
je     12fe <pmix_remove_leader_symlink+0x16e>
mov    0x2d18(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    0x2cfc(%rip),%rax
mov    (%rax),%rdi
call   10b0 <strerror@plt>
mov    -0x3c(%rbp),%edi
mov    -0x38(%rbp),%rdx
mov    %rax,%rcx
lea    0xd28(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
jmp    1303 <pmix_remove_leader_symlink+0x173>
jmp    1308 <pmix_remove_leader_symlink+0x178>
mov    -0x24(%rbp),%edi
call   1060 <close@plt>
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pmix_remove_leader_symlink>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%r15
call   1050 <_symlink_exists@plt>
test   %eax,%eax
js     1241 <pmix_remove_leader_symlink+0xb1>
je     1234 <pmix_remove_leader_symlink+0xa4>
mov    %rsp,%r12
mov    0x2e2d(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
lea    0xe38(%rip),%rsi
mov    %rbx,%rdi
mov    %r15,%rdx
call   1090 <sprintf@plt>
mov    %rbx,%rdi
call   1040 <pmix_create_locked_wait@plt>
mov    %eax,%r14d
mov    %r15,%rdi
call   1050 <_symlink_exists@plt>
test   %eax,%eax
js     1241 <pmix_remove_leader_symlink+0xb1>
je     1229 <pmix_remove_leader_symlink+0x99>
mov    %r15,%rdi
call   1070 <pmix_leader_is_alive@plt>
test   %rax,%rax
jne    1229 <pmix_remove_leader_symlink+0x99>
mov    %r15,%rdi
call   1030 <unlink@plt>
test   %rax,%rax
je     1229 <pmix_remove_leader_symlink+0x99>
mov    0x2da6(%rip),%rax
mov    0x2daf(%rip),%rcx
mov    (%rcx),%rdi
cmp    %rdi,(%rax)
jne    1262 <pmix_remove_leader_symlink+0xd2>
mov    %r14d,%edi
call   1060 <close@plt>
mov    %r12,%rsp
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d90(%rip),%rax
mov    (%rax),%edi
lea    0xdaf(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    0x2d6f(%rip),%rax
mov    (%rax),%ebx
call   10b0 <strerror@plt>
lea    0xd9e(%rip),%rsi
mov    %ebx,%edi
mov    %r15,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [13 x i8] c"FATAL error\0A\00"
@FILENAME_MAX = global i32 0
@.str.1 = [8 x i8] c"%s.lock\00"
@ENOENT = global i64 0
@errno = global i64 0
@.str.2 = [15 x i8] c"unlink(%s): %s\00"
define void @pmix_remove_leader_symlink(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
store i8* %0, i8** %2
%8 = load i8*, i8** %2
%9 = call i32 @_symlink_exists(i8* %8)
store i32 %9, i32* %3
%10 = load i32, i32* %3
%11 = icmp sgt i32 0, %10
br i1 %11, label %12, label %16
12: ; preds = %1
%13 = load i32, i32* @stderr
%14 = call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %1
%17 = load i32, i32* %3
%18 = icmp eq i32 0, %17
br i1 %18, label %19, label %20
19: ; preds = %16
br label %66
20: ; preds = %16
%21 = load i32, i32* @FILENAME_MAX
%22 = zext i32 %21 to i64
%23 = call i8* @llvm.stacksave()
store i8* %23, i8** %5
%24 = alloca i8, i64 %22
store i64 %22, i64* %6
%25 = load i8*, i8** %2
%26 = call i32 @sprintf(i8* %24, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %25)
%27 = call i32 @pmix_create_locked_wait(i8* %24)
store i32 %27, i32* %7
%28 = load i8*, i8** %2
%29 = call i32 @_symlink_exists(i8* %28)
store i32 %29, i32* %3
%30 = load i32, i32* %3
%31 = icmp sgt i32 0, %30
br i1 %31, label %32, label %36
32: ; preds = %20
%33 = load i32, i32* @stderr
%34 = call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%35 = call i32 @exit(i32 1)
unreachable
36: ; preds = %20
%37 = load i32, i32* %3
%38 = icmp eq i32 0, %37
br i1 %38, label %39, label %40
39: ; preds = %36
br label %62
40: ; preds = %36
%41 = load i8*, i8** %2
%42 = call i64 @pmix_leader_is_alive(i8* %41)
%43 = icmp ne i64 %42, 0
br i1 %43, label %44, label %45
44: ; preds = %40
br label %62
45: ; preds = %40
%46 = load i8*, i8** %2
%47 = call i64 @unlink(i8* %46)
%48 = icmp ne i64 %47, 0
br i1 %48, label %49, label %61
49: ; preds = %45
%50 = load i64, i64* @ENOENT
%51 = load i64, i64* @errno
%52 = icmp ne i64 %50, %51
br i1 %52, label %53, label %60
53: ; preds = %49
%54 = load i32, i32* @stderr
%55 = load i8*, i8** %2
%56 = load i64, i64* @errno
%57 = call i8* @strerror(i64 %56)
%58 = call i32 (i32, i8*, ...) @fprintf(i32 %54, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %55, i8* %57)
%59 = call i32 @exit(i32 1)
unreachable
60: ; preds = %49
br label %61
61: ; preds = %60, %45
br label %62
62: ; preds = %61, %44, %39
%63 = load i32, i32* %7
%64 = call i32 @close(i32 %63)
%65 = load i8*, i8** %5
br label %66
66: ; preds = %62, %19
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [13 x i8] c"FATAL error\0A\00"
@FILENAME_MAX = global i32 0
@.str.1 = [8 x i8] c"%s.lock\00"
@ENOENT = global i64 0
@errno = global i64 0
@.str.2 = [15 x i8] c"unlink(%s): %s\00"
define void @pmix_remove_leader_symlink(i8* %0) {
%2 = tail call i32 @_symlink_exists(i8* %0)
%3 = icmp slt i32 %2, 0
br i1 %3, label %4, label %8
4: ; preds = %1
%5 = load i32, i32* @stderr
%6 = tail call i32 (i32, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %1
%9 = icmp eq i32 %2, 0
br i1 %9, label %42, label %10
10: ; preds = %8
%11 = load i32, i32* @FILENAME_MAX
%12 = zext i32 %11 to i64
%13 = tail call i8* @llvm.stacksave()
%14 = alloca i8, i64 %12
%15 = call i32 @sprintf(i8* %14, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%16 = call i32 @pmix_create_locked_wait(i8* %14)
%17 = call i32 @_symlink_exists(i8* %0)
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %23
19: ; preds = %10
%20 = load i32, i32* @stderr
%21 = call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %10
%24 = icmp eq i32 %17, 0
br i1 %24, label %40, label %25
25: ; preds = %23
%26 = call i64 @pmix_leader_is_alive(i8* %0)
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %40
28: ; preds = %25
%29 = call i64 @unlink(i8* %0)
%30 = icmp eq i64 %29, 0
br i1 %30, label %40, label %31
31: ; preds = %28
%32 = load i64, i64* @ENOENT
%33 = load i64, i64* @errno
%34 = icmp eq i64 %32, %33
br i1 %34, label %40, label %35
35: ; preds = %31
%36 = load i32, i32* @stderr
%37 = call i8* @strerror(i64 %33)
%38 = call i32 (i32, i8*, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %0, i8* %37)
%39 = call i32 @exit(i32 1)
unreachable
40: ; preds = %28, %31, %25, %23
%41 = call i32 @close(i32 %16)
br label %42
42: ; preds = %8, %40
ret void
}