#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*/ printf(char *);
int rename(char *, char *);
int main() {
  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");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xecd(%rip),%rax
mov    %rax,-0x11(%rbp)
mov    0xecb(%rip),%al
mov    %al,-0x9(%rbp)
mov    0xeb6(%rip),%rax
mov    %rax,-0x1d(%rbp)
mov    0xeb4(%rip),%eax
mov    %eax,-0x15(%rbp)
lea    -0x11(%rbp),%rdi
lea    -0x1d(%rbp),%rsi
call   1040 <rename@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    1182 <main+0x62>
lea    0xe94(%rip),%rdi
call   1030 <printf@plt>
jmp    118e <main+0x6e>
lea    0xe9d(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x28,%rsp
movabs $0x7478742e656c6966,%rax
74 78 74
mov    %rax,0x8(%rsp)
movb   $0x0,0x10(%rsp)
movabs $0x2e656c696677656e,%rax
6c 65 2e
mov    %rax,0x18(%rsp)
movl   $0x747874,0x20(%rsp)
lea    0x8(%rsp),%rdi
lea    0x18(%rsp),%rsi
call   1040 <rename@plt>
test   %eax,%eax
lea    0xea5(%rip),%rax
lea    0xeb8(%rip),%rdi
cmove  %rax,%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x28,%rsp
ret

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

LLVM IR (-O2):
@__const.main.oldname = [9 x i8] c"file.txt\00"
@__const.main.newname = [12 x i8] c"newfile.txt\00"
@.str = [26 x i8] c"File renamed successfully\00"
@.str.1 = [33 x i8] c"Error: unable to rename the file\00"
define i32 @main() {
%1 = alloca [9 x i8]
%2 = alloca [12 x i8]
%3 = getelementptr inbounds [9 x i8], [9 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [12 x i8], [12 x i8]* %2, i64 0, i64 0
%5 = call i32 @rename(i8* %3, i8* %4)
%6 = icmp eq i32 %5, 0
%7 = select i1 %6, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0)
%8 = tail call i32 @printf(i8* dereferenceable(1) %7)
ret i32 0
}