#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_dir;
  char *mnt_type;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ endmntent(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
struct mntent *getmntent(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, char const *);
int /*<<< orphan*/ *setmntent(char *, char *);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  FILE *mount_table = NULL;
  struct mntent *mount_entry = NULL;
  mount_table = setmntent("/proc/mounts", "r");
  if (mount_table == NULL) {
    fprintf(stderr, "failed to open mtab entry\n");
    return -1;
  }
  while (1) {
    const char *mount_point;
    const char *fs_type;
    mount_entry = getmntent(mount_table);
    if (mount_entry == NULL) {
      endmntent(mount_table);
      break;
    }
    mount_point = mount_entry->mnt_dir;
    fs_type = mount_entry->mnt_type;
    printf("Mount Point: %s\n", mount_point);
    printf("Filesystem:  %s\n", fs_type);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
lea    0xe83(%rip),%rdi
lea    0xe89(%rip),%rsi
call   1070 <setmntent@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11b9 <main+0x69>
mov    0x2e41(%rip),%rax
mov    (%rax),%edi
lea    0xe67(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1227 <main+0xd7>
jmp    11be <main+0x6e>
mov    -0x18(%rbp),%rdi
call   1060 <getmntent@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11e4 <main+0x94>
mov    -0x18(%rbp),%rdi
call   1030 <endmntent@plt>
jmp    1220 <main+0xd0>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rsi
lea    0xe24(%rip),%rdi
call   1040 <printf@plt>
mov    -0x30(%rbp),%rsi
lea    0xe25(%rip),%rdi
call   1040 <printf@plt>
jmp    11be <main+0x6e>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
lea    0xea1(%rip),%rdi
lea    0xea7(%rip),%rsi
call   1070 <setmntent@plt>
test   %rax,%rax
je     11c3 <main+0x73>
mov    %rax,%r12
mov    %rax,%rdi
call   1060 <getmntent@plt>
test   %rax,%rax
je     11b7 <main+0x67>
lea    0xea3(%rip),%r14
lea    0xead(%rip),%r15
xchg   %ax,%ax
mov    (%rax),%rsi
mov    0x8(%rax),%rbx
mov    %r14,%rdi
call   1040 <printf@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
mov    %r12,%rdi
call   1060 <getmntent@plt>
test   %rax,%rax
jne    1190 <main+0x40>
mov    %r12,%rdi
call   1030 <endmntent@plt>
xor    %eax,%eax
jmp    11dd <main+0x8d>
mov    0x2e16(%rip),%rax
mov    (%rax),%edi
lea    0xe3c(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.mntent = type { i8*, i8* }
@.str = [13 x i8] c"/proc/mounts\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [27 x i8] c"failed to open mtab entry\0A\00"
@.str.3 = [17 x i8] c"Mount Point: %s\0A\00"
@.str.4 = [17 x i8] c"Filesystem: %s\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*
%8 = alloca i8*
%9 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32* null, i32** %6
store %struct.mntent* null, %struct.mntent** %7
%10 = call i32* @setmntent(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %10, i32** %6
%11 = load i32*, i32** %6
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %3
br label %37
16: ; preds = %2
br label %17
17: ; preds = %16, %25
%18 = load i32*, i32** %6
%19 = call %struct.mntent* @getmntent(i32* %18)
store %struct.mntent* %19, %struct.mntent** %7
%20 = load %struct.mntent*, %struct.mntent** %7
%21 = icmp eq %struct.mntent* %20, null
br i1 %21, label %22, label %25
22: ; preds = %17
%23 = load i32*, i32** %6
%24 = call i32 @endmntent(i32* %23)
br label %36
25: ; preds = %17
%26 = load %struct.mntent*, %struct.mntent** %7
%27 = getelementptr inbounds %struct.mntent, %struct.mntent* %26, i32 0, i32 0
%28 = load i8*, i8** %27
store i8* %28, i8** %8
%29 = load %struct.mntent*, %struct.mntent** %7
%30 = getelementptr inbounds %struct.mntent, %struct.mntent* %29, i32 0, i32 1
%31 = load i8*, i8** %30
store i8* %31, i8** %9
%32 = load i8*, i8** %8
%33 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i8* %32)
%34 = load i8*, i8** %9
%35 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i8* %34)
br label %17
36: ; preds = %22
store i32 0, i32* %3
br label %37
37: ; preds = %36, %13
%38 = load i32, i32* %3
ret i32 %38
}

LLVM IR (-O2):
%struct.mntent = type { i8*, i8* }
@.str = [13 x i8] c"/proc/mounts\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [27 x i8] c"failed to open mtab entry\0A\00"
@.str.3 = [17 x i8] c"Mount Point: %s\0A\00"
@.str.4 = [17 x i8] c"Filesystem: %s\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32* @setmntent(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %8, label %5
5: ; preds = %2
%6 = tail call %struct.mntent* @getmntent(i32* %3)
%7 = icmp eq %struct.mntent* %6, null
br i1 %7, label %11, label %13
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
br label %23
11: ; preds = %13, %5
%12 = tail call i32 @endmntent(i32* %3)
br label %23
13: ; preds = %5, %13
%14 = phi %struct.mntent* [ %21, %13 ], [ %6, %5 ]
%15 = getelementptr inbounds %struct.mntent, %struct.mntent* %14, i64 0, i32 0
%16 = load i8*, i8** %15
%17 = getelementptr inbounds %struct.mntent, %struct.mntent* %14, i64 0, i32 1
%18 = load i8*, i8** %17
%19 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i8* %16)
%20 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i8* %18)
%21 = tail call %struct.mntent* @getmntent(i32* %3)
%22 = icmp eq %struct.mntent* %21, null
br i1 %22, label %11, label %13
23: ; preds = %11, %8
%24 = phi i32 [ -1, %8 ], [ 0, %11 ]
ret i32 %24
}