#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 short atoi(char *);
int bmount(char *);
int bumount();
int /*<<< orphan*/ exit(int);
int mi_chmod(char *, unsigned short);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sem_del();
int /*<<< orphan*/ sem_init();
int main(int argc, char *argv[]) {
  unsigned short int mode;
  if (argc != 4) {
    printf("[mi_chmod.c] ERROR: Arguments incorrectes. Ex: mi_chmod <nomFS> "
           "<cami> <permissos_nous>\n");
    exit(-1);
  }
  sem_init();
  if (bmount(argv[1]) == -1) {
    sem_del();
    return -1;
  }
  mode = atoi(argv[3]);
  if (mi_chmod(argv[2], mode) != -1) {
    printf("\n[mi_chmod.c] INFO: Permisos canviats correctament\n\n");
  }
  if (bumount() == -1) {
    sem_del();
    return -1;
  }
  sem_del();
  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   $0x4,-0x8(%rbp)
je     11b6 <main+0x36>
lea    0xe59(%rip),%rdi
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
mov    $0x0,%al
call   1070 <sem_init@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <bmount@plt>
cmp    $0xffffffff,%eax
jne    11e6 <main+0x66>
mov    $0x0,%al
call   1030 <sem_del@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    124e <main+0xce>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1080 <atoi@plt>
mov    %ax,-0x12(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
movzwl -0x12(%rbp),%esi
call   10a0 <mi_chmod@plt>
cmp    $0xffffffff,%eax
je     121d <main+0x9d>
lea    0xe41(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1050 <bumount@plt>
cmp    $0xffffffff,%eax
jne    1240 <main+0xc0>
mov    $0x0,%al
call   1030 <sem_del@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    124e <main+0xce>
mov    $0x0,%al
call   1030 <sem_del@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
cmp    $0x4,%edi
jne    11ee <main+0x6e>
mov    %rsi,%rbx
xor    %eax,%eax
call   1070 <sem_init@plt>
mov    0x8(%rbx),%rdi
call   1060 <bmount@plt>
cmp    $0xffffffff,%eax
je     11de <main+0x5e>
mov    0x18(%rbx),%rdi
call   1080 <atoi@plt>
mov    0x10(%rbx),%rdi
movzwl %ax,%esi
call   10a0 <mi_chmod@plt>
cmp    $0xffffffff,%eax
je     11c4 <main+0x44>
lea    0xe41(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1050 <bumount@plt>
xor    %ebx,%ebx
cmp    $0xffffffff,%eax
sete   %bl
xor    %eax,%eax
call   1040 <sem_del@plt>
neg    %ebx
jmp    11ea <main+0x6a>
xor    %eax,%eax
call   1040 <sem_del@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
pop    %rbx
ret
lea    0xe3f(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [89 x i8] c"[mi_chmod.c] ERROR: Arguments incorrectes. Ex: mi_chmod <nomFS> <cami> <permissos_nous>\0A\00"
@.str.1 = [53 x i8] c"\0A[mi_chmod.c] INFO: Permisos canviats correctament\0A\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i16
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* %4
%8 = icmp ne i32 %7, 4
br i1 %8, label %9, label %12
9: ; preds = %2
%10 = call i32 @printf(i8* getelementptr inbounds ([89 x i8], [89 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @exit(i32 -1)
unreachable
12: ; preds = %2
%13 = call i32 (...) @sem_init()
%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 %21
19: ; preds = %12
%20 = call i32 (...) @sem_del()
store i32 -1, i32* %3
br label %41
21: ; preds = %12
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 3
%24 = load i8*, i8** %23
%25 = call zeroext i16 @atoi(i8* %24)
store i16 %25, i16* %6
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 2
%28 = load i8*, i8** %27
%29 = load i16, i16* %6
%30 = call i32 @mi_chmod(i8* %28, i16 zeroext %29)
%31 = icmp ne i32 %30, -1
br i1 %31, label %32, label %34
32: ; preds = %21
%33 = call i32 @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.1, i64 0, i64 0))
br label %34
34: ; preds = %32, %21
%35 = call i32 (...) @bumount()
%36 = icmp eq i32 %35, -1
br i1 %36, label %37, label %39
37: ; preds = %34
%38 = call i32 (...) @sem_del()
store i32 -1, i32* %3
br label %41
39: ; preds = %34
%40 = call i32 (...) @sem_del()
store i32 0, i32* %3
br label %41
41: ; preds = %39, %37, %19
%42 = load i32, i32* %3
ret i32 %42
}

LLVM IR (-O2):
@str = [52 x i8] c"\0A[mi_chmod.c] INFO: Permisos canviats correctament\0A\00"
@str.2 = [88 x i8] c"[mi_chmod.c] ERROR: Arguments incorrectes. Ex: mi_chmod <nomFS> <cami> <permissos_nous>\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 4
br i1 %3, label %7, label %4
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([88 x i8], [88 x i8]* @str.2, i64 0, i64 0))
%6 = tail call i32 @exit(i32 -1)
unreachable
7: ; preds = %2
%8 = tail call i32 (...) @sem_init()
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32 @bmount(i8* %10)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %15
13: ; preds = %7
%14 = tail call i32 (...) @sem_del()
br label %30
15: ; preds = %7
%16 = getelementptr inbounds i8*, i8** %1, i64 3
%17 = load i8*, i8** %16
%18 = tail call zeroext i16 @atoi(i8* %17)
%19 = getelementptr inbounds i8*, i8** %1, i64 2
%20 = load i8*, i8** %19
%21 = tail call i32 @mi_chmod(i8* %20, i16 zeroext %18)
%22 = icmp eq i32 %21, -1
br i1 %22, label %25, label %23
23: ; preds = %15
%24 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @str, i64 0, i64 0))
br label %25
25: ; preds = %23, %15
%26 = tail call i32 (...) @bumount()
%27 = icmp eq i32 %26, -1
%28 = tail call i32 (...) @sem_del()
%29 = sext i1 %27 to i32
br label %30
30: ; preds = %25, %13
%31 = phi i32 [ -1, %13 ], [ %29, %25 ]
ret i32 %31
}