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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ strcmp(char *, char *);
char *strstr(char *, char *);
char *find_mount(char *mp) {
  FILE *fp = fopen("/proc/mounts", "r");
  static char line[256];
  char *point = NULL;
  if (!fp)
    return NULL;
  while (fgets(line, sizeof(line), fp)) {
    char *s, *t = strstr(line, " ");
    if (!t)
      return NULL;
    t++;
    s = strstr(t, " ");
    if (!s)
      return NULL;
    *s = '\0';
    if (!strcmp(t, mp)) {
      fclose(fp);
      return t;
    }
  }
  fclose(fp);
  return point;
}


x86 assembly (clang, -O0):
<find_mount>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
lea    0xe9d(%rip),%rdi
lea    0xea3(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1193 <find_mount+0x43>
movq   $0x0,-0x8(%rbp)
jmp    1267 <find_mount+0x117>
jmp    1198 <find_mount+0x48>
mov    -0x18(%rbp),%rdx
lea    0x2ebd(%rip),%rdi
mov    $0x100,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
je     1256 <find_mount+0x106>
lea    0x2ea2(%rip),%rdi
lea    0xe4a(%rip),%rsi
call   1070 <strstr@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11e6 <find_mount+0x96>
movq   $0x0,-0x8(%rbp)
jmp    1267 <find_mount+0x117>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
lea    0xe12(%rip),%rsi
call   1070 <strstr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    121e <find_mount+0xce>
movq   $0x0,-0x8(%rbp)
jmp    1267 <find_mount+0x117>
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    1251 <find_mount+0x101>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1267 <find_mount+0x117>
jmp    1198 <find_mount+0x48>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_mount>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
lea    0xe9e(%rip),%rdi
lea    0xea4(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11d4 <find_mount+0x84>
mov    %rax,%r12
lea    0x2ee3(%rip),%r15
nopl   (%rax)
mov    %r15,%rdi
mov    $0x100,%esi
mov    %r12,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     11d8 <find_mount+0x88>
mov    %r15,%rdi
mov    $0x20,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     11d4 <find_mount+0x84>
mov    %rax,%rbx
add    $0x1,%rbx
mov    %rbx,%rdi
mov    $0x20,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     11d4 <find_mount+0x84>
movb   $0x0,(%rax)
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <strcmp@plt>
test   %eax,%eax
jne    1180 <find_mount+0x30>
jmp    11da <find_mount+0x8a>
xor    %ebx,%ebx
jmp    11e2 <find_mount+0x92>
xor    %ebx,%ebx
mov    %r12,%rdi
call   1030 <fclose@plt>
mov    %rbx,%rax
add    $0x8,%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"
@find_mount.line = internal global [256 x i8] zeroinitializer
@.str.2 = [2 x i8] c" \00"
define i8* @find_mount(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
store i8* %0, i8** %3
%8 = 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* %8, i32** %4
store i8* null, i8** %5
%9 = load i32*, i32** %4
%10 = icmp ne i32* %9, null
br i1 %10, label %12, label %11
11: ; preds = %1
store i8* null, i8** %2
br label %45
12: ; preds = %1
br label %13
13: ; preds = %40, %12
%14 = load i32*, i32** %4
%15 = call i64 @fgets(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @find_mount.line, i64 0, i64 0), i32 256, i32* %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %41
17: ; preds = %13
%18 = call i8* @strstr(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @find_mount.line, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i8* %18, i8** %7
%19 = load i8*, i8** %7
%20 = icmp ne i8* %19, null
br i1 %20, label %22, label %21
21: ; preds = %17
store i8* null, i8** %2
br label %45
22: ; preds = %17
%23 = load i8*, i8** %7
%24 = getelementptr inbounds i8, i8* %23, i32 1
store i8* %24, i8** %7
%25 = load i8*, i8** %7
%26 = call i8* @strstr(i8* %25, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i8* %26, i8** %6
%27 = load i8*, i8** %6
%28 = icmp ne i8* %27, null
br i1 %28, label %30, label %29
29: ; preds = %22
store i8* null, i8** %2
br label %45
30: ; preds = %22
%31 = load i8*, i8** %6
store i8 0, i8* %31
%32 = load i8*, i8** %7
%33 = load i8*, i8** %3
%34 = call i32 @strcmp(i8* %32, i8* %33)
%35 = icmp ne i32 %34, 0
br i1 %35, label %40, label %36
36: ; preds = %30
%37 = load i32*, i32** %4
%38 = call i32 @fclose(i32* %37)
%39 = load i8*, i8** %7
store i8* %39, i8** %2
br label %45
40: ; preds = %30
br label %13
41: ; preds = %13
%42 = load i32*, i32** %4
%43 = call i32 @fclose(i32* %42)
%44 = load i8*, i8** %5
store i8* %44, i8** %2
br label %45
45: ; preds = %41, %36, %29, %21, %11
%46 = load i8*, i8** %2
ret i8* %46
}

LLVM IR (-O2):
@.str = [13 x i8] c"/proc/mounts\00"
@.str.1 = [2 x i8] c"r\00"
@find_mount.line = internal global [256 x i8] zeroinitializer
define i8* @find_mount(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 %20, label %4
4: ; preds = %1, %14
%5 = tail call i64 @fgets(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @find_mount.line, i64 0, i64 0), i32 256, i32* %2)
%6 = icmp eq i64 %5, 0
br i1 %6, label %17, label %7
7: ; preds = %4
%8 = tail call i8* @strchr(i8* dereferenceable(1) getelementptr inbounds ([256 x i8], [256 x i8]* @find_mount.line, i64 0, i64 0), i32 32)
%9 = icmp eq i8* %8, null
br i1 %9, label %20, label %10
10: ; preds = %7
%11 = getelementptr inbounds i8, i8* %8, i64 1
%12 = tail call i8* @strchr(i8* %11, i32 32)
%13 = icmp eq i8* %12, null
br i1 %13, label %20, label %14
14: ; preds = %10
store i8 0, i8* %12
%15 = tail call i32 @strcmp(i8* %11, i8* dereferenceable(1) %0)
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %4
17: ; preds = %4, %14
%18 = phi i8* [ %11, %14 ], [ null, %4 ]
%19 = tail call i32 @fclose(i32* %2)
br label %20
20: ; preds = %10, %7, %17, %1
%21 = phi i8* [ null, %1 ], [ %18, %17 ], [ null, %7 ], [ null, %10 ]
ret i8* %21
}