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

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


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    0xe75(%rip),%rsi
call   1070 <setmntent@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1222 <getdev+0xb2>
jmp    11a4 <getdev+0x34>
mov    -0x20(%rbp),%rdi
call   1060 <getmntent@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     1219 <getdev+0xa9>
mov    -0x28(%rbp),%rdi
call   1080 <mnt_device_path@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
je     11f9 <getdev+0x89>
mov    -0x28(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    1214 <getdev+0xa4>
mov    -0x20(%rbp),%rdi
call   1030 <endmntent@plt>
mov    -0x30(%rbp),%rdi
call   1090 <strdup@plt>
mov    %rax,-0x8(%rbp)
jmp    1254 <getdev+0xe4>
jmp    11a4 <getdev+0x34>
mov    -0x20(%rbp),%rdi
call   1030 <endmntent@plt>
mov    -0x10(%rbp),%rdi
lea    0xdd5(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
je     1249 <getdev+0xd9>
movq   $0x0,-0x8(%rbp)
jmp    1254 <getdev+0xe4>
mov    $0x0,%al
call   1040 <root_device_name@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   %r12
push   %rbx
push   %rax
mov    %rsi,%rax
mov    %rdi,%r15
lea    0xe7b(%rip),%rsi
mov    %rax,%rdi
call   1070 <setmntent@plt>
test   %rax,%rax
je     11fe <getdev+0x8e>
mov    %rax,%r14
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r14,%rdi
call   1060 <getmntent@plt>
test   %rax,%rax
je     11f6 <getdev+0x86>
mov    %rax,%rbx
mov    %rax,%rdi
call   1080 <mnt_device_path@plt>
mov    %rax,%r12
mov    %rax,%rdi
mov    %r15,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     11db <getdev+0x6b>
mov    (%rbx),%rdi
mov    %r15,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
jne    11a0 <getdev+0x30>
mov    %r14,%rdi
call   1030 <endmntent@plt>
mov    %r12,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1090 <strdup@plt>
mov    %r14,%rdi
call   1030 <endmntent@plt>
lea    0xdfd(%rip),%rsi
mov    %r15,%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
je     1220 <getdev+0xb0>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1040 <root_device_name@plt>

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

LLVM IR (-O2):
%struct.mntent = type { 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 %22, label %5
5: ; preds = %2, %12
%6 = tail call %struct.mntent* @getmntent(i32* %3)
%7 = icmp eq %struct.mntent* %6, null
br i1 %7, label %20, label %8
8: ; preds = %5
%9 = tail call i8* @mnt_device_path(%struct.mntent* %6)
%10 = tail call i64 @strcmp(i8* %9, i8* %0)
%11 = icmp eq i64 %10, 0
br i1 %11, label %17, label %12
12: ; preds = %8
%13 = getelementptr inbounds %struct.mntent, %struct.mntent* %6, i64 0, i32 0
%14 = load i8*, i8** %13
%15 = tail call i64 @strcmp(i8* %14, i8* %0)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %5
17: ; preds = %12, %8
%18 = tail call i32 @endmntent(i32* %3)
%19 = tail call i8* @strdup(i8* %9)
br label %27
20: ; preds = %5
%21 = tail call i32 @endmntent(i32* %3)
br label %22
22: ; preds = %20, %2
%23 = tail call i64 @strcmp(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %22
%26 = tail call i8* (...) @root_device_name()
br label %27
27: ; preds = %22, %25, %17
%28 = phi i8* [ %19, %17 ], [ %26, %25 ], [ null, %22 ]
ret i8* %28
}