#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*/ *);
char *malloc(int);
int /*<<< orphan*/ memcpy(char *, char *, scalar_t__);
int /*<<< orphan*/ *openOrHang(char *, char *);
char *strchr(char *, char);
scalar_t__ strlen(char *);
scalar_t__ strncmp(char *, char *, scalar_t__);
char *findMountedPartitions(char *output[], int *pCount, char *devicePath) {
  char buf[32];
  FILE *file = openOrHang("/proc/mounts", "r");
  while (!feof(file)) {
    if (fgets(buf, sizeof(buf), file)) {
      if (strncmp(buf, devicePath, strlen(devicePath)) != 0)
        continue;
      char *p = strchr(buf, ' ');
      *p = 0;
      output[*pCount] = malloc(32);
      memcpy(output[*pCount], buf, strlen(buf) + 1);
      *pCount = *pCount + 1;
    }
  }
  fclose(file);
  return 0;
}


x86 assembly (clang, -O0):
<findMountedPartitions>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
lea    0xe55(%rip),%rdi
lea    0xe5b(%rip),%rsi
call   1080 <openOrHang@plt>
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rdi
call   1090 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11d9 <findMountedPartitions+0x49>
jmp    12ae <findMountedPartitions+0x11e>
lea    -0x40(%rbp),%rdi
mov    -0x48(%rbp),%rdx
mov    $0x20,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
je     12a9 <findMountedPartitions+0x119>
lea    -0x40(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x60(%rbp),%rdi
mov    -0x58(%rbp),%rsi
mov    %rax,%rdx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     122d <findMountedPartitions+0x9d>
jmp    11bb <findMountedPartitions+0x2b>
lea    -0x40(%rbp),%rdi
mov    $0x20,%esi
call   1060 <strchr@plt>
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rax
movb   $0x0,(%rax)
mov    $0x20,%edi
call   10b0 <malloc@plt>
mov    %rax,%rdx
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
movslq (%rcx),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x70(%rbp)
lea    -0x40(%rbp),%rax
mov    %rax,-0x68(%rbp)
lea    -0x40(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x70(%rbp),%rdi
mov    -0x68(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
call   10a0 <memcpy@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
jmp    11bb <findMountedPartitions+0x2b>
mov    -0x48(%rbp),%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<findMountedPartitions>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdx,%r12
mov    %rsi,%r14
mov    %rdi,%r15
lea    0xe52(%rip),%rdi
lea    0xe58(%rip),%rsi
call   1080 <openOrHang@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1090 <feof@plt>
test   %eax,%eax
je     11e2 <findMountedPartitions+0x52>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rsp,%r13
jmp    11fc <findMountedPartitions+0x6c>
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1090 <feof@plt>
test   %eax,%eax
jne    11c9 <findMountedPartitions+0x39>
mov    %r13,%rdi
mov    $0x20,%esi
mov    %rbx,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     11f0 <findMountedPartitions+0x60>
mov    %r12,%rdi
call   1050 <strlen@plt>
mov    %r13,%rdi
mov    %r12,%rsi
mov    %rax,%rdx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    11f0 <findMountedPartitions+0x60>
mov    %r13,%rdi
mov    $0x20,%esi
call   1060 <strchr@plt>
movb   $0x0,(%rax)
mov    $0x20,%edi
call   10b0 <malloc@plt>
mov    %rax,%rbp
movslq (%r14),%rax
mov    %rbp,(%r15,%rax,8)
mov    %r13,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%rdx
mov    %rbp,%rdi
mov    %r13,%rsi
call   10a0 <memcpy@plt>
addl   $0x1,(%r14)
jmp    11f0 <findMountedPartitions+0x60>

LLVM IR (-O0):
@.str = [13 x i8] c"/proc/mounts\00"
@.str.1 = [2 x i8] c"r\00"
define i8* @findMountedPartitions(i8** %0, i32* %1, i8* %2) {
%4 = alloca i8**
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca [32 x i8]
%8 = alloca i32*
%9 = alloca i8*
store i8** %0, i8*** %4
store i32* %1, i32** %5
store i8* %2, i8** %6
%10 = 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* %10, i32** %8
br label %11
11: ; preds = %54, %28, %3
%12 = load i32*, i32** %8
%13 = call i32 @feof(i32* %12)
%14 = icmp ne i32 %13, 0
%15 = xor i1 %14, true
br i1 %15, label %16, label %55
16: ; preds = %11
%17 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%18 = load i32*, i32** %8
%19 = call i64 @fgets(i8* %17, i32 32, i32* %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %54
21: ; preds = %16
%22 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%23 = load i8*, i8** %6
%24 = load i8*, i8** %6
%25 = call i64 @strlen(i8* %24)
%26 = call i64 @strncmp(i8* %22, i8* %23, i64 %25)
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %21
br label %11
29: ; preds = %21
%30 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%31 = call i8* @strchr(i8* %30, i8 signext 32)
store i8* %31, i8** %9
%32 = load i8*, i8** %9
store i8 0, i8* %32
%33 = call i8* @malloc(i32 32)
%34 = load i8**, i8*** %4
%35 = load i32*, i32** %5
%36 = load i32, i32* %35
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8*, i8** %34, i64 %37
store i8* %33, i8** %38
%39 = load i8**, i8*** %4
%40 = load i32*, i32** %5
%41 = load i32, i32* %40
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8*, i8** %39, i64 %42
%44 = load i8*, i8** %43
%45 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%46 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%47 = call i64 @strlen(i8* %46)
%48 = add nsw i64 %47, 1
%49 = call i32 @memcpy(i8* %44, i8* %45, i64 %48)
%50 = load i32*, i32** %5
%51 = load i32, i32* %50
%52 = add nsw i32 %51, 1
%53 = load i32*, i32** %5
store i32 %52, i32* %53
br label %54
54: ; preds = %29, %16
br label %11
55: ; preds = %11
%56 = load i32*, i32** %8
%57 = call i32 @fclose(i32* %56)
ret i8* null
}

LLVM IR (-O2):
@.str = [13 x i8] c"/proc/mounts\00"
@.str.1 = [2 x i8] c"r\00"
define noalias i8* @findMountedPartitions(i8** nocapture %0, i32* nocapture %1, i8* %2) {
%4 = alloca [32 x i8]
%5 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%6 = 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))
%7 = call i32 @feof(i32* %6)
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %30
9: ; preds = %3, %27
%10 = call i64 @fgets(i8* %5, i32 32, i32* %6)
%11 = icmp eq i64 %10, 0
br i1 %11, label %27, label %12
12: ; preds = %9
%13 = call i64 @strlen(i8* dereferenceable(1) %2)
%14 = call i64 @strncmp(i8* %5, i8* %2, i64 %13)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %27
16: ; preds = %12
%17 = call i8* @strchr(i8* %5, i8 signext 32)
store i8 0, i8* %17
%18 = call dereferenceable_or_null(32) i8* @malloc(i32 32)
%19 = load i32, i32* %1
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8*, i8** %0, i64 %20
store i8* %18, i8** %21
%22 = call i64 @strlen(i8* %5)
%23 = add nsw i64 %22, 1
%24 = call i32 @memcpy(i8* %18, i8* %5, i64 %23)
%25 = load i32, i32* %1
%26 = add nsw i32 %25, 1
store i32 %26, i32* %1
br label %27
27: ; preds = %9, %16, %12
%28 = call i32 @feof(i32* %6)
%29 = icmp eq i32 %28, 0
br i1 %29, label %9, label %30
30: ; preds = %27, %3
%31 = call i32 @fclose(i32* %6)
ret i8* null
}