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

/* Variables and functions */
int /*<<< orphan*/ bmount(char const *);
int /*<<< orphan*/ bumount();
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, unsigned int);
int mi_read(char const *, char *, unsigned int, unsigned int);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ sprintf(char *, char *, unsigned int);
int strlen(char *);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char const *argv[]) {
  if (argc != 3) {
    puts("Uso: mi_leer <nombre_dispositivo> <pathname>");
    return -1;
  }
  const char *camino = argv[2];
  unsigned int tamBuffer = 1024;
  unsigned int offset = 0, bytesLeidos = 0;
  char buffer[tamBuffer];
  bmount(argv[1]);
  memset(buffer, 0, tamBuffer);
  int respuesta = mi_read(camino, buffer, offset, tamBuffer);
  while (respuesta > 0) {
    write(1, buffer, respuesta);
    bytesLeidos += respuesta;
    offset += tamBuffer;
    memset(buffer, 0, tamBuffer);
    respuesta = mi_read(camino, buffer, offset, tamBuffer);
  }
  char infobuff[100];
  sprintf(infobuff, "%d bytes leidos\n", bytesLeidos);
  write(2, infobuff, strlen(infobuff));
  bumount();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11bb <main+0x3b>
lea    0xe56(%rip),%rdi
call   1040 <puts@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12f3 <main+0x173>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x18(%rbp)
movl   $0x400,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x1c(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0xa8(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1090 <bmount@plt>
mov    -0xa8(%rbp),%rdi
mov    -0x1c(%rbp),%edx
xor    %esi,%esi
call   1080 <memset@plt>
mov    -0xa8(%rbp),%rsi
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%edx
mov    -0x1c(%rbp),%ecx
call   1030 <mi_read@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0x0,-0x3c(%rbp)
jle    129b <main+0x11b>
mov    -0xa8(%rbp),%rsi
mov    -0x3c(%rbp),%edx
mov    $0x1,%edi
call   1050 <write@plt>
mov    -0xa8(%rbp),%rdi
mov    -0x3c(%rbp),%eax
add    -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x1c(%rbp),%eax
add    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%edx
xor    %esi,%esi
call   1080 <memset@plt>
mov    -0xa8(%rbp),%rsi
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%edx
mov    -0x1c(%rbp),%ecx
call   1030 <mi_read@plt>
mov    %eax,-0x3c(%rbp)
jmp    123c <main+0xbc>
lea    -0xa0(%rbp),%rdi
mov    -0x24(%rbp),%edx
lea    0xd81(%rip),%rsi
call   10a0 <sprintf@plt>
lea    -0xa0(%rbp),%rax
mov    %rax,-0xb0(%rbp)
lea    -0xa0(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0xb0(%rbp),%rsi
mov    %eax,%edx
mov    $0x2,%edi
call   1050 <write@plt>
mov    $0x0,%al
call   1070 <bumount@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x78,%rsp
cmp    $0x3,%edi
jne    1270 <main+0xf0>
mov    %rsp,-0x30(%rbp)
mov    0x10(%rsi),%r15
mov    %rsp,%r12
add    $0xfffffffffffffc00,%r12
mov    %r12,%rsp
mov    0x8(%rsi),%rdi
call   1090 <bmount@plt>
mov    $0x400,%ebx
mov    %r12,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1080 <memset@plt>
mov    %r15,%rdi
mov    %r12,%rsi
xor    %edx,%edx
mov    $0x400,%ecx
call   1030 <mi_read@plt>
mov    $0x0,%r13d
test   %eax,%eax
jle    1231 <main+0xb1>
mov    %eax,%r14d
xor    %r13d,%r13d
xchg   %ax,%ax
mov    $0x1,%edi
mov    %r12,%rsi
mov    %r14d,%edx
call   1050 <write@plt>
add    %r14d,%r13d
mov    %r12,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1080 <memset@plt>
mov    %r15,%rdi
mov    %r12,%rsi
mov    %ebx,%edx
mov    $0x400,%ecx
call   1030 <mi_read@plt>
mov    %eax,%r14d
add    $0x400,%ebx
test   %eax,%eax
jg     11f0 <main+0x70>
lea    0xdf5(%rip),%rsi
lea    -0xa0(%rbp),%rbx
mov    %rbx,%rdi
mov    %r13d,%edx
call   10a0 <sprintf@plt>
mov    %rbx,%rdi
call   1060 <strlen@plt>
mov    $0x2,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1050 <write@plt>
xor    %eax,%eax
call   1070 <bumount@plt>
mov    -0x30(%rbp),%rsp
xor    %eax,%eax
jmp    1281 <main+0x101>
lea    0xd89(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [45 x i8] c"Uso: mi_leer <nombre_dispositivo> <pathname>\00"
@.str.1 = [17 x i8] c"%d bytes leidos\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i64
%12 = alloca i32
%13 = alloca [100 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = load i32, i32* %4
%15 = icmp ne i32 %14, 3
br i1 %15, label %16, label %18
16: ; preds = %2
%17 = call i32 @puts(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %64
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 2
%21 = load i8*, i8** %20
store i8* %21, i8** %6
store i32 1024, i32* %7
store i32 0, i32* %8
store i32 0, i32* %9
%22 = load i32, i32* %7
%23 = zext i32 %22 to i64
%24 = call i8* @llvm.stacksave()
store i8* %24, i8** %10
%25 = alloca i8, i64 %23
store i64 %23, i64* %11
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = call i32 @bmount(i8* %28)
%30 = load i32, i32* %7
%31 = call i32 @memset(i8* %25, i32 0, i32 %30)
%32 = load i8*, i8** %6
%33 = load i32, i32* %8
%34 = load i32, i32* %7
%35 = call i32 @mi_read(i8* %32, i8* %25, i32 %33, i32 %34)
store i32 %35, i32* %12
br label %36
36: ; preds = %39, %18
%37 = load i32, i32* %12
%38 = icmp sgt i32 %37, 0
br i1 %38, label %39, label %54
39: ; preds = %36
%40 = load i32, i32* %12
%41 = call i32 @write(i32 1, i8* %25, i32 %40)
%42 = load i32, i32* %12
%43 = load i32, i32* %9
%44 = add i32 %43, %42
store i32 %44, i32* %9
%45 = load i32, i32* %7
%46 = load i32, i32* %8
%47 = add i32 %46, %45
store i32 %47, i32* %8
%48 = load i32, i32* %7
%49 = call i32 @memset(i8* %25, i32 0, i32 %48)
%50 = load i8*, i8** %6
%51 = load i32, i32* %8
%52 = load i32, i32* %7
%53 = call i32 @mi_read(i8* %50, i8* %25, i32 %51, i32 %52)
store i32 %53, i32* %12
br label %36
54: ; preds = %36
%55 = getelementptr inbounds [100 x i8], [100 x i8]* %13, i64 0, i64 0
%56 = load i32, i32* %9
%57 = call i32 @sprintf(i8* %55, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %56)
%58 = getelementptr inbounds [100 x i8], [100 x i8]* %13, i64 0, i64 0
%59 = getelementptr inbounds [100 x i8], [100 x i8]* %13, i64 0, i64 0
%60 = call i32 @strlen(i8* %59)
%61 = call i32 @write(i32 2, i8* %58, i32 %60)
%62 = call i32 (...) @bumount()
store i32 0, i32* %3
%63 = load i8*, i8** %10
br label %64
64: ; preds = %54, %16
%65 = load i32, i32* %3
ret i32 %65
}

LLVM IR (-O2):
@.str = [45 x i8] c"Uso: mi_leer <nombre_dispositivo> <pathname>\00"
@.str.1 = [17 x i8] c"%d bytes leidos\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [100 x i8]
%4 = icmp eq i32 %0, 3
br i1 %4, label %7, label %5
5: ; preds = %2
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0))
br label %36
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 2
%9 = load i8*, i8** %8
%10 = tail call i8* @llvm.stacksave()
%11 = alloca [1024 x i8]
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = tail call i32 @bmount(i8* %14)
%16 = call i32 @memset(i8* %12, i32 0, i32 1024)
%17 = call i32 @mi_read(i8* %9, i8* %12, i32 0, i32 1024)
%18 = icmp sgt i32 %17, 0
br i1 %18, label %19, label %29
19: ; preds = %7, %19
%20 = phi i32 [ %27, %19 ], [ %17, %7 ]
%21 = phi i32 [ %25, %19 ], [ 0, %7 ]
%22 = phi i32 [ %24, %19 ], [ 0, %7 ]
%23 = call i32 @write(i32 1, i8* %12, i32 %20)
%24 = add i32 %20, %22
%25 = add i32 %21, 1024
%26 = call i32 @memset(i8* %12, i32 0, i32 1024)
%27 = call i32 @mi_read(i8* %9, i8* %12, i32 %25, i32 1024)
%28 = icmp sgt i32 %27, 0
br i1 %28, label %19, label %29
29: ; preds = %19, %7
%30 = phi i32 [ 0, %7 ], [ %24, %19 ]
%31 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%32 = call i32 @sprintf(i8* %31, i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %30)
%33 = call i32 @strlen(i8* %31)
%34 = call i32 @write(i32 2, i8* %31, i32 %33)
%35 = call i32 (...) @bumount()
br label %36
36: ; preds = %29, %5
%37 = phi i32 [ -1, %5 ], [ 0, %29 ]
ret i32 %37
}