#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 bmount(char *);
int bumount();
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ memset(char *, char, int);
int mi_dir(char *, char *);
int /*<<< orphan*/ mi_lsdir(char *, char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sem_del();
int /*<<< orphan*/ sem_init();
int main(int argc, char *argv[]) {
  char buffer[(1024 * 4)];
  memset(buffer, '\0', (1024 * 4));
  if (argc != 3) {
    printf(
        "[mi_ls.c] ERROR: Arguments incorrectes. Ex: mi_ls <nomFS> <cami>\n");
    exit(-1);
  }
  sem_init();
  if (bmount(argv[1]) == -1) {
    sem_del();
    return -1;
  }
  if (mi_dir(argv[2], buffer) != -1) {
    mi_lsdir(argv[2], buffer);
  }
  if (bumount() == -1) {
    sem_del();
    return -1;
  }
  sem_del();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1010,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x1010(%rbp),%rdi
xor    %esi,%esi
mov    $0x1000,%edx
call   1060 <memset@plt>
cmpl   $0x3,-0x8(%rbp)
je     11dc <main+0x4c>
lea    0xe33(%rip),%rdi
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   10b0 <exit@plt>
mov    $0x0,%al
call   10a0 <sem_init@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <bmount@plt>
cmp    $0xffffffff,%eax
jne    120c <main+0x7c>
mov    $0x0,%al
call   1030 <sem_del@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    126e <main+0xde>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    -0x1010(%rbp),%rsi
call   1090 <mi_dir@plt>
cmp    $0xffffffff,%eax
je     123d <main+0xad>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    -0x1010(%rbp),%rsi
call   1080 <mi_lsdir@plt>
mov    $0x0,%al
call   1050 <bumount@plt>
cmp    $0xffffffff,%eax
jne    1260 <main+0xd0>
mov    $0x0,%al
call   1030 <sem_del@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    126e <main+0xde>
mov    $0x0,%al
call   1030 <sem_del@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1010,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x1008,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
mov    %rsp,%rdi
xor    %esi,%esi
mov    $0x1000,%edx
call   1060 <memset@plt>
cmp    $0x3,%ebp
jne    1216 <main+0x86>
xor    %eax,%eax
call   10a0 <sem_init@plt>
mov    0x8(%rbx),%rdi
call   1070 <bmount@plt>
cmp    $0xffffffff,%eax
je     11fe <main+0x6e>
mov    0x10(%rbx),%rdi
mov    %rsp,%rsi
call   1090 <mi_dir@plt>
cmp    $0xffffffff,%eax
je     11e4 <main+0x54>
mov    0x10(%rbx),%rdi
mov    %rsp,%rsi
call   1080 <mi_lsdir@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    120a <main+0x7a>
xor    %eax,%eax
call   1040 <sem_del@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x1008,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xde3(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [66 x i8] c"[mi_ls.c] ERROR: Arguments incorrectes. Ex: mi_ls <nomFS> <cami>\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [4096 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%8 = call i32 @memset(i8* %7, i8 signext 0, i32 4096)
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 3
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = call i32 @printf(i8* getelementptr inbounds ([66 x i8], [66 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 %43
23: ; preds = %14
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 2
%26 = load i8*, i8** %25
%27 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%28 = call i32 @mi_dir(i8* %26, i8* %27)
%29 = icmp ne i32 %28, -1
br i1 %29, label %30, label %36
30: ; preds = %23
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 2
%33 = load i8*, i8** %32
%34 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%35 = call i32 @mi_lsdir(i8* %33, i8* %34)
br label %36
36: ; preds = %30, %23
%37 = call i32 (...) @bumount()
%38 = icmp eq i32 %37, -1
br i1 %38, label %39, label %41
39: ; preds = %36
%40 = call i32 (...) @sem_del()
store i32 -1, i32* %3
br label %43
41: ; preds = %36
%42 = call i32 (...) @sem_del()
store i32 0, i32* %3
br label %43
43: ; preds = %41, %39, %21
%44 = load i32, i32* %3
ret i32 %44
}

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