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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *openOrHang(char *, char *);
int /*<<< orphan*/ strcat(char *, char *);
char *strchr(char *, char);
int /*<<< orphan*/ strlen(char *);
scalar_t__ strncmp(char *, char *, int /*<<< orphan*/);
void getMountPoint(char *out, char *devicePath) {
  char buf[1024];
  char *p1;
  char *p2;
  FILE *file = openOrHang("/proc/mounts", "r");
  out[0] = '\0';
  while (!feof(file)) {
    if (fgets(buf, sizeof(buf), file)) {
      if (strncmp(buf, devicePath, strlen(devicePath)) != 0)
        continue;
      p1 = strchr(buf, ' ');
      p1 = p1 + 1;
      p2 = strchr(p1, ' ');
      *p2 = 0;
      strcat(out, p1);
      break;
    }
  }
  fclose(file);
}


x86 assembly (clang, -O0):
<getMountPoint>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe66(%rip),%rdi
lea    0xe6c(%rip),%rsi
call   1080 <openOrHang@plt>
mov    %rax,-0x428(%rbp)
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x428(%rbp),%rdi
call   1090 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11d5 <getMountPoint+0x55>
jmp    12a3 <getMountPoint+0x123>
lea    -0x410(%rbp),%rdi
mov    -0x428(%rbp),%rdx
mov    $0x400,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
je     129e <getMountPoint+0x11e>
lea    -0x410(%rbp),%rax
mov    %rax,-0x438(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x430(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x438(%rbp),%rdi
mov    -0x430(%rbp),%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     123d <getMountPoint+0xbd>
jmp    11b4 <getMountPoint+0x34>
lea    -0x410(%rbp),%rdi
mov    $0x20,%esi
call   1060 <strchr@plt>
mov    %rax,-0x418(%rbp)
mov    -0x418(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x418(%rbp)
mov    -0x418(%rbp),%rdi
mov    $0x20,%esi
call   1060 <strchr@plt>
mov    %rax,-0x420(%rbp)
mov    -0x420(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
mov    -0x418(%rbp),%rsi
call   10a0 <strcat@plt>
jmp    12a3 <getMountPoint+0x123>
jmp    11b4 <getMountPoint+0x34>
mov    -0x428(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getMountPoint>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x408,%rsp
mov    %rsi,%r15
mov    %rdi,%r14
lea    0xe65(%rip),%rdi
lea    0xe6b(%rip),%rsi
call   1080 <openOrHang@plt>
mov    %rax,%rbx
movb   $0x0,(%r14)
mov    %rax,%rdi
call   1090 <feof@plt>
test   %eax,%eax
jne    1227 <getMountPoint+0xa7>
mov    %rsp,%r12
jmp    11cc <getMountPoint+0x4c>
nop
mov    %rbx,%rdi
call   1090 <feof@plt>
test   %eax,%eax
jne    1227 <getMountPoint+0xa7>
mov    %r12,%rdi
mov    $0x400,%esi
mov    %rbx,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     11c0 <getMountPoint+0x40>
mov    %r15,%rdi
call   1050 <strlen@plt>
mov    %r12,%rdi
mov    %r15,%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    11c0 <getMountPoint+0x40>
mov    %rsp,%rdi
mov    $0x20,%esi
call   1060 <strchr@plt>
lea    0x1(%rax),%r15
mov    %r15,%rdi
mov    $0x20,%esi
call   1060 <strchr@plt>
movb   $0x0,(%rax)
mov    %r14,%rdi
mov    %r15,%rsi
call   10a0 <strcat@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
add    $0x408,%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"
define void @getMountPoint(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca [1024 x i8]
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32*
store i8* %0, i8** %3
store i8* %1, i8** %4
%9 = call i32* @openOrHang(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** %8
%10 = load i8*, i8** %3
%11 = getelementptr inbounds i8, i8* %10, i64 0
store i8 0, i8* %11
br label %12
12: ; preds = %41, %29, %2
%13 = load i32*, i32** %8
%14 = call i32 @feof(i32* %13)
%15 = icmp ne i32 %14, 0
%16 = xor i1 %15, true
br i1 %16, label %17, label %42
17: ; preds = %12
%18 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%19 = load i32*, i32** %8
%20 = call i64 @fgets(i8* %18, i32 1024, i32* %19)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %41
22: ; preds = %17
%23 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%24 = load i8*, i8** %4
%25 = load i8*, i8** %4
%26 = call i32 @strlen(i8* %25)
%27 = call i64 @strncmp(i8* %23, i8* %24, i32 %26)
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %22
br label %12
30: ; preds = %22
%31 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%32 = call i8* @strchr(i8* %31, i8 signext 32)
store i8* %32, i8** %6
%33 = load i8*, i8** %6
%34 = getelementptr inbounds i8, i8* %33, i64 1
store i8* %34, i8** %6
%35 = load i8*, i8** %6
%36 = call i8* @strchr(i8* %35, i8 signext 32)
store i8* %36, i8** %7
%37 = load i8*, i8** %7
store i8 0, i8* %37
%38 = load i8*, i8** %3
%39 = load i8*, i8** %6
%40 = call i32 @strcat(i8* %38, i8* %39)
br label %42
41: ; preds = %17
br label %12
42: ; preds = %30, %12
%43 = load i32*, i32** %8
%44 = call i32 @fclose(i32* %43)
ret void
}

LLVM IR (-O2):
@.str = [13 x i8] c"/proc/mounts\00"
@.str.1 = [2 x i8] c"r\00"
define void @getMountPoint(i8* %0, i8* %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = tail call i32* @openOrHang(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 i8 0, i8* %0
%6 = call i32 @feof(i32* %5)
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %23
8: ; preds = %2, %15
%9 = call i64 @fgets(i8* %4, i32 1024, i32* %5)
%10 = icmp eq i64 %9, 0
br i1 %10, label %15, label %11
11: ; preds = %8
%12 = call i32 @strlen(i8* %1)
%13 = call i64 @strncmp(i8* %4, i8* %1, i32 %12)
%14 = icmp eq i64 %13, 0
br i1 %14, label %18, label %15
15: ; preds = %11, %8
%16 = call i32 @feof(i32* %5)
%17 = icmp eq i32 %16, 0
br i1 %17, label %8, label %23
18: ; preds = %11
%19 = call i8* @strchr(i8* %4, i8 signext 32)
%20 = getelementptr inbounds i8, i8* %19, i64 1
%21 = call i8* @strchr(i8* %20, i8 signext 32)
store i8 0, i8* %21
%22 = call i32 @strcat(i8* %0, i8* %20)
br label %23
23: ; preds = %15, %2, %18
%24 = call i32 @fclose(i32* %5)
ret void
}