#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 EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int fscanf(int /*<<< orphan*/ *, char *, char *, char *, char *, char *, int *,
           int *);
int /*<<< orphan*/ stdout;
scalar_t__ strcmp(char const *, char *);
char *strdup(char *);
int get_mounts_dev_dir(const char *arg, char **dev, char **dir) {
  FILE *f;
  char mount_dev[256];
  char mount_dir[256];
  char mount_type[256];
  char mount_opts[256];
  int mount_freq;
  int mount_passno;
  int match;
  f = fopen("/proc/mounts", "r");
  if (!f) {
    fprintf(stdout, "could not open /proc/mounts\n");
    return -1;
  }
  do {
    match = fscanf(f, "%255s %255s %255s %255s %d %d\n", mount_dev, mount_dir,
                   mount_type, mount_opts, &mount_freq, &mount_passno);
    mount_dev[255] = 0;
    mount_dir[255] = 0;
    mount_type[255] = 0;
    mount_opts[255] = 0;
    if (match == 6 &&
        (strcmp(arg, mount_dev) == 0 || strcmp(arg, mount_dir) == 0)) {
      *dev = strdup(mount_dev);
      *dir = strdup(mount_dir);
      fclose(f);
      return 0;
    }
  } while (match != EOF);
  fclose(f);
  return -1;
}


