#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 */
struct mntent {
  char *mnt_fsname;
  char *mnt_dir;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ endmntent(int /*<<< orphan*/ *);
struct mntent *getmntent(int /*<<< orphan*/ *);
char *root_device();
int /*<<< orphan*/ *setmntent(char *, char *);
scalar_t__ strcmp(char *, char *);
char *strdup(char *);
char *getdev(char *arg, char *p) {
  FILE *f;
  struct mntent *mnt;
  f = setmntent(p, "r");
  if (f) {
    while (mnt = getmntent(f)) {
      if ((strcmp(mnt->mnt_fsname, arg) == 0) ||
          (strcmp(mnt->mnt_dir, arg) == 0)) {
        endmntent(f);
        return strdup(mnt->mnt_fsname);
      }
    }
    endmntent(f);
  }
  if (strcmp(arg, "/"))
    return NULL;
  return root_device();
}


x86 assembly (clang, -O0):
<getdev>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe85(%rip),%rsi
call   1060 <setmntent@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     120c <getdev+0xac>
jmp    1194 <getdev+0x34>
mov    -0x20(%rbp),%rdi
call   1050 <getmntent@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     1203 <getdev+0xa3>
mov    -0x28(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
je     11e0 <getdev+0x80>
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    11fe <getdev+0x9e>
mov    -0x20(%rbp),%rdi
call   1030 <endmntent@plt>
mov    -0x28(%rbp),%rax
mov    (%rax),%rdi
call   1080 <strdup@plt>
mov    %rax,-0x8(%rbp)
jmp    123e <getdev+0xde>
jmp    1194 <getdev+0x34>
mov    -0x20(%rbp),%rdi
call   1030 <endmntent@plt>
mov    -0x10(%rbp),%rdi
lea    0xdeb(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
je     1233 <getdev+0xd3>
movq   $0x0,-0x8(%rbp)
jmp    123e <getdev+0xde>
mov    $0x0,%al
call   1070 <root_device@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getdev>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%rax
mov    %rdi,%r15
lea    0xe8e(%rip),%rsi
mov    %rax,%rdi
call   1060 <setmntent@plt>
test   %rax,%rax
je     11de <getdev+0x7e>
mov    %rax,%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14,%rdi
call   1050 <getmntent@plt>
test   %rax,%rax
je     11d6 <getdev+0x76>
mov    %rax,%rbx
mov    (%rax),%rdi
mov    %r15,%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
je     11c1 <getdev+0x61>
mov    0x8(%rbx),%rdi
mov    %r15,%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
jne    1190 <getdev+0x30>
mov    %r14,%rdi
call   1030 <endmntent@plt>
mov    (%rbx),%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1080 <strdup@plt>
mov    %r14,%rdi
call   1030 <endmntent@plt>
lea    0xe1d(%rip),%rsi
mov    %r15,%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
je     11fa <getdev+0x9a>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
jmp    1070 <root_device@plt>

LLVM IR (-O0):
%struct.mntent = type { i8*, i8* }
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c"/\00"
define i8* @getdev(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca %struct.mntent*
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = load i8*, i8** %5
%9 = call i32* @setmntent(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %9, i32** %6
%10 = load i32*, i32** %6
%11 = icmp ne i32* %10, null
br i1 %11, label %12, label %42
12: ; preds = %2
br label %13
13: ; preds = %38, %12
%14 = load i32*, i32** %6
%15 = call %struct.mntent* @getmntent(i32* %14)
store %struct.mntent* %15, %struct.mntent** %7
%16 = icmp ne %struct.mntent* %15, null
br i1 %16, label %17, label %39
17: ; preds = %13
%18 = load %struct.mntent*, %struct.mntent** %7
%19 = getelementptr inbounds %struct.mntent, %struct.mntent* %18, i32 0, i32 0
%20 = load i8*, i8** %19
%21 = load i8*, i8** %4
%22 = call i64 @strcmp(i8* %20, i8* %21)
%23 = icmp eq i64 %22, 0
br i1 %23, label %31, label %24
24: ; preds = %17
%25 = load %struct.mntent*, %struct.mntent** %7
%26 = getelementptr inbounds %struct.mntent, %struct.mntent* %25, i32 0, i32 1
%27 = load i8*, i8** %26
%28 = load i8*, i8** %4
%29 = call i64 @strcmp(i8* %27, i8* %28)
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %38
31: ; preds = %24, %17
%32 = load i32*, i32** %6
%33 = call i32 @endmntent(i32* %32)
%34 = load %struct.mntent*, %struct.mntent** %7
%35 = getelementptr inbounds %struct.mntent, %struct.mntent* %34, i32 0, i32 0
%36 = load i8*, i8** %35
%37 = call i8* @strdup(i8* %36)
store i8* %37, i8** %3
br label %49
38: ; preds = %24
br label %13
39: ; preds = %13
%40 = load i32*, i32** %6
%41 = call i32 @endmntent(i32* %40)
br label %42
42: ; preds = %39, %2
%43 = load i8*, i8** %4
%44 = call i64 @strcmp(i8* %43, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%45 = icmp ne i64 %44, 0
br i1 %45, label %46, label %47
46: ; preds = %42
store i8* null, i8** %3
br label %49
47: ; preds = %42
%48 = call i8* (...) @root_device()
store i8* %48, i8** %3
br label %49
49: ; preds = %47, %46, %31
%50 = load i8*, i8** %3
ret i8* %50
}

LLVM IR (-O2):
%struct.mntent = type { i8*, i8* }
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c"/\00"
define i8* @getdev(i8* %0, i8* %1) {
%3 = tail call i32* @setmntent(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %25, label %5
5: ; preds = %2, %13
%6 = tail call %struct.mntent* @getmntent(i32* %3)
%7 = icmp eq %struct.mntent* %6, null
br i1 %7, label %23, label %8
8: ; preds = %5
%9 = getelementptr inbounds %struct.mntent, %struct.mntent* %6, i64 0, i32 0
%10 = load i8*, i8** %9
%11 = tail call i64 @strcmp(i8* %10, i8* %0)
%12 = icmp eq i64 %11, 0
br i1 %12, label %18, label %13
13: ; preds = %8
%14 = getelementptr inbounds %struct.mntent, %struct.mntent* %6, i64 0, i32 1
%15 = load i8*, i8** %14
%16 = tail call i64 @strcmp(i8* %15, i8* %0)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %5
18: ; preds = %13, %8
%19 = getelementptr inbounds %struct.mntent, %struct.mntent* %6, i64 0, i32 0
%20 = tail call i32 @endmntent(i32* %3)
%21 = load i8*, i8** %19
%22 = tail call i8* @strdup(i8* %21)
br label %30
23: ; preds = %5
%24 = tail call i32 @endmntent(i32* %3)
br label %25
25: ; preds = %23, %2
%26 = tail call i64 @strcmp(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %25
%29 = tail call i8* (...) @root_device()
br label %30
30: ; preds = %25, %28, %18
%31 = phi i8* [ %22, %18 ], [ %29, %28 ], [ null, %25 ]
ret i8* %31
}