#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ rename(char *, char *);
void perror_t() {
  FILE *fp;
  rename("file.txt", "newfile.txt");
  fp = fopen("file.txt", "r");
  if (fp == NULL) {
    perror("Error: ");
    return;
  }
  fclose(fp);
}


x86 assembly (clang, -O0):
<perror_t>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xeb4(%rip),%rdi
lea    0xeaa(%rip),%rsi
call   1060 <rename@plt>
lea    0xea1(%rip),%rdi
lea    0xea3(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    118e <perror_t+0x4e>
lea    0xe8a(%rip),%rdi
call   1050 <perror@plt>
jmp    1197 <perror_t+0x57>
mov    -0x8(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<perror_t>:
push   %rbx
lea    0xebb(%rip),%rbx
lea    0xeb1(%rip),%rsi
mov    %rbx,%rdi
call   1060 <rename@plt>
lea    0xeae(%rip),%rsi
mov    %rbx,%rdi
call   1040 <fopen@plt>
test   %rax,%rax
je     1174 <perror_t+0x34>
mov    %rax,%rdi
pop    %rbx
jmp    1030 <fclose@plt>
lea    0xe93(%rip),%rdi
pop    %rbx
jmp    1050 <perror@plt>

LLVM IR (-O0):
@.str = [9 x i8] c"file.txt\00"
@.str.1 = [12 x i8] c"newfile.txt\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [8 x i8] c"Error: \00"
define void @perror_t() {
%1 = alloca i32*
%2 = call i32 @rename(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%3 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %3, i32** %1
%4 = load i32*, i32** %1
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
br label %11
8: ; preds = %0
%9 = load i32*, i32** %1
%10 = call i32 @fclose(i32* %9)
br label %11
11: ; preds = %8, %6
ret void
}

LLVM IR (-O2):
@.str = [9 x i8] c"file.txt\00"
@.str.1 = [12 x i8] c"newfile.txt\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [8 x i8] c"Error: \00"
define void @perror_t() {
%1 = tail call i32 @rename(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%2 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %4, label %6
4: ; preds = %0
%5 = tail call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
br label %8
6: ; preds = %0
%7 = tail call i32 @fclose(i32* %2)
br label %8
8: ; preds = %6, %4
ret void
}