#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*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *, char *);
scalar_t__ rename(char *, char *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int test_move_self_helper(char *oldpath, void *private) {
  char *newpath = (char *)private;
  if (rename(oldpath, newpath) < 0) {
    fprintf(stderr, "Cannot rename %s to %s: %s\n", oldpath, newpath,
            strerror(errno));
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<test_move_self_helper>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <rename@plt>
cmp    $0x0,%rax
jge    11af <test_move_self_helper+0x7f>
mov    0x2e7a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    0x2e56(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    %rax,%r8
lea    0xe62(%rip),%rsi
call   1030 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b6 <test_move_self_helper+0x86>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_move_self_helper>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
call   1040 <rename@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
jns    117c <test_move_self_helper+0x4c>
mov    0x2e90(%rip),%rax
mov    (%rax),%ebp
mov    0x2e7f(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
lea    0xe99(%rip),%rsi
mov    %ebp,%edi
mov    %rbx,%rdx
mov    %r14,%rcx
mov    %rax,%r8
call   1030 <fprintf@plt>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [28 x i8] c"Cannot rename %s to %s: %s\0A\00"
@errno = global i32 0
define i32 @test_move_self_helper(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%7 = load i8*, i8** %5
store i8* %7, i8** %6
%8 = load i8*, i8** %4
%9 = load i8*, i8** %6
%10 = call i64 @rename(i8* %8, i8* %9)
%11 = icmp slt i64 %10, 0
br i1 %11, label %12, label %19
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = load i8*, i8** %4
%15 = load i8*, i8** %6
%16 = load i32, i32* @errno
%17 = call i8* @strerror(i32 %16)
%18 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %14, i8* %15, i8* %17)
store i32 -1, i32* %3
br label %20
19: ; preds = %2
store i32 0, i32* %3
br label %20
20: ; preds = %19, %12
%21 = load i32, i32* %3
ret i32 %21
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [28 x i8] c"Cannot rename %s to %s: %s\0A\00"
@errno = global i32 0
define i32 @test_move_self_helper(i8* %0, i8* %1) {
%3 = tail call i64 @rename(i8* %0, i8* %1)
%4 = icmp slt i64 %3, 0
br i1 %4, label %5, label %10
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = load i32, i32* @errno
%8 = tail call i8* @strerror(i32 %7)
%9 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %1, i8* %8)
br label %10
10: ; preds = %2, %5
%11 = phi i32 [ -1, %5 ], [ 0, %2 ]
ret i32 %11
}