#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 EXIT_FAILURE;
int EXIT_SUCCESS;
unsigned int atoi(char *);
int bmount(char *);
int bumount();
int bwrite(int, char *);
int initAI(unsigned int);
int initMB(unsigned int);
int initSB(unsigned int, unsigned int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char **argv) {
  char buffer[1024];
  unsigned int cantidad_bloques = atoi(argv[2]);
  unsigned int cantidad_inodos = cantidad_bloques / 4;
  if (argc != 3) {
    printf("ERROR: mi_mkfs => main: Faltan argumentos!!! El número permitido "
           "de argumentos son 3. \n");
    return (EXIT_FAILURE);
  } else {
    if (cantidad_bloques <= 0) {
      printf("ERROR: mi_mkfs => main: Números de bloques incorrectos (menor o "
             "igual a 0)\n");
      return (EXIT_FAILURE);
    } else {
      if (bmount(argv[1]) == -1) {
        printf("ERROR: mi_mkfs => main: Error al montar (bmount) el sistema de "
               "ficheros.\n");
        return (EXIT_FAILURE);
      }
      printf("El nombre del Sistema de Ficheros es: %s \n", argv[1]);
      memset(buffer, 0, 1024);
      int i;
      for (i = 0; i < cantidad_bloques; i++) {
        if (bwrite(i, buffer) == -1) {
          printf("ERROR: mi_mkfs => main: Error al ejecutar el bwrite para "
                 "inicializar el bloque del sistema %i\n",
                 i);
          return (EXIT_FAILURE);
        }
      }
      if (initSB(cantidad_bloques, cantidad_inodos) == -1) {
        printf("ERROR: mi_mkfs => main: No se ha podido inicializar el "
               "superbloque\n");
        return (EXIT_FAILURE);
      }
      if (initMB(cantidad_bloques) == -1) {
        printf("ERROR: mi_mkfs => main: No se ha podido inicializar el mapa de "
               "bits\n");
        return (EXIT_FAILURE);
      }
      if (initAI(cantidad_inodos) == -1) {
        printf("ERROR: mi_mkfs => main: No se ha podido inicializar el array "
               "de inodos\n");
        return (EXIT_FAILURE);
      }
      if (bumount() == -1) {
        printf("ERROR: mi_mkfs => main =>Error al desmontar(bumount) el "
               "sistema de ficheros.\n");
        return (EXIT_FAILURE);
      }
    }
  }
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10b0 <atoi@plt>
mov    %eax,-0x414(%rbp)
mov    -0x414(%rbp),%eax
shr    $0x2,%eax
mov    %eax,-0x418(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11f4 <main+0x64>
lea    0xe24(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2df6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    13d7 <main+0x247>
cmpl   $0x0,-0x414(%rbp)
ja     1220 <main+0x90>
lea    0xe51(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2dca(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    13d7 <main+0x247>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <bmount@plt>
cmp    $0xffffffff,%eax
jne    1255 <main+0xc5>
lea    0xe69(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2d95(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    13d7 <main+0x247>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe8c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x410(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1060 <memset@plt>
movl   $0x0,-0x41c(%rbp)
mov    -0x41c(%rbp),%eax
cmp    -0x414(%rbp),%eax
jae    12f3 <main+0x163>
mov    -0x41c(%rbp),%edi
lea    -0x410(%rbp),%rsi
call   1030 <bwrite@plt>
cmp    $0xffffffff,%eax
jne    12da <main+0x14a>
mov    -0x41c(%rbp),%esi
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2d10(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    13d7 <main+0x247>
jmp    12df <main+0x14f>
mov    -0x41c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x41c(%rbp)
jmp    1288 <main+0xf8>
mov    -0x414(%rbp),%edi
mov    -0x418(%rbp),%esi
call   10a0 <initSB@plt>
cmp    $0xffffffff,%eax
jne    132c <main+0x19c>
lea    0xe66(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2cbe(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    13d7 <main+0x247>
mov    -0x414(%rbp),%edi
call   1090 <initMB@plt>
cmp    $0xffffffff,%eax
jne    135f <main+0x1cf>
lea    0xe77(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2c8b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    13d7 <main+0x247>
mov    -0x418(%rbp),%edi
call   1080 <initAI@plt>
cmp    $0xffffffff,%eax
jne    1392 <main+0x202>
lea    0xe89(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2c58(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    13d7 <main+0x247>
mov    $0x0,%al
call   1050 <bumount@plt>
cmp    $0xffffffff,%eax
jne    13c1 <main+0x231>
lea    0xea2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2c29(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    13d7 <main+0x247>
jmp    13c6 <main+0x236>
jmp    13cb <main+0x23b>
mov    0x2c06(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x408,%rsp
mov    %rsi,%r15
mov    %edi,%ebp
mov    0x10(%rsi),%rdi
call   10c0 <atoi@plt>
cmp    $0x3,%ebp
jne    1263 <main+0xc3>
mov    %eax,%ebx
test   %eax,%eax
je     126c <main+0xcc>
mov    0x8(%r15),%rdi
call   1080 <bmount@plt>
cmp    $0xffffffff,%eax
je     1275 <main+0xd5>
mov    %ebx,%r14d
shr    $0x2,%r14d
mov    0x8(%r15),%rsi
lea    0xe0e(%rip),%rdi
xor    %ebp,%ebp
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rsp,%r15
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1070 <memset@plt>
nopl   (%rax)
mov    %ebp,%edi
mov    %r15,%rsi
call   1040 <bwrite@plt>
cmp    $0xffffffff,%eax
je     127e <main+0xde>
add    $0x1,%ebp
cmp    %ebp,%ebx
jne    1210 <main+0x70>
mov    %ebx,%edi
mov    %r14d,%esi
call   10b0 <initSB@plt>
cmp    $0xffffffff,%eax
je     1290 <main+0xf0>
mov    %ebx,%edi
call   10a0 <initMB@plt>
cmp    $0xffffffff,%eax
je     1299 <main+0xf9>
mov    %r14d,%edi
call   1090 <initAI@plt>
cmp    $0xffffffff,%eax
je     12a2 <main+0x102>
xor    %eax,%eax
call   1060 <bumount@plt>
cmp    $0xffffffff,%eax
je     12ab <main+0x10b>
mov    0x2d77(%rip),%rax
jmp    12be <main+0x11e>
lea    0xfd0(%rip),%rdi
jmp    12b2 <main+0x112>
lea    0xf7b(%rip),%rdi
jmp    12b2 <main+0x112>
lea    0xf29(%rip),%rdi
jmp    12b2 <main+0x112>
lea    0xda6(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    12b7 <main+0x117>
lea    0xecb(%rip),%rdi
jmp    12b2 <main+0x112>
lea    0xe7e(%rip),%rdi
jmp    12b2 <main+0x112>
lea    0xe2e(%rip),%rdi
jmp    12b2 <main+0x112>
lea    0xdd8(%rip),%rdi
call   1030 <puts@plt>
mov    0x2d22(%rip),%rax
mov    (%rax),%eax
add    $0x408,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [89 x i8] c"ERROR: mi_mkfs => main: Faltan argumentos!!! El n\C3\BAmero permitido de argumentos son 3. \0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [77 x i8] c"ERROR: mi_mkfs => main: N\C3\BAmeros de bloques incorrectos (menor o igual a 0)\0A\00"
@.str.2 = [74 x i8] c"ERROR: mi_mkfs => main: Error al montar (bmount) el sistema de ficheros.\0A\00"
@.str.3 = [43 x i8] c"El nombre del Sistema de Ficheros es: %s \0A\00"
@.str.4 = [95 x i8] c"ERROR: mi_mkfs => main: Error al ejecutar el bwrite para inicializar el bloque del sistema %i\0A\00"
@.str.5 = [68 x i8] c"ERROR: mi_mkfs => main: No se ha podido inicializar el superbloque\0A\00"
@.str.6 = [69 x i8] c"ERROR: mi_mkfs => main: No se ha podido inicializar el mapa de bits\0A\00"
@.str.7 = [72 x i8] c"ERROR: mi_mkfs => main: No se ha podido inicializar el array de inodos\0A\00"
@.str.8 = [78 x i8] c"ERROR: mi_mkfs => main =>Error al desmontar(bumount) el sistema de ficheros.\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [1024 x i8]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i8**, i8*** %5
%11 = getelementptr inbounds i8*, i8** %10, i64 2
%12 = load i8*, i8** %11
%13 = call i32 @atoi(i8* %12)
store i32 %13, i32* %7
%14 = load i32, i32* %7
%15 = udiv i32 %14, 4
store i32 %15, i32* %8
%16 = load i32, i32* %4
%17 = icmp ne i32 %16, 3
br i1 %17, label %18, label %21
18: ; preds = %2
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([89 x i8], [89 x i8]* @.str, i64 0, i64 0))
%20 = load i32, i32* @EXIT_FAILURE
store i32 %20, i32* %3
br label %92
21: ; preds = %2
%22 = load i32, i32* %7
%23 = icmp ule i32 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %21
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([77 x i8], [77 x i8]* @.str.1, i64 0, i64 0))
%26 = load i32, i32* @EXIT_FAILURE
store i32 %26, i32* %3
br label %92
27: ; preds = %21
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 1
%30 = load i8*, i8** %29
%31 = call i32 @bmount(i8* %30)
%32 = icmp eq i32 %31, -1
br i1 %32, label %33, label %36
33: ; preds = %27
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([74 x i8], [74 x i8]* @.str.2, i64 0, i64 0))
%35 = load i32, i32* @EXIT_FAILURE
store i32 %35, i32* %3
br label %92
36: ; preds = %27
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 1
%39 = load i8*, i8** %38
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.3, i64 0, i64 0), i8* %39)
%41 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%42 = call i32 @memset(i8* %41, i32 0, i32 1024)
store i32 0, i32* %9
br label %43
43: ; preds = %57, %36
%44 = load i32, i32* %9
%45 = load i32, i32* %7
%46 = icmp ult i32 %44, %45
br i1 %46, label %47, label %60
47: ; preds = %43
%48 = load i32, i32* %9
%49 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%50 = call i32 @bwrite(i32 %48, i8* %49)
%51 = icmp eq i32 %50, -1
br i1 %51, label %52, label %56
52: ; preds = %47
%53 = load i32, i32* %9
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([95 x i8], [95 x i8]* @.str.4, i64 0, i64 0), i32 %53)
%55 = load i32, i32* @EXIT_FAILURE
store i32 %55, i32* %3
br label %92
56: ; preds = %47
br label %57
57: ; preds = %56
%58 = load i32, i32* %9
%59 = add nsw i32 %58, 1
store i32 %59, i32* %9
br label %43
60: ; preds = %43
%61 = load i32, i32* %7
%62 = load i32, i32* %8
%63 = call i32 @initSB(i32 %61, i32 %62)
%64 = icmp eq i32 %63, -1
br i1 %64, label %65, label %68
65: ; preds = %60
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str.5, i64 0, i64 0))
%67 = load i32, i32* @EXIT_FAILURE
store i32 %67, i32* %3
br label %92
68: ; preds = %60
%69 = load i32, i32* %7
%70 = call i32 @initMB(i32 %69)
%71 = icmp eq i32 %70, -1
br i1 %71, label %72, label %75
72: ; preds = %68
%73 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([69 x i8], [69 x i8]* @.str.6, i64 0, i64 0))
%74 = load i32, i32* @EXIT_FAILURE
store i32 %74, i32* %3
br label %92
75: ; preds = %68
%76 = load i32, i32* %8
%77 = call i32 @initAI(i32 %76)
%78 = icmp eq i32 %77, -1
br i1 %78, label %79, label %82
79: ; preds = %75
%80 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str.7, i64 0, i64 0))
%81 = load i32, i32* @EXIT_FAILURE
store i32 %81, i32* %3
br label %92
82: ; preds = %75
%83 = call i32 (...) @bumount()
%84 = icmp eq i32 %83, -1
br i1 %84, label %85, label %88
85: ; preds = %82
%86 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([78 x i8], [78 x i8]* @.str.8, i64 0, i64 0))
%87 = load i32, i32* @EXIT_FAILURE
store i32 %87, i32* %3
br label %92
88: ; preds = %82
br label %89
89: ; preds = %88
br label %90
90: ; preds = %89
%91 = load i32, i32* @EXIT_SUCCESS
store i32 %91, i32* %3
br label %92
92: ; preds = %90, %85, %79, %72, %65, %52, %33, %24, %18
%93 = load i32, i32* %3
ret i32 %93
}

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
@.str.3 = [43 x i8] c"El nombre del Sistema de Ficheros es: %s \0A\00"
@.str.4 = [95 x i8] c"ERROR: mi_mkfs => main: Error al ejecutar el bwrite para inicializar el bloque del sistema %i\0A\00"
@EXIT_SUCCESS = global i32 0
@str = [77 x i8] c"ERROR: mi_mkfs => main =>Error al desmontar(bumount) el sistema de ficheros.\00"
@str.9 = [71 x i8] c"ERROR: mi_mkfs => main: No se ha podido inicializar el array de inodos\00"
@str.10 = [68 x i8] c"ERROR: mi_mkfs => main: No se ha podido inicializar el mapa de bits\00"
@str.11 = [67 x i8] c"ERROR: mi_mkfs => main: No se ha podido inicializar el superbloque\00"
@str.12 = [73 x i8] c"ERROR: mi_mkfs => main: Error al montar (bmount) el sistema de ficheros.\00"
@str.13 = [76 x i8] c"ERROR: mi_mkfs => main: N\C3\BAmeros de bloques incorrectos (menor o igual a 0)\00"
@str.14 = [88 x i8] c"ERROR: mi_mkfs => main: Faltan argumentos!!! El n\C3\BAmero permitido de argumentos son 3. \00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = getelementptr inbounds i8*, i8** %1, i64 2
%6 = load i8*, i8** %5
%7 = tail call i32 @atoi(i8* %6)
%8 = lshr i32 %7, 2
%9 = icmp eq i32 %0, 3
br i1 %9, label %12, label %10
10: ; preds = %2
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([88 x i8], [88 x i8]* @str.14, i64 0, i64 0))
br label %56
12: ; preds = %2
%13 = icmp eq i32 %7, 0
br i1 %13, label %14, label %16
14: ; preds = %12
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([76 x i8], [76 x i8]* @str.13, i64 0, i64 0))
br label %56
16: ; preds = %12
%17 = getelementptr inbounds i8*, i8** %1, i64 1
%18 = load i8*, i8** %17
%19 = tail call i32 @bmount(i8* %18)
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %23
21: ; preds = %16
%22 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([73 x i8], [73 x i8]* @str.12, i64 0, i64 0))
br label %56
23: ; preds = %16
%24 = load i8*, i8** %17
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.3, i64 0, i64 0), i8* %24)
%26 = call i32 @memset(i8* %4, i32 0, i32 1024)
br label %27
27: ; preds = %23, %33
%28 = phi i32 [ %34, %33 ], [ 0, %23 ]
%29 = call i32 @bwrite(i32 %28, i8* %4)
%30 = icmp eq i32 %29, -1
br i1 %30, label %31, label %33
31: ; preds = %27
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([95 x i8], [95 x i8]* @.str.4, i64 0, i64 0), i32 %28)
br label %56
33: ; preds = %27
%34 = add nuw i32 %28, 1
%35 = icmp eq i32 %34, %7
br i1 %35, label %36, label %27
36: ; preds = %33
%37 = call i32 @initSB(i32 %7, i32 %8)
%38 = icmp eq i32 %37, -1
br i1 %38, label %39, label %41
39: ; preds = %36
%40 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([67 x i8], [67 x i8]* @str.11, i64 0, i64 0))
br label %56
41: ; preds = %36
%42 = call i32 @initMB(i32 %7)
%43 = icmp eq i32 %42, -1
br i1 %43, label %44, label %46
44: ; preds = %41
%45 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([68 x i8], [68 x i8]* @str.10, i64 0, i64 0))
br label %56
46: ; preds = %41
%47 = call i32 @initAI(i32 %8)
%48 = icmp eq i32 %47, -1
br i1 %48, label %49, label %51
49: ; preds = %46
%50 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([71 x i8], [71 x i8]* @str.9, i64 0, i64 0))
br label %56
51: ; preds = %46
%52 = call i32 (...) @bumount()
%53 = icmp eq i32 %52, -1
br i1 %53, label %54, label %56
54: ; preds = %51
%55 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([77 x i8], [77 x i8]* @str, i64 0, i64 0))
br label %56
56: ; preds = %51, %54, %49, %44, %39, %31, %21, %14, %10
%57 = phi i32* [ @EXIT_FAILURE, %10 ], [ @EXIT_FAILURE, %14 ], [ @EXIT_FAILURE, %21 ], [ @EXIT_FAILURE, %54 ], [ @EXIT_FAILURE, %49 ], [ @EXIT_FAILURE, %44 ], [ @EXIT_FAILURE, %39 ], [ @EXIT_FAILURE, %31 ], [ @EXIT_SUCCESS, %51 ]
%58 = load i32, i32* %57
ret i32 %58
}