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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ strncmp(char *, char *, int /*<<< orphan*/);
int find_overlay_mount(char *overlay) {
  FILE *fp = fopen("/proc/mounts", "r");
  static char line[256];
  int ret = -1;
  if (!fp)
    return ret;
  while (ret && fgets(line, sizeof(line), fp))
    if (!strncmp(line, overlay, strlen(overlay)))
      ret = 0;
  fclose(fp);
  return ret;
}


x86 assembly (clang, -O0):
<find_overlay_mount>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
lea    0xe9d(%rip),%rdi
lea    0xea3(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
movl   $0xffffffff,-0x1c(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1190 <find_overlay_mount+0x40>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    121a <find_overlay_mount+0xca>
jmp    1195 <find_overlay_mount+0x45>
xor    %eax,%eax
cmpl   $0x0,-0x1c(%rbp)
mov    %al,-0x1d(%rbp)
je     11c3 <find_overlay_mount+0x73>
mov    -0x18(%rbp),%rdx
lea    0x2eb1(%rip),%rdi
mov    $0x100,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    11d3 <find_overlay_mount+0x83>
jmp    120b <find_overlay_mount+0xbb>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x28(%rbp),%rsi
mov    %eax,%edx
lea    0x2e6f(%rip),%rdi
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    1206 <find_overlay_mount+0xb6>
movl   $0x0,-0x1c(%rbp)
jmp    1195 <find_overlay_mount+0x45>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_overlay_mount>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%rbx
lea    0xea1(%rip),%rdi
lea    0xea7(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11b2 <find_overlay_mount+0x62>
mov    %rax,%r14
lea    0x2ee6(%rip),%r15
nopw   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    $0x100,%esi
mov    %r14,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     11b9 <find_overlay_mount+0x69>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
jne    1180 <find_overlay_mount+0x30>
xor    %ebx,%ebx
jmp    11be <find_overlay_mount+0x6e>
mov    $0xffffffff,%ebx
jmp    11c6 <find_overlay_mount+0x76>
mov    $0xffffffff,%ebx
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [13 x i8] c"/proc/mounts\00"
@.str.1 = [2 x i8] c"r\00"
@find_overlay_mount.line = internal global [256 x i8] zeroinitializer
define i32 @find_overlay_mount(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32
store i8* %0, i8** %3
%6 = 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* %6, i32** %4
store i32 -1, i32* %5
%7 = load i32*, i32** %4
%8 = icmp ne i32* %7, null
br i1 %8, label %11, label %9
9: ; preds = %1
%10 = load i32, i32* %5
store i32 %10, i32* %2
br label %33
11: ; preds = %1
br label %12
12: ; preds = %28, %11
%13 = load i32, i32* %5
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %12
%16 = load i32*, i32** %4
%17 = call i64 @fgets(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @find_overlay_mount.line, i64 0, i64 0), i32 256, i32* %16)
%18 = icmp ne i64 %17, 0
br label %19
19: ; preds = %15, %12
%20 = phi i1 [ false, %12 ], [ %18, %15 ]
br i1 %20, label %21, label %29
21: ; preds = %19
%22 = load i8*, i8** %3
%23 = load i8*, i8** %3
%24 = call i32 @strlen(i8* %23)
%25 = call i32 @strncmp(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @find_overlay_mount.line, i64 0, i64 0), i8* %22, i32 %24)
%26 = icmp ne i32 %25, 0
br i1 %26, label %28, label %27
27: ; preds = %21
store i32 0, i32* %5
br label %28
28: ; preds = %27, %21
br label %12
29: ; preds = %19
%30 = load i32*, i32** %4
%31 = call i32 @fclose(i32* %30)
%32 = load i32, i32* %5
store i32 %32, i32* %2
br label %33
33: ; preds = %29, %9
%34 = load i32, i32* %2
ret i32 %34
}

LLVM IR (-O2):
@.str = [13 x i8] c"/proc/mounts\00"
@.str.1 = [2 x i8] c"r\00"
@find_overlay_mount.line = internal global [256 x i8] zeroinitializer
define i32 @find_overlay_mount(i8* %0) {
%2 = 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))
%3 = icmp eq i32* %2, null
br i1 %3, label %14, label %4
4: ; preds = %1, %7
%5 = tail call i64 @fgets(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @find_overlay_mount.line, i64 0, i64 0), i32 256, i32* %2)
%6 = icmp eq i64 %5, 0
br i1 %6, label %11, label %7
7: ; preds = %4
%8 = tail call i32 @strlen(i8* %0)
%9 = tail call i32 @strncmp(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @find_overlay_mount.line, i64 0, i64 0), i8* %0, i32 %8)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %4
11: ; preds = %7, %4
%12 = phi i32 [ 0, %7 ], [ -1, %4 ]
%13 = tail call i32 @fclose(i32* %2)
br label %14
14: ; preds = %1, %11
%15 = phi i32 [ %12, %11 ], [ -1, %1 ]
ret i32 %15
}