#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 */
scalar_t__ EOF;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *, int);
int /*<<< orphan*/ free(char *);
scalar_t__ getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, char **);
int main() {
  FILE *archivo1, *archivo2;
  char c;
  char *nombreArchivo;
  int fsize = 0;
  printf("Archivo de entrada: ");
  scanf("%ms", &nombreArchivo);
  archivo1 = fopen(nombreArchivo, "r");
  archivo2 = fopen("info.txt", "w");
  if (archivo1 == NULL)
    printf("Error al abrir ficheros");
  else {
    while ((getc(archivo1)) != EOF) {
      fsize += 1;
    }
    fprintf(archivo2, "%s [%d]Bytes", nombreArchivo, fsize);
    free(nombreArchivo);
    if (fclose(archivo1) != 0)
      printf("Error al cerrar fichero prueba");
    if (fclose(archivo2) != 0)
      printf("Error al cerrar fichero copia");
  }
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x2c(%rbp)
lea    0xe63(%rip),%rdi
call   1050 <printf@plt>
lea    0xe6c(%rip),%rdi
lea    -0x28(%rbp),%rsi
call   1070 <scanf@plt>
mov    -0x28(%rbp),%rdi
lea    0xe5c(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
lea    0xe4e(%rip),%rdi
lea    0xe50(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11f9 <main+0x79>
lea    0xe37(%rip),%rdi
call   1050 <printf@plt>
jmp    1288 <main+0x108>
jmp    11fe <main+0x7e>
mov    -0x10(%rbp),%rdi
call   10a0 <getc@plt>
mov    0x2dda(%rip),%rcx
cmp    (%rcx),%rax
je     1225 <main+0xa5>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11fe <main+0x7e>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    -0x2c(%rbp),%ecx
lea    0xe07(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
cmp    $0x0,%rax
je     1264 <main+0xe4>
lea    0xdec(%rip),%rdi
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
cmp    $0x0,%rax
je     1283 <main+0x103>
lea    0xdec(%rip),%rdi
call   1050 <printf@plt>
jmp    1288 <main+0x108>
xor    %edi,%edi
call   1090 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
lea    0xe72(%rip),%rdi
call   1050 <printf@plt>
lea    0xe7b(%rip),%rdi
mov    %rsp,%rsi
call   1070 <scanf@plt>
mov    (%rsp),%rdi
lea    0xe6c(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%rbx
lea    0xe5f(%rip),%rdi
lea    0xe61(%rip),%rsi
call   1080 <fopen@plt>
test   %rbx,%rbx
jne    11d6 <main+0x56>
lea    0xe52(%rip),%rdi
jmp    124b <main+0xcb>
mov    %rax,%r14
mov    $0xffffffff,%ebp
mov    0x2e03(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbx,%rdi
call   10a0 <getc@plt>
add    $0x1,%ebp
cmp    (%r15),%rax
jne    11f0 <main+0x70>
mov    (%rsp),%rdx
lea    0xe33(%rip),%rsi
mov    %r14,%rdi
mov    %ebp,%ecx
call   1060 <fprintf@plt>
mov    (%rsp),%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
test   %rax,%rax
je     1237 <main+0xb7>
lea    0xe19(%rip),%rdi
call   1050 <printf@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
test   %rax,%rax
je     1250 <main+0xd0>
lea    0xe1f(%rip),%rdi
call   1050 <printf@plt>
xor    %edi,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [21 x i8] c"Archivo de entrada: \00"
@.str.1 = [4 x i8] c"%ms\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [9 x i8] c"info.txt\00"
@.str.4 = [2 x i8] c"w\00"
@.str.5 = [24 x i8] c"Error al abrir ficheros\00"
@EOF = global i64 0
@.str.6 = [13 x i8] c"%s [%d]Bytes\00"
@.str.7 = [31 x i8] c"Error al cerrar fichero prueba\00"
@.str.8 = [30 x i8] c"Error al cerrar fichero copia\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca i8
%5 = alloca i8*
%6 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %6
%7 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8** %5)
%9 = load i8*, i8** %5
%10 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %10, i32** %2
%11 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %11, i32** %3
%12 = load i32*, i32** %2
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %16
14: ; preds = %0
%15 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0))
br label %44
16: ; preds = %0
br label %17
17: ; preds = %22, %16
%18 = load i32*, i32** %2
%19 = call i64 @getc(i32* %18)
%20 = load i64, i64* @EOF
%21 = icmp ne i64 %19, %20
br i1 %21, label %22, label %25
22: ; preds = %17
%23 = load i32, i32* %6
%24 = add nsw i32 %23, 1
store i32 %24, i32* %6
br label %17
25: ; preds = %17
%26 = load i32*, i32** %3
%27 = load i8*, i8** %5
%28 = load i32, i32* %6
%29 = call i32 @fprintf(i32* %26, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0), i8* %27, i32 %28)
%30 = load i8*, i8** %5
%31 = call i32 @free(i8* %30)
%32 = load i32*, i32** %2
%33 = call i64 @fclose(i32* %32)
%34 = icmp ne i64 %33, 0
br i1 %34, label %35, label %37
35: ; preds = %25
%36 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.7, i64 0, i64 0))
br label %37
37: ; preds = %35, %25
%38 = load i32*, i32** %3
%39 = call i64 @fclose(i32* %38)
%40 = icmp ne i64 %39, 0
br i1 %40, label %41, label %43
41: ; preds = %37
%42 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.8, i64 0, i64 0))
br label %43
43: ; preds = %41, %37
br label %44
44: ; preds = %43, %14
%45 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [21 x i8] c"Archivo de entrada: \00"
@.str.1 = [4 x i8] c"%ms\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [9 x i8] c"info.txt\00"
@.str.4 = [2 x i8] c"w\00"
@.str.5 = [24 x i8] c"Error al abrir ficheros\00"
@EOF = global i64 0
@.str.6 = [13 x i8] c"%s [%d]Bytes\00"
@.str.7 = [31 x i8] c"Error al cerrar fichero prueba\00"
@.str.8 = [30 x i8] c"Error al cerrar fichero copia\00"
define i32 @main() {
%1 = alloca i8*
%2 = bitcast i8** %1 to i8*
%3 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8** %1)
%5 = load i8*, i8** %1
%6 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%7 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%8 = icmp eq i32* %6, null
br i1 %8, label %27, label %9
9: ; preds = %0, %9
%10 = phi i32 [ %14, %9 ], [ 0, %0 ]
%11 = call i64 @getc(i32* %6)
%12 = load i64, i64* @EOF
%13 = icmp eq i64 %11, %12
%14 = add nuw nsw i32 %10, 1
br i1 %13, label %15, label %9
15: ; preds = %9
%16 = load i8*, i8** %1
%17 = call i32 @fprintf(i32* %7, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0), i8* %16, i32 %10)
%18 = load i8*, i8** %1
%19 = call i32 @free(i8* %18)
%20 = call i64 @fclose(i32* %6)
%21 = icmp eq i64 %20, 0
br i1 %21, label %24, label %22
22: ; preds = %15
%23 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.7, i64 0, i64 0))
br label %24
24: ; preds = %22, %15
%25 = call i64 @fclose(i32* %7)
%26 = icmp eq i64 %25, 0
br i1 %26, label %30, label %27
27: ; preds = %24, %0
%28 = phi i8* [ getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0), %0 ], [ getelementptr inbounds ([30 x i8], [30 x i8]* @.str.8, i64 0, i64 0), %24 ]
%29 = call i32 @printf(i8* dereferenceable(1) %28)
br label %30
30: ; preds = %27, %24
%31 = call i32 @exit(i32 0)
unreachable
}