#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 statvfs {
  int dummy;
};
struct mntent {
  char *mnt_fsname;
  char *mnt_dir;
};
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*/ print_mntinfo(struct mntent *, struct statvfs);
int /*<<< orphan*/ *setmntent(char *, char *);
scalar_t__ statvfs(char *, struct statvfs *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcmp(char *, char *);
int mntinfo(char *fs_name) {
  FILE *mtab;
  struct mntent *ent;
  struct statvfs stats;
  bool found = false;
  mtab = setmntent("/etc/mtab", "r");
  if (!mtab) {
    fprintf(stderr, "Fatal: Could not read /etc/mtab.\n");
    return 1;
  }
  while (!found && (ent = getmntent(mtab))) {
    if (!strcmp(fs_name, ent->mnt_fsname)) {
      found = true;
    }
  }
  if (!found) {
    fprintf(stderr, "Fatal: No entry for %s in /etc/mtab.\n", fs_name);
    return 1;
  }
  if (statvfs(ent->mnt_dir, &stats) < 0) {
    fprintf(stderr, "Fatal: Could not stat %s (%s).\n", ent->mnt_dir,
            ent->mnt_fsname);
    return 1;
  }
  print_mntinfo(ent, stats);
  endmntent(mtab);
  return 0;
}


x86 assembly (clang, -O0):
<mntinfo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x2c(%rbp)
lea    0xe76(%rip),%rdi
lea    0xe79(%rip),%rsi
call   1080 <setmntent@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11c8 <mntinfo+0x58>
mov    0x2e34(%rip),%rax
mov    (%rax),%edi
lea    0xe57(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12c2 <mntinfo+0x152>
jmp    11cd <mntinfo+0x5d>
xor    %eax,%eax
cmpl   $0x0,-0x2c(%rbp)
mov    %al,-0x2d(%rbp)
jne    11f3 <mntinfo+0x83>
mov    -0x18(%rbp),%rdi
call   1070 <getmntent@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
setne  %al
mov    %al,-0x2d(%rbp)
mov    -0x2d(%rbp),%al
test   $0x1,%al
jne    1203 <mntinfo+0x93>
jmp    1228 <mntinfo+0xb8>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    (%rax),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    1223 <mntinfo+0xb3>
movl   $0x1,-0x2c(%rbp)
jmp    11cd <mntinfo+0x5d>
cmpl   $0x0,-0x2c(%rbp)
jne    1259 <mntinfo+0xe9>
mov    0x2da7(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xde8(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12c2 <mntinfo+0x152>
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x28(%rbp),%rsi
call   1090 <statvfs@plt>
cmp    $0x0,%rax
jge    12a6 <mntinfo+0x136>
mov    0x2d65(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%rdx
mov    -0x20(%rbp),%rax
mov    (%rax),%rcx
lea    0xdc1(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12c2 <mntinfo+0x152>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%esi
call   1040 <print_mntinfo@plt>
mov    -0x18(%rbp),%rdi
call   1030 <endmntent@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mntinfo>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r14
lea    0xe7d(%rip),%rdi
lea    0xe80(%rip),%rsi
call   1080 <setmntent@plt>
test   %rax,%rax
je     11ea <mntinfo+0x7a>
mov    %rax,%r15
nopw   0x0(%rax,%rax,1)
mov    %r15,%rdi
call   1070 <getmntent@plt>
test   %rax,%rax
je     1203 <mntinfo+0x93>
mov    %rax,%rbx
mov    (%rax),%rsi
mov    %r14,%rdi
call   1050 <strcmp@plt>
test   %eax,%eax
jne    11a0 <mntinfo+0x30>
mov    0x8(%rbx),%rdi
lea    0x8(%rsp),%rsi
call   1090 <statvfs@plt>
test   %rax,%rax
js     121f <mntinfo+0xaf>
mov    0x8(%rsp),%esi
mov    %rbx,%rdi
call   1040 <print_mntinfo@plt>
mov    %r15,%rdi
call   1030 <endmntent@plt>
xor    %eax,%eax
jmp    1242 <mntinfo+0xd2>
mov    0x2def(%rip),%rax
mov    (%rax),%edi
lea    0xe12(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    123d <mntinfo+0xcd>
mov    0x2dd6(%rip),%rax
mov    (%rax),%edi
lea    0xe1b(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    123d <mntinfo+0xcd>
mov    0x2dba(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rcx
mov    0x8(%rbx),%rdx
lea    0xe1e(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.mntent = type { i8*, i8* }
%struct.statvfs = type { i32 }
@.str = [10 x i8] c"/etc/mtab\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [34 x i8] c"Fatal: Could not read /etc/mtab.\0A\00"
@.str.3 = [38 x i8] c"Fatal: No entry for %s in /etc/mtab.\0A\00"
@.str.4 = [32 x i8] c"Fatal: Could not stat %s (%s).\0A\00"
define i32 @mntinfo(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca %struct.mntent*
%6 = alloca %struct.statvfs
%7 = alloca i32
store i8* %0, i8** %3
store i32 0, i32* %7
%8 = call i32* @setmntent(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %8, i32** %4
%9 = load i32*, i32** %4
%10 = icmp ne i32* %9, null
br i1 %10, label %14, label %11
11: ; preds = %1
%12 = load i32, i32* @stderr
%13 = call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %2
br label %62
14: ; preds = %1
br label %15
15: ; preds = %32, %14
%16 = load i32, i32* %7
%17 = icmp ne i32 %16, 0
br i1 %17, label %22, label %18
18: ; preds = %15
%19 = load i32*, i32** %4
%20 = call %struct.mntent* @getmntent(i32* %19)
store %struct.mntent* %20, %struct.mntent** %5
%21 = icmp ne %struct.mntent* %20, null
br label %22
22: ; preds = %18, %15
%23 = phi i1 [ false, %15 ], [ %21, %18 ]
br i1 %23, label %24, label %33
24: ; preds = %22
%25 = load i8*, i8** %3
%26 = load %struct.mntent*, %struct.mntent** %5
%27 = getelementptr inbounds %struct.mntent, %struct.mntent* %26, i32 0, i32 0
%28 = load i8*, i8** %27
%29 = call i32 @strcmp(i8* %25, i8* %28)
%30 = icmp ne i32 %29, 0
br i1 %30, label %32, label %31
31: ; preds = %24
store i32 1, i32* %7
br label %32
32: ; preds = %31, %24
br label %15
33: ; preds = %22
%34 = load i32, i32* %7
%35 = icmp ne i32 %34, 0
br i1 %35, label %40, label %36
36: ; preds = %33
%37 = load i32, i32* @stderr
%38 = load i8*, i8** %3
%39 = call i32 (i32, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0), i8* %38)
store i32 1, i32* %2
br label %62
40: ; preds = %33
%41 = load %struct.mntent*, %struct.mntent** %5
%42 = getelementptr inbounds %struct.mntent, %struct.mntent* %41, i32 0, i32 1
%43 = load i8*, i8** %42
%44 = call i64 @statvfs(i8* %43, %struct.statvfs* %6)
%45 = icmp slt i64 %44, 0
br i1 %45, label %46, label %55
46: ; preds = %40
%47 = load i32, i32* @stderr
%48 = load %struct.mntent*, %struct.mntent** %5
%49 = getelementptr inbounds %struct.mntent, %struct.mntent* %48, i32 0, i32 1
%50 = load i8*, i8** %49
%51 = load %struct.mntent*, %struct.mntent** %5
%52 = getelementptr inbounds %struct.mntent, %struct.mntent* %51, i32 0, i32 0
%53 = load i8*, i8** %52
%54 = call i32 (i32, i8*, ...) @fprintf(i32 %47, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i8* %50, i8* %53)
store i32 1, i32* %2
br label %62
55: ; preds = %40
%56 = load %struct.mntent*, %struct.mntent** %5
%57 = getelementptr inbounds %struct.statvfs, %struct.statvfs* %6, i32 0, i32 0
%58 = load i32, i32* %57
%59 = call i32 @print_mntinfo(%struct.mntent* %56, i32 %58)
%60 = load i32*, i32** %4
%61 = call i32 @endmntent(i32* %60)
store i32 0, i32* %2
br label %62
62: ; preds = %55, %46, %36, %11
%63 = load i32, i32* %2
ret i32 %63
}

LLVM IR (-O2):
%struct.statvfs = type { i32 }
%struct.mntent = type { i8*, i8* }
@.str = [10 x i8] c"/etc/mtab\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [34 x i8] c"Fatal: Could not read /etc/mtab.\0A\00"
@.str.3 = [38 x i8] c"Fatal: No entry for %s in /etc/mtab.\0A\00"
@.str.4 = [32 x i8] c"Fatal: Could not stat %s (%s).\0A\00"
define i32 @mntinfo(i8* %0) {
%2 = alloca %struct.statvfs
%3 = bitcast %struct.statvfs* %2 to i8*
%4 = tail call i32* @setmntent(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %9
6: ; preds = %1
%7 = load i32, i32* @stderr
%8 = tail call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0))
br label %36
9: ; preds = %1, %12
%10 = tail call %struct.mntent* @getmntent(i32* %4)
%11 = icmp eq %struct.mntent* %10, null
br i1 %11, label %17, label %12
12: ; preds = %9
%13 = getelementptr inbounds %struct.mntent, %struct.mntent* %10, i64 0, i32 0
%14 = load i8*, i8** %13
%15 = tail call i32 @strcmp(i8* dereferenceable(1) %0, i8* dereferenceable(1) %14)
%16 = icmp eq i32 %15, 0
br i1 %16, label %20, label %9
17: ; preds = %9
%18 = load i32, i32* @stderr
%19 = tail call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0), i8* %0)
br label %36
20: ; preds = %12
%21 = getelementptr inbounds %struct.mntent, %struct.mntent* %10, i64 0, i32 1
%22 = load i8*, i8** %21
%23 = call i64 @statvfs(i8* %22, %struct.statvfs* %2)
%24 = icmp slt i64 %23, 0
br i1 %24, label %25, label %31
25: ; preds = %20
%26 = getelementptr inbounds %struct.mntent, %struct.mntent* %10, i64 0, i32 0
%27 = load i32, i32* @stderr
%28 = load i8*, i8** %21
%29 = load i8*, i8** %26
%30 = call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i8* %28, i8* %29)
br label %36
31: ; preds = %20
%32 = getelementptr inbounds %struct.statvfs, %struct.statvfs* %2, i64 0, i32 0
%33 = load i32, i32* %32
%34 = call i32 @print_mntinfo(%struct.mntent* %10, i32 %33)
%35 = call i32 @endmntent(i32* %4)
br label %36
36: ; preds = %31, %25, %17, %6
%37 = phi i32 [ 1, %25 ], [ 0, %31 ], [ 1, %17 ], [ 1, %6 ]
ret i32 %37
}