#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*/ exit(int);
int /*<<< orphan*/ perror(char *);
int remove(char *);
int rename(char *, char *);
int /*<<< orphan*/ substr(char *, char *, int /*<<< orphan*/, int);
void rename_file_(char *dir1, char *dir2, int *len_dir1, int *len_dir2) {
  int status, errno;
  char dirOld[*len_dir1];
  char dirNew[*len_dir2];
  substr(dirOld, dir1, 0, *len_dir1);
  substr(dirNew, dir2, 0, *len_dir2);
  status = remove(dirNew);
  status = rename(dirOld, dirNew);
  if (status == -1) {
    perror("rename Error");
    exit(1);
  }
}


x86 assembly (clang, -O0):
<rename_file_>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x50(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x48(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x40(%rbp)
mov    -0x8(%rbp),%rsi
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
xor    %edx,%edx
call   1040 <substr@plt>
mov    -0x48(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rax
mov    (%rax),%ecx
xor    %edx,%edx
call   1040 <substr@plt>
mov    -0x48(%rbp),%rdi
call   1030 <remove@plt>
mov    -0x50(%rbp),%rdi
mov    -0x48(%rbp),%rsi
mov    %eax,-0x24(%rbp)
call   1060 <rename@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    1215 <rename_file_+0xc5>
lea    0xdfa(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x30(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rename_file_>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rcx,%r15
mov    %rsi,%r14
mov    %rdi,%rsi
mov    (%rdx),%ecx
mov    %rsp,%r12
mov    %rcx,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
mov    (%r15),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %r12,%rdi
xor    %edx,%edx
call   1040 <substr@plt>
mov    (%r15),%ecx
mov    %rbx,%rdi
mov    %r14,%rsi
xor    %edx,%edx
call   1040 <substr@plt>
mov    %rbx,%rdi
call   1030 <remove@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
call   1060 <rename@plt>
cmp    $0xffffffff,%eax
je     11cd <rename_file_+0x7d>
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe2c(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [13 x i8] c"rename Error\00"
define void @rename_file_(i8* %0, i8* %1, i32* %2, i32* %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i64
%13 = alloca i64
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32* %2, i32** %7
store i32* %3, i32** %8
%14 = load i32*, i32** %7
%15 = load i32, i32* %14
%16 = zext i32 %15 to i64
%17 = call i8* @llvm.stacksave()
store i8* %17, i8** %11
%18 = alloca i8, i64 %16
store i64 %16, i64* %12
%19 = load i32*, i32** %8
%20 = load i32, i32* %19
%21 = zext i32 %20 to i64
%22 = alloca i8, i64 %21
store i64 %21, i64* %13
%23 = load i8*, i8** %5
%24 = load i32*, i32** %7
%25 = load i32, i32* %24
%26 = call i32 @substr(i8* %18, i8* %23, i32 0, i32 %25)
%27 = load i8*, i8** %6
%28 = load i32*, i32** %8
%29 = load i32, i32* %28
%30 = call i32 @substr(i8* %22, i8* %27, i32 0, i32 %29)
%31 = call i32 @remove(i8* %22)
store i32 %31, i32* %9
%32 = call i32 @rename(i8* %18, i8* %22)
store i32 %32, i32* %9
%33 = load i32, i32* %9
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %38
35: ; preds = %4
%36 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%37 = call i32 @exit(i32 1)
unreachable
38: ; preds = %4
%39 = load i8*, i8** %11
ret void
}

LLVM IR (-O2):
@.str = [13 x i8] c"rename Error\00"
define void @rename_file_(i8* %0, i8* %1, i32* nocapture %2, i32* nocapture %3) {
%5 = load i32, i32* %2
%6 = zext i32 %5 to i64
%7 = alloca i8, i64 %6
%8 = load i32, i32* %3
%9 = zext i32 %8 to i64
%10 = alloca i8, i64 %9
%11 = call i32 @substr(i8* %7, i8* %0, i32 0, i32 %5)
%12 = load i32, i32* %3
%13 = call i32 @substr(i8* %10, i8* %1, i32 0, i32 %12)
%14 = call i32 @remove(i8* %10)
%15 = call i32 @rename(i8* %7, i8* %10)
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %20
17: ; preds = %4
%18 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %4
ret void
}