#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*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ gets(char *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ rename(char *, char *);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  char oldname[80], newname[80];
  printf("Enter current filename: ");
  gets(oldname);
  printf("Enter new name for file: ");
  gets(newname);
  if (rename(oldname, newname) == 0)
    printf("%s has been renamed %s.\n", oldname, newname);
  else
    fprintf(stderr, "An error has occurred renaming %s.\n", oldname);
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xea0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x60(%rbp),%rdi
call   1050 <gets@plt>
lea    0xea2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0xb0(%rbp),%rdi
call   1050 <gets@plt>
lea    -0x60(%rbp),%rdi
lea    -0xb0(%rbp),%rsi
call   1060 <rename@plt>
cmp    $0x0,%rax
jne    11c2 <main+0x82>
lea    -0x60(%rbp),%rsi
lea    -0xb0(%rbp),%rdx
lea    0xe7d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11db <main+0x9b>
mov    0x2e17(%rip),%rax
mov    (%rax),%edi
lea    -0x60(%rbp),%rdx
lea    0xe76(%rip),%rsi
call   1040 <fprintf@plt>
xor    %eax,%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0xa8,%rsp
lea    0xeaf(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %rsp,%r14
mov    %r14,%rdi
call   1050 <gets@plt>
lea    0xeaf(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0x50(%rsp),%rbx
mov    %rbx,%rdi
call   1050 <gets@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1060 <rename@plt>
test   %rax,%rax
je     11a8 <main+0x68>
mov    0x2e4b(%rip),%rax
mov    (%rax),%edi
lea    0xeae(%rip),%rsi
mov    %rsp,%rdx
call   1040 <fprintf@plt>
jmp    11be <main+0x7e>
lea    0xe84(%rip),%rdi
mov    %rsp,%rsi
lea    0x50(%rsp),%rdx
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0xa8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [25 x i8] c"Enter current filename: \00"
@.str.1 = [26 x i8] c"Enter new name for file: \00"
@.str.2 = [25 x i8] c"%s has been renamed %s.\0A\00"
@stderr = global i32 0
@.str.3 = [36 x i8] c"An error has occurred renaming %s.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [80 x i8]
%7 = alloca [80 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%9 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%10 = call i32 @gets(i8* %9)
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
%12 = getelementptr inbounds [80 x i8], [80 x i8]* %7, i64 0, i64 0
%13 = call i32 @gets(i8* %12)
%14 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%15 = getelementptr inbounds [80 x i8], [80 x i8]* %7, i64 0, i64 0
%16 = call i64 @rename(i8* %14, i8* %15)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %22
18: ; preds = %2
%19 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%20 = getelementptr inbounds [80 x i8], [80 x i8]* %7, i64 0, i64 0
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i8* %19, i8* %20)
br label %26
22: ; preds = %2
%23 = load i32, i32* @stderr
%24 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%25 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), i8* %24)
br label %26
26: ; preds = %22, %18
ret i32 0
}

LLVM IR (-O2):
@.str = [25 x i8] c"Enter current filename: \00"
@.str.1 = [26 x i8] c"Enter new name for file: \00"
@.str.2 = [25 x i8] c"%s has been renamed %s.\0A\00"
@stderr = global i32 0
@.str.3 = [36 x i8] c"An error has occurred renaming %s.\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [80 x i8]
%4 = alloca [80 x i8]
%5 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 0
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @gets(i8* %5)
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
%10 = call i32 @gets(i8* %6)
%11 = call i64 @rename(i8* %5, i8* %6)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i8* %5, i8* %6)
br label %18
15: ; preds = %2
%16 = load i32, i32* @stderr
%17 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), i8* %5)
br label %18
18: ; preds = %15, %13
ret i32 0
}