#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 const *, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ puts(char *);
scalar_t__ remove(char const *);
int srfdel(const char *ftex) {
  FILE *pFile;
  pFile = fopen(ftex, "r+w");
  if (pFile != NULL) {
    fclose(pFile);
    if (remove(ftex) != 0)
      perror("Error deleting file\n");
    else
      puts("File successfully deleted\n");
  } else
    printf("%s", "error");
  return 0;
}


x86 assembly (clang, -O0):
<srfdel>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe89(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11c9 <srfdel+0x69>
mov    -0x10(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x8(%rbp),%rdi
call   1030 <remove@plt>
cmp    $0x0,%rax
je     11b8 <srfdel+0x58>
lea    0xe56(%rip),%rdi
call   1080 <perror@plt>
jmp    11c4 <srfdel+0x64>
lea    0xe5a(%rip),%rdi
call   1040 <puts@plt>
jmp    11dc <srfdel+0x7c>
lea    0xe64(%rip),%rdi
lea    0xe60(%rip),%rsi
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<srfdel>:
push   %rbx
mov    %rdi,%rbx
lea    0xe95(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1198 <srfdel+0x38>
mov    %rax,%rdi
call   1050 <fclose@plt>
mov    %rbx,%rdi
call   1030 <remove@plt>
test   %rax,%rax
jne    11af <srfdel+0x4f>
lea    0xe88(%rip),%rdi
call   1040 <puts@plt>
jmp    11ab <srfdel+0x4b>
lea    0xe95(%rip),%rdi
lea    0xe91(%rip),%rsi
call   1060 <printf@plt>
xor    %eax,%eax
pop    %rbx
ret
lea    0xe4e(%rip),%rdi
call   1080 <perror@plt>
jmp    11ab <srfdel+0x4b>

LLVM IR (-O0):
@.str = [4 x i8] c"r+w\00"
@.str.1 = [21 x i8] c"Error deleting file\0A\00"
@.str.2 = [27 x i8] c"File successfully deleted\0A\00"
@.str.3 = [3 x i8] c"%s\00"
@.str.4 = [6 x i8] c"error\00"
define i32 @srfdel(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = call i32* @fopen(i8* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i32* %5, i32** %3
%6 = load i32*, i32** %3
%7 = icmp ne i32* %6, null
br i1 %7, label %8, label %19
8: ; preds = %1
%9 = load i32*, i32** %3
%10 = call i32 @fclose(i32* %9)
%11 = load i8*, i8** %2
%12 = call i64 @remove(i8* %11)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %8
%15 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
br label %18
16: ; preds = %8
%17 = call i32 @puts(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
br label %18
18: ; preds = %16, %14
br label %21
19: ; preds = %1
%20 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
br label %21
21: ; preds = %19, %18
ret i32 0
}

LLVM IR (-O2):
@.str = [4 x i8] c"r+w\00"
@.str.1 = [21 x i8] c"Error deleting file\0A\00"
@.str.2 = [27 x i8] c"File successfully deleted\0A\00"
@.str.3 = [3 x i8] c"%s\00"
@.str.4 = [6 x i8] c"error\00"
define i32 @srfdel(i8* nocapture %0) {
%2 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %12, label %4
4: ; preds = %1
%5 = tail call i32 @fclose(i32* %2)
%6 = tail call i64 @remove(i8* %0)
%7 = icmp eq i64 %6, 0
br i1 %7, label %10, label %8
8: ; preds = %4
%9 = tail call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
br label %14
10: ; preds = %4
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
br label %14
12: ; preds = %1
%13 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
br label %14
14: ; preds = %8, %10, %12
ret i32 0
}