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

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ perror(char *);
scalar_t__ rename(char *, char *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *strtok(char *, char *);
char *tmpnam(int /*<<< orphan*/ *);
scalar_t__ unlink(char *);
int rm_mtab(char *devname) {
  FILE *inpf, *outf;
  char *tmp_fname;
  static char tmp[160];
  static char tmp2[160];
  char *dev;
  char *mntpt;
  if ((tmp_fname = tmpnam(NULL)) == NULL) {
    perror("Error getting temporary file name");
    exit(1);
  }
  inpf = fopen("/etc/mtab", "r");
  if (!inpf) {
    perror("Can't open /etc/mtab");
    exit(1);
  }
  outf = fopen(tmp_fname, "w");
  if (!outf) {
    perror("Can't create temporary file");
    exit(1);
  }
  while (fgets(tmp, sizeof(tmp), inpf)) {
    strncpy(tmp2, tmp, 160);
    dev = strtok(tmp, " ");
    if (strcmp(dev, devname) == 0) {
      continue;
    } else {
      fprintf(outf, "%s", tmp2);
    }
  }
  fclose(inpf);
  fclose(outf);
  if (unlink("/etc/mtab") < 0) {
    perror("Can't delete old /etc/mtab file");
    exit(1);
  }
  if (rename(tmp_fname, "/etc/mtab") < 0) {
    perror("Error installing /etc/mtab");
    exit(1);
  }
  return 0;
}


x86 assembly (clang, -O0):
<rm_mtab>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   10e0 <tmpnam@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11f9 <rm_mtab+0x39>
lea    0xe16(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
lea    0xe8d(%rip),%rdi
lea    0xe1b(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1231 <rm_mtab+0x71>
lea    0xe02(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x20(%rbp),%rdi
lea    0xdfd(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1266 <rm_mtab+0xa6>
lea    0xde4(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
jmp    126b <rm_mtab+0xab>
mov    -0x10(%rbp),%rdx
lea    0x2e1a(%rip),%rdi
mov    $0xa0,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     12f1 <rm_mtab+0x131>
lea    0x2e9f(%rip),%rdi
lea    0x2df8(%rip),%rsi
mov    $0xa0,%edx
call   1040 <strncpy@plt>
lea    0x2de7(%rip),%rdi
lea    0xda7(%rip),%rsi
call   10b0 <strtok@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    12d5 <rm_mtab+0x115>
jmp    126b <rm_mtab+0xab>
mov    -0x18(%rbp),%rdi
lea    0xd79(%rip),%rsi
lea    0x2e49(%rip),%rdx
call   1080 <fprintf@plt>
jmp    126b <rm_mtab+0xab>
mov    -0x10(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
lea    0xd83(%rip),%rdi
call   1030 <unlink@plt>
cmp    $0x0,%rax
jge    132f <rm_mtab+0x16f>
lea    0xd3c(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x20(%rbp),%rdi
lea    0xd53(%rip),%rsi
call   10c0 <rename@plt>
cmp    $0x0,%rax
jge    135f <rm_mtab+0x19f>
lea    0xd2c(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rm_mtab>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r15
xor    %edi,%edi
call   10e0 <tmpnam@plt>
test   %rax,%rax
je     12e4 <rm_mtab+0x124>
mov    %rax,%rbx
lea    0xea2(%rip),%rdi
lea    0xe33(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     12ed <rm_mtab+0x12d>
mov    %rax,%r13
lea    0xe32(%rip),%rsi
mov    %rbx,(%rsp)
mov    %rbx,%rdi
call   1090 <fopen@plt>
test   %rax,%rax
je     12f6 <rm_mtab+0x136>
mov    %rax,%r12
lea    0x2e6a(%rip),%rdi
mov    $0xa0,%esi
mov    %r13,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     129d <rm_mtab+0xdd>
lea    0x2ef1(%rip),%rbx
lea    0x2e4a(%rip),%rbp
lea    0xe0a(%rip),%r14
jmp    1265 <rm_mtab+0xa5>
nop
mov    %rbp,%rdi
mov    $0xa0,%esi
mov    %r13,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     129d <rm_mtab+0xdd>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    $0xa0,%edx
call   1040 <strncpy@plt>
mov    %rbp,%rdi
mov    %r14,%rsi
call   10b0 <strtok@plt>
mov    %rax,%rdi
mov    %r15,%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
je     1250 <rm_mtab+0x90>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1060 <fputs@plt>
jmp    1250 <rm_mtab+0x90>
mov    %r13,%rdi
call   1050 <fclose@plt>
mov    %r12,%rdi
call   1050 <fclose@plt>
lea    0xdd6(%rip),%rdi
call   1030 <unlink@plt>
test   %rax,%rax
js     12ff <rm_mtab+0x13f>
lea    0xdc5(%rip),%rsi
mov    (%rsp),%rdi
call   10c0 <rename@plt>
test   %rax,%rax
js     1308 <rm_mtab+0x148>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd15(%rip),%rdi
jmp    130f <rm_mtab+0x14f>
lea    0xd30(%rip),%rdi
jmp    130f <rm_mtab+0x14f>
lea    0xd3e(%rip),%rdi
jmp    130f <rm_mtab+0x14f>
lea    0xd53(%rip),%rdi
jmp    130f <rm_mtab+0x14f>
lea    0xd6a(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
@rm_mtab.tmp = internal global [160 x i8] zeroinitializer
@rm_mtab.tmp2 = internal global [160 x i8] zeroinitializer
@.str = [34 x i8] c"Error getting temporary file name\00"
@.str.1 = [10 x i8] c"/etc/mtab\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [21 x i8] c"Can't open /etc/mtab\00"
@.str.4 = [2 x i8] c"w\00"
@.str.5 = [28 x i8] c"Can't create temporary file\00"
@.str.6 = [2 x i8] c" \00"
@.str.7 = [3 x i8] c"%s\00"
@.str.8 = [32 x i8] c"Can't delete old /etc/mtab file\00"
@.str.9 = [27 x i8] c"Error installing /etc/mtab\00"
define i32 @rm_mtab(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
store i8* %0, i8** %2
%8 = call i8* @tmpnam(i32* null)
store i8* %8, i8** %5
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %13
10: ; preds = %1
%11 = call i32 @perror(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @exit(i32 1)
unreachable
13: ; preds = %1
%14 = call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %14, i32** %3
%15 = load i32*, i32** %3
%16 = icmp ne i32* %15, null
br i1 %16, label %20, label %17
17: ; preds = %13
%18 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %13
%21 = load i8*, i8** %5
%22 = call i32* @fopen(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %22, i32** %4
%23 = load i32*, i32** %4
%24 = icmp ne i32* %23, null
br i1 %24, label %28, label %25
25: ; preds = %20
%26 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0))
%27 = call i32 @exit(i32 1)
unreachable
28: ; preds = %20
br label %29
29: ; preds = %44, %40, %28
%30 = load i32*, i32** %3
%31 = call i64 @fgets(i8* getelementptr inbounds ([160 x i8], [160 x i8]* @rm_mtab.tmp, i64 0, i64 0), i32 160, i32* %30)
%32 = icmp ne i64 %31, 0
br i1 %32, label %33, label %45
33: ; preds = %29
%34 = call i32 @strncpy(i8* getelementptr inbounds ([160 x i8], [160 x i8]* @rm_mtab.tmp2, i64 0, i64 0), i8* getelementptr inbounds ([160 x i8], [160 x i8]* @rm_mtab.tmp, i64 0, i64 0), i32 160)
%35 = call i8* @strtok(i8* getelementptr inbounds ([160 x i8], [160 x i8]* @rm_mtab.tmp, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
store i8* %35, i8** %6
%36 = load i8*, i8** %6
%37 = load i8*, i8** %2
%38 = call i64 @strcmp(i8* %36, i8* %37)
%39 = icmp eq i64 %38, 0
br i1 %39, label %40, label %41
40: ; preds = %33
br label %29
41: ; preds = %33
%42 = load i32*, i32** %4
%43 = call i32 @fprintf(i32* %42, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([160 x i8], [160 x i8]* @rm_mtab.tmp2, i64 0, i64 0))
br label %44
44: ; preds = %41
br label %29
45: ; preds = %29
%46 = load i32*, i32** %3
%47 = call i32 @fclose(i32* %46)
%48 = load i32*, i32** %4
%49 = call i32 @fclose(i32* %48)
%50 = call i64 @unlink(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%51 = icmp slt i64 %50, 0
br i1 %51, label %52, label %55
52: ; preds = %45
%53 = call i32 @perror(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.8, i64 0, i64 0))
%54 = call i32 @exit(i32 1)
unreachable
55: ; preds = %45
%56 = load i8*, i8** %5
%57 = call i64 @rename(i8* %56, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%58 = icmp slt i64 %57, 0
br i1 %58, label %59, label %62
59: ; preds = %55
%60 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.9, i64 0, i64 0))
%61 = call i32 @exit(i32 1)
unreachable
62: ; preds = %55
ret i32 0
}

LLVM IR (-O2):
@rm_mtab.tmp = internal global [160 x i8] zeroinitializer
@rm_mtab.tmp2 = internal global [160 x i8] zeroinitializer
@.str = [34 x i8] c"Error getting temporary file name\00"
@.str.1 = [10 x i8] c"/etc/mtab\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [21 x i8] c"Can't open /etc/mtab\00"
@.str.4 = [2 x i8] c"w\00"
@.str.5 = [28 x i8] c"Can't create temporary file\00"
@.str.6 = [2 x i8] c" \00"
@.str.8 = [32 x i8] c"Can't delete old /etc/mtab file\00"
@.str.9 = [27 x i8] c"Error installing /etc/mtab\00"
define i32 @rm_mtab(i8* %0) {
%2 = tail call i8* @tmpnam(i32* null)
%3 = icmp eq i8* %2, null
br i1 %3, label %4, label %7
4: ; preds = %1
%5 = tail call i32 @perror(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
%6 = tail call i32 @exit(i32 1)
unreachable
7: ; preds = %1
%8 = tail call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %13
10: ; preds = %7
%11 = tail call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %7
%14 = tail call i32* @fopen(i8* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%15 = icmp eq i32* %14, null
br i1 %15, label %19, label %16
16: ; preds = %13
%17 = tail call i64 @fgets(i8* getelementptr inbounds ([160 x i8], [160 x i8]* @rm_mtab.tmp, i64 0, i64 0), i32 160, i32* %8)
%18 = icmp eq i64 %17, 0
br i1 %18, label %32, label %22
19: ; preds = %13
%20 = tail call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0))
%21 = tail call i32 @exit(i32 1)
unreachable
22: ; preds = %16, %29
%23 = tail call i32 @strncpy(i8* getelementptr inbounds ([160 x i8], [160 x i8]* @rm_mtab.tmp2, i64 0, i64 0), i8* getelementptr inbounds ([160 x i8], [160 x i8]* @rm_mtab.tmp, i64 0, i64 0), i32 160)
%24 = tail call i8* @strtok(i8* getelementptr inbounds ([160 x i8], [160 x i8]* @rm_mtab.tmp, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%25 = tail call i64 @strcmp(i8* %24, i8* %0)
%26 = icmp eq i64 %25, 0
br i1 %26, label %29, label %27
27: ; preds = %22
%28 = tail call i32 @fputs(i8* getelementptr inbounds ([160 x i8], [160 x i8]* @rm_mtab.tmp2, i64 0, i64 0), i32* %14)
br label %29
29: ; preds = %27, %22
%30 = tail call i64 @fgets(i8* getelementptr inbounds ([160 x i8], [160 x i8]* @rm_mtab.tmp, i64 0, i64 0), i32 160, i32* %8)
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %22
32: ; preds = %29, %16
%33 = tail call i32 @fclose(i32* %8)
%34 = tail call i32 @fclose(i32* %14)
%35 = tail call i64 @unlink(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%36 = icmp slt i64 %35, 0
br i1 %36, label %37, label %40
37: ; preds = %32
%38 = tail call i32 @perror(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.8, i64 0, i64 0))
%39 = tail call i32 @exit(i32 1)
unreachable
40: ; preds = %32
%41 = tail call i64 @rename(i8* %2, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%42 = icmp slt i64 %41, 0
br i1 %42, label %43, label %46
43: ; preds = %40
%44 = tail call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.9, i64 0, i64 0))
%45 = tail call i32 @exit(i32 1)
unreachable
46: ; preds = %40
ret i32 0
}