#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;
  char tmp[160];
  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    $0x170,%rsp
mov    %rdi,-0x8(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   10e0 <tmpnam@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11fc <rm_mtab+0x3c>
lea    0xe13(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
lea    0xe8a(%rip),%rdi
lea    0xe18(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1234 <rm_mtab+0x74>
lea    0xdff(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x20(%rbp),%rdi
lea    0xdfa(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1269 <rm_mtab+0xa9>
lea    0xde1(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
jmp    126e <rm_mtab+0xae>
lea    -0xc0(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0xa0,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     12fa <rm_mtab+0x13a>
lea    -0x160(%rbp),%rdi
lea    -0xc0(%rbp),%rsi
mov    $0xa0,%edx
call   1040 <strncpy@plt>
lea    -0xc0(%rbp),%rdi
lea    0xda4(%rip),%rsi
call   10b0 <strtok@plt>
mov    %rax,-0x168(%rbp)
mov    -0x168(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    12de <rm_mtab+0x11e>
jmp    126e <rm_mtab+0xae>
mov    -0x18(%rbp),%rdi
lea    -0x160(%rbp),%rdx
lea    0xd69(%rip),%rsi
call   1080 <fprintf@plt>
jmp    126e <rm_mtab+0xae>
mov    -0x10(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
lea    0xd7a(%rip),%rdi
call   1030 <unlink@plt>
cmp    $0x0,%rax
jge    1338 <rm_mtab+0x178>
lea    0xd33(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x20(%rbp),%rdi
lea    0xd4a(%rip),%rsi
call   10c0 <rename@plt>
cmp    $0x0,%rax
jge    1368 <rm_mtab+0x1a8>
lea    0xd23(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
xor    %eax,%eax
add    $0x170,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rm_mtab>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x158,%rsp
mov    %rdi,%r15
xor    %edi,%edi
call   10e0 <tmpnam@plt>
test   %rax,%rax
je     12f8 <rm_mtab+0x138>
mov    %rax,%rbx
lea    0xe9c(%rip),%rdi
lea    0xe2d(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     1301 <rm_mtab+0x141>
mov    %rax,%r13
lea    0xe2c(%rip),%rsi
mov    %rbx,0x8(%rsp)
mov    %rbx,%rdi
call   1090 <fopen@plt>
test   %rax,%rax
je     130a <rm_mtab+0x14a>
mov    %rax,%r12
lea    0x10(%rsp),%rdi
mov    $0xa0,%esi
mov    %r13,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     12ad <rm_mtab+0xed>
lea    0xb0(%rsp),%rbx
lea    0x10(%rsp),%rbp
lea    0xe06(%rip),%r14
jmp    1275 <rm_mtab+0xb5>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbp,%rdi
mov    $0xa0,%esi
mov    %r13,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     12ad <rm_mtab+0xed>
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     1260 <rm_mtab+0xa0>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1060 <fputs@plt>
jmp    1260 <rm_mtab+0xa0>
mov    %r13,%rdi
call   1050 <fclose@plt>
mov    %r12,%rdi
call   1050 <fclose@plt>
lea    0xdc6(%rip),%rdi
call   1030 <unlink@plt>
test   %rax,%rax
js     1313 <rm_mtab+0x153>
lea    0xdb5(%rip),%rsi
mov    0x8(%rsp),%rdi
call   10c0 <rename@plt>
test   %rax,%rax
js     131c <rm_mtab+0x15c>
xor    %eax,%eax
add    $0x158,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd01(%rip),%rdi
jmp    1323 <rm_mtab+0x163>
lea    0xd1c(%rip),%rdi
jmp    1323 <rm_mtab+0x163>
lea    0xd2a(%rip),%rdi
jmp    1323 <rm_mtab+0x163>
lea    0xd3f(%rip),%rdi
jmp    1323 <rm_mtab+0x163>
lea    0xd56(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10d0 <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 [160 x i8]
%8 = alloca i8*
%9 = alloca i8*
store i8* %0, i8** %2
%10 = call i8* @tmpnam(i32* null)
store i8* %10, i8** %5
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %15
12: ; preds = %1
%13 = call i32 @perror(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %1
%16 = 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* %16, i32** %3
%17 = load i32*, i32** %3
%18 = icmp ne i32* %17, null
br i1 %18, label %22, label %19
19: ; preds = %15
%20 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %15
%23 = load i8*, i8** %5
%24 = call i32* @fopen(i8* %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %24, i32** %4
%25 = load i32*, i32** %4
%26 = icmp ne i32* %25, null
br i1 %26, label %30, label %27
27: ; preds = %22
%28 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0))
%29 = call i32 @exit(i32 1)
unreachable
30: ; preds = %22
br label %31
31: ; preds = %51, %46, %30
%32 = getelementptr inbounds [160 x i8], [160 x i8]* %6, i64 0, i64 0
%33 = load i32*, i32** %3
%34 = call i64 @fgets(i8* %32, i32 160, i32* %33)
%35 = icmp ne i64 %34, 0
br i1 %35, label %36, label %52
36: ; preds = %31
%37 = getelementptr inbounds [160 x i8], [160 x i8]* %7, i64 0, i64 0
%38 = getelementptr inbounds [160 x i8], [160 x i8]* %6, i64 0, i64 0
%39 = call i32 @strncpy(i8* %37, i8* %38, i32 160)
%40 = getelementptr inbounds [160 x i8], [160 x i8]* %6, i64 0, i64 0
%41 = call i8* @strtok(i8* %40, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
store i8* %41, i8** %8
%42 = load i8*, i8** %8
%43 = load i8*, i8** %2
%44 = call i64 @strcmp(i8* %42, i8* %43)
%45 = icmp eq i64 %44, 0
br i1 %45, label %46, label %47
46: ; preds = %36
br label %31
47: ; preds = %36
%48 = load i32*, i32** %4
%49 = getelementptr inbounds [160 x i8], [160 x i8]* %7, i64 0, i64 0
%50 = call i32 @fprintf(i32* %48, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i8* %49)
br label %51
51: ; preds = %47
br label %31
52: ; preds = %31
%53 = load i32*, i32** %3
%54 = call i32 @fclose(i32* %53)
%55 = load i32*, i32** %4
%56 = call i32 @fclose(i32* %55)
%57 = call i64 @unlink(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 = %52
%60 = call i32 @perror(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.8, i64 0, i64 0))
%61 = call i32 @exit(i32 1)
unreachable
62: ; preds = %52
%63 = load i8*, i8** %5
%64 = call i64 @rename(i8* %63, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%65 = icmp slt i64 %64, 0
br i1 %65, label %66, label %69
66: ; preds = %62
%67 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.9, i64 0, i64 0))
%68 = call i32 @exit(i32 1)
unreachable
69: ; preds = %62
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 = alloca [160 x i8]
%4 = getelementptr inbounds [160 x i8], [160 x i8]* %2, i64 0, i64 0
%5 = getelementptr inbounds [160 x i8], [160 x i8]* %3, i64 0, i64 0
%6 = tail call i8* @tmpnam(i32* null)
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %11
8: ; preds = %1
%9 = tail call i32 @perror(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %1
%12 = 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))
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %17
14: ; preds = %11
%15 = tail call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
%16 = tail call i32 @exit(i32 1)
unreachable
17: ; preds = %11
%18 = tail call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%19 = icmp eq i32* %18, null
br i1 %19, label %23, label %20
20: ; preds = %17
%21 = call i64 @fgets(i8* %4, i32 160, i32* %12)
%22 = icmp eq i64 %21, 0
br i1 %22, label %36, label %26
23: ; preds = %17
%24 = tail call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0))
%25 = tail call i32 @exit(i32 1)
unreachable
26: ; preds = %20, %33
%27 = call i32 @strncpy(i8* %5, i8* %4, i32 160)
%28 = call i8* @strtok(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%29 = call i64 @strcmp(i8* %28, i8* %0)
%30 = icmp eq i64 %29, 0
br i1 %30, label %33, label %31
31: ; preds = %26
%32 = call i32 @fputs(i8* %5, i32* %18)
br label %33
33: ; preds = %31, %26
%34 = call i64 @fgets(i8* %4, i32 160, i32* %12)
%35 = icmp eq i64 %34, 0
br i1 %35, label %36, label %26
36: ; preds = %33, %20
%37 = call i32 @fclose(i32* %12)
%38 = call i32 @fclose(i32* %18)
%39 = call i64 @unlink(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%40 = icmp slt i64 %39, 0
br i1 %40, label %41, label %44
41: ; preds = %36
%42 = call i32 @perror(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.8, i64 0, i64 0))
%43 = call i32 @exit(i32 1)
unreachable
44: ; preds = %36
%45 = call i64 @rename(i8* %6, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%46 = icmp slt i64 %45, 0
br i1 %46, label %47, label %50
47: ; preds = %44
%48 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.9, i64 0, i64 0))
%49 = call i32 @exit(i32 1)
unreachable
50: ; preds = %44
ret i32 0
}