#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 */
unsigned int atoi(char const *);
int /*<<< orphan*/ bmount(char const *);
int /*<<< orphan*/ bumount();
int /*<<< orphan*/ bwrite(int, unsigned char *);
int /*<<< orphan*/ initAI(unsigned int);
int /*<<< orphan*/ initMB(unsigned int);
int /*<<< orphan*/ initSB(unsigned int, unsigned int);
int /*<<< orphan*/ memset(unsigned char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ reservar_inodo(char, int);
int main(int argc, char const *argv[]) {
  if (argc != 3) {
    puts("Uso: mi_mkfs <nombre_fichero> <cantidad_bloques>");
    return -1;
  }
  bmount(argv[1]);
  unsigned int nbloques = atoi(argv[2]);
  unsigned char buf[1024];
  memset(buf, 0, 1024);
  for (int i = 0; i < nbloques; ++i)
    bwrite(i, buf);
  unsigned int ninodos = nbloques / 4;
  initSB(nbloques, ninodos);
  initMB(nbloques);
  initAI(ninodos);
  reservar_inodo('d', 7);
  bumount();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11db <main+0x3b>
lea    0xe36(%rip),%rdi
call   1030 <puts@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1294 <main+0xf4>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <bmount@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10c0 <atoi@plt>
mov    %eax,-0x14(%rbp)
lea    -0x420(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1060 <memset@plt>
movl   $0x0,-0x424(%rbp)
mov    -0x424(%rbp),%eax
cmp    -0x14(%rbp),%eax
jae    124a <main+0xaa>
mov    -0x424(%rbp),%edi
lea    -0x420(%rbp),%rsi
call   1040 <bwrite@plt>
mov    -0x424(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x424(%rbp)
jmp    1215 <main+0x75>
mov    -0x14(%rbp),%eax
shr    $0x2,%eax
mov    %eax,-0x428(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x428(%rbp),%esi
call   10b0 <initSB@plt>
mov    -0x14(%rbp),%edi
call   10a0 <initMB@plt>
mov    -0x428(%rbp),%edi
call   1080 <initAI@plt>
mov    $0x64,%edi
mov    $0x7,%esi
call   1090 <reservar_inodo@plt>
mov    $0x0,%al
call   1050 <bumount@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x400,%rsp
cmp    $0x3,%edi
jne    1227 <main+0x87>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
call   1070 <bmount@plt>
mov    0x10(%rbx),%rdi
call   10c0 <atoi@plt>
mov    %eax,%ebx
mov    %rsp,%rdi
xor    %ebp,%ebp
xor    %esi,%esi
mov    $0x400,%edx
call   1060 <memset@plt>
test   %ebx,%ebx
je     11f1 <main+0x51>
mov    %rsp,%r14
nop
mov    %ebp,%edi
mov    %r14,%rsi
call   1040 <bwrite@plt>
add    $0x1,%ebp
cmp    %ebp,%ebx
jne    11e0 <main+0x40>
mov    %ebx,%ebp
shr    $0x2,%ebp
mov    %ebx,%edi
mov    %ebp,%esi
call   10b0 <initSB@plt>
mov    %ebx,%edi
call   10a0 <initMB@plt>
mov    %ebp,%edi
call   1080 <initAI@plt>
mov    $0x64,%edi
mov    $0x7,%esi
call   1090 <reservar_inodo@plt>
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <bumount@plt>
jmp    1238 <main+0x98>
lea    0xdd2(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [49 x i8] c"Uso: mi_mkfs <nombre_fichero> <cantidad_bloques>\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [1024 x i8]
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 3
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = call i32 @puts(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %48
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 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 2
%21 = load i8*, i8** %20
%22 = call i32 @atoi(i8* %21)
store i32 %22, i32* %6
%23 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%24 = call i32 @memset(i8* %23, i32 0, i32 1024)
store i32 0, i32* %8
br label %25
25: ; preds = %33, %14
%26 = load i32, i32* %8
%27 = load i32, i32* %6
%28 = icmp ult i32 %26, %27
br i1 %28, label %29, label %36
29: ; preds = %25
%30 = load i32, i32* %8
%31 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%32 = call i32 @bwrite(i32 %30, i8* %31)
br label %33
33: ; preds = %29
%34 = load i32, i32* %8
%35 = add nsw i32 %34, 1
store i32 %35, i32* %8
br label %25
36: ; preds = %25
%37 = load i32, i32* %6
%38 = udiv i32 %37, 4
store i32 %38, i32* %9
%39 = load i32, i32* %6
%40 = load i32, i32* %9
%41 = call i32 @initSB(i32 %39, i32 %40)
%42 = load i32, i32* %6
%43 = call i32 @initMB(i32 %42)
%44 = load i32, i32* %9
%45 = call i32 @initAI(i32 %44)
%46 = call i32 @reservar_inodo(i8 signext 100, i32 7)
%47 = call i32 (...) @bumount()
store i32 0, i32* %3
br label %48
48: ; preds = %36, %12
%49 = load i32, i32* %3
ret i32 %49
}

LLVM IR (-O2):
@.str = [49 x i8] c"Uso: mi_mkfs <nombre_fichero> <cantidad_bloques>\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 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 ([49 x i8], [49 x i8]* @.str, i64 0, i64 0))
br label %29
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32 @bmount(i8* %9)
%11 = getelementptr inbounds i8*, i8** %1, i64 2
%12 = load i8*, i8** %11
%13 = tail call i32 @atoi(i8* %12)
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%15 = call i32 @memset(i8* %14, i32 0, i32 1024)
%16 = icmp eq i32 %13, 0
br i1 %16, label %17, label %24
17: ; preds = %24, %7
%18 = lshr i32 %13, 2
%19 = call i32 @initSB(i32 %13, i32 %18)
%20 = call i32 @initMB(i32 %13)
%21 = call i32 @initAI(i32 %18)
%22 = call i32 @reservar_inodo(i8 signext 100, i32 7)
%23 = call i32 (...) @bumount()
br label %29
24: ; preds = %7, %24
%25 = phi i32 [ %27, %24 ], [ 0, %7 ]
%26 = call i32 @bwrite(i32 %25, i8* %14)
%27 = add nuw i32 %25, 1
%28 = icmp eq i32 %27, %13
br i1 %28, label %17, label %24
29: ; preds = %17, %5
%30 = phi i32 [ -1, %5 ], [ 0, %17 ]
ret i32 %30
}