#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 const *,
                           char const *, char *);
scalar_t__ rename(char const *, char const *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int rename_file(const char *source, const char *target) {
  if (rename(source, target) != 0) {
    fprintf(stderr, "Error renaming %s to %s: %s\n", source, target,
            strerror(errno));
    return 0;
  }
  return 1;
}


x86 assembly (clang, -O0):
<rename_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <rename@plt>
cmp    $0x0,%rax
je     11a7 <rename_file+0x77>
mov    0x2e82(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    0x2e5e(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    %rax,%r8
lea    0xe6a(%rip),%rsi
call   1030 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11ae <rename_file+0x7e>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rename_file>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
call   1040 <rename@plt>
test   %rax,%rax
je     1176 <rename_file+0x46>
mov    0x2e95(%rip),%rax
mov    (%rax),%ebp
mov    0x2e84(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
lea    0xe9e(%rip),%rsi
mov    %ebp,%edi
mov    %rbx,%rdx
mov    %r14,%rcx
mov    %rax,%r8
call   1030 <fprintf@plt>
xor    %eax,%eax
jmp    117b <rename_file+0x4b>
mov    $0x1,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
@stderr = global i32 0
@.str = [29 x i8] c"Error renaming %s to %s: %s\0A\00"
@errno = global i32 0
define i32 @rename_file(i8* %0, i8* %1) {
%3 = tail call i64 @rename(i8* %0, i8* %1)
%4 = icmp eq i64 %3, 0
br i1 %4, label %10, label %5
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 ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %1, i8* %8)
br label %10
10: ; preds = %2, %5
%11 = phi i32 [ 0, %5 ], [ 1, %2 ]
ret i32 %11
}