#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 *);
char *strtok(char *, char *);
char *tmpnam(int /*<<< orphan*/ *);
scalar_t__ unlink(char *);
int rm_mtab(char *devname) {
  FILE *inpf, *outf;
  char *tmp_fname;
  char tmp[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)) {
    dev = strtok(tmp, " ");
    mntpt = strtok(NULL, " ");
    if (strcmp(dev, devname) == 0) {
      continue;
    } else {
      fprintf(outf, "%s", tmp);
    }
  }
  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    $0xd0,%rsp
mov    %rdi,-0x8(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   10d0 <tmpnam@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11ec <rm_mtab+0x3c>
lea    0xe23(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
lea    0xe9a(%rip),%rdi
lea    0xe28(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1224 <rm_mtab+0x74>
lea    0xe0f(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x20(%rbp),%rdi
lea    0xe0a(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1259 <rm_mtab+0xa9>
lea    0xdf1(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
jmp    125e <rm_mtab+0xae>
lea    -0xc0(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0xa0,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     12e9 <rm_mtab+0x139>
lea    -0xc0(%rbp),%rdi
lea    0xdcc(%rip),%rsi
call   10a0 <strtok@plt>
mov    %rax,-0xc8(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xdb5(%rip),%rsi
call   10a0 <strtok@plt>
mov    %rax,-0xd0(%rbp)
mov    -0xc8(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    12cd <rm_mtab+0x11d>
jmp    125e <rm_mtab+0xae>
mov    -0x18(%rbp),%rdi
lea    -0xc0(%rbp),%rdx
lea    0xd7a(%rip),%rsi
call   1070 <fprintf@plt>
jmp    125e <rm_mtab+0xae>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
lea    0xd8b(%rip),%rdi
call   1030 <unlink@plt>
cmp    $0x0,%rax
jge    1327 <rm_mtab+0x177>
lea    0xd44(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x20(%rbp),%rdi
lea    0xd5b(%rip),%rsi
call   10b0 <rename@plt>
cmp    $0x0,%rax
jge    1357 <rm_mtab+0x1a7>
lea    0xd34(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
xor    %eax,%eax
add    $0xd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rm_mtab>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xb8,%rsp
mov    %rdi,%r15
xor    %edi,%edi
call   10d0 <tmpnam@plt>
test   %rax,%rax
je     12d5 <rm_mtab+0x125>
mov    %rax,%rbx
lea    0xeac(%rip),%rdi
lea    0xe3d(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     12de <rm_mtab+0x12e>
mov    %rax,%r13
lea    0xe3c(%rip),%rsi
mov    %rbx,0x8(%rsp)
mov    %rbx,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     12e7 <rm_mtab+0x137>
mov    %rax,%r12
lea    0x10(%rsp),%rdi
mov    $0xa0,%esi
mov    %r13,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     128a <rm_mtab+0xda>
lea    0xe23(%rip),%rbx
lea    0x10(%rsp),%rbp
jmp    1255 <rm_mtab+0xa5>
nopl   0x0(%rax,%rax,1)
mov    %rbp,%rdi
mov    $0xa0,%esi
mov    %r13,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     128a <rm_mtab+0xda>
mov    %rbp,%rdi
mov    %rbx,%rsi
call   10a0 <strtok@plt>
mov    %rax,%r14
xor    %edi,%edi
mov    %rbx,%rsi
call   10a0 <strtok@plt>
mov    %r14,%rdi
mov    %r15,%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     1240 <rm_mtab+0x90>
mov    %rbp,%rdi
mov    %r12,%rsi
call   1050 <fputs@plt>
jmp    1240 <rm_mtab+0x90>
mov    %r13,%rdi
call   1040 <fclose@plt>
mov    %r12,%rdi
call   1040 <fclose@plt>
lea    0xde9(%rip),%rdi
call   1030 <unlink@plt>
test   %rax,%rax
js     12f0 <rm_mtab+0x140>
lea    0xdd8(%rip),%rsi
mov    0x8(%rsp),%rdi
call   10b0 <rename@plt>
test   %rax,%rax
js     12f9 <rm_mtab+0x149>
xor    %eax,%eax
add    $0xb8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd24(%rip),%rdi
jmp    1300 <rm_mtab+0x150>
lea    0xd3f(%rip),%rdi
jmp    1300 <rm_mtab+0x150>
lea    0xd4d(%rip),%rdi
jmp    1300 <rm_mtab+0x150>
lea    0xd62(%rip),%rdi
jmp    1300 <rm_mtab+0x150>
lea    0xd79(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@.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 [160 x i8]
%7 = alloca i8*
%8 = alloca i8*
store i8* %0, i8** %2
%9 = call i8* @tmpnam(i32* null)
store i8* %9, i8** %5
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %14
11: ; preds = %1
%12 = call i32 @perror(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %1
%15 = 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* %15, i32** %3
%16 = load i32*, i32** %3
%17 = icmp ne i32* %16, null
br i1 %17, label %21, label %18
18: ; preds = %14
%19 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %14
%22 = load i8*, i8** %5
%23 = call i32* @fopen(i8* %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %23, i32** %4
%24 = load i32*, i32** %4
%25 = icmp ne i32* %24, null
br i1 %25, label %29, label %26
26: ; preds = %21
%27 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0))
%28 = call i32 @exit(i32 1)
unreachable
29: ; preds = %21
br label %30
30: ; preds = %48, %43, %29
%31 = getelementptr inbounds [160 x i8], [160 x i8]* %6, i64 0, i64 0
%32 = load i32*, i32** %3
%33 = call i64 @fgets(i8* %31, i32 160, i32* %32)
%34 = icmp ne i64 %33, 0
br i1 %34, label %35, label %49
35: ; preds = %30
%36 = getelementptr inbounds [160 x i8], [160 x i8]* %6, i64 0, i64 0
%37 = call i8* @strtok(i8* %36, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
store i8* %37, i8** %7
%38 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
store i8* %38, i8** %8
%39 = load i8*, i8** %7
%40 = load i8*, i8** %2
%41 = call i64 @strcmp(i8* %39, i8* %40)
%42 = icmp eq i64 %41, 0
br i1 %42, label %43, label %44
43: ; preds = %35
br label %30
44: ; preds = %35
%45 = load i32*, i32** %4
%46 = getelementptr inbounds [160 x i8], [160 x i8]* %6, i64 0, i64 0
%47 = call i32 @fprintf(i32* %45, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i8* %46)
br label %48
48: ; preds = %44
br label %30
49: ; preds = %30
%50 = load i32*, i32** %3
%51 = call i32 @fclose(i32* %50)
%52 = load i32*, i32** %4
%53 = call i32 @fclose(i32* %52)
%54 = call i64 @unlink(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%55 = icmp slt i64 %54, 0
br i1 %55, label %56, label %59
56: ; preds = %49
%57 = call i32 @perror(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.8, i64 0, i64 0))
%58 = call i32 @exit(i32 1)
unreachable
59: ; preds = %49
%60 = load i8*, i8** %5
%61 = call i64 @rename(i8* %60, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%62 = icmp slt i64 %61, 0
br i1 %62, label %63, label %66
63: ; preds = %59
%64 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.9, i64 0, i64 0))
%65 = call i32 @exit(i32 1)
unreachable
66: ; preds = %59
ret i32 0
}

LLVM IR (-O2):
@.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 = alloca [160 x i8]
%3 = getelementptr inbounds [160 x i8], [160 x i8]* %2, i64 0, i64 0
%4 = tail call i8* @tmpnam(i32* null)
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %9
6: ; preds = %1
%7 = tail call i32 @perror(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %1
%10 = 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))
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %15
12: ; preds = %9
%13 = tail call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
%14 = tail call i32 @exit(i32 1)
unreachable
15: ; preds = %9
%16 = tail call i32* @fopen(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%17 = icmp eq i32* %16, null
br i1 %17, label %21, label %18
18: ; preds = %15
%19 = call i64 @fgets(i8* %3, i32 160, i32* %10)
%20 = icmp eq i64 %19, 0
br i1 %20, label %34, label %24
21: ; preds = %15
%22 = tail call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0))
%23 = tail call i32 @exit(i32 1)
unreachable
24: ; preds = %18, %31
%25 = call i8* @strtok(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%26 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%27 = call i64 @strcmp(i8* %25, i8* %0)
%28 = icmp eq i64 %27, 0
br i1 %28, label %31, label %29
29: ; preds = %24
%30 = call i32 @fputs(i8* %3, i32* %16)
br label %31
31: ; preds = %29, %24
%32 = call i64 @fgets(i8* %3, i32 160, i32* %10)
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %24
34: ; preds = %31, %18
%35 = call i32 @fclose(i32* %10)
%36 = call i32 @fclose(i32* %16)
%37 = call i64 @unlink(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%38 = icmp slt i64 %37, 0
br i1 %38, label %39, label %42
39: ; preds = %34
%40 = call i32 @perror(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.8, i64 0, i64 0))
%41 = call i32 @exit(i32 1)
unreachable
42: ; preds = %34
%43 = call i64 @rename(i8* %4, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%44 = icmp slt i64 %43, 0
br i1 %44, label %45, label %48
45: ; preds = %42
%46 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.9, i64 0, i64 0))
%47 = call i32 @exit(i32 1)
unreachable
48: ; preds = %42
ret i32 0
}