#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 errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ memcpy(char *, char const *, int const);
int rename(char *, char *);
int /*<<< orphan*/ stderr;
char *strerror(int);
scalar_t__ xcmalloc(int const);
int c_rename_(const char *oldname, const int *oldlength, const char *newname,
              const int *newlength) {
  int retval = -1;
  char *oldname_ = (char *)xcmalloc((*oldlength) + 1);
  char *newname_ = (char *)xcmalloc((*newlength) + 1);
  memcpy(oldname_, oldname, *oldlength);
  memcpy(newname_, newname, *newlength);
  oldname_[*oldlength] = '\0';
  newname_[*newlength] = '\0';
  retval = rename(oldname_, newname_);
  if (retval == -1)
    fprintf(stderr, "mv fail: [%d] %s\n", errno, strerror(errno));
  free(oldname_);
  free(newname_);
  return retval;
}


x86 assembly (clang, -O0):
<c_rename_>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movl   $0xffffffff,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
add    $0x1,%edi
call   1060 <xcmalloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%edi
add    $0x1,%edi
call   1060 <xcmalloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rax
mov    (%rax),%edx
call   1050 <memcpy@plt>
mov    -0x38(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rax
mov    (%rax),%edx
call   1050 <memcpy@plt>
mov    -0x30(%rbp),%rax
mov    -0x10(%rbp),%rcx
movslq (%rcx),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x38(%rbp),%rax
mov    -0x20(%rbp),%rcx
movslq (%rcx),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   1070 <rename@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    123c <c_rename_+0xdc>
mov    0x2dd8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x40(%rbp)
mov    0x2dc4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    0x2db8(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x40(%rbp),%edi
mov    -0x3c(%rbp),%edx
mov    %rax,%rcx
lea    0xdc9(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x24(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<c_rename_>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r12
mov    %rdx,%r13
mov    %rsi,%rbx
mov    %rdi,%rbp
mov    (%rsi),%edi
add    $0x1,%edi
call   1060 <xcmalloc@plt>
mov    %rax,%r14
mov    (%r12),%edi
add    $0x1,%edi
call   1060 <xcmalloc@plt>
mov    %rax,%r15
mov    (%rbx),%edx
mov    %r14,%rdi
mov    %rbp,%rsi
call   1050 <memcpy@plt>
mov    (%r12),%edx
mov    %r15,%rdi
mov    %r13,%rsi
call   1050 <memcpy@plt>
movslq (%rbx),%rax
movb   $0x0,(%r14,%rax,1)
movslq (%r12),%rax
movb   $0x0,(%r15,%rax,1)
mov    %r14,%rdi
mov    %r15,%rsi
call   1070 <rename@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
jne    1200 <c_rename_+0xa0>
mov    0x2e07(%rip),%rax
mov    (%rax),%r12d
mov    0x2df5(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%edi
call   1080 <strerror@plt>
lea    0xe0d(%rip),%rsi
mov    %r12d,%edi
mov    %ebp,%edx
mov    %rax,%rcx
call   1040 <fprintf@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [18 x i8] c"mv fail: [%d] %s\0A\00"
@errno = global i32 0
define i32 @c_rename_(i8* %0, i32* %1, i8* %2, i32* %3) {
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i8*
store i8* %0, i8** %5
store i32* %1, i32** %6
store i8* %2, i8** %7
store i32* %3, i32** %8
store i32 -1, i32* %9
%12 = load i32*, i32** %6
%13 = load i32, i32* %12
%14 = add nsw i32 %13, 1
%15 = call i64 @xcmalloc(i32 %14)
%16 = inttoptr i64 %15 to i8*
store i8* %16, i8** %10
%17 = load i32*, i32** %8
%18 = load i32, i32* %17
%19 = add nsw i32 %18, 1
%20 = call i64 @xcmalloc(i32 %19)
%21 = inttoptr i64 %20 to i8*
store i8* %21, i8** %11
%22 = load i8*, i8** %10
%23 = load i8*, i8** %5
%24 = load i32*, i32** %6
%25 = load i32, i32* %24
%26 = call i32 @memcpy(i8* %22, i8* %23, i32 %25)
%27 = load i8*, i8** %11
%28 = load i8*, i8** %7
%29 = load i32*, i32** %8
%30 = load i32, i32* %29
%31 = call i32 @memcpy(i8* %27, i8* %28, i32 %30)
%32 = load i8*, i8** %10
%33 = load i32*, i32** %6
%34 = load i32, i32* %33
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %32, i64 %35
store i8 0, i8* %36
%37 = load i8*, i8** %11
%38 = load i32*, i32** %8
%39 = load i32, i32* %38
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %37, i64 %40
store i8 0, i8* %41
%42 = load i8*, i8** %10
%43 = load i8*, i8** %11
%44 = call i32 @rename(i8* %42, i8* %43)
store i32 %44, i32* %9
%45 = load i32, i32* %9
%46 = icmp eq i32 %45, -1
br i1 %46, label %47, label %53
47: ; preds = %4
%48 = load i32, i32* @stderr
%49 = load i32, i32* @errno
%50 = load i32, i32* @errno
%51 = call i8* @strerror(i32 %50)
%52 = call i32 @fprintf(i32 %48, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %49, i8* %51)
br label %53
53: ; preds = %47, %4
%54 = load i8*, i8** %10
%55 = call i32 @free(i8* %54)
%56 = load i8*, i8** %11
%57 = call i32 @free(i8* %56)
%58 = load i32, i32* %9
ret i32 %58
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [18 x i8] c"mv fail: [%d] %s\0A\00"
@errno = global i32 0
define i32 @c_rename_(i8* %0, i32* nocapture %1, i8* %2, i32* nocapture %3) {
%5 = load i32, i32* %1
%6 = add nsw i32 %5, 1
%7 = tail call i64 @xcmalloc(i32 %6)
%8 = inttoptr i64 %7 to i8*
%9 = load i32, i32* %3
%10 = add nsw i32 %9, 1
%11 = tail call i64 @xcmalloc(i32 %10)
%12 = inttoptr i64 %11 to i8*
%13 = load i32, i32* %1
%14 = tail call i32 @memcpy(i8* %8, i8* %0, i32 %13)
%15 = load i32, i32* %3
%16 = tail call i32 @memcpy(i8* %12, i8* %2, i32 %15)
%17 = load i32, i32* %1
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %8, i64 %18
store i8 0, i8* %19
%20 = load i32, i32* %3
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %12, i64 %21
store i8 0, i8* %22
%23 = tail call i32 @rename(i8* %8, i8* %12)
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %30
25: ; preds = %4
%26 = load i32, i32* @stderr
%27 = load i32, i32* @errno
%28 = tail call i8* @strerror(i32 %27)
%29 = tail call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %27, i8* %28)
br label %30
30: ; preds = %25, %4
%31 = tail call i32 @free(i8* %8)
%32 = tail call i32 @free(i8* %12)
ret i32 %23
}