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

/* Variables and functions */
int /*<<< orphan*/ addmntent(int /*<<< orphan*/ *, struct mntent *);
scalar_t__ deleted(int /*<<< orphan*/);
int /*<<< orphan*/ endmntent(int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int);
struct mntent *getmntent(int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
scalar_t__ rename(char *, char *);
int /*<<< orphan*/ *setmntent(char *, char *);
int rewrite_mtab(void) {
  FILE *inpf, *outf;
  struct mntent *mnt;
  inpf = setmntent("/etc/mtab", "r");
  if (!inpf) {
    perror("Can't open /etc/mtab");
    exit(1);
  }
  outf = setmntent("/etc/mtab.new", "w");
  if (!outf) {
    perror("Can't create temporary file");
    exit(1);
  }
  while (mnt = getmntent(inpf)) {
    if (deleted(mnt->mnt_fsname))
      continue;
    else
      addmntent(outf, mnt);
  }
  endmntent(inpf);
  endmntent(outf);
  if (rename("/etc/mtab.new", "/etc/mtab") < 0) {
    perror("Error installing /etc/mtab");
    exit(1);
  }
  return 0;
}


x86 assembly (clang, -O0):
<rewrite_mtab>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xec3(%rip),%rdi
lea    0xe6a(%rip),%rsi
call   1070 <setmntent@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    11c0 <rewrite_mtab+0x40>
lea    0xe51(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
lea    0xe50(%rip),%rdi
lea    0xe55(%rip),%rsi
call   1070 <setmntent@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11f8 <rewrite_mtab+0x78>
lea    0xe3c(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
jmp    11fd <rewrite_mtab+0x7d>
mov    -0x8(%rbp),%rdi
call   1060 <getmntent@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     1240 <rewrite_mtab+0xc0>
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
call   1040 <deleted@plt>
cmp    $0x0,%rax
je     122e <rewrite_mtab+0xae>
jmp    11fd <rewrite_mtab+0x7d>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <addmntent@plt>
jmp    11fd <rewrite_mtab+0x7d>
mov    -0x8(%rbp),%rdi
call   1030 <endmntent@plt>
mov    -0x10(%rbp),%rdi
call   1030 <endmntent@plt>
lea    0xdbe(%rip),%rdi
lea    0xdf2(%rip),%rsi
call   1090 <rename@plt>
cmp    $0x0,%rax
jge    1285 <rewrite_mtab+0x105>
lea    0xdcb(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rewrite_mtab>:
push   %r15
push   %r14
push   %rbx
lea    0xec6(%rip),%rdi
lea    0xe6d(%rip),%rsi
call   1070 <setmntent@plt>
test   %rax,%rax
je     1239 <rewrite_mtab+0xb9>
mov    %rax,%r15
lea    0xe6c(%rip),%rdi
lea    0xe71(%rip),%rsi
call   1070 <setmntent@plt>
test   %rax,%rax
je     1242 <rewrite_mtab+0xc2>
mov    %rax,%r14
mov    %r15,%rdi
call   1060 <getmntent@plt>
test   %rax,%rax
je     1209 <rewrite_mtab+0x89>
mov    %rax,%rbx
jmp    11f0 <rewrite_mtab+0x70>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r15,%rdi
call   1060 <getmntent@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1209 <rewrite_mtab+0x89>
mov    (%rbx),%edi
call   1040 <deleted@plt>
test   %rax,%rax
jne    11e0 <rewrite_mtab+0x60>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <addmntent@plt>
jmp    11e0 <rewrite_mtab+0x60>
mov    %r15,%rdi
call   1030 <endmntent@plt>
mov    %r14,%rdi
call   1030 <endmntent@plt>
lea    0xdf7(%rip),%rdi
lea    0xe2b(%rip),%rsi
call   1090 <rename@plt>
test   %rax,%rax
js     124b <rewrite_mtab+0xcb>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xdc2(%rip),%rdi
jmp    1252 <rewrite_mtab+0xd2>
lea    0xddc(%rip),%rdi
jmp    1252 <rewrite_mtab+0xd2>
lea    0xdef(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
%struct.mntent = type { i32 }
@.str = [10 x i8] c"/etc/mtab\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [21 x i8] c"Can't open /etc/mtab\00"
@.str.3 = [14 x i8] c"/etc/mtab.new\00"
@.str.4 = [2 x i8] c"w\00"
@.str.5 = [28 x i8] c"Can't create temporary file\00"
@.str.6 = [27 x i8] c"Error installing /etc/mtab\00"
define i32 @rewrite_mtab() {
%1 = alloca i32*
%2 = alloca i32*
%3 = alloca %struct.mntent*
%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** %1
%5 = load i32*, i32** %1
%6 = icmp ne i32* %5, null
br i1 %6, label %10, label %7
7: ; preds = %0
%8 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%9 = call i32 @exit(i32 1)
unreachable
10: ; preds = %0
%11 = call i32* @setmntent(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %11, i32** %2
%12 = load i32*, i32** %2
%13 = icmp ne i32* %12, null
br i1 %13, label %17, label %14
14: ; preds = %10
%15 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0))
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %10
br label %18
18: ; preds = %33, %28, %17
%19 = load i32*, i32** %1
%20 = call %struct.mntent* @getmntent(i32* %19)
store %struct.mntent* %20, %struct.mntent** %3
%21 = icmp ne %struct.mntent* %20, null
br i1 %21, label %22, label %34
22: ; preds = %18
%23 = load %struct.mntent*, %struct.mntent** %3
%24 = getelementptr inbounds %struct.mntent, %struct.mntent* %23, i32 0, i32 0
%25 = load i32, i32* %24
%26 = call i64 @deleted(i32 %25)
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %22
br label %18
29: ; preds = %22
%30 = load i32*, i32** %2
%31 = load %struct.mntent*, %struct.mntent** %3
%32 = call i32 @addmntent(i32* %30, %struct.mntent* %31)
br label %33
33: ; preds = %29
br label %18
34: ; preds = %18
%35 = load i32*, i32** %1
%36 = call i32 @endmntent(i32* %35)
%37 = load i32*, i32** %2
%38 = call i32 @endmntent(i32* %37)
%39 = call i64 @rename(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%40 = icmp slt i64 %39, 0
br i1 %40, label %41, label %44
41: ; preds = %34
%42 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.6, i64 0, i64 0))
%43 = call i32 @exit(i32 1)
unreachable
44: ; preds = %34
ret i32 0
}

LLVM IR (-O2):
%struct.mntent = type { i32 }
@.str = [10 x i8] c"/etc/mtab\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [21 x i8] c"Can't open /etc/mtab\00"
@.str.3 = [14 x i8] c"/etc/mtab.new\00"
@.str.4 = [2 x i8] c"w\00"
@.str.5 = [28 x i8] c"Can't create temporary file\00"
@.str.6 = [27 x i8] c"Error installing /etc/mtab\00"
define i32 @rewrite_mtab() {
%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 %3, label %6
3: ; preds = %0
%4 = tail call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%5 = tail call i32 @exit(i32 1)
unreachable
6: ; preds = %0
%7 = tail call i32* @setmntent(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %12, label %9
9: ; preds = %6
%10 = tail call %struct.mntent* @getmntent(i32* %1)
%11 = icmp eq %struct.mntent* %10, null
br i1 %11, label %26, label %15
12: ; preds = %6
%13 = tail call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0))
%14 = tail call i32 @exit(i32 1)
unreachable
15: ; preds = %9, %23
%16 = phi %struct.mntent* [ %24, %23 ], [ %10, %9 ]
%17 = getelementptr inbounds %struct.mntent, %struct.mntent* %16, i64 0, i32 0
%18 = load i32, i32* %17
%19 = tail call i64 @deleted(i32 %18)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %15
%22 = tail call i32 @addmntent(i32* %7, %struct.mntent* %16)
br label %23
23: ; preds = %21, %15
%24 = tail call %struct.mntent* @getmntent(i32* %1)
%25 = icmp eq %struct.mntent* %24, null
br i1 %25, label %26, label %15
26: ; preds = %23, %9
%27 = tail call i32 @endmntent(i32* %1)
%28 = tail call i32 @endmntent(i32* %7)
%29 = tail call i64 @rename(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%30 = icmp slt i64 %29, 0
br i1 %30, label %31, label %34
31: ; preds = %26
%32 = tail call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.6, i64 0, i64 0))
%33 = tail call i32 @exit(i32 1)
unreachable
34: ; preds = %26
ret i32 0
}