#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 */
int dir_mutex_lock(int);
int /*<<< orphan*/ dir_mutex_unlock();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, int);
int rename(char const *, char const *);
int /*<<< orphan*/ stderr;
int renameat(int olddirfd, const char *oldpath, int newdirfd,
             const char *newpath) {
  int rc;
  if (olddirfd != newdirfd) {
    fprintf(stderr, "tup compat renameat error: olddirfd=%i but newdirfd=%i\n",
            olddirfd, newdirfd);
    return -1;
  }
  rc = dir_mutex_lock(olddirfd);
  if (rc < 0)
    return rc;
  rc = rename(oldpath, newpath);
  dir_mutex_unlock();
  return rc;
}


x86 assembly (clang, -O0):
<renameat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x14(%rbp),%eax
je     1189 <renameat+0x49>
mov    0x2e77(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%edx
mov    -0x14(%rbp),%ecx
lea    0xe88(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c6 <renameat+0x86>
mov    -0x8(%rbp),%edi
call   1030 <dir_mutex_lock@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    11a9 <renameat+0x69>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11c6 <renameat+0x86>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1050 <rename@plt>
mov    %eax,-0x24(%rbp)
mov    $0x0,%al
call   1060 <dir_mutex_unlock@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<renameat>:
push   %r14
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %edx,%ecx
mov    %edi,%edx
cmp    %ecx,%edi
jne    1175 <renameat+0x35>
mov    %rsi,%rbx
mov    %edx,%edi
call   1030 <dir_mutex_lock@plt>
test   %eax,%eax
js     118f <renameat+0x4f>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <rename@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1060 <dir_mutex_unlock@plt>
mov    %ebx,%eax
jmp    118f <renameat+0x4f>
mov    0x2e64(%rip),%rax
mov    (%rax),%edi
lea    0xe7b(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [56 x i8] c"tup compat renameat error: olddirfd=%i but newdirfd=%i\0A\00"
define i32 @renameat(i32 %0, i8* %1, i32 %2, i8* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32
store i32 %0, i32* %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i8* %3, i8** %9
%11 = load i32, i32* %6
%12 = load i32, i32* %8
%13 = icmp ne i32 %11, %12
br i1 %13, label %14, label %19
14: ; preds = %4
%15 = load i32, i32* @stderr
%16 = load i32, i32* %6
%17 = load i32, i32* %8
%18 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str, i64 0, i64 0), i32 %16, i32 %17)
store i32 -1, i32* %5
br label %32
19: ; preds = %4
%20 = load i32, i32* %6
%21 = call i32 @dir_mutex_lock(i32 %20)
store i32 %21, i32* %10
%22 = load i32, i32* %10
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %19
%25 = load i32, i32* %10
store i32 %25, i32* %5
br label %32
26: ; preds = %19
%27 = load i8*, i8** %7
%28 = load i8*, i8** %9
%29 = call i32 @rename(i8* %27, i8* %28)
store i32 %29, i32* %10
%30 = call i32 (...) @dir_mutex_unlock()
%31 = load i32, i32* %10
store i32 %31, i32* %5
br label %32
32: ; preds = %26, %24, %14
%33 = load i32, i32* %5
ret i32 %33
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [56 x i8] c"tup compat renameat error: olddirfd=%i but newdirfd=%i\0A\00"
define i32 @renameat(i32 %0, i8* nocapture %1, i32 %2, i8* nocapture %3) {
%5 = icmp eq i32 %0, %2
br i1 %5, label %9, label %6
6: ; preds = %4
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str, i64 0, i64 0), i32 %0, i32 %2)
br label %15
9: ; preds = %4
%10 = tail call i32 @dir_mutex_lock(i32 %0)
%11 = icmp slt i32 %10, 0
br i1 %11, label %15, label %12
12: ; preds = %9
%13 = tail call i32 @rename(i8* %1, i8* %3)
%14 = tail call i32 (...) @dir_mutex_unlock()
br label %15
15: ; preds = %9, %12, %6
%16 = phi i32 [ -1, %6 ], [ %13, %12 ], [ %10, %9 ]
ret i32 %16
}