#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*/ assert(int);
int endmntent(int /*<<< orphan*/ *);
struct mntent *getmntent(int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ *setmntent(char *, char *);
int main() {
  int entsuccess = 0;
  FILE *fstab = setmntent("fstab", "r");
  struct mntent *e;
  if (!fstab) {
    perror("setmntent()");
    return 1;
  }
  while ((e = getmntent(fstab))) {
    entsuccess = 1;
    printf(
        "fsname %s\n  dir %s\n  type %s\n  opts %s\n  freq %d\n  passno %d\n\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/fstab\n");
  assert(1 == endmntent(fstab));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
lea    0xe83(%rip),%rdi
lea    0xe82(%rip),%rsi
call   1070 <setmntent@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11b0 <main+0x50>
lea    0xe69(%rip),%rdi
call   1080 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    126d <main+0x10d>
jmp    11b5 <main+0x55>
mov    -0x10(%rbp),%rdi
call   1060 <getmntent@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     1217 <main+0xb7>
movl   $0x1,-0x8(%rbp)
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    0xe0c(%rip),%rdi
mov    %eax,(%rsp)
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11b5 <main+0x55>
cmpl   $0x0,-0x8(%rbp)
jne    1239 <main+0xd9>
lea    0xe2b(%rip),%rdi
call   1080 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    126d <main+0x10d>
lea    0xe1f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <endmntent@plt>
mov    %eax,%ecx
mov    $0x1,%eax
cmp    %ecx,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
lea    0xeeb(%rip),%rdi
lea    0xe7e(%rip),%rsi
call   1080 <setmntent@plt>
test   %rax,%rax
je     120c <main+0x9c>
mov    %rax,%rbx
mov    %rax,%rdi
call   1070 <getmntent@plt>
test   %rax,%rax
je     121f <main+0xaf>
lea    0xe63(%rip),%r14
nopl   0x0(%rax,%rax,1)
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   1070 <getmntent@plt>
test   %rax,%rax
jne    11b0 <main+0x40>
lea    0xe72(%rip),%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
call   1030 <endmntent@plt>
xor    %edi,%edi
cmp    $0x1,%eax
sete   %dil
call   1060 <assert@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xdef(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%eax
jmp    1204 <main+0x94>
lea    0xe27(%rip),%rdi
call   1090 <perror@plt>
mov    $0x2,%eax
jmp    1204 <main+0x94>

LLVM IR (-O0):
%struct.mntent = type { i8*, i8*, i8*, i8*, i32, i32 }
@.str = [6 x i8] c"fstab\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [12 x i8] c"setmntent()\00"
@.str.3 = [63 x i8] c"fsname %s\0A dir %s\0A type %s\0A opts %s\0A freq %d\0A passno %d\0A\0A\00"
@.str.4 = [12 x i8] c"getmntent()\00"
@.str.5 = [20 x i8] c"closing /etc/fstab\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32*
%4 = alloca %struct.mntent*
store i32 0, i32* %1
store i32 0, i32* %2
%5 = call i32* @setmntent(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %5, i32** %3
%6 = load i32*, i32** %3
%7 = icmp ne i32* %6, null
br i1 %7, label %10, label %8
8: ; preds = %0
%9 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %1
br label %47
10: ; preds = %0
br label %11
11: ; preds = %15, %10
%12 = load i32*, i32** %3
%13 = call %struct.mntent* @getmntent(i32* %12)
store %struct.mntent* %13, %struct.mntent** %4
%14 = icmp ne %struct.mntent* %13, null
br i1 %14, label %15, label %35
15: ; preds = %11
store i32 1, i32* %2
%16 = load %struct.mntent*, %struct.mntent** %4
%17 = getelementptr inbounds %struct.mntent, %struct.mntent* %16, i32 0, i32 0
%18 = load i8*, i8** %17
%19 = load %struct.mntent*, %struct.mntent** %4
%20 = getelementptr inbounds %struct.mntent, %struct.mntent* %19, i32 0, i32 1
%21 = load i8*, i8** %20
%22 = load %struct.mntent*, %struct.mntent** %4
%23 = getelementptr inbounds %struct.mntent, %struct.mntent* %22, i32 0, i32 2
%24 = load i8*, i8** %23
%25 = load %struct.mntent*, %struct.mntent** %4
%26 = getelementptr inbounds %struct.mntent, %struct.mntent* %25, i32 0, i32 3
%27 = load i8*, i8** %26
%28 = load %struct.mntent*, %struct.mntent** %4
%29 = getelementptr inbounds %struct.mntent, %struct.mntent* %28, i32 0, i32 4
%30 = load i32, i32* %29
%31 = load %struct.mntent*, %struct.mntent** %4
%32 = getelementptr inbounds %struct.mntent, %struct.mntent* %31, i32 0, i32 5
%33 = load i32, i32* %32
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.3, i64 0, i64 0), i8* %18, i8* %21, i8* %24, i8* %27, i32 %30, i32 %33)
br label %11
35: ; preds = %11
%36 = load i32, i32* %2
%37 = icmp ne i32 %36, 0
br i1 %37, label %40, label %38
38: ; preds = %35
%39 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
store i32 2, i32* %1
br label %47
40: ; preds = %35
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0))
%42 = load i32*, i32** %3
%43 = call i32 @endmntent(i32* %42)
%44 = icmp eq i32 1, %43
%45 = zext i1 %44 to i32
%46 = call i32 @assert(i32 %45)
store i32 0, i32* %1
br label %47
47: ; preds = %40, %38, %8
%48 = load i32, i32* %1
ret i32 %48
}

