#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*/ envia(int, char *, int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int remove(char *);
int /*<<< orphan*/ rename(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, ...);
int /*<<< orphan*/ strlen(char *);
int petic_rclose(int sockCliente, FILE *pFich, char *nombreFich,
                 unsigned int numCopia) {
  int error;
  char cadena[300] = "";
  if (pFich != NULL)
    fclose(pFich);
  if (nombreFich != NULL && strlen(nombreFich) > 0) {
    if (remove(nombreFich) == -1)
      perror("petic_rclose(): remove()");
    sprintf(cadena, "%s.%.3u", nombreFich, numCopia);
    rename(cadena, nombreFich);
  }
  error = 0;
  sprintf(cadena, "%d\n", error);
  envia(sockCliente, cadena, strlen(cadena));
  return 0;
}


x86 assembly (clang, -O0):
<petic_rclose>:
push   %rbp
mov    %rsp,%rbp
sub    $0x160,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
lea    -0x150(%rbp),%rdi
xor    %esi,%esi
mov    $0x12c,%edx
call   1070 <memset@plt>
cmpq   $0x0,-0x10(%rbp)
je     11c0 <petic_rclose+0x40>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
cmpq   $0x0,-0x18(%rbp)
je     1227 <petic_rclose+0xa7>
mov    -0x18(%rbp),%rdi
call   1060 <strlen@plt>
cmp    $0x0,%eax
jle    1227 <petic_rclose+0xa7>
mov    -0x18(%rbp),%rdi
call   1030 <remove@plt>
cmp    $0xffffffff,%eax
jne    11fb <petic_rclose+0x7b>
lea    0xe0a(%rip),%rdi
call   1080 <perror@plt>
lea    -0x150(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
lea    0xe09(%rip),%rsi
mov    $0x0,%al
call   10a0 <sprintf@plt>
lea    -0x150(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1090 <rename@plt>
movl   $0x0,-0x20(%rbp)
lea    -0x150(%rbp),%rdi
mov    -0x20(%rbp),%edx
lea    0xde2(%rip),%rsi
mov    $0x0,%al
call   10a0 <sprintf@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x15c(%rbp)
lea    -0x150(%rbp),%rax
mov    %rax,-0x158(%rbp)
lea    -0x150(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x15c(%rbp),%edi
mov    -0x158(%rbp),%rsi
mov    %eax,%edx
call   1050 <envia@plt>
xor    %eax,%eax
add    $0x160,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<petic_rclose>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x138,%rsp
mov    %ecx,%r14d
mov    %rdx,%rbx
mov    %rsi,%rbp
mov    %edi,%r15d
mov    %rsp,%rdi
mov    $0x12c,%edx
xor    %esi,%esi
call   1070 <memset@plt>
test   %rbp,%rbp
je     11b5 <petic_rclose+0x35>
mov    %rbp,%rdi
call   1040 <fclose@plt>
test   %rbx,%rbx
je     11f8 <petic_rclose+0x78>
mov    %rbx,%rdi
call   1060 <strlen@plt>
test   %eax,%eax
jle    11f8 <petic_rclose+0x78>
mov    %rbx,%rdi
call   1030 <remove@plt>
cmp    $0xffffffff,%eax
je     1233 <petic_rclose+0xb3>
lea    0xe3f(%rip),%rsi
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    %rbx,%rdx
mov    %r14d,%ecx
xor    %eax,%eax
call   10a0 <sprintf@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1090 <rename@plt>
lea    0xe22(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
xor    %edx,%edx
xor    %eax,%eax
call   10a0 <sprintf@plt>
mov    %rbx,%rdi
call   1060 <strlen@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1050 <envia@plt>
xor    %eax,%eax
add    $0x138,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdc6(%rip),%rdi
call   1080 <perror@plt>
jmp    11d3 <petic_rclose+0x53>

LLVM IR (-O0):
@.str = [25 x i8] c"petic_rclose(): remove()\00"
@.str.1 = [8 x i8] c"%s.%.3u\00"
@.str.2 = [4 x i8] c"%d\0A\00"
define i32 @petic_rclose(i32 %0, i32* %1, i8* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca [300 x i8]
store i32 %0, i32* %5
store i32* %1, i32** %6
store i8* %2, i8** %7
store i32 %3, i32* %8
%11 = bitcast [300 x i8]* %10 to i8*
%12 = load i32*, i32** %6
%13 = icmp ne i32* %12, null
br i1 %13, label %14, label %17
14: ; preds = %4
%15 = load i32*, i32** %6
%16 = call i32 @fclose(i32* %15)
br label %17
17: ; preds = %14, %4
%18 = load i8*, i8** %7
%19 = icmp ne i8* %18, null
br i1 %19, label %20, label %38
20: ; preds = %17
%21 = load i8*, i8** %7
%22 = call i32 @strlen(i8* %21)
%23 = icmp sgt i32 %22, 0
br i1 %23, label %24, label %38
24: ; preds = %20
%25 = load i8*, i8** %7
%26 = call i32 @remove(i8* %25)
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %30
28: ; preds = %24
%29 = call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
br label %30
30: ; preds = %28, %24
%31 = getelementptr inbounds [300 x i8], [300 x i8]* %10, i64 0, i64 0
%32 = load i8*, i8** %7
%33 = load i32, i32* %8
%34 = call i32 (i8*, i8*, ...) @sprintf(i8* %31, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %32, i32 %33)
%35 = getelementptr inbounds [300 x i8], [300 x i8]* %10, i64 0, i64 0
%36 = load i8*, i8** %7
%37 = call i32 @rename(i8* %35, i8* %36)
br label %38
38: ; preds = %30, %20, %17
store i32 0, i32* %9
%39 = getelementptr inbounds [300 x i8], [300 x i8]* %10, i64 0, i64 0
%40 = load i32, i32* %9
%41 = call i32 (i8*, i8*, ...) @sprintf(i8* %39, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %40)
%42 = load i32, i32* %5
%43 = getelementptr inbounds [300 x i8], [300 x i8]* %10, i64 0, i64 0
%44 = getelementptr inbounds [300 x i8], [300 x i8]* %10, i64 0, i64 0
%45 = call i32 @strlen(i8* %44)
%46 = call i32 @envia(i32 %42, i8* %43, i32 %45)
ret i32 0
}

LLVM IR (-O2):
@.str = [25 x i8] c"petic_rclose(): remove()\00"
@.str.1 = [8 x i8] c"%s.%.3u\00"
@.str.2 = [4 x i8] c"%d\0A\00"
define i32 @petic_rclose(i32 %0, i32* %1, i8* %2, i32 %3) {
%5 = alloca [300 x i8]
%6 = getelementptr inbounds [300 x i8], [300 x i8]* %5, i64 0, i64 0
%7 = icmp eq i32* %1, null
br i1 %7, label %10, label %8
8: ; preds = %4
%9 = tail call i32 @fclose(i32* %1)
br label %10
10: ; preds = %8, %4
%11 = icmp eq i8* %2, null
br i1 %11, label %23, label %12
12: ; preds = %10
%13 = tail call i32 @strlen(i8* %2)
%14 = icmp sgt i32 %13, 0
br i1 %14, label %15, label %23
15: ; preds = %12
%16 = tail call i32 @remove(i8* %2)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %20
18: ; preds = %15
%19 = tail call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
br label %20
20: ; preds = %18, %15
%21 = call i32 (i8*, i8*, ...) @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %2, i32 %3)
%22 = call i32 @rename(i8* %6, i8* %2)
br label %23
23: ; preds = %20, %12, %10
%24 = call i32 (i8*, i8*, ...) @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 0)
%25 = call i32 @strlen(i8* %6)
%26 = call i32 @envia(i32 %0, i8* %6, i32 %25)
ret i32 0
}