#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 bmount(char *);
int bumount();
int buscar_entrada(char *, unsigned int *, unsigned int *, unsigned int *, char,
                   unsigned char);
int /*<<< orphan*/ mi_read_f(unsigned int, unsigned char *, int /*<<< orphan*/,
                             int);
scalar_t__ mi_write_f(unsigned int, char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ write(int, unsigned char *, int);
int main(int argc, char **argv) {
  if (argc != 3) {
    printf("ERROR: escribir.c => main: Faltan argumentos!!! El número "
           "permitido de argumentos son 3. \n");
    return -1;
  } else {
    if (bmount(argv[1]) == -1) {
      printf("ERROR: escribir.c => main: Error al abrir (bmount) el sistema de "
             "ficheros.\n");
      return -1;
    }
    char *buffer = "Esto es una prueba";
    unsigned int p_inodo_dir;
    unsigned int p_entrada;
    unsigned int p_inodo;
    char reservar = 1;
    unsigned char modo = 1;
    int resultado_busqueda = buscar_entrada(argv[2], &p_inodo_dir, &p_inodo,
                                            &p_entrada, reservar, modo);
    if (resultado_busqueda == -1) {
      printf("ERROR: escribir_fichero.c => main=> Error al buscar la entrada");
    } else {
      if (mi_write_f(p_inodo, buffer, 0, sizeof(buffer)) < 0) {
        printf("ERROR: escribir_fichero.c => main=> Error al escribir en el "
               "fichero");
      } else {
        unsigned char leido[sizeof(buffer)];
        mi_read_f(p_inodo, leido, 0, sizeof(buffer));
        write(1, leido, 19);
      }
    }
    if (bumount() == -1) {
      printf("ERROR: escribir_fichero.c => main =>Error al cerrar(bumount) el "
             "sistema de ficheros.\n");
      return -1;
    }
  }
  return 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11a8 <main+0x38>
lea    0xe69(%rip),%rdi
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12b9 <main+0x149>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <bmount@plt>
cmp    $0xffffffff,%eax
jne    11d6 <main+0x66>
lea    0xe97(%rip),%rdi
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12b9 <main+0x149>
lea    0xecb(%rip),%rax
mov    %rax,-0x18(%rbp)
movb   $0x1,-0x25(%rbp)
movb   $0x1,-0x26(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    -0x25(%rbp),%al
lea    -0x1c(%rbp),%rsi
lea    -0x24(%rbp),%rdx
lea    -0x20(%rbp),%rcx
movsbl %al,%r8d
movzbl -0x26(%rbp),%r9d
call   1090 <buscar_entrada@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0xffffffff,-0x2c(%rbp)
jne    122c <main+0xbc>
lea    0xe99(%rip),%rdi
call   1060 <printf@plt>
jmp    1285 <main+0x115>
mov    -0x24(%rbp),%edi
mov    -0x18(%rbp),%rsi
xor    %edx,%edx
mov    $0x8,%ecx
call   1050 <mi_write_f@plt>
cmp    $0x0,%rax
jge    125a <main+0xea>
lea    0xeaa(%rip),%rdi
call   1060 <printf@plt>
jmp    1280 <main+0x110>
mov    -0x24(%rbp),%edi
lea    -0x34(%rbp),%rsi
xor    %edx,%edx
mov    $0x8,%ecx
call   1030 <mi_read_f@plt>
lea    -0x34(%rbp),%rsi
mov    $0x1,%edi
mov    $0x13,%edx
call   1040 <write@plt>
jmp    1285 <main+0x115>
mov    $0x0,%al
call   1070 <bumount@plt>
cmp    $0xffffffff,%eax
jne    12ad <main+0x13d>
lea    0xea2(%rip),%rdi
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12b9 <main+0x149>
jmp    12b2 <main+0x142>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x20,%rsp
cmp    $0x3,%edi
jne    1210 <main+0x90>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
call   1090 <bmount@plt>
cmp    $0xffffffff,%eax
je     1219 <main+0x99>
mov    0x10(%rbx),%rdi
lea    0x14(%rsp),%rsi
lea    0xc(%rsp),%rdx
lea    0x10(%rsp),%rcx
mov    $0x1,%r8d
mov    $0x1,%r9d
call   10a0 <buscar_entrada@plt>
cmp    $0xffffffff,%eax
je     1222 <main+0xa2>
mov    0xc(%rsp),%edi
lea    0xe2d(%rip),%rsi
xor    %edx,%edx
mov    $0x8,%ecx
call   1060 <mi_write_f@plt>
test   %rax,%rax
js     122b <main+0xab>
mov    0xc(%rsp),%edi
lea    0x18(%rsp),%rbx
mov    %rbx,%rsi
xor    %edx,%edx
mov    $0x8,%ecx
call   1030 <mi_read_f@plt>
mov    $0x1,%edi
mov    %rbx,%rsi
mov    $0x13,%edx
call   1050 <write@plt>
jmp    1237 <main+0xb7>
lea    0xf1f(%rip),%rdi
jmp    1251 <main+0xd1>
lea    0xecb(%rip),%rdi
jmp    1251 <main+0xd1>
lea    0xdea(%rip),%rdi
jmp    1232 <main+0xb2>
lea    0xe20(%rip),%rdi
call   1070 <printf@plt>
xor    %eax,%eax
call   1080 <bumount@plt>
mov    %eax,%ecx
mov    $0x1,%eax
cmp    $0xffffffff,%ecx
jne    125b <main+0xdb>
lea    0xe45(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%eax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [92 x i8] c"ERROR: escribir.c => main: Faltan argumentos!!! El n\C3\BAmero permitido de argumentos son 3. \0A\00"
@.str.1 = [76 x i8] c"ERROR: escribir.c => main: Error al abrir (bmount) el sistema de ficheros.\0A\00"
@.str.2 = [19 x i8] c"Esto es una prueba\00"
@.str.3 = [63 x i8] c"ERROR: escribir_fichero.c => main=> Error al buscar la entrada\00"
@.str.4 = [68 x i8] c"ERROR: escribir_fichero.c => main=> Error al escribir en el fichero\00"
@.str.5 = [86 x i8] c"ERROR: escribir_fichero.c => main =>Error al cerrar(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 i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8
%11 = alloca i8
%12 = alloca i32
%13 = alloca [8 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 @printf(i8* getelementptr inbounds ([92 x i8], [92 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %58
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call i32 @bmount(i8* %21)
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %26
24: ; preds = %18
%25 = call i32 @printf(i8* getelementptr inbounds ([76 x i8], [76 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %58
26: ; preds = %18
store i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8** %6
store i8 1, i8* %10
store i8 1, i8* %11
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 2
%29 = load i8*, i8** %28
%30 = load i8, i8* %10
%31 = load i8, i8* %11
%32 = call i32 @buscar_entrada(i8* %29, i32* %7, i32* %9, i32* %8, i8 signext %30, i8 zeroext %31)
store i32 %32, i32* %12
%33 = load i32, i32* %12
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %37
35: ; preds = %26
%36 = call i32 @printf(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.3, i64 0, i64 0))
br label %51
37: ; preds = %26
%38 = load i32, i32* %9
%39 = load i8*, i8** %6
%40 = call i64 @mi_write_f(i32 %38, i8* %39, i32 0, i32 8)
%41 = icmp slt i64 %40, 0
br i1 %41, label %42, label %44
42: ; preds = %37
%43 = call i32 @printf(i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str.4, i64 0, i64 0))
br label %50
44: ; preds = %37
%45 = load i32, i32* %9
%46 = getelementptr inbounds [8 x i8], [8 x i8]* %13, i64 0, i64 0
%47 = call i32 @mi_read_f(i32 %45, i8* %46, i32 0, i32 8)
%48 = getelementptr inbounds [8 x i8], [8 x i8]* %13, i64 0, i64 0
%49 = call i32 @write(i32 1, i8* %48, i32 19)
br label %50
50: ; preds = %44, %42
br label %51
51: ; preds = %50, %35
%52 = call i32 (...) @bumount()
%53 = icmp eq i32 %52, -1
br i1 %53, label %54, label %56
54: ; preds = %51
%55 = call i32 @printf(i8* getelementptr inbounds ([86 x i8], [86 x i8]* @.str.5, i64 0, i64 0))
store i32 -1, i32* %3
br label %58
56: ; preds = %51
br label %57
57: ; preds = %56
store i32 1, i32* %3
br label %58
58: ; preds = %57, %54, %24, %16
%59 = load i32, i32* %3
ret i32 %59
}

LLVM IR (-O2):
@.str.2 = [19 x i8] c"Esto es una prueba\00"
@.str.3 = [63 x i8] c"ERROR: escribir_fichero.c => main=> Error al buscar la entrada\00"
@.str.4 = [68 x i8] c"ERROR: escribir_fichero.c => main=> Error al escribir en el fichero\00"
@str = [85 x i8] c"ERROR: escribir_fichero.c => main =>Error al cerrar(bumount) el sistema de ficheros.\00"
@str.6 = [75 x i8] c"ERROR: escribir.c => main: Error al abrir (bmount) el sistema de ficheros.\00"
@str.7 = [91 x i8] c"ERROR: escribir.c => main: Faltan argumentos!!! El n\C3\BAmero permitido de argumentos son 3. \00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [8 x i8]
%7 = icmp eq i32 %0, 3
br i1 %7, label %10, label %8
8: ; preds = %2
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([91 x i8], [91 x i8]* @str.7, i64 0, i64 0))
br label %45
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i32 @bmount(i8* %12)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %17
15: ; preds = %10
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([75 x i8], [75 x i8]* @str.6, i64 0, i64 0))
br label %45
17: ; preds = %10
%18 = bitcast i32* %3 to i8*
%19 = bitcast i32* %4 to i8*
%20 = bitcast i32* %5 to i8*
%21 = getelementptr inbounds i8*, i8** %1, i64 2
%22 = load i8*, i8** %21
%23 = call i32 @buscar_entrada(i8* %22, i32* %3, i32* %5, i32* %4, i8 signext 1, i8 zeroext 1)
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %27
25: ; preds = %17
%26 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([63 x i8], [63 x i8]* @.str.3, i64 0, i64 0))
br label %38
27: ; preds = %17
%28 = load i32, i32* %5
%29 = call i64 @mi_write_f(i32 %28, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 0, i32 8)
%30 = icmp slt i64 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %27
%32 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([68 x i8], [68 x i8]* @.str.4, i64 0, i64 0))
br label %38
33: ; preds = %27
%34 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 0
%35 = load i32, i32* %5
%36 = call i32 @mi_read_f(i32 %35, i8* %34, i32 0, i32 8)
%37 = call i32 @write(i32 1, i8* %34, i32 19)
br label %38
38: ; preds = %31, %33, %25
%39 = call i32 (...) @bumount()
%40 = icmp eq i32 %39, -1
br i1 %40, label %41, label %43
41: ; preds = %38
%42 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([85 x i8], [85 x i8]* @str, i64 0, i64 0))
br label %43
43: ; preds = %38, %41
%44 = phi i32 [ 1, %38 ], [ -1, %41 ]
br label %45
45: ; preds = %43, %15, %8
%46 = phi i32 [ -1, %8 ], [ -1, %15 ], [ %44, %43 ]
ret i32 %46
}