#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, unsigned int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ remove(char *);
int /*<<< orphan*/ rename(char *, char *);
int /*<<< orphan*/ *strstr(char *, char *);
void uMountDrive(char *mnt) {
  FILE *log = fopen("/dtv/usb/log", "r");
  if (log == NULL)
    return;
  FILE *tmp = fopen("/dtv/usb/log_tmp", "w");
  unsigned int lineL = 100, deleted = 0;
  char line[lineL];
  while (fgets(line, lineL, log) != NULL) {
    if (strstr(line, mnt) != NULL)
      deleted++;
    else if (deleted == 0 || deleted == 9) {
      fprintf(tmp, "%s", line);
    } else
      deleted++;
  }
  fclose(log);
  fclose(tmp);
  remove("/dtv/usb/log");
  rename("/dtv/usb/log_tmp", "/dtv/usb/log");
}


x86 assembly (clang, -O0):
<uMountDrive>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xe7d(%rip),%rdi
lea    0xe83(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11a3 <uMountDrive+0x33>
jmp    12a5 <uMountDrive+0x135>
lea    0xe65(%rip),%rdi
lea    0xe6f(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
movl   $0x64,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x10(%rbp),%rdx
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     126d <uMountDrive+0xfd>
mov    -0x38(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1090 <strstr@plt>
cmp    $0x0,%rax
je     122d <uMountDrive+0xbd>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1268 <uMountDrive+0xf8>
cmpl   $0x0,-0x20(%rbp)
je     1241 <uMountDrive+0xd1>
cmpl   $0x9,-0x20(%rbp)
jne    125a <uMountDrive+0xea>
mov    -0x38(%rbp),%rdx
mov    -0x18(%rbp),%rdi
lea    0xdd2(%rip),%rsi
call   1060 <fprintf@plt>
jmp    1263 <uMountDrive+0xf3>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1268 <uMountDrive+0xf8>
jmp    11ee <uMountDrive+0x7e>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
lea    0xd7a(%rip),%rdi
call   1030 <remove@plt>
lea    0xd7d(%rip),%rdi
lea    0xd67(%rip),%rsi
call   1080 <rename@plt>
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<uMountDrive>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
lea    0xe78(%rip),%rdi
lea    0xe7e(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1253 <uMountDrive+0xe3>
mov    %rax,%r12
lea    0xe68(%rip),%rdi
lea    0xe72(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%r15
mov    %rsp,-0x30(%rbp)
mov    %rsp,%rbx
add    $0xffffffffffffff90,%rbx
mov    %rbx,%rsp
mov    %rbx,%rdi
mov    $0x64,%esi
mov    %r12,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     1221 <uMountDrive+0xb1>
xor    %r13d,%r13d
jmp    11f9 <uMountDrive+0x89>
xchg   %ax,%ax
add    $0x1,%r13d
mov    %rbx,%rdi
mov    $0x64,%esi
mov    %r12,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     1221 <uMountDrive+0xb1>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1090 <strstr@plt>
test   %rax,%rax
jne    11e0 <uMountDrive+0x70>
cmp    $0x9,%r13d
je     1214 <uMountDrive+0xa4>
test   %r13d,%r13d
jne    11e0 <uMountDrive+0x70>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1050 <fputs@plt>
jmp    11e4 <uMountDrive+0x74>
mov    %r12,%rdi
call   1040 <fclose@plt>
mov    %r15,%rdi
call   1040 <fclose@plt>
lea    0xdc8(%rip),%rbx
mov    %rbx,%rdi
call   1030 <remove@plt>
lea    0xdc8(%rip),%rdi
mov    %rbx,%rsi
call   1080 <rename@plt>
mov    -0x30(%rbp),%rsp
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"/dtv/usb/log\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [17 x i8] c"/dtv/usb/log_tmp\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [3 x i8] c"%s\00"
define void @uMountDrive(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
store i8* %0, i8** %2
%9 = call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %9, i32** %3
%10 = load i32*, i32** %3
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %13
12: ; preds = %1
br label %53
13: ; preds = %1
%14 = call i32* @fopen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %14, i32** %4
store i32 100, i32* %5
store i32 0, i32* %6
%15 = load i32, i32* %5
%16 = zext i32 %15 to i64
%17 = call i8* @llvm.stacksave()
store i8* %17, i8** %7
%18 = alloca i8, i64 %16
store i64 %16, i64* %8
br label %19
19: ; preds = %44, %13
%20 = load i32, i32* %5
%21 = load i32*, i32** %3
%22 = call i32* @fgets(i8* %18, i32 %20, i32* %21)
%23 = icmp ne i32* %22, null
br i1 %23, label %24, label %45
24: ; preds = %19
%25 = load i8*, i8** %2
%26 = call i32* @strstr(i8* %18, i8* %25)
%27 = icmp ne i32* %26, null
br i1 %27, label %28, label %31
28: ; preds = %24
%29 = load i32, i32* %6
%30 = add i32 %29, 1
store i32 %30, i32* %6
br label %44
31: ; preds = %24
%32 = load i32, i32* %6
%33 = icmp eq i32 %32, 0
br i1 %33, label %37, label %34
34: ; preds = %31
%35 = load i32, i32* %6
%36 = icmp eq i32 %35, 9
br i1 %36, label %37, label %40
37: ; preds = %34, %31
%38 = load i32*, i32** %4
%39 = call i32 @fprintf(i32* %38, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %18)
br label %43
40: ; preds = %34
%41 = load i32, i32* %6
%42 = add i32 %41, 1
store i32 %42, i32* %6
br label %43
43: ; preds = %40, %37
br label %44
44: ; preds = %43, %28
br label %19
45: ; preds = %19
%46 = load i32*, i32** %3
%47 = call i32 @fclose(i32* %46)
%48 = load i32*, i32** %4
%49 = call i32 @fclose(i32* %48)
%50 = call i32 @remove(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%51 = call i32 @rename(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%52 = load i8*, i8** %7
br label %53
53: ; preds = %45, %12
ret void
}

LLVM IR (-O2):
@.str = [13 x i8] c"/dtv/usb/log\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [17 x i8] c"/dtv/usb/log_tmp\00"
@.str.3 = [2 x i8] c"w\00"
define void @uMountDrive(i8* nocapture %0) {
%2 = tail call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %31, label %4
4: ; preds = %1
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%6 = tail call i8* @llvm.stacksave()
%7 = alloca [100 x i8]
%8 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%9 = call i32* @fgets(i8* %8, i32 100, i32* %2)
%10 = icmp eq i32* %9, null
br i1 %10, label %26, label %11
11: ; preds = %4, %22
%12 = phi i32 [ %23, %22 ], [ 0, %4 ]
%13 = call i32* @strstr(i8* %8, i8* dereferenceable(1) %0)
%14 = icmp eq i32* %13, null
br i1 %14, label %17, label %15
15: ; preds = %11
%16 = add i32 %12, 1
br label %22
17: ; preds = %11
switch i32 %12, label %20 [
i32 9, label %18
i32 0, label %18
]
18: ; preds = %17, %17
%19 = call i32 @fputs(i8* %8, i32* %5)
br label %22
20: ; preds = %17
%21 = add i32 %12, 1
br label %22
22: ; preds = %18, %20, %15
%23 = phi i32 [ %16, %15 ], [ %12, %18 ], [ %21, %20 ]
%24 = call i32* @fgets(i8* %8, i32 100, i32* %2)
%25 = icmp eq i32* %24, null
br i1 %25, label %26, label %11
26: ; preds = %22, %4
%27 = call i32 @fclose(i32* %2)
%28 = call i32 @fclose(i32* %5)
%29 = call i32 @remove(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%30 = call i32 @rename(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
br label %31
31: ; preds = %1, %26
ret void
}