#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 LINE_MAX;
int /*<<< orphan*/ error(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
char *strchr(char *, char);
int /*<<< orphan*/ strcmp(char *, char const *);
int check_home_directory(const char *dst) {
  FILE *file;
  char line[LINE_MAX], *s, *e;
  int found;
  file = fopen("/proc/mounts", "r");
  if (!file)
    error("Failed to open /proc/mounts.\n");
  found = 0;
  while (fgets(line, sizeof line, file)) {
    s = strchr(line, ' ');
    if (!s)
      continue;
    e = strchr(++s, ' ');
    if (!e)
      continue;
    *e = 0;
    if (!strcmp(s, dst)) {
      found = 1;
      break;
    }
  }
  fclose(file);
  return found;
}


x86 assembly (clang, -O0):
<check_home_directory>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2e75(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x48(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
lea    0xe5d(%rip),%rdi
lea    0xe63(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11ca <check_home_directory+0x6a>
lea    0xe4a(%rip),%rdi
call   1070 <error@plt>
movl   $0x0,-0x34(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x48(%rbp),%rax
mov    %eax,%esi
mov    -0x10(%rbp),%rdx
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     1268 <check_home_directory+0x108>
mov    -0x40(%rbp),%rdi
mov    $0x20,%esi
call   1040 <strchr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1210 <check_home_directory+0xb0>
jmp    11d1 <check_home_directory+0x71>
mov    -0x28(%rbp),%rdi
add    $0x1,%rdi
mov    %rdi,-0x28(%rbp)
mov    $0x20,%esi
call   1040 <strchr@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    123a <check_home_directory+0xda>
jmp    11d1 <check_home_directory+0x71>
mov    -0x30(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    1263 <check_home_directory+0x103>
movl   $0x1,-0x34(%rbp)
jmp    1268 <check_home_directory+0x108>
jmp    11d1 <check_home_directory+0x71>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x34(%rbp),%eax
mov    -0x18(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_home_directory>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
mov    0x2e70(%rip),%rax
mov    (%rax),%r15d
mov    %rsp,%rbx
mov    %r15,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
lea    0xe6a(%rip),%rdi
lea    0xe70(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%r12
test   %rax,%rax
jne    11b6 <check_home_directory+0x56>
lea    0xe5e(%rip),%rdi
call   1070 <error@plt>
mov    %rbx,%rdi
mov    %r15d,%esi
mov    %r12,%rdx
call   1050 <fgets@plt>
xor    %r13d,%r13d
test   %rax,%rax
jne    11e3 <check_home_directory+0x83>
jmp    122b <check_home_directory+0xcb>
xchg   %ax,%ax
mov    %rbx,%rdi
mov    %r15d,%esi
mov    %r12,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     1228 <check_home_directory+0xc8>
mov    %rbx,%rdi
mov    $0x20,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     11d0 <check_home_directory+0x70>
mov    %rax,%r13
add    $0x1,%r13
mov    %r13,%rdi
mov    $0x20,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     11d0 <check_home_directory+0x70>
movb   $0x0,(%rax)
mov    %r13,%rdi
mov    %r14,%rsi
call   1060 <strcmp@plt>
test   %eax,%eax
jne    11d0 <check_home_directory+0x70>
mov    $0x1,%r13d
jmp    122b <check_home_directory+0xcb>
xor    %r13d,%r13d
mov    %r12,%rdi
call   1030 <fclose@plt>
mov    %r13d,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@LINE_MAX = global i32 0
@.str = [13 x i8] c"/proc/mounts\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [30 x i8] c"Failed to open /proc/mounts.\0A\00"
define i32 @check_home_directory(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
store i8* %0, i8** %2
%9 = load i32, i32* @LINE_MAX
%10 = zext i32 %9 to i64
%11 = call i8* @llvm.stacksave()
store i8* %11, i8** %4
%12 = alloca i8, i64 %10
store i64 %10, i64* %5
%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** %3
%14 = load i32*, i32** %3
%15 = icmp ne i32* %14, null
br i1 %15, label %18, label %16
16: ; preds = %1
%17 = call i32 @error(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
br label %18
18: ; preds = %16, %1
store i32 0, i32* %8
br label %19
19: ; preds = %43, %35, %28, %18
%20 = trunc i64 %10 to i32
%21 = load i32*, i32** %3
%22 = call i64 @fgets(i8* %12, i32 %20, i32* %21)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %44
24: ; preds = %19
%25 = call i8* @strchr(i8* %12, i8 signext 32)
store i8* %25, i8** %6
%26 = load i8*, i8** %6
%27 = icmp ne i8* %26, null
br i1 %27, label %29, label %28
28: ; preds = %24
br label %19
29: ; preds = %24
%30 = load i8*, i8** %6
%31 = getelementptr inbounds i8, i8* %30, i32 1
store i8* %31, i8** %6
%32 = call i8* @strchr(i8* %31, i8 signext 32)
store i8* %32, i8** %7
%33 = load i8*, i8** %7
%34 = icmp ne i8* %33, null
br i1 %34, label %36, label %35
35: ; preds = %29
br label %19
36: ; preds = %29
%37 = load i8*, i8** %7
store i8 0, i8* %37
%38 = load i8*, i8** %6
%39 = load i8*, i8** %2
%40 = call i32 @strcmp(i8* %38, i8* %39)
%41 = icmp ne i32 %40, 0
br i1 %41, label %43, label %42
42: ; preds = %36
store i32 1, i32* %8
br label %44
43: ; preds = %36
br label %19
44: ; preds = %42, %19
%45 = load i32*, i32** %3
%46 = call i32 @fclose(i32* %45)
%47 = load i32, i32* %8
%48 = load i8*, i8** %4
ret i32 %47
}

LLVM IR (-O2):
@LINE_MAX = global i32 0
@.str = [13 x i8] c"/proc/mounts\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [30 x i8] c"Failed to open /proc/mounts.\0A\00"
define i32 @check_home_directory(i8* nocapture %0) {
%2 = load i32, i32* @LINE_MAX
%3 = zext i32 %2 to i64
%4 = alloca i8, i64 %3
%5 = 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))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = tail call i32 @error(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
br label %9
9: ; preds = %7, %1
%10 = call i64 @fgets(i8* %4, i32 %2, i32* %5)
%11 = icmp eq i64 %10, 0
br i1 %11, label %25, label %12
12: ; preds = %9, %15
%13 = call i8* @strchr(i8* %4, i8 signext 32)
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %18
15: ; preds = %12, %18, %22
%16 = call i64 @fgets(i8* %4, i32 %2, i32* %5)
%17 = icmp eq i64 %16, 0
br i1 %17, label %25, label %12
18: ; preds = %12
%19 = getelementptr inbounds i8, i8* %13, i64 1
%20 = call i8* @strchr(i8* %19, i8 signext 32)
%21 = icmp eq i8* %20, null
br i1 %21, label %15, label %22
22: ; preds = %18
store i8 0, i8* %20
%23 = call i32 @strcmp(i8* %19, i8* dereferenceable(1) %0)
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %15
25: ; preds = %15, %22, %9
%26 = phi i32 [ 0, %9 ], [ 1, %22 ], [ 0, %15 ]
%27 = call i32 @fclose(i32* %5)
ret i32 %26
}