#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 uint;

/* Variables and functions */
int alliberarInode(int);
int /*<<< orphan*/ atoi(char *);
int bmount(char *);
int bumount();
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ printf(char *, ...);
int reservarInode(int, int);
int traduirBlocInode(int, int /*<<< orphan*/, int *, int);
int main(int argc, char *argv[]) {
  uint bfisic = 0;
  if (argc != 3) {
    printf("[traduir.c] ERROR: Arguments incorrectes. Ex: ./traduir "
           "disco.imagen <num_bloc>\n");
    exit(-1);
  }
  if (bmount(argv[1]) == -1) {
    return -1;
  }
  int r;
  r = reservarInode(2, 7);
  if (r == -1) {
    printf("[traduir.c] ERROR: falla reservarInode()\n");
    bumount();
    return -1;
  }
  printf("[traduir.c] INFO: Inode reservat: %d\n", r);
  if (traduirBlocInode(r, atoi(argv[2]), &bfisic, 1) == -1) {
    printf("[traduir.c] ERROR: falla traduir_bloc_inode\n");
    bumount();
    return -1;
  }
  printf("[traduir.c] INFO: bloc fisic = %d\n", bfisic);
  if (alliberarInode(r) == -1) {
    printf("[traduir.c] ERROR: falla alliberarInode()\n");
    bumount();
    return -1;
  }
  if (bumount() == -1) {
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11bf <main+0x3f>
lea    0xe52(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <bmount@plt>
cmp    $0xffffffff,%eax
jne    11e1 <main+0x61>
movl   $0xffffffff,-0x4(%rbp)
jmp    12e5 <main+0x165>
mov    $0x2,%edi
mov    $0x7,%esi
call   10a0 <reservarInode@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    121e <main+0x9e>
lea    0xe4d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1040 <bumount@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12e5 <main+0x165>
mov    -0x18(%rbp),%esi
lea    0xe53(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1070 <atoi@plt>
mov    -0x1c(%rbp),%edi
mov    %eax,%esi
lea    -0x14(%rbp),%rdx
mov    $0x1,%ecx
call   1090 <traduirBlocInode@plt>
cmp    $0xffffffff,%eax
jne    127f <main+0xff>
lea    0xe3c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1040 <bumount@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12e5 <main+0x165>
mov    -0x14(%rbp),%esi
lea    0xe45(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%edi
call   1060 <alliberarInode@plt>
cmp    $0xffffffff,%eax
jne    12c2 <main+0x142>
lea    0xe49(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1040 <bumount@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12e5 <main+0x165>
mov    $0x0,%al
call   1040 <bumount@plt>
cmp    $0xffffffff,%eax
jne    12de <main+0x15e>
movl   $0xffffffff,-0x4(%rbp)
jmp    12e5 <main+0x165>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
movl   $0x0,0xc(%rsp)
cmp    $0x3,%edi
jne    1270 <main+0xe0>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
call   1060 <bmount@plt>
mov    $0xffffffff,%r14d
cmp    $0xffffffff,%eax
je     1264 <main+0xd4>
mov    $0x2,%edi
mov    $0x7,%esi
call   10b0 <reservarInode@plt>
cmp    $0xffffffff,%eax
je     123f <main+0xaf>
mov    %eax,%ebp
lea    0xe1f(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x10(%rbx),%rdi
call   1080 <atoi@plt>
lea    0xc(%rsp),%rdx
mov    %ebp,%edi
mov    %eax,%esi
mov    $0x1,%ecx
call   10a0 <traduirBlocInode@plt>
cmp    $0xffffffff,%eax
je     1248 <main+0xb8>
mov    0xc(%rsp),%esi
lea    0xe10(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebp,%edi
call   1070 <alliberarInode@plt>
cmp    $0xffffffff,%eax
je     1251 <main+0xc1>
xor    %eax,%eax
call   1050 <bumount@plt>
xor    %r14d,%r14d
cmp    $0xffffffff,%eax
sete   %r14b
neg    %r14d
jmp    1264 <main+0xd4>
lea    0xe59(%rip),%rdi
jmp    1258 <main+0xc8>
lea    0xe24(%rip),%rdi
jmp    1258 <main+0xc8>
lea    0xdf1(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1050 <bumount@plt>
mov    %r14d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe51(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [81 x i8] c"[traduir.c] ERROR: Arguments incorrectes. Ex: ./traduir disco.imagen <num_bloc>\0A\00"
@.str.1 = [42 x i8] c"[traduir.c] ERROR: falla reservarInode()\0A\00"
@.str.2 = [38 x i8] c"[traduir.c] INFO: Inode reservat: %d\0A\00"
@.str.3 = [45 x i8] c"[traduir.c] ERROR: falla traduir_bloc_inode\0A\00"
@.str.4 = [35 x i8] c"[traduir.c] INFO: bloc fisic = %d\0A\00"
@.str.5 = [43 x i8] c"[traduir.c] ERROR: falla alliberarInode()\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 3
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([81 x i8], [81 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @exit(i32 -1)
unreachable
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = call i32 @bmount(i8* %16)
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %20
19: ; preds = %13
store i32 -1, i32* %3
br label %54
20: ; preds = %13
%21 = call i32 @reservarInode(i32 2, i32 7)
store i32 %21, i32* %7
%22 = load i32, i32* %7
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %27
24: ; preds = %20
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0))
%26 = call i32 (...) @bumount()
store i32 -1, i32* %3
br label %54
27: ; preds = %20
%28 = load i32, i32* %7
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i32 %28)
%30 = load i32, i32* %7
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 2
%33 = load i8*, i8** %32
%34 = call i32 @atoi(i8* %33)
%35 = call i32 @traduirBlocInode(i32 %30, i32 %34, i32* %6, i32 1)
%36 = icmp eq i32 %35, -1
br i1 %36, label %37, label %40
37: ; preds = %27
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.3, i64 0, i64 0))
%39 = call i32 (...) @bumount()
store i32 -1, i32* %3
br label %54
40: ; preds = %27
%41 = load i32, i32* %6
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0), i32 %41)
%43 = load i32, i32* %7
%44 = call i32 @alliberarInode(i32 %43)
%45 = icmp eq i32 %44, -1
br i1 %45, label %46, label %49
46: ; preds = %40
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.5, i64 0, i64 0))
%48 = call i32 (...) @bumount()
store i32 -1, i32* %3
br label %54
49: ; preds = %40
%50 = call i32 (...) @bumount()
%51 = icmp eq i32 %50, -1
br i1 %51, label %52, label %53
52: ; preds = %49
store i32 -1, i32* %3
br label %54
53: ; preds = %49
store i32 0, i32* %3
br label %54
54: ; preds = %53, %52, %46, %37, %24, %19
%55 = load i32, i32* %3
ret i32 %55
}

LLVM IR (-O2):
@.str.2 = [38 x i8] c"[traduir.c] INFO: Inode reservat: %d\0A\00"
@.str.4 = [35 x i8] c"[traduir.c] INFO: bloc fisic = %d\0A\00"
@str = [42 x i8] c"[traduir.c] ERROR: falla alliberarInode()\00"
@str.6 = [44 x i8] c"[traduir.c] ERROR: falla traduir_bloc_inode\00"
@str.7 = [41 x i8] c"[traduir.c] ERROR: falla reservarInode()\00"
@str.8 = [80 x i8] c"[traduir.c] ERROR: Arguments incorrectes. Ex: ./traduir disco.imagen <num_bloc>\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%5 = icmp eq i32 %0, 3
br i1 %5, label %9, label %6
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([80 x i8], [80 x i8]* @str.8, i64 0, i64 0))
%8 = tail call i32 @exit(i32 -1)
unreachable
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32 @bmount(i8* %11)
%13 = icmp eq i32 %12, -1
br i1 %13, label %42, label %14
14: ; preds = %9
%15 = tail call i32 @reservarInode(i32 2, i32 7)
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %20
17: ; preds = %14
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @str.7, i64 0, i64 0))
%19 = tail call i32 (...) @bumount()
br label %42
20: ; preds = %14
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i32 %15)
%22 = getelementptr inbounds i8*, i8** %1, i64 2
%23 = load i8*, i8** %22
%24 = tail call i32 @atoi(i8* %23)
%25 = call i32 @traduirBlocInode(i32 %15, i32 %24, i32* %3, i32 1)
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %30
27: ; preds = %20
%28 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @str.6, i64 0, i64 0))
%29 = call i32 (...) @bumount()
br label %42
30: ; preds = %20
%31 = load i32, i32* %3
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0), i32 %31)
%33 = call i32 @alliberarInode(i32 %15)
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %38
35: ; preds = %30
%36 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @str, i64 0, i64 0))
%37 = call i32 (...) @bumount()
br label %42
38: ; preds = %30
%39 = call i32 (...) @bumount()
%40 = icmp eq i32 %39, -1
%41 = sext i1 %40 to i32
br label %42
42: ; preds = %17, %27, %35, %38, %9
%43 = phi i32 [ -1, %9 ], [ -1, %17 ], [ -1, %27 ], [ -1, %35 ], [ %41, %38 ]
ret i32 %43
}