#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*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
scalar_t__ ferror(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputc(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
main(int argc, char *argv[]) {
  FILE *des = NULL, *org = NULL;
  int conta = 0, car = 0;
  if (argc != 3) {
    printf("Sintaxis: copiar origen destino\n");
    exit(1);
  }
  if ((org = fopen(argv[1], "rb")) == NULL ||
      (des = fopen(argv[2], "wb")) == NULL) {
    printf("No se puede realizar la copia\n");
    exit(1);
  }
  while (!ferror(org) && !feof(org) && !ferror(des)) {
    car = fgetc(org);
    conta++;
    fputc(car, des);
  }
  if (ferror(org) || ferror(des))
    perror("Error durante la copia");
  else
    printf("Se han copiado %d caracteres\n", conta - 1);
  fclose(org);
  fclose(des);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11e6 <main+0x56>
lea    0xe2b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe2c(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     122a <main+0x9a>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe0d(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1242 <main+0xb2>
lea    0xdf6(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
jmp    1247 <main+0xb7>
mov    -0x20(%rbp),%rdi
call   1030 <ferror@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x29(%rbp)
jne    1290 <main+0x100>
mov    -0x20(%rbp),%rdi
call   1080 <feof@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x29(%rbp)
jne    1290 <main+0x100>
mov    -0x18(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
setne  %al
xor    $0xff,%al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    12a0 <main+0x110>
jmp    12c6 <main+0x136>
mov    -0x20(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x28(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1070 <fputc@plt>
jmp    1247 <main+0xb7>
mov    -0x20(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
jne    12ec <main+0x15c>
mov    -0x18(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     12fd <main+0x16d>
lea    0xd53(%rip),%rdi
call   10a0 <perror@plt>
jmp    1311 <main+0x181>
mov    -0x24(%rbp),%esi
sub    $0x1,%esi
lea    0xd53(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
cmp    $0x3,%edi
jne    12a7 <main+0x107>
mov    %rsi,%rbp
mov    0x8(%rsi),%rdi
lea    0xe45(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     129e <main+0xfe>
mov    %rax,%rbx
mov    0x10(%rbp),%rdi
lea    0xe2c(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     129e <main+0xfe>
mov    %rax,%r14
mov    %rbx,%rdi
call   1040 <ferror@plt>
xor    %ebp,%ebp
test   %rax,%rax
je     123f <main+0x9f>
mov    %rbx,%rdi
call   1040 <ferror@plt>
test   %rax,%rax
jne    1290 <main+0xf0>
mov    %r14,%rdi
call   1040 <ferror@plt>
test   %rax,%rax
jne    1290 <main+0xf0>
add    $0xffffffff,%ebp
lea    0xdfe(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    %r14,%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1090 <feof@plt>
test   %eax,%eax
jne    11f7 <main+0x57>
mov    %r14,%rdi
call   1040 <ferror@plt>
test   %rax,%rax
jne    11f7 <main+0x57>
mov    %rbx,%rdi
call   1070 <fgetc@plt>
add    $0x1,%ebp
mov    %eax,%edi
mov    %r14,%rsi
call   1080 <fputc@plt>
mov    %rbx,%rdi
call   1040 <ferror@plt>
test   %rax,%rax
je     1250 <main+0xb0>
jmp    11f7 <main+0x57>
lea    0xd6f(%rip),%rdi
call   10b0 <perror@plt>
jmp    1228 <main+0x88>
lea    0xd96(%rip),%rdi
jmp    12ae <main+0x10e>
lea    0xdab(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@.str = [33 x i8] c"Sintaxis: copiar origen destino\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [3 x i8] c"wb\00"
@.str.3 = [31 x i8] c"No se puede realizar la copia\0A\00"
@.str.4 = [23 x i8] c"Error durante la copia\00"
@.str.5 = [30 x i8] c"Se han copiado %d caracteres\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32* null, i32** %6
store i32* null, i32** %7
store i32 0, i32* %8
store i32 0, i32* %9
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 3
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i32* @fopen(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %19, i32** %7
%20 = icmp eq i32* %19, null
br i1 %20, label %27, label %21
21: ; preds = %15
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 2
%24 = load i8*, i8** %23
%25 = call i32* @fopen(i8* %24, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %25, i32** %6
%26 = icmp eq i32* %25, null
br i1 %26, label %27, label %30
27: ; preds = %21, %15
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0))
%29 = call i32 @exit(i32 1)
unreachable
30: ; preds = %21
br label %31
31: ; preds = %46, %30
%32 = load i32*, i32** %7
%33 = call i64 @ferror(i32* %32)
%34 = icmp ne i64 %33, 0
br i1 %34, label %44, label %35
35: ; preds = %31
%36 = load i32*, i32** %7
%37 = call i32 @feof(i32* %36)
%38 = icmp ne i32 %37, 0
br i1 %38, label %44, label %39
39: ; preds = %35
%40 = load i32*, i32** %6
%41 = call i64 @ferror(i32* %40)
%42 = icmp ne i64 %41, 0
%43 = xor i1 %42, true
br label %44
44: ; preds = %39, %35, %31
%45 = phi i1 [ false, %35 ], [ false, %31 ], [ %43, %39 ]
br i1 %45, label %46, label %54
46: ; preds = %44
%47 = load i32*, i32** %7
%48 = call i32 @fgetc(i32* %47)
store i32 %48, i32* %9
%49 = load i32, i32* %8
%50 = add nsw i32 %49, 1
store i32 %50, i32* %8
%51 = load i32, i32* %9
%52 = load i32*, i32** %6
%53 = call i32 @fputc(i32 %51, i32* %52)
br label %31
54: ; preds = %44
%55 = load i32*, i32** %7
%56 = call i64 @ferror(i32* %55)
%57 = icmp ne i64 %56, 0
br i1 %57, label %62, label %58
58: ; preds = %54
%59 = load i32*, i32** %6
%60 = call i64 @ferror(i32* %59)
%61 = icmp ne i64 %60, 0
br i1 %61, label %62, label %64
62: ; preds = %58, %54
%63 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
br label %68
64: ; preds = %58
%65 = load i32, i32* %8
%66 = sub nsw i32 %65, 1
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0), i32 %66)
br label %68
68: ; preds = %64, %62
%69 = load i32*, i32** %7
%70 = call i32 @fclose(i32* %69)
%71 = load i32*, i32** %6
%72 = call i32 @fclose(i32* %71)
%73 = load i32, i32* %3
ret i32 %73
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [3 x i8] c"wb\00"
@.str.4 = [23 x i8] c"Error durante la copia\00"
@.str.5 = [30 x i8] c"Se han copiado %d caracteres\0A\00"
@str = [30 x i8] c"No se puede realizar la copia\00"
@str.6 = [32 x i8] c"Sintaxis: copiar origen destino\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 3
br i1 %3, label %7, label %4
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str.6, i64 0, i64 0))
%6 = tail call i32 @exit(i32 1)
unreachable
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32* @fopen(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp eq i32* %10, null
br i1 %11, label %20, label %12
12: ; preds = %7
%13 = getelementptr inbounds i8*, i8** %1, i64 2
%14 = load i8*, i8** %13
%15 = tail call i32* @fopen(i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%16 = icmp eq i32* %15, null
br i1 %16, label %20, label %17
17: ; preds = %12
%18 = tail call i64 @ferror(i32* %10)
%19 = icmp eq i64 %18, 0
br i1 %19, label %23, label %36
20: ; preds = %12, %7
%21 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str, i64 0, i64 0))
%22 = tail call i32 @exit(i32 1)
unreachable
23: ; preds = %17, %30
%24 = phi i32 [ %32, %30 ], [ 0, %17 ]
%25 = tail call i32 @feof(i32* %10)
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %36
27: ; preds = %23
%28 = tail call i64 @ferror(i32* %15)
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %36
30: ; preds = %27
%31 = tail call i32 @fgetc(i32* %10)
%32 = add nuw nsw i32 %24, 1
%33 = tail call i32 @fputc(i32 %31, i32* %15)
%34 = tail call i64 @ferror(i32* %10)
%35 = icmp eq i64 %34, 0
br i1 %35, label %23, label %36
36: ; preds = %27, %23, %30, %17
%37 = phi i32 [ 0, %17 ], [ %32, %30 ], [ %24, %23 ], [ %24, %27 ]
%38 = tail call i64 @ferror(i32* %10)
%39 = icmp eq i64 %38, 0
br i1 %39, label %40, label %43
40: ; preds = %36
%41 = tail call i64 @ferror(i32* %15)
%42 = icmp eq i64 %41, 0
br i1 %42, label %45, label %43
43: ; preds = %40, %36
%44 = tail call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
br label %48
45: ; preds = %40
%46 = add nsw i32 %37, -1
%47 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0), i32 %46)
br label %48
48: ; preds = %45, %43
%49 = tail call i32 @fclose(i32* %10)
%50 = tail call i32 @fclose(i32* %15)
ret i32 0
}