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

/* Variables and functions */
int /*<<< orphan*/ endmntent(int /*<<< orphan*/ *);
struct mntent *getmntent(int /*<<< orphan*/ *);
int /*<<< orphan*/ *setmntent(char *, char *);
scalar_t__ strcmp(int /*<<< orphan*/, char *);
char *strdup(int /*<<< orphan*/);
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);
  }
  return NULL;
}


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    0xe95(%rip),%rsi
call   1060 <setmntent@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11f9 <getdev+0xa9>
jmp    1184 <getdev+0x34>
mov    -0x20(%rbp),%rdi
call   1050 <getmntent@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     11f0 <getdev+0xa0>
mov    -0x28(%rbp),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
je     11ce <getdev+0x7e>
mov    -0x28(%rbp),%rax
mov    0x4(%rax),%edi
mov    -0x10(%rbp),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    11eb <getdev+0x9b>
mov    -0x20(%rbp),%rdi
call   1030 <endmntent@plt>
mov    -0x28(%rbp),%rax
mov    (%rax),%edi
call   1070 <strdup@plt>
mov    %rax,-0x8(%rbp)
jmp    1201 <getdev+0xb1>
jmp    1184 <getdev+0x34>
mov    -0x20(%rbp),%rdi
call   1030 <endmntent@plt>
movq   $0x0,-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    0xe9e(%rip),%rsi
mov    %rax,%rdi
call   1060 <setmntent@plt>
test   %rax,%rax
je     11cb <getdev+0x7b>
mov    %rax,%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14,%rdi
call   1050 <getmntent@plt>
test   %rax,%rax
je     11c3 <getdev+0x73>
mov    %rax,%rbx
mov    (%rax),%edi
mov    %r15,%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
je     11af <getdev+0x5f>
mov    0x4(%rbx),%edi
mov    %r15,%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
jne    1180 <getdev+0x30>
mov    %r14,%rdi
call   1030 <endmntent@plt>
mov    (%rbx),%edi
pop    %rbx
pop    %r14
pop    %r15
jmp    1070 <strdup@plt>
mov    %r14,%rdi
call   1030 <endmntent@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.mntent = type { i32, i32 }
@.str = [2 x i8] c"r\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 i32, i32* %19
%21 = load i8*, i8** %4
%22 = call i64 @strcmp(i32 %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 i32, i32* %26
%28 = load i8*, i8** %4
%29 = call i64 @strcmp(i32 %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 i32, i32* %35
%37 = call i8* @strdup(i32 %36)
store i8* %37, i8** %3
br label %43
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
store i8* null, i8** %3
br label %43
43: ; preds = %42, %31
%44 = load i8*, i8** %3
ret i8* %44
}

LLVM IR (-O2):
%struct.mntent = type { i32, i32 }
@.str = [2 x i8] c"r\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 i32, i32* %9
%11 = tail call i64 @strcmp(i32 %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 i32, i32* %14
%16 = tail call i64 @strcmp(i32 %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 i32, i32* %19
%22 = tail call i8* @strdup(i32 %21)
br label %25
23: ; preds = %5
%24 = tail call i32 @endmntent(i32* %3)
br label %25
25: ; preds = %2, %23, %18
%26 = phi i8* [ %22, %18 ], [ null, %23 ], [ null, %2 ]
ret i8* %26
}