#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 /*<<< orphan*/ 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;
  }
  dir_mutex_lock(olddirfd);
  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    11ae <renameat+0x6e>
mov    -0x8(%rbp),%edi
call   1030 <dir_mutex_lock@plt>
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    1171 <renameat+0x31>
mov    %rsi,%rbx
mov    %edx,%edi
call   1030 <dir_mutex_lock@plt>
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    118b <renameat+0x4b>
mov    0x2e68(%rip),%rax
mov    (%rax),%edi
lea    0xe7f(%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 %27
19: ; preds = %4
%20 = load i32, i32* %6
%21 = call i32 @dir_mutex_lock(i32 %20)
%22 = load i8*, i8** %7
%23 = load i8*, i8** %9
%24 = call i32 @rename(i8* %22, i8* %23)
store i32 %24, i32* %10
%25 = call i32 (...) @dir_mutex_unlock()
%26 = load i32, i32* %10
store i32 %26, i32* %5
br label %27
27: ; preds = %19, %14
%28 = load i32, i32* %5
ret i32 %28
}

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 %13
9: ; preds = %4
%10 = tail call i32 @dir_mutex_lock(i32 %0)
%11 = tail call i32 @rename(i8* %1, i8* %3)
%12 = tail call i32 (...) @dir_mutex_unlock()
br label %13
13: ; preds = %9, %6
%14 = phi i32 [ -1, %6 ], [ %11, %9 ]
ret i32 %14
}