#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 alliberarBloc(int);
int bmount(char *);
int bumount();
int /*<<< orphan*/ exit(int);
int llegirBit(int);
int /*<<< orphan*/ printf(char *, ...);
int reservarBloc();
int main(int argc, char *argv[]) {
  if (argc != 2) {
    printf(
        "[RWBlocs.c] ERROR: Arguments incorrectes. Ex: RWBlocs disco.imagen\n");
    exit(-1);
  }
  if (bmount(argv[1]) == -1) {
    return -1;
  }
  int b = -1;
  if ((b = reservarBloc()) == -1) {
    if (bumount() == -1) {
      return -1;
    }
    return -1;
  }
  printf("Bloc reservat: %d\n", b);
  int bit;
  if ((bit = llegirBit(b)) == -1) {
    return -1;
  }
  printf("Bit llegit: %d\n", bit);
  int d = -1;
  if ((d = alliberarBloc(b)) == -1) {
    return -1;
  }
  printf("Bloc alliberat: %d\n", d);
  bit = -1;
  if ((bit = llegirBit(b)) == -1) {
    return -1;
  }
  printf("Bit llegit: %d\n", bit);
  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)
cmpl   $0x2,-0x8(%rbp)
je     11a8 <main+0x38>
lea    0xe69(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <bmount@plt>
cmp    $0xffffffff,%eax
jne    11ca <main+0x5a>
movl   $0xffffffff,-0x4(%rbp)
jmp    12e1 <main+0x171>
movl   $0xffffffff,-0x14(%rbp)
mov    $0x0,%al
call   1080 <reservarBloc@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    120c <main+0x9c>
mov    $0x0,%al
call   1050 <bumount@plt>
cmp    $0xffffffff,%eax
jne    1200 <main+0x90>
movl   $0xffffffff,-0x4(%rbp)
jmp    12e1 <main+0x171>
movl   $0xffffffff,-0x4(%rbp)
jmp    12e1 <main+0x171>
mov    -0x14(%rbp),%esi
lea    0xe2e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%edi
call   1060 <llegirBit@plt>
mov    %eax,-0x18(%rbp)
cmp    $0xffffffff,%eax
jne    123d <main+0xcd>
movl   $0xffffffff,-0x4(%rbp)
jmp    12e1 <main+0x171>
mov    -0x18(%rbp),%esi
lea    0xe10(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x1c(%rbp)
mov    -0x14(%rbp),%edi
call   1030 <alliberarBloc@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0xffffffff,%eax
jne    1275 <main+0x105>
movl   $0xffffffff,-0x4(%rbp)
jmp    12e1 <main+0x171>
mov    -0x1c(%rbp),%esi
lea    0xde8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x18(%rbp)
mov    -0x14(%rbp),%edi
call   1060 <llegirBit@plt>
mov    %eax,-0x18(%rbp)
cmp    $0xffffffff,%eax
jne    12ad <main+0x13d>
movl   $0xffffffff,-0x4(%rbp)
jmp    12e1 <main+0x171>
mov    -0x18(%rbp),%esi
lea    0xda0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1050 <bumount@plt>
cmp    $0xffffffff,%eax
jne    12da <main+0x16a>
movl   $0xffffffff,-0x4(%rbp)
jmp    12e1 <main+0x171>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
cmp    $0x2,%edi
jne    1238 <main+0xb8>
mov    0x8(%rsi),%rdi
call   1080 <bmount@plt>
mov    $0xffffffff,%ebx
cmp    $0xffffffff,%eax
je     122f <main+0xaf>
xor    %eax,%eax
call   1090 <reservarBloc@plt>
cmp    $0xffffffff,%eax
je     1228 <main+0xa8>
mov    %eax,%ebp
lea    0xe48(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebp,%edi
call   1070 <llegirBit@plt>
cmp    $0xffffffff,%eax
je     122f <main+0xaf>
lea    0xe3f(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebp,%edi
call   1040 <alliberarBloc@plt>
cmp    $0xffffffff,%eax
je     122f <main+0xaf>
lea    0xe33(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebp,%edi
call   1070 <llegirBit@plt>
cmp    $0xffffffff,%eax
je     122f <main+0xaf>
lea    0xe07(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1060 <bumount@plt>
xor    %ebx,%ebx
cmp    $0xffffffff,%eax
sete   %bl
neg    %ebx
jmp    122f <main+0xaf>
xor    %eax,%eax
call   1060 <bumount@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xdf8(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [68 x i8] c"[RWBlocs.c] ERROR: Arguments incorrectes. Ex: RWBlocs disco.imagen\0A\00"
@.str.1 = [19 x i8] c"Bloc reservat: %d\0A\00"
@.str.2 = [16 x i8] c"Bit llegit: %d\0A\00"
@.str.3 = [20 x i8] c"Bloc alliberat: %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 2
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @exit(i32 -1)
unreachable
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 = icmp eq i32 %18, -1
br i1 %19, label %20, label %21
20: ; preds = %14
store i32 -1, i32* %3
br label %57
21: ; preds = %14
store i32 -1, i32* %6
%22 = call i32 (...) @reservarBloc()
store i32 %22, i32* %6
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %29
24: ; preds = %21
%25 = call i32 (...) @bumount()
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %28
27: ; preds = %24
store i32 -1, i32* %3
br label %57
28: ; preds = %24
store i32 -1, i32* %3
br label %57
29: ; preds = %21
%30 = load i32, i32* %6
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %30)
%32 = load i32, i32* %6
%33 = call i32 @llegirBit(i32 %32)
store i32 %33, i32* %7
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %36
35: ; preds = %29
store i32 -1, i32* %3
br label %57
36: ; preds = %29
%37 = load i32, i32* %7
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 %37)
store i32 -1, i32* %8
%39 = load i32, i32* %6
%40 = call i32 @alliberarBloc(i32 %39)
store i32 %40, i32* %8
%41 = icmp eq i32 %40, -1
br i1 %41, label %42, label %43
42: ; preds = %36
store i32 -1, i32* %3
br label %57
43: ; preds = %36
%44 = load i32, i32* %8
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i32 %44)
store i32 -1, i32* %7
%46 = load i32, i32* %6
%47 = call i32 @llegirBit(i32 %46)
store i32 %47, i32* %7
%48 = icmp eq i32 %47, -1
br i1 %48, label %49, label %50
49: ; preds = %43
store i32 -1, i32* %3
br label %57
50: ; preds = %43
%51 = load i32, i32* %7
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 %51)
%53 = call i32 (...) @bumount()
%54 = icmp eq i32 %53, -1
br i1 %54, label %55, label %56
55: ; preds = %50
store i32 -1, i32* %3
br label %57
56: ; preds = %50
store i32 0, i32* %3
br label %57
57: ; preds = %56, %55, %49, %42, %35, %28, %27, %20
%58 = load i32, i32* %3
ret i32 %58
}

LLVM IR (-O2):
@.str.1 = [19 x i8] c"Bloc reservat: %d\0A\00"
@.str.2 = [16 x i8] c"Bit llegit: %d\0A\00"
@.str.3 = [20 x i8] c"Bloc alliberat: %d\0A\00"
@str = [67 x i8] c"[RWBlocs.c] ERROR: Arguments incorrectes. Ex: RWBlocs disco.imagen\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %7, label %4
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([67 x i8], [67 x i8]* @str, i64 0, i64 0))
%6 = tail call i32 @exit(i32 -1)
unreachable
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32 @bmount(i8* %9)
%11 = icmp eq i32 %10, -1
br i1 %11, label %34, label %12
12: ; preds = %7
%13 = tail call i32 (...) @reservarBloc()
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = tail call i32 (...) @bumount()
br label %34
17: ; preds = %12
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %13)
%19 = tail call i32 @llegirBit(i32 %13)
%20 = icmp eq i32 %19, -1
br i1 %20, label %34, label %21
21: ; preds = %17
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 %19)
%23 = tail call i32 @alliberarBloc(i32 %13)
%24 = icmp eq i32 %23, -1
br i1 %24, label %34, label %25
25: ; preds = %21
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i32 %23)
%27 = tail call i32 @llegirBit(i32 %13)
%28 = icmp eq i32 %27, -1
br i1 %28, label %34, label %29
29: ; preds = %25
%30 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 %27)
%31 = tail call i32 (...) @bumount()
%32 = icmp eq i32 %31, -1
%33 = sext i1 %32 to i32
br label %34
34: ; preds = %15, %21, %25, %29, %17, %7
%35 = phi i32 [ -1, %7 ], [ -1, %15 ], [ -1, %17 ], [ -1, %21 ], [ -1, %25 ], [ %33, %29 ]
ret i32 %35
}