#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(
        "[RWBits.c] ERROR: Arguments incorrectes. Ex: RWBits disco.imagen\n");
    exit(-1);
  }
  if (bmount(argv[1]) == -1) {
    return -1;
  }
  int b;
  if ((b = reservarBloc()) == -1) {
    return -1;
  }
  printf("Bloc reservat: %d\n", b);
  int c;
  if ((c = llegirBit(b)) == -1) {
    return -1;
  }
  printf("Bit llegit: %d\n", c);
  int d;
  if ((d = alliberarBloc(b)) == -1) {
    return -1;
  }
  printf("Bloc alliberat: %d\n", d);
  int e;
  if ((e = llegirBit(b)) == -1) {
    return -1;
  }
  printf("Bit llegit: %d\n", e);
  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    12b0 <main+0x140>
mov    $0x0,%al
call   1080 <reservarBloc@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    11e9 <main+0x79>
movl   $0xffffffff,-0x4(%rbp)
jmp    12b0 <main+0x140>
mov    -0x14(%rbp),%esi
lea    0xe4f(%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    121a <main+0xaa>
movl   $0xffffffff,-0x4(%rbp)
jmp    12b0 <main+0x140>
mov    -0x18(%rbp),%esi
lea    0xe31(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%edi
call   1030 <alliberarBloc@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0xffffffff,%eax
jne    124b <main+0xdb>
movl   $0xffffffff,-0x4(%rbp)
jmp    12b0 <main+0x140>
mov    -0x1c(%rbp),%esi
lea    0xe10(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%edi
call   1060 <llegirBit@plt>
mov    %eax,-0x20(%rbp)
cmp    $0xffffffff,%eax
jne    127c <main+0x10c>
movl   $0xffffffff,-0x4(%rbp)
jmp    12b0 <main+0x140>
mov    -0x20(%rbp),%esi
lea    0xdcf(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1050 <bumount@plt>
cmp    $0xffffffff,%eax
jne    12a9 <main+0x139>
movl   $0xffffffff,-0x4(%rbp)
jmp    12b0 <main+0x140>
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    122f <main+0xaf>
mov    0x8(%rsi),%rdi
call   1080 <bmount@plt>
mov    $0xffffffff,%ebx
cmp    $0xffffffff,%eax
je     1226 <main+0xa6>
xor    %eax,%eax
call   1090 <reservarBloc@plt>
cmp    $0xffffffff,%eax
je     1226 <main+0xa6>
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     1226 <main+0xa6>
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     1226 <main+0xa6>
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     1226 <main+0xa6>
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
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe01(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [66 x i8] c"[RWBits.c] ERROR: Arguments incorrectes. Ex: RWBits 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
%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, 2
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @exit(i32 -1)
unreachable
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i32 @bmount(i8* %18)
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %22
21: ; preds = %15
store i32 -1, i32* %3
br label %54
22: ; preds = %15
%23 = call i32 (...) @reservarBloc()
store i32 %23, i32* %6
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %26
25: ; preds = %22
store i32 -1, i32* %3
br label %54
26: ; preds = %22
%27 = load i32, i32* %6
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %27)
%29 = load i32, i32* %6
%30 = call i32 @llegirBit(i32 %29)
store i32 %30, i32* %7
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %33
32: ; preds = %26
store i32 -1, i32* %3
br label %54
33: ; preds = %26
%34 = load i32, i32* %7
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 %34)
%36 = load i32, i32* %6
%37 = call i32 @alliberarBloc(i32 %36)
store i32 %37, i32* %8
%38 = icmp eq i32 %37, -1
br i1 %38, label %39, label %40
39: ; preds = %33
store i32 -1, i32* %3
br label %54
40: ; preds = %33
%41 = load i32, i32* %8
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i32 %41)
%43 = load i32, i32* %6
%44 = call i32 @llegirBit(i32 %43)
store i32 %44, i32* %9
%45 = icmp eq i32 %44, -1
br i1 %45, label %46, label %47
46: ; preds = %40
store i32 -1, i32* %3
br label %54
47: ; preds = %40
%48 = load i32, i32* %9
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 %48)
%50 = call i32 (...) @bumount()
%51 = icmp eq i32 %50, -1
br i1 %51, label %52, label %53
52: ; preds = %47
store i32 -1, i32* %3
br label %54
53: ; preds = %47
store i32 0, i32* %3
br label %54
54: ; preds = %53, %52, %46, %39, %32, %25, %21
%55 = load i32, i32* %3
ret i32 %55
}

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 = [65 x i8] c"[RWBits.c] ERROR: Arguments incorrectes. Ex: RWBits 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 ([65 x i8], [65 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 %32, label %12
12: ; preds = %7
%13 = tail call i32 (...) @reservarBloc()
%14 = icmp eq i32 %13, -1
br i1 %14, label %32, label %15
15: ; preds = %12
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %13)
%17 = tail call i32 @llegirBit(i32 %13)
%18 = icmp eq i32 %17, -1
br i1 %18, label %32, label %19
19: ; preds = %15
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 %17)
%21 = tail call i32 @alliberarBloc(i32 %13)
%22 = icmp eq i32 %21, -1
br i1 %22, label %32, label %23
23: ; preds = %19
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i32 %21)
%25 = tail call i32 @llegirBit(i32 %13)
%26 = icmp eq i32 %25, -1
br i1 %26, label %32, label %27
27: ; preds = %23
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 %25)
%29 = tail call i32 (...) @bumount()
%30 = icmp eq i32 %29, -1
%31 = sext i1 %30 to i32
br label %32
32: ; preds = %12, %19, %27, %23, %15, %7
%33 = phi i32 [ -1, %7 ], [ -1, %12 ], [ -1, %15 ], [ -1, %19 ], [ -1, %23 ], [ %31, %27 ]
ret i32 %33
}