#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 atoi(char *);
int bmount(char *);
int bumount();
int /*<<< orphan*/ exit(int);
int mi_write(char *, char *, int, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sem_del();
int /*<<< orphan*/ sem_init();
int main(int argc, char *argv[]) {
  char *buff;
  int offset;
  int nbytes;
  if (argc != 6) {
    printf("[mi_write.c] ERROR: Arguments incorrectes. Ex: mi_write <nomFS> "
           "<cami> <buff> <offset> <nbytes>\n");
    exit(-1);
  }
  sem_init();
  if (bmount(argv[1]) == -1) {
    sem_del();
    return -1;
  }
  offset = atoi(argv[4]);
  nbytes = atoi(argv[5]);
  buff = argv[3];
  if (mi_write(argv[2], buff, offset, nbytes) == -1) {
    printf("[mi_write.c] ERROR: No s'ha pogut escriure!\n");
  } else {
    printf("[mi_write.c] INFO: S'ha escrit correctament.\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   $0x6,-0x8(%rbp)
je     11b6 <main+0x36>
lea    0xe59(%rip),%rdi
call   1050 <printf@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
mov    $0x0,%al
call   1080 <sem_init@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <bmount@plt>
cmp    $0xffffffff,%eax
jne    11e6 <main+0x66>
mov    $0x0,%al
call   1040 <sem_del@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1280 <main+0x100>
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x28(%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    -0x20(%rbp),%ecx
call   1030 <mi_write@plt>
cmp    $0xffffffff,%eax
jne    1243 <main+0xc3>
lea    0xe28(%rip),%rdi
call   1050 <printf@plt>
jmp    124f <main+0xcf>
lea    0xe44(%rip),%rdi
call   1050 <printf@plt>
mov    $0x0,%al
call   1060 <bumount@plt>
cmp    $0xffffffff,%eax
jne    1272 <main+0xf2>
mov    $0x0,%al
call   1040 <sem_del@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1280 <main+0x100>
mov    $0x0,%al
call   1040 <sem_del@plt>
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    $0x6,%edi
jne    1207 <main+0x87>
mov    %rsi,%rbx
xor    %eax,%eax
call   1080 <sem_init@plt>
mov    0x8(%rbx),%rdi
call   1070 <bmount@plt>
cmp    $0xffffffff,%eax
je     11f2 <main+0x72>
mov    0x20(%rbx),%rdi
call   1090 <atoi@plt>
mov    %eax,%ebp
mov    0x28(%rbx),%rdi
call   1090 <atoi@plt>
mov    0x10(%rbx),%rdi
mov    0x18(%rbx),%rsi
mov    %ebp,%edx
mov    %eax,%ecx
call   1040 <mi_write@plt>
cmp    $0xffffffff,%eax
lea    0xe5e(%rip),%rax
lea    0xe2a(%rip),%rdi
cmove  %rax,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1060 <bumount@plt>
xor    %ebx,%ebx
cmp    $0xffffffff,%eax
sete   %bl
neg    %ebx
jmp    11f7 <main+0x77>
mov    $0xffffffff,%ebx
xor    %eax,%eax
call   1050 <sem_del@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe4b(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [97 x i8] c"[mi_write.c] ERROR: Arguments incorrectes. Ex: mi_write <nomFS> <cami> <buff> <offset> <nbytes>\0A\00"
@.str.1 = [45 x i8] c"[mi_write.c] ERROR: No s'ha pogut escriure!\0A\00"
@.str.2 = [46 x i8] c"[mi_write.c] INFO: S'ha escrit correctament.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%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, 6
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = call i32 @printf(i8* getelementptr inbounds ([97 x i8], [97 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @exit(i32 -1)
unreachable
14: ; preds = %2
%15 = call i32 (...) @sem_init()
%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 %23
21: ; preds = %14
%22 = call i32 (...) @sem_del()
store i32 -1, i32* %3
br label %54
23: ; preds = %14
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 4
%26 = load i8*, i8** %25
%27 = call i32 @atoi(i8* %26)
store i32 %27, i32* %7
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 5
%30 = load i8*, i8** %29
%31 = call i32 @atoi(i8* %30)
store i32 %31, i32* %8
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 3
%34 = load i8*, i8** %33
store i8* %34, i8** %6
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 2
%37 = load i8*, i8** %36
%38 = load i8*, i8** %6
%39 = load i32, i32* %7
%40 = load i32, i32* %8
%41 = call i32 @mi_write(i8* %37, i8* %38, i32 %39, i32 %40)
%42 = icmp eq i32 %41, -1
br i1 %42, label %43, label %45
43: ; preds = %23
%44 = call i32 @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0))
br label %47
45: ; preds = %23
%46 = call i32 @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.2, i64 0, i64 0))
br label %47
47: ; preds = %45, %43
%48 = call i32 (...) @bumount()
%49 = icmp eq i32 %48, -1
br i1 %49, label %50, label %52
50: ; preds = %47
%51 = call i32 (...) @sem_del()
store i32 -1, i32* %3
br label %54
52: ; preds = %47
%53 = call i32 (...) @sem_del()
store i32 0, i32* %3
br label %54
54: ; preds = %52, %50, %21
%55 = load i32, i32* %3
ret i32 %55
}

LLVM IR (-O2):
@str = [45 x i8] c"[mi_write.c] INFO: S'ha escrit correctament.\00"
@str.3 = [44 x i8] c"[mi_write.c] ERROR: No s'ha pogut escriure!\00"
@str.4 = [96 x i8] c"[mi_write.c] ERROR: Arguments incorrectes. Ex: mi_write <nomFS> <cami> <buff> <offset> <nbytes>\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 6
br i1 %3, label %7, label %4
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([96 x i8], [96 x i8]* @str.4, 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 %31, label %13
13: ; preds = %7
%14 = getelementptr inbounds i8*, i8** %1, i64 4
%15 = load i8*, i8** %14
%16 = tail call i32 @atoi(i8* %15)
%17 = getelementptr inbounds i8*, i8** %1, i64 5
%18 = load i8*, i8** %17
%19 = tail call i32 @atoi(i8* %18)
%20 = getelementptr inbounds i8*, i8** %1, i64 3
%21 = load i8*, i8** %20
%22 = getelementptr inbounds i8*, i8** %1, i64 2
%23 = load i8*, i8** %22
%24 = tail call i32 @mi_write(i8* %23, i8* %21, i32 %16, i32 %19)
%25 = icmp eq i32 %24, -1
%26 = select i1 %25, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @str.3, i64 0, i64 0), i8* getelementptr inbounds ([45 x i8], [45 x i8]* @str, i64 0, i64 0)
%27 = tail call i32 @puts(i8* dereferenceable(1) %26)
%28 = tail call i32 (...) @bumount()
%29 = icmp eq i32 %28, -1
%30 = sext i1 %29 to i32
br label %31
31: ; preds = %13, %7
%32 = phi i32 [ -1, %7 ], [ %30, %13 ]
%33 = tail call i32 (...) @sem_del()
ret i32 %32
}