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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ panic(char *);
char *strchr(char *, char);
scalar_t__ strncmp(char *, char *, int);
void check_mounts(void) {
  FILE *mnt;
  char str[256];
  char *p;
  mnt = fopen("/proc/mounts", "r");
  if (mnt == NULL)
    panic("cannot get mountpoints\n");
  while (fgets(str, sizeof(str), mnt) != NULL) {
    p = strchr(str, ' ');
    if (p != NULL) {
      *p = '\0';
      if (strncmp(str, "/dev/mtd", 8) == 0) {
        panic("you must umount any flash file systems before upgrading\n");
      }
    }
  }
  fclose(mnt);
}


x86 assembly (clang, -O0):
<check_mounts>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
lea    0xe8e(%rip),%rdi
lea    0xe94(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1199 <check_mounts+0x39>
lea    0xe7b(%rip),%rdi
call   1060 <panic@plt>
jmp    119e <check_mounts+0x3e>
lea    -0x110(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0x100,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
je     1225 <check_mounts+0xc5>
lea    -0x110(%rbp),%rdi
mov    $0x20,%esi
call   1050 <strchr@plt>
mov    %rax,-0x118(%rbp)
cmpq   $0x0,-0x118(%rbp)
je     1220 <check_mounts+0xc0>
mov    -0x118(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x110(%rbp),%rdi
lea    0xe2c(%rip),%rsi
mov    $0x8,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    121b <check_mounts+0xbb>
lea    0xe1a(%rip),%rdi
call   1060 <panic@plt>
jmp    1220 <check_mounts+0xc0>
jmp    119e <check_mounts+0x3e>
mov    -0x8(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_mounts>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x108,%rsp
lea    0xe8b(%rip),%rdi
lea    0xe91(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%r14
test   %rax,%rax
jne    1195 <check_mounts+0x35>
lea    0xe7f(%rip),%rdi
call   1060 <panic@plt>
mov    %rsp,%rdi
mov    $0x100,%esi
mov    %r14,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     1209 <check_mounts+0xa9>
mov    %rsp,%rbx
lea    0xe73(%rip),%r15
lea    0xe75(%rip),%r12
jmp    11d5 <check_mounts+0x75>
nopl   (%rax)
mov    %rbx,%rdi
mov    $0x100,%esi
mov    %r14,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     1209 <check_mounts+0xa9>
mov    %rbx,%rdi
mov    $0x20,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     11c0 <check_mounts+0x60>
movb   $0x0,(%rax)
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x8,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    11c0 <check_mounts+0x60>
mov    %r12,%rdi
call   1060 <panic@plt>
jmp    11c0 <check_mounts+0x60>
mov    %r14,%rdi
call   1040 <fclose@plt>
add    $0x108,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [13 x i8] c"/proc/mounts\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [24 x i8] c"cannot get mountpoints\0A\00"
@.str.3 = [9 x i8] c"/dev/mtd\00"
@.str.4 = [57 x i8] c"you must umount any flash file systems before upgrading\0A\00"
define void @check_mounts() {
%1 = alloca i32*
%2 = alloca [256 x i8]
%3 = alloca i8*
%4 = 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* %4, i32** %1
%5 = load i32*, i32** %1
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = call i32 @panic(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
br label %9
9: ; preds = %7, %0
br label %10
10: ; preds = %28, %9
%11 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%12 = load i32*, i32** %1
%13 = call i32* @fgets(i8* %11, i32 256, i32* %12)
%14 = icmp ne i32* %13, null
br i1 %14, label %15, label %29
15: ; preds = %10
%16 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%17 = call i8* @strchr(i8* %16, i8 signext 32)
store i8* %17, i8** %3
%18 = load i8*, i8** %3
%19 = icmp ne i8* %18, null
br i1 %19, label %20, label %28
20: ; preds = %15
%21 = load i8*, i8** %3
store i8 0, i8* %21
%22 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%23 = call i64 @strncmp(i8* %22, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 8)
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %20
%26 = call i32 @panic(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.4, i64 0, i64 0))
br label %27
27: ; preds = %25, %20
br label %28
28: ; preds = %27, %15
br label %10
29: ; preds = %10
%30 = load i32*, i32** %1
%31 = call i32 @fclose(i32* %30)
ret void
}

LLVM IR (-O2):
@.str = [13 x i8] c"/proc/mounts\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [24 x i8] c"cannot get mountpoints\0A\00"
@.str.3 = [9 x i8] c"/dev/mtd\00"
@.str.4 = [57 x i8] c"you must umount any flash file systems before upgrading\0A\00"
define void @check_mounts() {
%1 = alloca [256 x i8]
%2 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%3 = 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))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = tail call i32 @panic(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
br label %7
7: ; preds = %5, %0
%8 = call i32* @fgets(i8* %2, i32 256, i32* %3)
%9 = icmp eq i32* %8, null
br i1 %9, label %21, label %10
10: ; preds = %7, %18
%11 = call i8* @strchr(i8* %2, i8 signext 32)
%12 = icmp eq i8* %11, null
br i1 %12, label %18, label %13
13: ; preds = %10
store i8 0, i8* %11
%14 = call i64 @strncmp(i8* %2, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 8)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %13
%17 = call i32 @panic(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.4, i64 0, i64 0))
br label %18
18: ; preds = %13, %16, %10
%19 = call i32* @fgets(i8* %2, i32 256, i32* %3)
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %10
21: ; preds = %18, %7
%22 = call i32 @fclose(i32* %3)
ret void
}