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

/* Variables and functions */
int /*<<< orphan*/ endmntent(int /*<<< orphan*/ *);
struct mntent *getmntent(int /*<<< orphan*/ *);
int /*<<< orphan*/ *setmntent(char *, char *);
int main(void) {
  FILE *mounts;
  struct mntent *mount;
  mounts = setmntent("/etc/mtab", "r");
  if (!mounts)
    return 1;
  while ((mount = getmntent(mounts)) != NULL)
    ;
  (void)endmntent(mounts);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
lea    0xebd(%rip),%rsi
call   1050 <setmntent@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    116d <main+0x3d>
movl   $0x1,-0x4(%rbp)
jmp    119e <main+0x6e>
jmp    1172 <main+0x42>
mov    -0x10(%rbp),%rdi
call   1040 <getmntent@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     118e <main+0x5e>
jmp    1172 <main+0x42>
mov    -0x10(%rbp),%rdi
call   1030 <endmntent@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
lea    0xec8(%rip),%rdi
lea    0xecb(%rip),%rsi
call   1050 <setmntent@plt>
test   %rax,%rax
je     1169 <main+0x39>
mov    %rax,%rbx
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1040 <getmntent@plt>
test   %rax,%rax
jne    1150 <main+0x20>
mov    %rbx,%rdi
call   1030 <endmntent@plt>
xor    %eax,%eax
pop    %rbx
ret
mov    $0x1,%eax
pop    %rbx
ret

LLVM IR (-O0):
%struct.mntent = type { i32 }
@.str = [10 x i8] c"/etc/mtab\00"
@.str.1 = [2 x i8] c"r\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca %struct.mntent*
store i32 0, i32* %1
%4 = 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* %4, i32** %2
%5 = load i32*, i32** %2
%6 = icmp ne i32* %5, null
br i1 %6, label %8, label %7
7: ; preds = %0
store i32 1, i32* %1
br label %17
8: ; preds = %0
br label %9
9: ; preds = %13, %8
%10 = load i32*, i32** %2
%11 = call %struct.mntent* @getmntent(i32* %10)
store %struct.mntent* %11, %struct.mntent** %3
%12 = icmp ne %struct.mntent* %11, null
br i1 %12, label %13, label %14
13: ; preds = %9
br label %9
14: ; preds = %9
%15 = load i32*, i32** %2
%16 = call i32 @endmntent(i32* %15)
store i32 0, i32* %1
br label %17
17: ; preds = %14, %7
%18 = load i32, i32* %1
ret i32 %18
}

LLVM IR (-O2):
%struct.mntent = type { i32 }
@.str = [10 x i8] c"/etc/mtab\00"
@.str.1 = [2 x i8] c"r\00"
define i32 @main() {
%1 = 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))
%2 = icmp eq i32* %1, null
br i1 %2, label %8, label %3
3: ; preds = %0, %3
%4 = tail call %struct.mntent* @getmntent(i32* %1)
%5 = icmp eq %struct.mntent* %4, null
br i1 %5, label %6, label %3
6: ; preds = %3
%7 = tail call i32 @endmntent(i32* %1)
br label %8
8: ; preds = %0, %6
%9 = phi i32 [ 0, %6 ], [ 1, %0 ]
ret i32 %9
}