#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*/ file(char const *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int rename(char const *, char *);
int main(int argc, char *argv[]) {
  const char *filename = "test.txt";
  file(filename);
  int i = rename(filename, "a.txt");
  if (i == -1) {
    perror("rename");
  } else {
    printf("rename success\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xea3(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <file@plt>
mov    -0x18(%rbp),%rdi
lea    0xe94(%rip),%rsi
call   1050 <rename@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    1198 <main+0x58>
lea    0xe81(%rip),%rdi
call   1040 <perror@plt>
jmp    11a4 <main+0x64>
lea    0xe77(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
lea    0xeb8(%rip),%rbx
mov    %rbx,%rdi
call   1060 <file@plt>
lea    0xeb2(%rip),%rsi
mov    %rbx,%rdi
call   1050 <rename@plt>
cmp    $0xffffffff,%eax
je     1174 <main+0x34>
lea    0xeab(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rbx
ret
lea    0xe94(%rip),%rdi
call   1040 <perror@plt>
jmp    1170 <main+0x30>

LLVM IR (-O0):
@.str = [9 x i8] c"test.txt\00"
@.str.1 = [6 x i8] c"a.txt\00"
@.str.2 = [7 x i8] c"rename\00"
@.str.3 = [16 x i8] c"rename success\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8** %6
%8 = load i8*, i8** %6
%9 = call i32 @file(i8* %8)
%10 = load i8*, i8** %6
%11 = call i32 @rename(i8* %10, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
store i32 %11, i32* %7
%12 = load i32, i32* %7
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %18
16: ; preds = %2
%17 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
br label %18
18: ; preds = %16, %14
ret i32 0
}

LLVM IR (-O2):
@.str = [9 x i8] c"test.txt\00"
@.str.1 = [6 x i8] c"a.txt\00"
@.str.2 = [7 x i8] c"rename\00"
@str = [15 x i8] c"rename success\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 @file(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%4 = tail call i32 @rename(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %10
8: ; preds = %2
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
br label %10
10: ; preds = %8, %6
ret i32 0
}