#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) {
  FILE *f;
  struct mntent *mnt;
  f = setmntent("/etc/mtab", "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    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
lea    0xe9d(%rip),%rdi
lea    0xea0(%rip),%rsi
call   1060 <setmntent@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11f8 <getdev+0xa8>
jmp    1183 <getdev+0x33>
mov    -0x18(%rbp),%rdi
call   1050 <getmntent@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     11ef <getdev+0x9f>
mov    -0x20(%rbp),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
je     11cd <getdev+0x7d>
mov    -0x20(%rbp),%rax
mov    0x4(%rax),%edi
mov    -0x10(%rbp),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    11ea <getdev+0x9a>
mov    -0x18(%rbp),%rdi
call   1030 <endmntent@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%edi
call   1070 <strdup@plt>
mov    %rax,-0x8(%rbp)
jmp    1200 <getdev+0xb0>
jmp    1183 <getdev+0x33>
mov    -0x18(%rbp),%rdi
call   1030 <endmntent@plt>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getdev>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r15
lea    0xea1(%rip),%rdi
lea    0xea4(%rip),%rsi
call   1060 <setmntent@plt>
test   %rax,%rax
je     11cb <getdev+0x7b>
mov    %rax,%r14
cs nopw 0x0(%rax,%rax,1)
nopl   (%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 = [10 x i8] c"/etc/mtab\00"
@.str.1 = [2 x i8] c"r\00"
define i8* @getdev(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca %struct.mntent*
store i8* %0, i8** %3
%6 = call i32* @setmntent(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %6, i32** %4
%7 = load i32*, i32** %4
%8 = icmp ne i32* %7, null
br i1 %8, label %9, label %39
9: ; preds = %1
br label %10
10: ; preds = %35, %9
%11 = load i32*, i32** %4
%12 = call %struct.mntent* @getmntent(i32* %11)
store %struct.mntent* %12, %struct.mntent** %5
%13 = icmp ne %struct.mntent* %12, null
br i1 %13, label %14, label %36
14: ; preds = %10
%15 = load %struct.mntent*, %struct.mntent** %5
%16 = getelementptr inbounds %struct.mntent, %struct.mntent* %15, i32 0, i32 0
%17 = load i32, i32* %16
%18 = load i8*, i8** %3
%19 = call i64 @strcmp(i32 %17, i8* %18)
%20 = icmp eq i64 %19, 0
br i1 %20, label %28, label %21
21: ; preds = %14
%22 = load %struct.mntent*, %struct.mntent** %5
%23 = getelementptr inbounds %struct.mntent, %struct.mntent* %22, i32 0, i32 1
%24 = load i32, i32* %23
%25 = load i8*, i8** %3
%26 = call i64 @strcmp(i32 %24, i8* %25)
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %35
28: ; preds = %21, %14
%29 = load i32*, i32** %4
%30 = call i32 @endmntent(i32* %29)
%31 = load %struct.mntent*, %struct.mntent** %5
%32 = getelementptr inbounds %struct.mntent, %struct.mntent* %31, i32 0, i32 0
%33 = load i32, i32* %32
%34 = call i8* @strdup(i32 %33)
store i8* %34, i8** %2
br label %40
35: ; preds = %21
br label %10
36: ; preds = %10
%37 = load i32*, i32** %4
%38 = call i32 @endmntent(i32* %37)
br label %39
39: ; preds = %36, %1
store i8* null, i8** %2
br label %40
40: ; preds = %39, %28
%41 = load i8*, i8** %2
ret i8* %41
}

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