#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 */
struct mntent {
  char *mnt_fsname;
  char *mnt_dir;
  char *mnt_type;
  char *mnt_opts;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
char *_PATH_MOUNTED;
int /*<<< orphan*/ endmntent(int /*<<< orphan*/ *);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
struct mntent *getmntent(int /*<<< orphan*/ *);
scalar_t__ mount(char const *, char const *, char *, int /*<<< orphan*/,
                 int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, char *, char *, char *, char *);
int /*<<< orphan*/ *setmntent(char *, char *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int main(int argc, const char **argv) {
  if (argc == 1) {
    FILE *mntfp = setmntent(_PATH_MOUNTED, "r");
    if (!mntfp) {
      fprintf(stderr, "Could not open %s: %s\n", _PATH_MOUNTED,
              strerror(errno));
      return 1;
    }
    struct mntent *ent;
    while (NULL != (ent = getmntent(mntfp))) {
      printf("%s on %s type %s (%s)\n", ent->mnt_fsname, ent->mnt_dir,
             ent->mnt_type, ent->mnt_opts);
    }
    endmntent(mntfp);
    return 0;
  } else if (argc == 3) {
    if (mount(argv[1], argv[2], "ext2", 0, NULL) < 0) {
      fprintf(stderr, "Could not mount %s to %s: %s\n", argv[1], argv[2],
              strerror(errno));
      return 1;
    }
    return 0;
  }
  fprintf(stderr, "Usage:\n"
                  "    mount\n"
                  "    mount <source> <directory>\n\n"
                  "view mount points and mount file systems\n\n"
                  "Options:\n"
                  "    -h, --help     display this help\n\n"
                  "mount is part of xelix-utils. "
                  "Please report bugs to <hello@lutoma.org>.\n");
  return 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    1266 <main+0xf6>
mov    0x2e51(%rip),%rax
mov    (%rax),%rdi
lea    0xe5f(%rip),%rsi
call   1080 <setmntent@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1201 <main+0x91>
mov    0x2e1c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    0x2e20(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    0x2dfa(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rdx
mov    %rax,%rcx
lea    0xe14(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1326 <main+0x1b6>
jmp    1206 <main+0x96>
mov    -0x18(%rbp),%rdi
call   1070 <getmntent@plt>
mov    %rax,%rcx
mov    %rcx,-0x20(%rbp)
xor    %eax,%eax
cmp    %rcx,%rax
je     1251 <main+0xe1>
mov    -0x20(%rbp),%rax
mov    (%rax),%rsi
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%rdx
mov    -0x20(%rbp),%rax
mov    0x10(%rax),%rcx
mov    -0x20(%rbp),%rax
mov    0x18(%rax),%r8
lea    0xdd2(%rip),%rdi
call   1050 <printf@plt>
jmp    1206 <main+0x96>
mov    -0x18(%rbp),%rdi
call   1030 <endmntent@plt>
movl   $0x0,-0x4(%rbp)
jmp    1326 <main+0x1b6>
cmpl   $0x3,-0x8(%rbp)
jne    1303 <main+0x193>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xda9(%rip),%rdx
xor    %ecx,%ecx
xor    %eax,%eax
mov    %eax,%r8d
call   1040 <mount@plt>
cmp    $0x0,%rax
jge    12f7 <main+0x187>
mov    0x2d34(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x38(%rbp)
mov    0x2d08(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x44(%rbp),%edi
mov    -0x40(%rbp),%rdx
mov    -0x38(%rbp),%rcx
mov    %rax,%r8
lea    0xd51(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1326 <main+0x1b6>
movl   $0x0,-0x4(%rbp)
jmp    1326 <main+0x1b6>
jmp    1308 <main+0x198>
mov    0x2cc9(%rip),%rax
mov    (%rax),%edi
lea    0xd3b(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
cmp    $0x3,%edi
je     11f3 <main+0x83>
cmp    $0x1,%edi
jne    1254 <main+0xe4>
mov    0x2e5e(%rip),%r14
mov    (%r14),%rdi
lea    0xe6c(%rip),%rsi
call   1080 <setmntent@plt>
test   %rax,%rax
je     126d <main+0xfd>
mov    %rax,%rbx
mov    %rax,%rdi
call   1070 <getmntent@plt>
test   %rax,%rax
je     11e4 <main+0x74>
lea    0xe60(%rip),%r14
nopl   0x0(%rax)
mov    (%rax),%rsi
mov    0x8(%rax),%rdx
mov    0x10(%rax),%rcx
mov    0x18(%rax),%r8
mov    %r14,%rdi
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1070 <getmntent@plt>
test   %rax,%rax
jne    11c0 <main+0x50>
mov    %rbx,%rdi
call   1030 <endmntent@plt>
xor    %ebx,%ebx
jmp    12a2 <main+0x132>
mov    %rsi,%r14
mov    0x8(%rsi),%rdi
mov    0x10(%rsi),%rsi
lea    0xe2b(%rip),%rdx
xor    %ebx,%ebx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1040 <mount@plt>
test   %rax,%rax
jns    12a2 <main+0x132>
mov    0x2db7(%rip),%rax
mov    (%rax),%ebx
mov    0x8(%r14),%r15
mov    0x10(%r14),%r14
mov    0x2d9e(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xdf5(%rip),%rsi
mov    %ebx,%edi
mov    %r15,%rdx
mov    %r14,%rcx
mov    %rax,%r8
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    129d <main+0x12d>
mov    0x2d7d(%rip),%rax
mov    (%rax),%edi
lea    0xdef(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    129d <main+0x12d>
mov    0x2d64(%rip),%rax
mov    (%rax),%ebx
mov    (%r14),%r14
mov    0x2d50(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xd74(%rip),%rsi
mov    %ebx,%edi
mov    %r14,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.mntent = type { i8*, i8*, i8*, i8* }
@_PATH_MOUNTED = global i8* null
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [23 x i8] c"Could not open %s: %s\0A\00"
@errno = global i32 0
@.str.2 = [23 x i8] c"%s on %s type %s (%s)\0A\00"
@.str.3 = [5 x i8] c"ext2\00"
@.str.4 = [30 x i8] c"Could not mount %s to %s: %s\0A\00"
@.str.5 = [211 x i8] c"Usage:\0A mount\0A mount <source> <directory>\0A\0Aview mount points and mount file systems\0A\0AOptions:\0A -h, --help display this help\0A\0Amount is part of xelix-utils. Please report bugs to <hello@lutoma.org>.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca %struct.mntent*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp eq i32 %8, 1
br i1 %9, label %10, label %43
10: ; preds = %2
%11 = load i8*, i8** @_PATH_MOUNTED
%12 = call i32* @setmntent(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %12, i32** %6
%13 = load i32*, i32** %6
%14 = icmp ne i32* %13, null
br i1 %14, label %21, label %15
15: ; preds = %10
%16 = load i32, i32* @stderr
%17 = load i8*, i8** @_PATH_MOUNTED
%18 = load i32, i32* @errno
%19 = call i8* @strerror(i32 %18)
%20 = call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %17, i8* %19)
store i32 1, i32* %3
br label %71
21: ; preds = %10
br label %22
22: ; preds = %26, %21
%23 = load i32*, i32** %6
%24 = call %struct.mntent* @getmntent(i32* %23)
store %struct.mntent* %24, %struct.mntent** %7
%25 = icmp ne %struct.mntent* null, %24
br i1 %25, label %26, label %40
26: ; preds = %22
%27 = load %struct.mntent*, %struct.mntent** %7
%28 = getelementptr inbounds %struct.mntent, %struct.mntent* %27, i32 0, i32 0
%29 = load i8*, i8** %28
%30 = load %struct.mntent*, %struct.mntent** %7
%31 = getelementptr inbounds %struct.mntent, %struct.mntent* %30, i32 0, i32 1
%32 = load i8*, i8** %31
%33 = load %struct.mntent*, %struct.mntent** %7
%34 = getelementptr inbounds %struct.mntent, %struct.mntent* %33, i32 0, i32 2
%35 = load i8*, i8** %34
%36 = load %struct.mntent*, %struct.mntent** %7
%37 = getelementptr inbounds %struct.mntent, %struct.mntent* %36, i32 0, i32 3
%38 = load i8*, i8** %37
%39 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %29, i8* %32, i8* %35, i8* %38)
br label %22
40: ; preds = %22
%41 = load i32*, i32** %6
%42 = call i32 @endmntent(i32* %41)
store i32 0, i32* %3
br label %71
43: ; preds = %2
%44 = load i32, i32* %4
%45 = icmp eq i32 %44, 3
br i1 %45, label %46, label %67
46: ; preds = %43
%47 = load i8**, i8*** %5
%48 = getelementptr inbounds i8*, i8** %47, i64 1
%49 = load i8*, i8** %48
%50 = load i8**, i8*** %5
%51 = getelementptr inbounds i8*, i8** %50, i64 2
%52 = load i8*, i8** %51
%53 = call i64 @mount(i8* %49, i8* %52, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 0, i32* null)
%54 = icmp slt i64 %53, 0
br i1 %54, label %55, label %66
55: ; preds = %46
%56 = load i32, i32* @stderr
%57 = load i8**, i8*** %5
%58 = getelementptr inbounds i8*, i8** %57, i64 1
%59 = load i8*, i8** %58
%60 = load i8**, i8*** %5
%61 = getelementptr inbounds i8*, i8** %60, i64 2
%62 = load i8*, i8** %61
%63 = load i32, i32* @errno
%64 = call i8* @strerror(i32 %63)
%65 = call i32 (i32, i8*, ...) @fprintf(i32 %56, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i8* %59, i8* %62, i8* %64)
store i32 1, i32* %3
br label %71
66: ; preds = %46
store i32 0, i32* %3
br label %71
67: ; preds = %43
br label %68
68: ; preds = %67
%69 = load i32, i32* @stderr
%70 = call i32 (i32, i8*, ...) @fprintf(i32 %69, i8* getelementptr inbounds ([211 x i8], [211 x i8]* @.str.5, i64 0, i64 0))
store i32 1, i32* %3
br label %71
71: ; preds = %68, %66, %55, %40, %15
%72 = load i32, i32* %3
ret i32 %72
}

LLVM IR (-O2):
%struct.mntent = type { i8*, i8*, i8*, i8* }
@_PATH_MOUNTED = global i8* null
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [23 x i8] c"Could not open %s: %s\0A\00"
@errno = global i32 0
@.str.2 = [23 x i8] c"%s on %s type %s (%s)\0A\00"
@.str.3 = [5 x i8] c"ext2\00"
@.str.4 = [30 x i8] c"Could not mount %s to %s: %s\0A\00"
@.str.5 = [211 x i8] c"Usage:\0A mount\0A mount <source> <directory>\0A\0Aview mount points and mount file systems\0A\0AOptions:\0A -h, --help display this help\0A\0Amount is part of xelix-utils. Please report bugs to <hello@lutoma.org>.\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
switch i32 %0, label %45 [
i32 1, label %3
i32 3, label %31
]
3: ; preds = %2
%4 = load i8*, i8** @_PATH_MOUNTED
%5 = tail call i32* @setmntent(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %10, label %7
7: ; preds = %3
%8 = tail call %struct.mntent* @getmntent(i32* %5)
%9 = icmp eq %struct.mntent* %8, null
br i1 %9, label %29, label %16
10: ; preds = %3
%11 = load i32, i32* @stderr
%12 = load i8*, i8** @_PATH_MOUNTED
%13 = load i32, i32* @errno
%14 = tail call i8* @strerror(i32 %13)
%15 = tail call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %12, i8* %14)
br label %48
16: ; preds = %7, %16
%17 = phi %struct.mntent* [ %27, %16 ], [ %8, %7 ]
%18 = getelementptr inbounds %struct.mntent, %struct.mntent* %17, i64 0, i32 0
%19 = load i8*, i8** %18
%20 = getelementptr inbounds %struct.mntent, %struct.mntent* %17, i64 0, i32 1
%21 = load i8*, i8** %20
%22 = getelementptr inbounds %struct.mntent, %struct.mntent* %17, i64 0, i32 2
%23 = load i8*, i8** %22
%24 = getelementptr inbounds %struct.mntent, %struct.mntent* %17, i64 0, i32 3
%25 = load i8*, i8** %24
%26 = tail call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %19, i8* %21, i8* %23, i8* %25)
%27 = tail call %struct.mntent* @getmntent(i32* %5)
%28 = icmp eq %struct.mntent* %27, null
br i1 %28, label %29, label %16
29: ; preds = %16, %7
%30 = tail call i32 @endmntent(i32* %5)
br label %48
31: ; preds = %2
%32 = getelementptr inbounds i8*, i8** %1, i64 1
%33 = load i8*, i8** %32
%34 = getelementptr inbounds i8*, i8** %1, i64 2
%35 = load i8*, i8** %34
%36 = tail call i64 @mount(i8* %33, i8* %35, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 0, i32* null)
%37 = icmp slt i64 %36, 0
br i1 %37, label %38, label %48
38: ; preds = %31
%39 = load i32, i32* @stderr
%40 = load i8*, i8** %32
%41 = load i8*, i8** %34
%42 = load i32, i32* @errno
%43 = tail call i8* @strerror(i32 %42)
%44 = tail call i32 (i32, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i8* %40, i8* %41, i8* %43)
br label %48
45: ; preds = %2
%46 = load i32, i32* @stderr
%47 = tail call i32 (i32, i8*, ...) @fprintf(i32 %46, i8* getelementptr inbounds ([211 x i8], [211 x i8]* @.str.5, i64 0, i64 0))
br label %48
48: ; preds = %31, %10, %29, %45, %38
%49 = phi i32 [ 1, %38 ], [ 1, %45 ], [ 0, %29 ], [ 1, %10 ], [ 0, %31 ]
ret i32 %49
}