x86 assembly (clang, -O0):
<get_mounts_dev_dir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x450,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
lea    0xe82(%rip),%rdi
lea    0xe88(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11ba <get_mounts_dev_dir+0x5a>
mov    0x2e38(%rip),%rax
mov    (%rax),%edi
lea    0xe66(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12cd <get_mounts_dev_dir+0x16d>
jmp    11bf <get_mounts_dev_dir+0x5f>
mov    -0x28(%rbp),%rdi
lea    -0x130(%rbp),%rdx
lea    -0x230(%rbp),%rcx
lea    -0x330(%rbp),%r8
lea    -0x430(%rbp),%r9
lea    0xe46(%rip),%rsi
lea    -0x434(%rbp),%r10
lea    -0x438(%rbp),%rax
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
call   1040 <fscanf@plt>
mov    %eax,-0x43c(%rbp)
movb   $0x0,-0x31(%rbp)
movb   $0x0,-0x131(%rbp)
movb   $0x0,-0x231(%rbp)
movb   $0x0,-0x331(%rbp)
cmpl   $0x6,-0x43c(%rbp)
jne    12a3 <get_mounts_dev_dir+0x143>
mov    -0x10(%rbp),%rdi
lea    -0x130(%rbp),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
je     1262 <get_mounts_dev_dir+0x102>
mov    -0x10(%rbp),%rdi
lea    -0x230(%rbp),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    12a3 <get_mounts_dev_dir+0x143>
lea    -0x130(%rbp),%rdi
call   1080 <strdup@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
lea    -0x230(%rbp),%rdi
call   1080 <strdup@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
jmp    12cd <get_mounts_dev_dir+0x16d>
jmp    12a8 <get_mounts_dev_dir+0x148>
mov    -0x43c(%rbp),%eax
mov    0x2d33(%rip),%rcx
cmp    (%rcx),%eax
jne    11bf <get_mounts_dev_dir+0x5f>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x450,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_mounts_dev_dir>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x428,%rsp
mov    %rdx,%r14
mov    %rsi,%rbp
mov    %rdi,%r12
lea    0xe7f(%rip),%rdi
lea    0xe85(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     127f <get_mounts_dev_dir+0x11f>
mov    %rax,%rbx
mov    %rbp,0x8(%rsp)
mov    %r14,0x10(%rsp)
lea    0x120(%rsp),%rbp
lea    0x20(%rsp),%r14
lea    0x220(%rsp),%r13
jmp    11d0 <get_mounts_dev_dir+0x70>
nopw   0x0(%rax,%rax,1)
mov    0x2e21(%rip),%rax
cmp    (%rax),%r15d
je     1296 <get_mounts_dev_dir+0x136>
mov    %rbx,%rdi
lea    0xe52(%rip),%rsi
mov    %rbp,%rdx
mov    %r14,%rcx
lea    0x320(%rsp),%r8
mov    %r13,%r9
lea    0x18(%rsp),%rax
push   %rax
lea    0x24(%rsp),%rax
push   %rax
call   1040 <fscanf@plt>
add    $0x10,%rsp
mov    %eax,%r15d
movb   $0x0,0x21f(%rsp)
movb   $0x0,0x11f(%rsp)
movb   $0x0,0x41f(%rsp)
movb   $0x0,0x31f(%rsp)
cmp    $0x6,%eax
jne    11c0 <get_mounts_dev_dir+0x60>
mov    %r12,%rdi
mov    %rbp,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     124c <get_mounts_dev_dir+0xec>
mov    %r12,%rdi
mov    %r14,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
jne    11c0 <get_mounts_dev_dir+0x60>
lea    0x120(%rsp),%rdi
call   1080 <strdup@plt>
mov    0x8(%rsp),%rcx
mov    %rax,(%rcx)
lea    0x20(%rsp),%rdi
call   1080 <strdup@plt>
mov    0x10(%rsp),%rcx
mov    %rax,(%rcx)
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
jmp    12a3 <get_mounts_dev_dir+0x143>
mov    0x2d52(%rip),%rax
mov    (%rax),%edi
lea    0xd80(%rip),%rsi
call   1060 <fprintf@plt>
jmp    129e <get_mounts_dev_dir+0x13e>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    $0xffffffff,%eax
add    $0x428,%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 = [31 x i8] c"%255s %255s %255s %255s %d %d\0A\00"
@EOF = global i32 0
define i32 @get_mounts_dev_dir(i8* %0, i8** %1, i8** %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8**
%7 = alloca i8**
%8 = alloca i32*
%9 = alloca [256 x i8]
%10 = alloca [256 x i8]
%11 = alloca [256 x i8]
%12 = alloca [256 x i8]
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
store i8* %0, i8** %5
store i8** %1, i8*** %6
store i8** %2, i8*** %7
%16 = 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* %16, i32** %8
%17 = load i32*, i32** %8
%18 = icmp ne i32* %17, null
br i1 %18, label %22, label %19
19: ; preds = %3
%20 = load i32, i32* @stdout
%21 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %4
br label %63
22: ; preds = %3
br label %23
23: ; preds = %56, %22
%24 = load i32*, i32** %8
%25 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%26 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%27 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%28 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%29 = call i32 @fscanf(i32* %24, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i8* %25, i8* %26, i8* %27, i8* %28, i32* %13, i32* %14)
store i32 %29, i32* %15
%30 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 255
store i8 0, i8* %30
%31 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 255
store i8 0, i8* %31
%32 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 255
store i8 0, i8* %32
%33 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 255
store i8 0, i8* %33
%34 = load i32, i32* %15
%35 = icmp eq i32 %34, 6
br i1 %35, label %36, label %55
36: ; preds = %23
%37 = load i8*, i8** %5
%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 %46, label %41
41: ; preds = %36
%42 = load i8*, i8** %5
%43 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%44 = call i64 @strcmp(i8* %42, i8* %43)
%45 = icmp eq i64 %44, 0
br i1 %45, label %46, label %55
46: ; preds = %41, %36
%47 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%48 = call i8* @strdup(i8* %47)
%49 = load i8**, i8*** %6
store i8* %48, i8** %49
%50 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%51 = call i8* @strdup(i8* %50)
%52 = load i8**, i8*** %7
store i8* %51, i8** %52
%53 = load i32*, i32** %8
%54 = call i32 @fclose(i32* %53)
store i32 0, i32* %4
br label %63
55: ; preds = %41, %23
br label %56
56: ; preds = %55
%57 = load i32, i32* %15
%58 = load i32, i32* @EOF
%59 = icmp ne i32 %57, %58
br i1 %59, label %23, label %60
60: ; preds = %56
%61 = load i32*, i32** %8
%62 = call i32 @fclose(i32* %61)
store i32 -1, i32* %4
br label %63
63: ; preds = %60, %46, %19
%64 = load i32, i32* %4
ret i32 %64
}

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 = [31 x i8] c"%255s %255s %255s %255s %d %d\0A\00"
@EOF = global i32 0
define i32 @get_mounts_dev_dir(i8* %0, i8** nocapture writeonly %1, i8** nocapture writeonly %2) {
%4 = alloca [256 x i8]
%5 = alloca [256 x i8]
%6 = alloca [256 x i8]
%7 = alloca [256 x i8]
%8 = alloca i32
%9 = alloca i32
%10 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%11 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%12 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%13 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%14 = bitcast i32* %8 to i8*
%15 = bitcast i32* %9 to i8*
%16 = 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))
%17 = icmp eq i32* %16, null
br i1 %17, label %23, label %18
18: ; preds = %3
%19 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 255
%20 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 255
%21 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 255
%22 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 255
br label %26
23: ; preds = %3
%24 = load i32, i32* @stdout
%25 = tail call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
br label %44
26: ; preds = %18, %39
%27 = call i32 @fscanf(i32* %16, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i8* %10, i8* %11, i8* %12, i8* %13, i32* %8, i32* %9)
store i8 0, i8* %19
store i8 0, i8* %20
store i8 0, i8* %21
store i8 0, i8* %22
%28 = icmp eq i32 %27, 6
br i1 %28, label %29, label %39
29: ; preds = %26
%30 = call i64 @strcmp(i8* %0, i8* %10)
%31 = icmp eq i64 %30, 0
br i1 %31, label %35, label %32
32: ; preds = %29
%33 = call i64 @strcmp(i8* %0, i8* %11)
%34 = icmp eq i64 %33, 0
br i1 %34, label %35, label %39
35: ; preds = %32, %29
%36 = call i8* @strdup(i8* %10)
store i8* %36, i8** %1
%37 = call i8* @strdup(i8* %11)
store i8* %37, i8** %2
%38 = call i32 @fclose(i32* %16)
br label %44
39: ; preds = %26, %32
%40 = load i32, i32* @EOF
%41 = icmp eq i32 %27, %40
br i1 %41, label %42, label %26
42: ; preds = %39
%43 = call i32 @fclose(i32* %16)
br label %44
44: ; preds = %42, %35, %23
%45 = phi i32 [ 0, %35 ], [ -1, %42 ], [ -1, %23 ]
ret i32 %45
}