#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*/ AT_FDCWD;
scalar_t__ EISDIR;
scalar_t__ ENOENT;
scalar_t__ ENOTDIR;
int /*<<< orphan*/ F_OK;
int /*<<< orphan*/ RENAME_EXCHANGE;
int /*<<< orphan*/ SYS_renameat2;
int access(char *, int /*<<< orphan*/);
scalar_t__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
int /*<<< orphan*/ stderr;
char *strerror(scalar_t__);
int syscall(int /*<<< orphan*/, int /*<<< orphan*/, char *, int /*<<< orphan*/,
            char *, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  const char *error_src = NULL;
  if (argc != 3) {
    fprintf(stderr, "Usage: %s FILE1 FILE2\n", argv[0]);
    return 255;
  }
  if (access(argv[2], F_OK) == -1)
    error_src = argv[2];
  else if (syscall(SYS_renameat2, AT_FDCWD, argv[1], AT_FDCWD, argv[2],
                   RENAME_EXCHANGE) == -1)
    if (errno == ENOENT) {
      error_src = argv[1];
    } else if (errno == EISDIR || errno == ENOTDIR) {
      error_src = argv[2];
    } else {
      error_src = "renameat2";
    }
  if (error_src) {
    fprintf(stderr, "%s: %s: %s\n", argv[0], error_src, strerror(errno));
    return 1;
  } else {
    return 0;
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     1192 <main+0x52>
mov    0x2e59(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe81(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0xff,-0x4(%rbp)
jmp    12f7 <main+0x1b7>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    0x2dff(%rip),%rax
mov    (%rax),%esi
call   1050 <access@plt>
cmp    $0xffffffff,%eax
jne    11c2 <main+0x82>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x18(%rbp)
jmp    128f <main+0x14f>
mov    0x2e1f(%rip),%rax
mov    (%rax),%edi
mov    0x2dc6(%rip),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
mov    0x2db5(%rip),%rax
mov    (%rax),%ecx
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%r8
mov    0x2dc4(%rip),%rax
mov    (%rax),%r9d
call   1040 <syscall@plt>
cmp    $0xffffffff,%eax
jne    128a <main+0x14a>
mov    0x2db4(%rip),%rax
mov    (%rax),%rax
mov    0x2d92(%rip),%rcx
cmp    (%rcx),%rax
jne    1230 <main+0xf0>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
jmp    1285 <main+0x145>
mov    0x2d89(%rip),%rax
mov    (%rax),%rax
mov    0x2d97(%rip),%rcx
cmp    (%rcx),%rax
je     1264 <main+0x124>
mov    0x2d6f(%rip),%rax
mov    (%rax),%rax
mov    0x2d9d(%rip),%rcx
cmp    (%rcx),%rax
jne    1275 <main+0x135>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x18(%rbp)
jmp    1280 <main+0x140>
lea    0xd9b(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    1285 <main+0x145>
jmp    128a <main+0x14a>
jmp    128f <main+0x14f>
cmpq   $0x0,-0x18(%rbp)
je     12f0 <main+0x1b0>
mov    0x2d27(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    0x2d00(%rip),%rax
mov    (%rax),%rdi
call   1060 <strerror@plt>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    %rax,%r8
lea    0xd44(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12f7 <main+0x1b7>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
cmp    $0x3,%edi
jne    11bf <main+0x7f>
lea    0x10(%rbx),%rbp
mov    0x10(%rbx),%rdi
mov    0x2e45(%rip),%rax
mov    (%rax),%esi
call   1050 <access@plt>
cmp    $0xffffffff,%eax
je     1201 <main+0xc1>
mov    0x2e76(%rip),%rax
mov    (%rax),%edi
mov    0x2e1d(%rip),%rax
mov    (%rax),%ecx
mov    0x8(%rbx),%rdx
mov    0x10(%rbx),%r8
mov    0x2e2c(%rip),%rax
mov    (%rax),%r9d
mov    %ecx,%esi
call   1040 <syscall@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0xffffffff,%ecx
jne    1247 <main+0x107>
mov    0x2e16(%rip),%rax
mov    (%rax),%rdi
mov    0x2df4(%rip),%rax
cmp    (%rax),%rdi
jne    11e0 <main+0xa0>
lea    0x8(%rbx),%rbp
jmp    1201 <main+0xc1>
mov    0x2e02(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xe2e(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    $0xff,%eax
jmp    1247 <main+0x107>
mov    0x2df1(%rip),%rax
cmp    (%rax),%rdi
je     1201 <main+0xc1>
mov    0x2e05(%rip),%rax
cmp    (%rax),%rdi
je     1201 <main+0xc1>
lea    0xe18(%rip),%r14
jmp    1214 <main+0xd4>
mov    0x0(%rbp),%r14
test   %r14,%r14
je     1245 <main+0x105>
mov    0x2daf(%rip),%rax
mov    (%rax),%rdi
mov    0x2dad(%rip),%rax
mov    (%rax),%ebp
mov    (%rbx),%rbx
call   1060 <strerror@plt>
lea    0xdf5(%rip),%rsi
mov    %ebp,%edi
mov    %rbx,%rdx
mov    %r14,%rcx
mov    %rax,%r8
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    $0x1,%eax
jmp    1247 <main+0x107>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [23 x i8] c"Usage: %s FILE1 FILE2\0A\00"
@F_OK = global i32 0
@SYS_renameat2 = global i32 0
@AT_FDCWD = global i32 0
@RENAME_EXCHANGE = global i32 0
@errno = global i64 0
@ENOENT = global i64 0
@EISDIR = global i64 0
@ENOTDIR = global i64 0
@.str.1 = [10 x i8] c"renameat2\00"
@.str.2 = [12 x i8] c"%s: %s: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %6
%7 = load i32, i32* %4
%8 = icmp ne i32 %7, 3
br i1 %8, label %9, label %15
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 0
%13 = load i8*, i8** %12
%14 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %13)
store i32 255, i32* %3
br label %76
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 2
%18 = load i8*, i8** %17
%19 = load i32, i32* @F_OK
%20 = call i32 @access(i8* %18, i32 %19)
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %26
22: ; preds = %15
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 2
%25 = load i8*, i8** %24
store i8* %25, i8** %6
br label %63
26: ; preds = %15
%27 = load i32, i32* @SYS_renameat2
%28 = load i32, i32* @AT_FDCWD
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 1
%31 = load i8*, i8** %30
%32 = load i32, i32* @AT_FDCWD
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 2
%35 = load i8*, i8** %34
%36 = load i32, i32* @RENAME_EXCHANGE
%37 = call i32 @syscall(i32 %27, i32 %28, i8* %31, i32 %32, i8* %35, i32 %36)
%38 = icmp eq i32 %37, -1
br i1 %38, label %39, label %62
39: ; preds = %26
%40 = load i64, i64* @errno
%41 = load i64, i64* @ENOENT
%42 = icmp eq i64 %40, %41
br i1 %42, label %43, label %47
43: ; preds = %39
%44 = load i8**, i8*** %5
%45 = getelementptr inbounds i8*, i8** %44, i64 1
%46 = load i8*, i8** %45
store i8* %46, i8** %6
br label %61
47: ; preds = %39
%48 = load i64, i64* @errno
%49 = load i64, i64* @EISDIR
%50 = icmp eq i64 %48, %49
br i1 %50, label %55, label %51
51: ; preds = %47
%52 = load i64, i64* @errno
%53 = load i64, i64* @ENOTDIR
%54 = icmp eq i64 %52, %53
br i1 %54, label %55, label %59
55: ; preds = %51, %47
%56 = load i8**, i8*** %5
%57 = getelementptr inbounds i8*, i8** %56, i64 2
%58 = load i8*, i8** %57
store i8* %58, i8** %6
br label %60
59: ; preds = %51
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8** %6
br label %60
60: ; preds = %59, %55
br label %61
61: ; preds = %60, %43
br label %62
62: ; preds = %61, %26
br label %63
63: ; preds = %62, %22
%64 = load i8*, i8** %6
%65 = icmp ne i8* %64, null
br i1 %65, label %66, label %75
66: ; preds = %63
%67 = load i32, i32* @stderr
%68 = load i8**, i8*** %5
%69 = getelementptr inbounds i8*, i8** %68, i64 0
%70 = load i8*, i8** %69
%71 = load i8*, i8** %6
%72 = load i64, i64* @errno
%73 = call i8* @strerror(i64 %72)
%74 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %67, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* %70, i8* %71, i8* %73)
store i32 1, i32* %3
br label %76
75: ; preds = %63
store i32 0, i32* %3
br label %76
76: ; preds = %75, %66, %9
%77 = load i32, i32* %3
ret i32 %77
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [23 x i8] c"Usage: %s FILE1 FILE2\0A\00"
@F_OK = global i32 0
@SYS_renameat2 = global i32 0
@AT_FDCWD = global i32 0
@RENAME_EXCHANGE = global i32 0
@errno = global i64 0
@ENOENT = global i64 0
@EISDIR = global i64 0
@ENOTDIR = global i64 0
@.str.1 = [10 x i8] c"renameat2\00"
@.str.2 = [12 x i8] c"%s: %s: %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 3
br i1 %3, label %8, label %4
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = load i8*, i8** %1
%7 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %6)
br label %46
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 2
%10 = load i8*, i8** %9
%11 = load i32, i32* @F_OK
%12 = tail call i32 @access(i8* %10, i32 %11)
%13 = icmp eq i32 %12, -1
br i1 %13, label %33, label %14
14: ; preds = %8
%15 = load i32, i32* @SYS_renameat2
%16 = load i32, i32* @AT_FDCWD
%17 = getelementptr inbounds i8*, i8** %1, i64 1
%18 = load i8*, i8** %17
%19 = load i8*, i8** %9
%20 = load i32, i32* @RENAME_EXCHANGE
%21 = tail call i32 @syscall(i32 %15, i32 %16, i8* %18, i32 %16, i8* %19, i32 %20)
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %46
23: ; preds = %14
%24 = load i64, i64* @errno
%25 = load i64, i64* @ENOENT
%26 = icmp eq i64 %24, %25
br i1 %26, label %33, label %27
27: ; preds = %23
%28 = load i64, i64* @EISDIR
%29 = icmp eq i64 %24, %28
%30 = load i64, i64* @ENOTDIR
%31 = icmp eq i64 %24, %30
%32 = select i1 %29, i1 true, i1 %31
br i1 %32, label %33, label %39
33: ; preds = %27, %23, %8
%34 = phi i8** [ %9, %8 ], [ %17, %23 ], [ %9, %27 ]
%35 = load i8*, i8** %34
%36 = icmp eq i8* %35, null
br i1 %36, label %46, label %37
37: ; preds = %33
%38 = load i64, i64* @errno
br label %39
39: ; preds = %37, %27
%40 = phi i64 [ %38, %37 ], [ %24, %27 ]
%41 = phi i8* [ %35, %37 ], [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), %27 ]
%42 = load i32, i32* @stderr
%43 = load i8*, i8** %1
%44 = tail call i8* @strerror(i64 %40)
%45 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %42, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* %43, i8* %41, i8* %44)
br label %46
46: ; preds = %14, %33, %39, %4
%47 = phi i32 [ 255, %4 ], [ 1, %39 ], [ 0, %33 ], [ 0, %14 ]
ret i32 %47
}