#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*/ err(int, char *, char *, char *);
char *name_get(unsigned int);
int /*<<< orphan*/ printf(char *, char *, char *);
int rename(char *, char *);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
void do_renamexd(unsigned fromdir, unsigned from, unsigned todir, unsigned to) {
  char frombuf[64];
  char tobuf[64];
  strcpy(frombuf, name_get(fromdir));
  strcat(frombuf, "/");
  strcat(frombuf, name_get(from));
  strcpy(tobuf, name_get(todir));
  strcat(tobuf, "/");
  strcat(tobuf, name_get(to));
  if (rename(frombuf, tobuf) == -1) {
    err(1, "rename %s to %s", frombuf, tobuf);
  }
  printf("rename %s %s\n", frombuf, tobuf);
}


x86 assembly (clang, -O0):
<do_renamexd>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %ecx,-0x10(%rbp)
lea    -0x50(%rbp),%rax
mov    %rax,-0xb0(%rbp)
mov    -0x4(%rbp),%edi
call   1060 <name_get@plt>
mov    -0xb0(%rbp),%rdi
mov    %rax,%rsi
call   1030 <strcpy@plt>
lea    -0x50(%rbp),%rdi
lea    0xe5c(%rip),%rsi
call   1080 <strcat@plt>
lea    -0x50(%rbp),%rax
mov    %rax,-0xa8(%rbp)
mov    -0x8(%rbp),%edi
call   1060 <name_get@plt>
mov    -0xa8(%rbp),%rdi
mov    %rax,%rsi
call   1080 <strcat@plt>
lea    -0x90(%rbp),%rax
mov    %rax,-0xa0(%rbp)
mov    -0xc(%rbp),%edi
call   1060 <name_get@plt>
mov    -0xa0(%rbp),%rdi
mov    %rax,%rsi
call   1030 <strcpy@plt>
lea    -0x90(%rbp),%rdi
lea    0xe02(%rip),%rsi
call   1080 <strcat@plt>
lea    -0x90(%rbp),%rax
mov    %rax,-0x98(%rbp)
mov    -0x10(%rbp),%edi
call   1060 <name_get@plt>
mov    -0x98(%rbp),%rdi
mov    %rax,%rsi
call   1080 <strcat@plt>
lea    -0x50(%rbp),%rdi
lea    -0x90(%rbp),%rsi
call   1070 <rename@plt>
cmp    $0xffffffff,%eax
jne    125d <do_renamexd+0xfd>
lea    -0x50(%rbp),%rdx
lea    -0x90(%rbp),%rcx
mov    $0x1,%edi
lea    0xdaa(%rip),%rsi
call   1050 <err@plt>
lea    -0x50(%rbp),%rsi
lea    -0x90(%rbp),%rdx
lea    0xda3(%rip),%rdi
call   1040 <printf@plt>
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_renamexd>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x80,%rsp
mov    %ecx,%r14d
mov    %edx,%ebp
mov    %esi,%ebx
call   1060 <name_get@plt>
lea    0x40(%rsp),%r15
mov    %r15,%rdi
mov    %rax,%rsi
call   1030 <strcpy@plt>
lea    0xe6e(%rip),%r12
mov    %r15,%rdi
mov    %r12,%rsi
call   1080 <strcat@plt>
mov    %ebx,%edi
call   1060 <name_get@plt>
mov    %r15,%rdi
mov    %rax,%rsi
call   1080 <strcat@plt>
mov    %ebp,%edi
call   1060 <name_get@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %rax,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1080 <strcat@plt>
mov    %r14d,%edi
call   1060 <name_get@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
call   1080 <strcat@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1070 <rename@plt>
cmp    $0xffffffff,%eax
jne    120b <do_renamexd+0xab>
lea    0xe09(%rip),%rsi
lea    0x40(%rsp),%rdx
mov    %rsp,%rcx
mov    $0x1,%edi
call   1050 <err@plt>
lea    0xe00(%rip),%rdi
lea    0x40(%rsp),%rsi
mov    %rsp,%rdx
call   1040 <printf@plt>
add    $0x80,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"/\00"
@.str.1 = [16 x i8] c"rename %s to %s\00"
@.str.2 = [14 x i8] c"rename %s %s\0A\00"
define void @do_renamexd(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca [64 x i8]
%10 = alloca [64 x i8]
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%11 = getelementptr inbounds [64 x i8], [64 x i8]* %9, i64 0, i64 0
%12 = load i32, i32* %5
%13 = call i8* @name_get(i32 %12)
%14 = call i32 @strcpy(i8* %11, i8* %13)
%15 = getelementptr inbounds [64 x i8], [64 x i8]* %9, i64 0, i64 0
%16 = call i32 @strcat(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%17 = getelementptr inbounds [64 x i8], [64 x i8]* %9, i64 0, i64 0
%18 = load i32, i32* %6
%19 = call i8* @name_get(i32 %18)
%20 = call i32 @strcat(i8* %17, i8* %19)
%21 = getelementptr inbounds [64 x i8], [64 x i8]* %10, i64 0, i64 0
%22 = load i32, i32* %7
%23 = call i8* @name_get(i32 %22)
%24 = call i32 @strcpy(i8* %21, i8* %23)
%25 = getelementptr inbounds [64 x i8], [64 x i8]* %10, i64 0, i64 0
%26 = call i32 @strcat(i8* %25, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%27 = getelementptr inbounds [64 x i8], [64 x i8]* %10, i64 0, i64 0
%28 = load i32, i32* %8
%29 = call i8* @name_get(i32 %28)
%30 = call i32 @strcat(i8* %27, i8* %29)
%31 = getelementptr inbounds [64 x i8], [64 x i8]* %9, i64 0, i64 0
%32 = getelementptr inbounds [64 x i8], [64 x i8]* %10, i64 0, i64 0
%33 = call i32 @rename(i8* %31, i8* %32)
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %39
35: ; preds = %4
%36 = getelementptr inbounds [64 x i8], [64 x i8]* %9, i64 0, i64 0
%37 = getelementptr inbounds [64 x i8], [64 x i8]* %10, i64 0, i64 0
%38 = call i32 @err(i32 1, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %36, i8* %37)
br label %39
39: ; preds = %35, %4
%40 = getelementptr inbounds [64 x i8], [64 x i8]* %9, i64 0, i64 0
%41 = getelementptr inbounds [64 x i8], [64 x i8]* %10, i64 0, i64 0
%42 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* %40, i8* %41)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"/\00"
@.str.1 = [16 x i8] c"rename %s to %s\00"
@.str.2 = [14 x i8] c"rename %s %s\0A\00"
define void @do_renamexd(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca [64 x i8]
%6 = alloca [64 x i8]
%7 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%8 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
%9 = tail call i8* @name_get(i32 %0)
%10 = call i32 @strcpy(i8* %7, i8* %9)
%11 = call i32 @strcat(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%12 = call i8* @name_get(i32 %1)
%13 = call i32 @strcat(i8* %7, i8* %12)
%14 = call i8* @name_get(i32 %2)
%15 = call i32 @strcpy(i8* %8, i8* %14)
%16 = call i32 @strcat(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%17 = call i8* @name_get(i32 %3)
%18 = call i32 @strcat(i8* %8, i8* %17)
%19 = call i32 @rename(i8* %7, i8* %8)
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %23
21: ; preds = %4
%22 = call i32 @err(i32 1, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %7, i8* %8)
br label %23
23: ; preds = %21, %4
%24 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* %7, i8* %8)
ret void
}