#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int fscanf(int /*<<< orphan*/ *, char *, char *, char *, char *);
int /*<<< orphan*/ stdout;
scalar_t__ strcmp(char const *, char *);
int strlen(char const *);
int is_loop_mount(const char *path) {
  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\n");
    return -1;
  }
  do {
    count = fscanf(f, "%255s %255s %255s\n", device, mount_path, rest);
    if (count == 3) {
      if (strcmp("/dev/block/loop0", device) == 0 &&
          strcmp(path, mount_path) == 0) {
        result = 1;
        break;
      }
    }
  } while (count == 3);
  fclose(f);
  return result;
}


x86 assembly (clang, -O0):
<is_loop_mount>:
push   %rbp
mov    %rsp,%rbp
sub    $0x330,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x324(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x328(%rbp)
lea    0xe71(%rip),%rdi
lea    0xe77(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11cb <is_loop_mount+0x6b>
mov    0x2e2f(%rip),%rax
mov    (%rax),%edi
lea    0xe55(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    126e <is_loop_mount+0x10e>
jmp    11d0 <is_loop_mount+0x70>
mov    -0x18(%rbp),%rdi
lea    -0x120(%rbp),%rdx
lea    -0x220(%rbp),%rcx
lea    -0x320(%rbp),%r8
lea    0xe3c(%rip),%rsi
call   1050 <fscanf@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x3,-0x1c(%rbp)
jne    124d <is_loop_mount+0xed>
lea    -0x120(%rbp),%rsi
lea    0xe2f(%rip),%rdi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    1248 <is_loop_mount+0xe8>
mov    -0x10(%rbp),%rdi
lea    -0x220(%rbp),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    1248 <is_loop_mount+0xe8>
movl   $0x1,-0x324(%rbp)
jmp    125c <is_loop_mount+0xfc>
jmp    124d <is_loop_mount+0xed>
jmp    1252 <is_loop_mount+0xf2>
cmpl   $0x3,-0x1c(%rbp)
je     11d0 <is_loop_mount+0x70>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x324(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x330,%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    %rdi,0x8(%rsp)
call   1040 <strlen@plt>
lea    0xe7e(%rip),%rdi
lea    0xe84(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1232 <is_loop_mount+0xd2>
mov    %rax,%rbx
lea    0xe8b(%rip),%rsi
lea    0x210(%rsp),%rdx
lea    0x110(%rsp),%rcx
lea    0x10(%rsp),%r8
mov    %rax,%rdi
call   1050 <fscanf@plt>
xor    %ebp,%ebp
cmp    $0x3,%eax
jne    1250 <is_loop_mount+0xf0>
lea    0xe6f(%rip),%r12
lea    0x210(%rsp),%rbp
lea    0x110(%rsp),%r13
lea    0xe45(%rip),%r15
lea    0x10(%rsp),%r14
jmp    1209 <is_loop_mount+0xa9>
xchg   %ax,%ax
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %rbp,%rdx
mov    %r13,%rcx
mov    %r14,%r8
call   1050 <fscanf@plt>
cmp    $0x3,%eax
jne    124e <is_loop_mount+0xee>
mov    %r12,%rdi
mov    %rbp,%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
jne    11f0 <is_loop_mount+0x90>
mov    0x8(%rsp),%rdi
mov    %r13,%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
jne    11f0 <is_loop_mount+0x90>
mov    $0x1,%ebp
jmp    1250 <is_loop_mount+0xf0>
mov    0x2da7(%rip),%rax
mov    (%rax),%edi
lea    0xdcd(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0xffffffff,%ebp
jmp    1258 <is_loop_mount+0xf8>
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 = [29 x i8] c"could not open /proc/mounts\0A\00"
@.str.3 = [19 x i8] c"%255s %255s %255s\0A\00"
@.str.4 = [17 x i8] c"/dev/block/loop0\00"
define i32 @is_loop_mount(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca [256 x i8]
%7 = alloca [256 x i8]
%8 = alloca [256 x i8]
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %3
store i32 0, i32* %9
%11 = load i8*, i8** %3
%12 = call i32 @strlen(i8* %11)
store i32 %12, i32* %10
%13 = 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* %13, i32** %4
%14 = load i32*, i32** %4
%15 = icmp ne i32* %14, null
br i1 %15, label %19, label %16
16: ; preds = %1
%17 = load i32, i32* @stdout
%18 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %2
br label %47
19: ; preds = %1
br label %20
20: ; preds = %40, %19
%21 = load i32*, i32** %4
%22 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%23 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%24 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%25 = call i32 @fscanf(i32* %21, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %22, i8* %23, i8* %24)
store i32 %25, i32* %5
%26 = load i32, i32* %5
%27 = icmp eq i32 %26, 3
br i1 %27, label %28, label %39
28: ; preds = %20
%29 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%30 = call i64 @strcmp(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i8* %29)
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %38
32: ; preds = %28
%33 = load i8*, i8** %3
%34 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%35 = call i64 @strcmp(i8* %33, i8* %34)
%36 = icmp eq i64 %35, 0
br i1 %36, label %37, label %38
37: ; preds = %32
store i32 1, i32* %9
br label %43
38: ; preds = %32, %28
br label %39
39: ; preds = %38, %20
br label %40
40: ; preds = %39
%41 = load i32, i32* %5
%42 = icmp eq i32 %41, 3
br i1 %42, label %20, label %43
43: ; preds = %40, %37
%44 = load i32*, i32** %4
%45 = call i32 @fclose(i32* %44)
%46 = load i32, i32* %9
store i32 %46, i32* %2
br label %47
47: ; preds = %43, %16
%48 = load i32, i32* %2
ret i32 %48
}

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