#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*/ buffer;

/* Variables and functions */
int EXIT_FAILURE;
int bmount(char *);
int bumount();
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int mi_read(char *, char *, int, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char **argv) {
  if (argc != 3) {
    printf("ERROR: mi_cat => main: Faltan argumentos!!! El número permitido de "
           "argumentos son 3. \n");
    exit(1);
  }
  if (bmount(argv[1]) == -1) {
    printf("ERROR: mi_cat => main: Error al abrir (bmount) el sistema de "
           "ficheros.\n");
    return (EXIT_FAILURE);
  }
  int bytes_leidos;
  char buffer[1024 * 4];
  int offset = 0;
  memset(buffer, 0, sizeof(buffer));
  while ((bytes_leidos = mi_read(argv[2], buffer, offset, sizeof(buffer))) >
         0) {
    write(1, buffer, bytes_leidos);
    offset += bytes_leidos;
    memset(buffer, 0, sizeof(buffer));
  }
  if (bumount() == -1) {
    printf("ERROR: mi_cat => main =>Error al desmontar(bumount) el sistema de "
           "ficheros.\n");
    exit(1);
  }
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1030,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11a9 <main+0x39>
lea    0xe66(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <bmount@plt>
cmp    $0xffffffff,%eax
jne    11dd <main+0x6d>
lea    0xe92(%rip),%rdi
call   1050 <printf@plt>
mov    0x2e0e(%rip),%rax
mov    (%rax),%eax
add    $0x1030,%rsp
pop    %rbp
ret
movl   $0x0,-0x1024(%rbp)
lea    -0x1020(%rbp),%rdi
xor    %esi,%esi
mov    $0x1000,%edx
call   1070 <memset@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    -0x1020(%rbp),%rsi
mov    -0x1024(%rbp),%edx
mov    $0x1000,%ecx
call   1030 <mi_read@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jle    1260 <main+0xf0>
lea    -0x1020(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    $0x1,%edi
call   1040 <write@plt>
mov    -0x14(%rbp),%eax
add    -0x1024(%rbp),%eax
mov    %eax,-0x1024(%rbp)
lea    -0x1020(%rbp),%rdi
xor    %esi,%esi
mov    $0x1000,%edx
call   1070 <memset@plt>
jmp    11fa <main+0x8a>
mov    $0x0,%al
call   1060 <bumount@plt>
cmp    $0xffffffff,%eax
jne    1286 <main+0x116>
lea    0xe29(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
xor    %edi,%edi
call   1090 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x1008,%rsp
cmp    $0x3,%edi
jne    11b6 <main+0x46>
mov    %rsi,%r15
mov    0x8(%rsi),%rdi
call   1080 <bmount@plt>
cmp    $0xffffffff,%eax
jne    11bf <main+0x4f>
lea    0xeb2(%rip),%rdi
call   1040 <puts@plt>
mov    0x2e3a(%rip),%rax
mov    (%rax),%eax
add    $0x1008,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xed6(%rip),%rdi
jmp    123c <main+0xcc>
mov    %rsp,%rbx
xor    %ebp,%ebp
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x1000,%edx
call   1070 <memset@plt>
mov    0x10(%r15),%rdi
mov    %rbx,%rsi
xor    %edx,%edx
mov    $0x1000,%ecx
call   1030 <mi_read@plt>
test   %eax,%eax
jle    1229 <main+0xb9>
mov    %eax,%ebx
mov    %rsp,%r14
nop
mov    $0x1,%edi
mov    %r14,%rsi
mov    %ebx,%edx
call   1050 <write@plt>
add    %ebx,%ebp
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x1000,%edx
call   1070 <memset@plt>
mov    0x10(%r15),%rdi
mov    %r14,%rsi
mov    %ebp,%edx
mov    $0x1000,%ecx
call   1030 <mi_read@plt>
mov    %eax,%ebx
test   %eax,%eax
jg     11f0 <main+0x80>
xor    %eax,%eax
call   1060 <bumount@plt>
cmp    $0xffffffff,%eax
jne    124b <main+0xdb>
lea    0xdc4(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
xor    %edi,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [88 x i8] c"ERROR: mi_cat => main: Faltan argumentos!!! El n\C3\BAmero permitido de argumentos son 3. \0A\00"
@.str.1 = [72 x i8] c"ERROR: mi_cat => main: Error al abrir (bmount) el sistema de ficheros.\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [77 x i8] c"ERROR: mi_cat => main =>Error al desmontar(bumount) el sistema de ficheros.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [4096 x i8]
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 3
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = call i32 @printf(i8* getelementptr inbounds ([88 x i8], [88 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i32 @bmount(i8* %17)
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %23
20: ; preds = %14
%21 = call i32 @printf(i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str.1, i64 0, i64 0))
%22 = load i32, i32* @EXIT_FAILURE
ret i32 %22
23: ; preds = %14
store i32 0, i32* %8
%24 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%25 = call i32 @memset(i8* %24, i32 0, i32 4096)
br label %26
26: ; preds = %34, %23
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 2
%29 = load i8*, i8** %28
%30 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%31 = load i32, i32* %8
%32 = call i32 @mi_read(i8* %29, i8* %30, i32 %31, i32 4096)
store i32 %32, i32* %6
%33 = icmp sgt i32 %32, 0
br i1 %33, label %34, label %43
34: ; preds = %26
%35 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%36 = load i32, i32* %6
%37 = call i32 @write(i32 1, i8* %35, i32 %36)
%38 = load i32, i32* %6
%39 = load i32, i32* %8
%40 = add nsw i32 %39, %38
store i32 %40, i32* %8
%41 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%42 = call i32 @memset(i8* %41, i32 0, i32 4096)
br label %26
43: ; preds = %26
%44 = call i32 (...) @bumount()
%45 = icmp eq i32 %44, -1
br i1 %45, label %46, label %49
46: ; preds = %43
%47 = call i32 @printf(i8* getelementptr inbounds ([77 x i8], [77 x i8]* @.str.2, i64 0, i64 0))
%48 = call i32 @exit(i32 1)
unreachable
49: ; preds = %43
%50 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
@str = [76 x i8] c"ERROR: mi_cat => main =>Error al desmontar(bumount) el sistema de ficheros.\00"
@str.3 = [71 x i8] c"ERROR: mi_cat => main: Error al abrir (bmount) el sistema de ficheros.\00"
@str.4 = [87 x i8] c"ERROR: mi_cat => main: Faltan argumentos!!! El n\C3\BAmero permitido de argumentos son 3. \00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [4096 x i8]
%4 = icmp eq i32 %0, 3
br i1 %4, label %8, label %5
5: ; preds = %2
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([87 x i8], [87 x i8]* @str.4, i64 0, i64 0))
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32 @bmount(i8* %10)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %16
13: ; preds = %8
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([71 x i8], [71 x i8]* @str.3, i64 0, i64 0))
%15 = load i32, i32* @EXIT_FAILURE
ret i32 %15
16: ; preds = %8
%17 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%18 = call i32 @memset(i8* %17, i32 0, i32 4096)
%19 = getelementptr inbounds i8*, i8** %1, i64 2
%20 = load i8*, i8** %19
%21 = call i32 @mi_read(i8* %20, i8* %17, i32 0, i32 4096)
%22 = icmp sgt i32 %21, 0
br i1 %22, label %23, label %32
23: ; preds = %16, %23
%24 = phi i32 [ %30, %23 ], [ %21, %16 ]
%25 = phi i32 [ %27, %23 ], [ 0, %16 ]
%26 = call i32 @write(i32 1, i8* %17, i32 %24)
%27 = add nsw i32 %24, %25
%28 = call i32 @memset(i8* %17, i32 0, i32 4096)
%29 = load i8*, i8** %19
%30 = call i32 @mi_read(i8* %29, i8* %17, i32 %27, i32 4096)
%31 = icmp sgt i32 %30, 0
br i1 %31, label %23, label %32
32: ; preds = %23, %16
%33 = call i32 (...) @bumount()
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %38
35: ; preds = %32
%36 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([76 x i8], [76 x i8]* @str, i64 0, i64 0))
%37 = call i32 @exit(i32 1)
unreachable
38: ; preds = %32
%39 = call i32 @exit(i32 0)
unreachable
}