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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int readlink(char *, char *, int);
int /*<<< orphan*/ sprintf(char *, char *, char const *);
int /*<<< orphan*/ strncmp(char *, char *, int);
int is_lv_mounted(const char *lv) {
  FILE *mounts_fp;
  char mount_str[128], real_dev[64], dev[32];
  int nchars;
  sprintf(dev, "/dev/store/%s", lv);
  nchars = readlink(dev, real_dev, sizeof(real_dev) - 1);
  real_dev[nchars] = '\0';
  mounts_fp = fopen("/proc/mounts", "r");
  while (!feof(mounts_fp)) {
    if (fgets(mount_str, 128, mounts_fp) == NULL)
      return 0;
    if (!strncmp(mount_str, real_dev, nchars - 1)) {
      fclose(mounts_fp);
      return 1;
    }
  }
  fclose(mounts_fp);
  return 0;
}


x86 assembly (clang, -O0):
<is_lv_mounted>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x100(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe6f(%rip),%rsi
call   1090 <sprintf@plt>
lea    -0x100(%rbp),%rdi
lea    -0xe0(%rbp),%rsi
mov    $0x3f,%edx
call   1040 <readlink@plt>
mov    %eax,-0x104(%rbp)
movslq -0x104(%rbp),%rax
movb   $0x0,-0xe0(%rbp,%rax,1)
lea    0xe44(%rip),%rdi
lea    0xe4a(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11f8 <is_lv_mounted+0x88>
jmp    1262 <is_lv_mounted+0xf2>
lea    -0xa0(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x80,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
jne    1223 <is_lv_mounted+0xb3>
movl   $0x0,-0x4(%rbp)
jmp    1272 <is_lv_mounted+0x102>
lea    -0xa0(%rbp),%rdi
lea    -0xe0(%rbp),%rsi
mov    -0x104(%rbp),%edx
sub    $0x1,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    125d <is_lv_mounted+0xed>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x1,-0x4(%rbp)
jmp    1272 <is_lv_mounted+0x102>
jmp    11da <is_lv_mounted+0x6a>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_lv_mounted>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0xe0,%rsp
mov    %rdi,%rdx
lea    0xe77(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1090 <sprintf@plt>
lea    0x20(%rsp),%r14
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x3f,%edx
call   1040 <readlink@plt>
movslq %eax,%r15
movb   $0x0,0x20(%rsp,%r15,1)
lea    0xe55(%rip),%rdi
lea    0xe5b(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%rbx
add    $0xffffffff,%r15d
lea    0x60(%rsp),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1070 <feof@plt>
test   %eax,%eax
jne    121a <is_lv_mounted+0xaa>
mov    %r12,%rdi
mov    $0x80,%esi
mov    %rbx,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     1226 <is_lv_mounted+0xb6>
mov    %r12,%rdi
mov    %r14,%rsi
mov    %r15d,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
jne    11e0 <is_lv_mounted+0x70>
mov    $0x1,%ebp
jmp    121c <is_lv_mounted+0xac>
xor    %ebp,%ebp
mov    %rbx,%rdi
call   1050 <fclose@plt>
jmp    1228 <is_lv_mounted+0xb8>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0xe0,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"/dev/store/%s\00"
@.str.1 = [13 x i8] c"/proc/mounts\00"
@.str.2 = [2 x i8] c"r\00"
define i32 @is_lv_mounted(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca [128 x i8]
%6 = alloca [64 x i8]
%7 = alloca [32 x i8]
%8 = alloca i32
store i8* %0, i8** %3
%9 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%10 = load i8*, i8** %3
%11 = call i32 @sprintf(i8* %9, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%13 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
%14 = call i32 @readlink(i8* %12, i8* %13, i32 63)
store i32 %14, i32* %8
%15 = load i32, i32* %8
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 %16
store i8 0, i8* %17
%18 = call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %18, i32** %4
br label %19
19: ; preds = %40, %1
%20 = load i32*, i32** %4
%21 = call i32 @feof(i32* %20)
%22 = icmp ne i32 %21, 0
%23 = xor i1 %22, true
br i1 %23, label %24, label %41
24: ; preds = %19
%25 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%26 = load i32*, i32** %4
%27 = call i32* @fgets(i8* %25, i32 128, i32* %26)
%28 = icmp eq i32* %27, null
br i1 %28, label %29, label %30
29: ; preds = %24
store i32 0, i32* %2
br label %44
30: ; preds = %24
%31 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%32 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
%33 = load i32, i32* %8
%34 = sub nsw i32 %33, 1
%35 = call i32 @strncmp(i8* %31, i8* %32, i32 %34)
%36 = icmp ne i32 %35, 0
br i1 %36, label %40, label %37
37: ; preds = %30
%38 = load i32*, i32** %4
%39 = call i32 @fclose(i32* %38)
store i32 1, i32* %2
br label %44
40: ; preds = %30
br label %19
41: ; preds = %19
%42 = load i32*, i32** %4
%43 = call i32 @fclose(i32* %42)
store i32 0, i32* %2
br label %44
44: ; preds = %41, %37, %29
%45 = load i32, i32* %2
ret i32 %45
}

LLVM IR (-O2):
@.str = [14 x i8] c"/dev/store/%s\00"
@.str.1 = [13 x i8] c"/proc/mounts\00"
@.str.2 = [2 x i8] c"r\00"
define i32 @is_lv_mounted(i8* %0) {
%2 = alloca [128 x i8]
%3 = alloca [64 x i8]
%4 = alloca [32 x i8]
%5 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%8 = call i32 @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %0)
%9 = call i32 @readlink(i8* %7, i8* %6, i32 63)
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 %10
store i8 0, i8* %11
%12 = tail call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%13 = add nsw i32 %9, -1
br label %14
14: ; preds = %20, %1
%15 = call i32 @feof(i32* %12)
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %23
17: ; preds = %14
%18 = call i32* @fgets(i8* %5, i32 128, i32* %12)
%19 = icmp eq i32* %18, null
br i1 %19, label %26, label %20
20: ; preds = %17
%21 = call i32 @strncmp(i8* %5, i8* %6, i32 %13)
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %14
23: ; preds = %14, %20
%24 = phi i32 [ 1, %20 ], [ 0, %14 ]
%25 = call i32 @fclose(i32* %12)
br label %26
26: ; preds = %17, %23
%27 = phi i32 [ %24, %23 ], [ 0, %17 ]
ret i32 %27
}