#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int fscanf(int /*<<< orphan*/ *, char *, char *, char *, char *);
scalar_t__ is_loop(char *);
int /*<<< orphan*/ stdout;
scalar_t__ strcmp(char const *, char *);
char *strerror(int /*<<< orphan*/);
int /*<<< orphan*/ strlcpy(char *, char *, int);
int strlen(char const *);
int is_loop_mount(const char *path, char *loopdev) {
  FILE *f;
  int count;
  char device[256];
  char mount_path[256];
  char rest[256];
  int result = 0;
  int path_length = strlen(path);
  f = fopen("/proc/mounts", "r");
  if (!f) {
    fprintf(stdout, "could not open /proc/mounts: %s\n", strerror(errno));
    return -1;
  }
  do {
    count = fscanf(f, "%255s %255s %255s\n", device, mount_path, rest);
    if (count == 3) {
      if (is_loop(device) && strcmp(path, mount_path) == 0) {
        strlcpy(loopdev, device, 64);
        result = 1;
        break;
      }
    }
  } while (count == 3);
  fclose(f);
  return result;
}


x86 assembly (clang, -O0):
<is_loop_mount>:
push   %rbp
mov    %rsp,%rbp
sub    $0x340,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x334(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x338(%rbp)
lea    0xe3d(%rip),%rdi
lea    0xe43(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    121c <is_loop_mount+0x8c>
mov    0x2df3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x33c(%rbp)
mov    0x2dec(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x33c(%rbp),%edi
mov    %rax,%rdx
lea    0xe04(%rip),%rsi
call   1080 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12cd <is_loop_mount+0x13d>
jmp    1221 <is_loop_mount+0x91>
mov    -0x20(%rbp),%rdi
lea    -0x130(%rbp),%rdx
lea    -0x230(%rbp),%rcx
lea    -0x330(%rbp),%r8
lea    0xdef(%rip),%rsi
call   1060 <fscanf@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x3,-0x24(%rbp)
jne    12ac <is_loop_mount+0x11c>
lea    -0x130(%rbp),%rdi
call   1050 <is_loop@plt>
cmp    $0x0,%rax
je     12a7 <is_loop_mount+0x117>
mov    -0x10(%rbp),%rdi
lea    -0x230(%rbp),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    12a7 <is_loop_mount+0x117>
mov    -0x18(%rbp),%rdi
lea    -0x130(%rbp),%rsi
mov    $0x40,%edx
call   1090 <strlcpy@plt>
movl   $0x1,-0x334(%rbp)
jmp    12bb <is_loop_mount+0x12b>
jmp    12ac <is_loop_mount+0x11c>
jmp    12b1 <is_loop_mount+0x121>
cmpl   $0x3,-0x24(%rbp)
je     1221 <is_loop_mount+0x91>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x334(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x340,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_loop_mount>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x318,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
call   1040 <strlen@plt>
lea    0xe4d(%rip),%rdi
lea    0xe53(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     1271 <is_loop_mount+0xe1>
mov    %rax,%rbx
lea    0xe5e(%rip),%rsi
lea    0x10(%rsp),%rdx
lea    0x210(%rsp),%rcx
lea    0x110(%rsp),%r8
mov    %rax,%rdi
call   1060 <fscanf@plt>
xor    %ebp,%ebp
cmp    $0x3,%eax
jne    12a2 <is_loop_mount+0x112>
mov    %r14,0x8(%rsp)
lea    0x10(%rsp),%rbp
lea    0xe25(%rip),%r13
lea    0x210(%rsp),%r14
lea    0x110(%rsp),%r12
jmp    1239 <is_loop_mount+0xa9>
nopl   (%rax)
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %rbp,%rdx
mov    %r14,%rcx
mov    %r12,%r8
call   1060 <fscanf@plt>
cmp    $0x3,%eax
jne    12a0 <is_loop_mount+0x110>
mov    %rbp,%rdi
call   1050 <is_loop@plt>
test   %rax,%rax
je     1220 <is_loop_mount+0x90>
mov    %r15,%rdi
mov    %r14,%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
jne    1220 <is_loop_mount+0x90>
lea    0x10(%rsp),%rsi
mov    0x8(%rsp),%rdi
mov    $0x40,%edx
call   1090 <strlcpy@plt>
mov    $0x1,%ebp
jmp    12a2 <is_loop_mount+0x112>
mov    0x2d60(%rip),%rax
mov    (%rax),%ebx
mov    0x2d5f(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xd80(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1080 <fprintf@plt>
mov    $0xffffffff,%ebp
jmp    12aa <is_loop_mount+0x11a>
xor    %ebp,%ebp
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %ebp,%eax
add    $0x318,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"/proc/mounts\00"
@.str.1 = [2 x i8] c"r\00"
@stdout = global i32 0
@.str.2 = [33 x i8] c"could not open /proc/mounts: %s\0A\00"
@errno = global i32 0
@.str.3 = [19 x i8] c"%255s %255s %255s\0A\00"
define i32 @is_loop_mount(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca [256 x i8]
%9 = alloca [256 x i8]
%10 = alloca [256 x i8]
%11 = alloca i32
%12 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 0, i32* %11
%13 = load i8*, i8** %4
%14 = call i32 @strlen(i8* %13)
store i32 %14, i32* %12
%15 = 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* %15, i32** %6
%16 = load i32*, i32** %6
%17 = icmp ne i32* %16, null
br i1 %17, label %23, label %18
18: ; preds = %2
%19 = load i32, i32* @stdout
%20 = load i32, i32* @errno
%21 = call i8* @strerror(i32 %20)
%22 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i8* %21)
store i32 -1, i32* %3
br label %54
23: ; preds = %2
br label %24
24: ; preds = %47, %23
%25 = load i32*, i32** %6
%26 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%27 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%28 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%29 = call i32 @fscanf(i32* %25, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %26, i8* %27, i8* %28)
store i32 %29, i32* %7
%30 = load i32, i32* %7
%31 = icmp eq i32 %30, 3
br i1 %31, label %32, label %46
32: ; preds = %24
%33 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%34 = call i64 @is_loop(i8* %33)
%35 = icmp ne i64 %34, 0
br i1 %35, label %36, label %45
36: ; preds = %32
%37 = load i8*, i8** %4
%38 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%39 = call i64 @strcmp(i8* %37, i8* %38)
%40 = icmp eq i64 %39, 0
br i1 %40, label %41, label %45
41: ; preds = %36
%42 = load i8*, i8** %5
%43 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%44 = call i32 @strlcpy(i8* %42, i8* %43, i32 64)
store i32 1, i32* %11
br label %50
45: ; preds = %36, %32
br label %46
46: ; preds = %45, %24
br label %47
47: ; preds = %46
%48 = load i32, i32* %7
%49 = icmp eq i32 %48, 3
br i1 %49, label %24, label %50
50: ; preds = %47, %41
%51 = load i32*, i32** %6
%52 = call i32 @fclose(i32* %51)
%53 = load i32, i32* %11
store i32 %53, i32* %3
br label %54
54: ; preds = %50, %18
%55 = load i32, i32* %3
ret i32 %55
}

LLVM IR (-O2):
@.str = [13 x i8] c"/proc/mounts\00"
@.str.1 = [2 x i8] c"r\00"
@stdout = global i32 0
@.str.2 = [33 x i8] c"could not open /proc/mounts: %s\0A\00"
@errno = global i32 0
@.str.3 = [19 x i8] c"%255s %255s %255s\0A\00"
define i32 @is_loop_mount(i8* %0, i8* %1) {
%3 = alloca [256 x i8]
%4 = alloca [256 x i8]
%5 = alloca [256 x i8]
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%8 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%9 = tail call i32 @strlen(i8* %0)
%10 = 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))
%11 = icmp eq i32* %10, null
br i1 %11, label %15, label %12
12: ; preds = %2
%13 = call i32 @fscanf(i32* %10, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %6, i8* %7, i8* %8)
%14 = icmp eq i32 %13, 3
br i1 %14, label %20, label %31
15: ; preds = %2
%16 = load i32, i32* @stdout
%17 = load i32, i32* @errno
%18 = tail call i8* @strerror(i32 %17)
%19 = tail call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i8* %18)
br label %34
20: ; preds = %12, %28
%21 = call i64 @is_loop(i8* %6)
%22 = icmp eq i64 %21, 0
br i1 %22, label %28, label %23
23: ; preds = %20
%24 = call i64 @strcmp(i8* %0, i8* %7)
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %23
%27 = call i32 @strlcpy(i8* %1, i8* %6, i32 64)
br label %31
28: ; preds = %23, %20
%29 = call i32 @fscanf(i32* %10, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %6, i8* %7, i8* %8)
%30 = icmp eq i32 %29, 3
br i1 %30, label %20, label %31
31: ; preds = %28, %12, %26
%32 = phi i32 [ 1, %26 ], [ 0, %12 ], [ 0, %28 ]
%33 = call i32 @fclose(i32* %10)
br label %34
34: ; preds = %31, %15
%35 = phi i32 [ %32, %31 ], [ -1, %15 ]
ret i32 %35
}