LLVM IR (-O2):
%struct.mntent = type { i8*, i8*, i8*, i8*, i32, i32 }
@.str = [6 x i8] c"fstab\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [12 x i8] c"setmntent()\00"
@.str.3 = [63 x i8] c"fsname %s\0A dir %s\0A type %s\0A opts %s\0A freq %d\0A passno %d\0A\0A\00"
@.str.4 = [12 x i8] c"getmntent()\00"
@str = [19 x i8] c"closing /etc/fstab\00"
define i32 @main() {
%1 = tail call i32* @setmntent(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%2 = icmp eq i32* %1, null
br i1 %2, label %6, label %3
3: ; preds = %0
%4 = tail call %struct.mntent* @getmntent(i32* %1)
%5 = icmp eq %struct.mntent* %4, null
br i1 %5, label %25, label %8
6: ; preds = %0
%7 = tail call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
br label %33
8: ; preds = %3, %8
%9 = phi %struct.mntent* [ %23, %8 ], [ %4, %3 ]
%10 = getelementptr inbounds %struct.mntent, %struct.mntent* %9, i64 0, i32 0
%11 = load i8*, i8** %10
%12 = getelementptr inbounds %struct.mntent, %struct.mntent* %9, i64 0, i32 1
%13 = load i8*, i8** %12
%14 = getelementptr inbounds %struct.mntent, %struct.mntent* %9, i64 0, i32 2
%15 = load i8*, i8** %14
%16 = getelementptr inbounds %struct.mntent, %struct.mntent* %9, i64 0, i32 3
%17 = load i8*, i8** %16
%18 = getelementptr inbounds %struct.mntent, %struct.mntent* %9, i64 0, i32 4
%19 = load i32, i32* %18
%20 = getelementptr inbounds %struct.mntent, %struct.mntent* %9, i64 0, i32 5
%21 = load i32, i32* %20
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([63 x i8], [63 x i8]* @.str.3, i64 0, i64 0), i8* %11, i8* %13, i8* %15, i8* %17, i32 %19, i32 %21)
%23 = tail call %struct.mntent* @getmntent(i32* %1)
%24 = icmp eq %struct.mntent* %23, null
br i1 %24, label %27, label %8
25: ; preds = %3
%26 = tail call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
br label %33
27: ; preds = %8
%28 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
%29 = tail call i32 @endmntent(i32* %1)
%30 = icmp eq i32 %29, 1
%31 = zext i1 %30 to i32
%32 = tail call i32 @assert(i32 %31)
br label %33
33: ; preds = %27, %25, %6
%34 = phi i32 [ 0, %27 ], [ 2, %25 ], [ 1, %6 ]
ret i32 %34
}