#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*/ printf(char *, ...);
int rename(char *, char *);
char *strerror(int);
void rename_t() {
  int ret;
  char oldname[] = "./file.txt";
  char newname[] = "./newfile.txt";
  ret = rename(oldname, newname);
  if (ret == 0) {
    printf("File renamed successfully");
  } else {
    printf("Error: unable to rename the file error %d %s", errno,
           strerror(errno));
  }
}


x86 assembly (clang, -O0):
<rename_t>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    0xec1(%rip),%rax
mov    %rax,-0xf(%rbp)
mov    0xebe(%rip),%ax
mov    %ax,-0x7(%rbp)
mov    0xeb6(%rip),%al
mov    %al,-0x5(%rbp)
mov    0xead(%rip),%rax
mov    %rax,-0x1d(%rbp)
mov    0xeab(%rip),%eax
mov    %eax,-0x15(%rbp)
mov    0xea5(%rip),%ax
mov    %ax,-0x11(%rbp)
lea    -0xf(%rbp),%rdi
lea    -0x1d(%rbp),%rsi
call   1040 <rename@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jne    11a3 <rename_t+0x73>
lea    0xe82(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11d1 <rename_t+0xa1>
mov    0x2e36(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    0x2e2a(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    -0x24(%rbp),%esi
mov    %rax,%rdx
lea    0xe69(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rename_t>:
push   %rbx
sub    $0x20,%rsp
movabs $0x742e656c69662f2e,%rax
65 2e 74
mov    %rax,(%rsp)
movl   $0x747874,0x7(%rsp)
movabs $0x7478742e656c69,%rax
mov    %rax,0x16(%rsp)
movabs $0x6c696677656e2f2e,%rax
66 69 6c
mov    %rax,0x10(%rsp)
mov    %rsp,%rdi
lea    0x10(%rsp),%rsi
call   1040 <rename@plt>
test   %eax,%eax
je     11a2 <rename_t+0x72>
mov    0x2e5f(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%edi
call   1050 <strerror@plt>
lea    0xea2(%rip),%rdi
mov    %ebx,%esi
mov    %rax,%rdx
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
jmp    1030 <printf@plt>
lea    0xe70(%rip),%rdi
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
jmp    1030 <printf@plt>

LLVM IR (-O0):
@__const.rename_t.oldname = [11 x i8] c"./file.txt\00"
@__const.rename_t.newname = [14 x i8] c"./newfile.txt\00"
@.str = [26 x i8] c"File renamed successfully\00"
@.str.1 = [45 x i8] c"Error: unable to rename the file error %d %s\00"
@errno = global i32 0
define void @rename_t() {
%1 = alloca i32
%2 = alloca [11 x i8]
%3 = alloca [14 x i8]
%4 = bitcast [11 x i8]* %2 to i8*
%5 = bitcast [14 x i8]* %3 to i8*
%6 = getelementptr inbounds [11 x i8], [11 x i8]* %2, i64 0, i64 0
%7 = getelementptr inbounds [14 x i8], [14 x i8]* %3, i64 0, i64 0
%8 = call i32 @rename(i8* %6, i8* %7)
store i32 %8, i32* %1
%9 = load i32, i32* %1
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %0
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %18
13: ; preds = %0
%14 = load i32, i32* @errno
%15 = load i32, i32* @errno
%16 = call i8* @strerror(i32 %15)
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0), i32 %14, i8* %16)
br label %18
18: ; preds = %13, %11
ret void
}

LLVM IR (-O2):
@__const.rename_t.oldname = [11 x i8] c"./file.txt\00"
@__const.rename_t.newname = [14 x i8] c"./newfile.txt\00"
@.str = [26 x i8] c"File renamed successfully\00"
@.str.1 = [45 x i8] c"Error: unable to rename the file error %d %s\00"
@errno = global i32 0
define void @rename_t() {
%1 = alloca [11 x i8]
%2 = alloca [14 x i8]
%3 = getelementptr inbounds [11 x i8], [11 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [14 x i8], [14 x i8]* %2, i64 0, i64 0
%5 = call i32 @rename(i8* %3, i8* %4)
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %13
9: ; preds = %0
%10 = load i32, i32* @errno
%11 = tail call i8* @strerror(i32 %10)
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0), i32 %10, i8* %11)
br label %13
13: ; preds = %9, %7
ret void
}