#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;
  int mnt_freq;
  int mnt_passno;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
struct mntent *getmntent(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, char *, ...);
int /*<<< orphan*/ *setmntent(char *, char *);
int main(int agrv, char *argc[]) {
  struct mntent *mntent;
  FILE *file = NULL;
  file = setmntent("/etc/mtab", "r");
  if (!file) {
    printf("failed to open %s", "/etc/mtab");
    return -1;
  }
  while ((mntent = getmntent(file))) {
    printf("%s, dir:%s, type:%s, opts:%s, freq:%d, passno:%d\n",
           mntent->mnt_fsname, mntent->mnt_dir, mntent->mnt_type,
           mntent->mnt_opts, mntent->mnt_freq, mntent->mnt_passno);
  };
  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,-0x20(%rbp)
lea    0xeab(%rip),%rdi
lea    0xeae(%rip),%rsi
call   1050 <setmntent@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1191 <main+0x61>
lea    0xe95(%rip),%rdi
lea    0xe82(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f8 <main+0xc8>
jmp    1196 <main+0x66>
mov    -0x20(%rbp),%rdi
call   1040 <getmntent@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     11f1 <main+0xc1>
mov    -0x18(%rbp),%rax
mov    (%rax),%rsi
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rdx
mov    -0x18(%rbp),%rax
mov    0x10(%rax),%rcx
mov    -0x18(%rbp),%rax
mov    0x18(%rax),%r8
mov    -0x18(%rbp),%rax
mov    0x20(%rax),%r9d
mov    -0x18(%rbp),%rax
mov    0x24(%rax),%eax
lea    0xe3c(%rip),%rdi
mov    %eax,(%rsp)
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1196 <main+0x66>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xec1(%rip),%rdi
lea    0xec4(%rip),%rsi
call   1050 <setmntent@plt>
test   %rax,%rax
je     11a2 <main+0x72>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <getmntent@plt>
test   %rax,%rax
je     11be <main+0x8e>
lea    0xeb7(%rip),%r14
xor    %ebp,%ebp
nopl   0x0(%rax)
mov    (%rax),%rsi
mov    0x8(%rax),%rdx
mov    0x10(%rax),%rcx
mov    0x18(%rax),%r8
mov    0x20(%rax),%r9d
mov    0x24(%rax),%eax
mov    %eax,(%rsp)
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %rbx,%rdi
call   1040 <getmntent@plt>
test   %rax,%rax
jne    1170 <main+0x40>
jmp    11c0 <main+0x90>
lea    0xe63(%rip),%rdi
lea    0xe50(%rip),%rsi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0xffffffff,%ebp
jmp    11c0 <main+0x90>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.mntent = type { i8*, i8*, i8*, i8*, i32, i32 }
@.str = [10 x i8] c"/etc/mtab\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [18 x i8] c"failed to open %s\00"
@.str.3 = [50 x i8] c"%s, dir:%s, type:%s, opts:%s, freq:%d, passno:%d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.mntent*
%7 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32* null, 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** %7
%9 = load i32*, i32** %7
%10 = icmp ne i32* %9, null
br i1 %10, label %13, label %11
11: ; preds = %2
%12 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %39
13: ; preds = %2
br label %14
14: ; preds = %18, %13
%15 = load i32*, i32** %7
%16 = call %struct.mntent* @getmntent(i32* %15)
store %struct.mntent* %16, %struct.mntent** %6
%17 = icmp ne %struct.mntent* %16, null
br i1 %17, label %18, label %38
18: ; preds = %14
%19 = load %struct.mntent*, %struct.mntent** %6
%20 = getelementptr inbounds %struct.mntent, %struct.mntent* %19, i32 0, i32 0
%21 = load i8*, i8** %20
%22 = load %struct.mntent*, %struct.mntent** %6
%23 = getelementptr inbounds %struct.mntent, %struct.mntent* %22, i32 0, i32 1
%24 = load i8*, i8** %23
%25 = load %struct.mntent*, %struct.mntent** %6
%26 = getelementptr inbounds %struct.mntent, %struct.mntent* %25, i32 0, i32 2
%27 = load i8*, i8** %26
%28 = load %struct.mntent*, %struct.mntent** %6
%29 = getelementptr inbounds %struct.mntent, %struct.mntent* %28, i32 0, i32 3
%30 = load i8*, i8** %29
%31 = load %struct.mntent*, %struct.mntent** %6
%32 = getelementptr inbounds %struct.mntent, %struct.mntent* %31, i32 0, i32 4
%33 = load i32, i32* %32
%34 = load %struct.mntent*, %struct.mntent** %6
%35 = getelementptr inbounds %struct.mntent, %struct.mntent* %34, i32 0, i32 5
%36 = load i32, i32* %35
%37 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.3, i64 0, i64 0), i8* %21, i8* %24, i8* %27, i8* %30, i32 %33, i32 %36)
br label %14
38: ; preds = %14
store i32 0, i32* %3
br label %39
39: ; preds = %38, %11
%40 = load i32, i32* %3
ret i32 %40
}

LLVM IR (-O2):
%struct.mntent = type { i8*, i8*, i8*, i8*, i32, i32 }
@.str = [10 x i8] c"/etc/mtab\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [18 x i8] c"failed to open %s\00"
@.str.3 = [50 x i8] c"%s, dir:%s, type:%s, opts:%s, freq:%d, passno:%d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = 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))
%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 %27, label %10
8: ; preds = %2
%9 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %27
10: ; preds = %5, %10
%11 = phi %struct.mntent* [ %25, %10 ], [ %6, %5 ]
%12 = getelementptr inbounds %struct.mntent, %struct.mntent* %11, i64 0, i32 0
%13 = load i8*, i8** %12
%14 = getelementptr inbounds %struct.mntent, %struct.mntent* %11, i64 0, i32 1
%15 = load i8*, i8** %14
%16 = getelementptr inbounds %struct.mntent, %struct.mntent* %11, i64 0, i32 2
%17 = load i8*, i8** %16
%18 = getelementptr inbounds %struct.mntent, %struct.mntent* %11, i64 0, i32 3
%19 = load i8*, i8** %18
%20 = getelementptr inbounds %struct.mntent, %struct.mntent* %11, i64 0, i32 4
%21 = load i32, i32* %20
%22 = getelementptr inbounds %struct.mntent, %struct.mntent* %11, i64 0, i32 5
%23 = load i32, i32* %22
%24 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.3, i64 0, i64 0), i8* %13, i8* %15, i8* %17, i8* %19, i32 %21, i32 %23)
%25 = tail call %struct.mntent* @getmntent(i32* %3)
%26 = icmp eq %struct.mntent* %25, null
br i1 %26, label %27, label %10
27: ; preds = %10, %5, %8
%28 = phi i32 [ -1, %8 ], [ 0, %5 ], [ 0, %10 ]
ret i32 %28
}