#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 */
struct stat {
  int /*<<< orphan*/ st_dev;
};
typedef int /*<<< orphan*/ buffer;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ dev_add(char *, int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ stat(char *, struct stat *);
void dev_cache_mounts(void) {
  FILE *fp;
  char buffer[1024];
  fp = fopen("/proc/mounts", "r");
  if (!fp)
    return;
  while (fgets(buffer, sizeof(buffer), fp)) {
    struct stat statbuf;
    char *ptr = buffer;
    char *path;
    while (*ptr && *ptr != ' ' && *ptr != '\n')
      ptr++;
    if (!*ptr)
      continue;
    ptr++;
    path = ptr;
    while (*ptr && *ptr != ' ' && *ptr != '\n')
      ptr++;
    *ptr = '\0';
    if (stat(path, &statbuf) < 0)
      continue;
    dev_add(path, statbuf.st_dev);
  }
  (void)fclose(fp);
}


x86 assembly (clang, -O0):
<dev_cache_mounts>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
lea    0xe9e(%rip),%rdi
lea    0xea4(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1182 <dev_cache_mounts+0x32>
jmp    1321 <dev_cache_mounts+0x1d1>
jmp    1187 <dev_cache_mounts+0x37>
lea    -0x410(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0x400,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     1318 <dev_cache_mounts+0x1c8>
lea    -0x410(%rbp),%rax
mov    %rax,-0x420(%rbp)
mov    -0x420(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x429(%rbp)
je     1200 <dev_cache_mounts+0xb0>
mov    -0x420(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x20,%ecx
mov    %al,-0x429(%rbp)
je     1200 <dev_cache_mounts+0xb0>
mov    -0x420(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
setne  %al
mov    %al,-0x429(%rbp)
mov    -0x429(%rbp),%al
test   $0x1,%al
jne    1213 <dev_cache_mounts+0xc3>
jmp    122a <dev_cache_mounts+0xda>
mov    -0x420(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x420(%rbp)
jmp    11b4 <dev_cache_mounts+0x64>
mov    -0x420(%rbp),%rax
cmpb   $0x0,(%rax)
jne    123f <dev_cache_mounts+0xef>
jmp    1187 <dev_cache_mounts+0x37>
mov    -0x420(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x420(%rbp)
mov    -0x420(%rbp),%rax
mov    %rax,-0x428(%rbp)
mov    -0x420(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x42a(%rbp)
je     12ab <dev_cache_mounts+0x15b>
mov    -0x420(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x20,%ecx
mov    %al,-0x42a(%rbp)
je     12ab <dev_cache_mounts+0x15b>
mov    -0x420(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
setne  %al
mov    %al,-0x42a(%rbp)
mov    -0x42a(%rbp),%al
test   $0x1,%al
jne    12be <dev_cache_mounts+0x16e>
jmp    12d5 <dev_cache_mounts+0x185>
mov    -0x420(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x420(%rbp)
jmp    125f <dev_cache_mounts+0x10f>
mov    -0x420(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x428(%rbp),%rdi
lea    -0x418(%rbp),%rsi
call   1060 <stat@plt>
cmp    $0x0,%rax
jge    1301 <dev_cache_mounts+0x1b1>
jmp    1187 <dev_cache_mounts+0x37>
mov    -0x428(%rbp),%rdi
mov    -0x418(%rbp),%esi
call   1040 <dev_add@plt>
jmp    1187 <dev_cache_mounts+0x37>
mov    -0x8(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dev_cache_mounts>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x418,%rsp
lea    0xe98(%rip),%rdi
lea    0xe9e(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     124f <dev_cache_mounts+0xff>
mov    %rax,%r12
lea    0x10(%rsp),%rdi
mov    $0x400,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     1247 <dev_cache_mounts+0xf7>
lea    0x11(%rsp),%r13
lea    0x10(%rsp),%r14
movabs $0x100000401,%rbp
lea    0x8(%rsp),%r15
jmp    11d5 <dev_cache_mounts+0x85>
cs nopw 0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    $0x400,%esi
mov    %r12,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     1247 <dev_cache_mounts+0xf7>
mov    %r13,%rbx
nopl   0x0(%rax,%rax,1)
movzbl -0x1(%rbx),%eax
test   %al,%al
je     11c0 <dev_cache_mounts+0x70>
cmp    $0xa,%al
je     1200 <dev_cache_mounts+0xb0>
cmp    $0x20,%al
je     1200 <dev_cache_mounts+0xb0>
add    $0x1,%rbx
jmp    11e0 <dev_cache_mounts+0x90>
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rax
jmp    1214 <dev_cache_mounts+0xc4>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%rax
movzbl (%rax),%ecx
cmp    $0x20,%rcx
ja     1210 <dev_cache_mounts+0xc0>
bt     %rcx,%rbp
jae    1210 <dev_cache_mounts+0xc0>
movb   $0x0,(%rax)
mov    %rbx,%rdi
mov    %r15,%rsi
call   1060 <stat@plt>
test   %rax,%rax
js     11c0 <dev_cache_mounts+0x70>
mov    0x8(%rsp),%esi
mov    %rbx,%rdi
call   1040 <dev_add@plt>
jmp    11c0 <dev_cache_mounts+0x70>
mov    %r12,%rdi
call   1030 <fclose@plt>
add    $0x418,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [13 x i8] c"/proc/mounts\00"
@.str.1 = [2 x i8] c"r\00"
define void @dev_cache_mounts() {
%1 = alloca i32*
%2 = alloca [1024 x i8]
%3 = alloca %struct.stat
%4 = alloca i8*
%5 = alloca i8*
%6 = 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* %6, i32** %1
%7 = load i32*, i32** %1
%8 = icmp ne i32* %7, null
br i1 %8, label %10, label %9
9: ; preds = %0
br label %81
10: ; preds = %0
br label %11
11: ; preds = %73, %72, %42, %10
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%13 = load i32*, i32** %1
%14 = call i64 @fgets(i8* %12, i32 1024, i32* %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %78
16: ; preds = %11
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
store i8* %17, i8** %4
br label %18
18: ; preds = %35, %16
%19 = load i8*, i8** %4
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %33
23: ; preds = %18
%24 = load i8*, i8** %4
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp ne i32 %26, 32
br i1 %27, label %28, label %33
28: ; preds = %23
%29 = load i8*, i8** %4
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = icmp ne i32 %31, 10
br label %33
33: ; preds = %28, %23, %18
%34 = phi i1 [ false, %23 ], [ false, %18 ], [ %32, %28 ]
br i1 %34, label %35, label %38
35: ; preds = %33
%36 = load i8*, i8** %4
%37 = getelementptr inbounds i8, i8* %36, i32 1
store i8* %37, i8** %4
br label %18
38: ; preds = %33
%39 = load i8*, i8** %4
%40 = load i8, i8* %39
%41 = icmp ne i8 %40, 0
br i1 %41, label %43, label %42
42: ; preds = %38
br label %11
43: ; preds = %38
%44 = load i8*, i8** %4
%45 = getelementptr inbounds i8, i8* %44, i32 1
store i8* %45, i8** %4
%46 = load i8*, i8** %4
store i8* %46, i8** %5
br label %47
47: ; preds = %64, %43
%48 = load i8*, i8** %4
%49 = load i8, i8* %48
%50 = sext i8 %49 to i32
%51 = icmp ne i32 %50, 0
br i1 %51, label %52, label %62
52: ; preds = %47
%53 = load i8*, i8** %4
%54 = load i8, i8* %53
%55 = sext i8 %54 to i32
%56 = icmp ne i32 %55, 32
br i1 %56, label %57, label %62
57: ; preds = %52
%58 = load i8*, i8** %4
%59 = load i8, i8* %58
%60 = sext i8 %59 to i32
%61 = icmp ne i32 %60, 10
br label %62
62: ; preds = %57, %52, %47
%63 = phi i1 [ false, %52 ], [ false, %47 ], [ %61, %57 ]
br i1 %63, label %64, label %67
64: ; preds = %62
%65 = load i8*, i8** %4
%66 = getelementptr inbounds i8, i8* %65, i32 1
store i8* %66, i8** %4
br label %47
67: ; preds = %62
%68 = load i8*, i8** %4
store i8 0, i8* %68
%69 = load i8*, i8** %5
%70 = call i64 @stat(i8* %69, %struct.stat* %3)
%71 = icmp slt i64 %70, 0
br i1 %71, label %72, label %73
72: ; preds = %67
br label %11
73: ; preds = %67
%74 = load i8*, i8** %5
%75 = getelementptr inbounds %struct.stat, %struct.stat* %3, i32 0, i32 0
%76 = load i32, i32* %75
%77 = call i32 @dev_add(i8* %74, i32 %76)
br label %11
78: ; preds = %11
%79 = load i32*, i32** %1
%80 = call i32 @fclose(i32* %79)
br label %81
81: ; preds = %78, %9
ret void
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [13 x i8] c"/proc/mounts\00"
@.str.1 = [2 x i8] c"r\00"
define void @dev_cache_mounts() {
%1 = alloca [1024 x i8]
%2 = alloca %struct.stat
%3 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%4 = 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))
%5 = icmp eq i32* %4, null
br i1 %5, label %36, label %6
6: ; preds = %0
%7 = call i64 @fgets(i8* %3, i32 1024, i32* %4)
%8 = icmp eq i64 %7, 0
br i1 %8, label %34, label %9
9: ; preds = %6
%10 = bitcast %struct.stat* %2 to i8*
%11 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
br label %12
12: ; preds = %9, %31
br label %13
13: ; preds = %16, %12
%14 = phi i8* [ %3, %12 ], [ %17, %16 ]
%15 = load i8, i8* %14
switch i8 %15, label %16 [
i8 0, label %31
i8 10, label %18
i8 32, label %18
]
16: ; preds = %13
%17 = getelementptr inbounds i8, i8* %14, i64 1
br label %13
18: ; preds = %13, %13
%19 = getelementptr inbounds i8, i8* %14, i64 1
br label %20
20: ; preds = %23, %18
%21 = phi i8* [ %19, %18 ], [ %24, %23 ]
%22 = load i8, i8* %21
switch i8 %22, label %23 [
i8 0, label %25
i8 32, label %25
i8 10, label %25
]
23: ; preds = %20
%24 = getelementptr inbounds i8, i8* %21, i64 1
br label %20
25: ; preds = %20, %20, %20
store i8 0, i8* %21
%26 = call i64 @stat(i8* %19, %struct.stat* %2)
%27 = icmp slt i64 %26, 0
br i1 %27, label %31, label %28
28: ; preds = %25
%29 = load i32, i32* %11
%30 = call i32 @dev_add(i8* %19, i32 %29)
br label %31
31: ; preds = %13, %25, %28
%32 = call i64 @fgets(i8* %3, i32 1024, i32* %4)
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %12
34: ; preds = %31, %6
%35 = call i32 @fclose(i32* %4)
br label %36
36: ; preds = %0, %34
ret void
}