#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 */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
struct mntent *getmntent(int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char **argv) {
  int entsuccess = 0;
  FILE *mtab = fopen("/etc/mtab", "r");
  struct mntent *e;
  (void)argc;
  (void)argv;
  if (!mtab) {
    perror("Cannot open mtab");
    return 1;
  }
  printf("%-15s %-30s %-12s %-40s %-4s %-10s\n", "fsname", "dir", "type",
         "opts", "freq", "passno");
  while ((e = getmntent(mtab))) {
    entsuccess = 1;
    printf("%-15s %-30s %-12s %-40s %-4d %-10d\n", e->mnt_fsname, e->mnt_dir,
           e->mnt_type, e->mnt_opts, e->mnt_freq, e->mnt_passno);
  }
  if (!entsuccess) {
    perror("getmntent()");
    return 2;
  }
  printf("closing /etc/mtab\n");
  fclose(mtab);
  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)
movl   $0x0,-0x14(%rbp)
lea    0xe8c(%rip),%rdi
lea    0xecd(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11a7 <main+0x57>
lea    0xe74(%rip),%rdi
call   1070 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1285 <main+0x135>
lea    0xe6d(%rip),%rdi
lea    0xe8a(%rip),%rsi
lea    0xe8a(%rip),%rdx
lea    0xe87(%rip),%rcx
lea    0xe85(%rip),%r8
lea    0xe83(%rip),%r9
lea    0xe81(%rip),%rax
mov    %rax,(%rsp)
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1050 <getmntent@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     1245 <main+0xf5>
movl   $0x1,-0x14(%rbp)
mov    -0x28(%rbp),%rax
mov    (%rax),%rsi
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%rdx
mov    -0x28(%rbp),%rax
mov    0x10(%rax),%rcx
mov    -0x28(%rbp),%rax
mov    0x18(%rax),%r8
mov    -0x28(%rbp),%rax
mov    0x20(%rax),%r9d
mov    -0x28(%rbp),%rax
mov    0x24(%rax),%eax
lea    0xe2a(%rip),%rdi
mov    %eax,(%rsp)
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11e3 <main+0x93>
cmpl   $0x0,-0x14(%rbp)
jne    1267 <main+0x117>
lea    0xe2e(%rip),%rdi
call   1070 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    1285 <main+0x135>
lea    0xe22(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
lea    0xf23(%rip),%rdi
lea    0xecc(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     122e <main+0xce>
mov    %rax,%rbx
lea    0xec5(%rip),%rax
mov    %rax,(%rsp)
lea    0xe7c(%rip),%rdi
lea    0xe99(%rip),%rsi
lea    0xe99(%rip),%rdx
lea    0xe96(%rip),%rcx
lea    0xe94(%rip),%r8
lea    0xe92(%rip),%r9
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1060 <getmntent@plt>
test   %rax,%rax
je     1241 <main+0xe1>
lea    0xe83(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   (%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   1050 <printf@plt>
mov    %rbx,%rdi
call   1060 <getmntent@plt>
test   %rax,%rax
jne    11e0 <main+0x80>
lea    0xe6f(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xdcb(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%eax
jmp    1226 <main+0xc6>
lea    0xe32(%rip),%rdi
call   1080 <perror@plt>
mov    $0x2,%eax
jmp    1226 <main+0xc6>

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

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