#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_dir;
  int /*<<< orphan*/ mnt_fsname;
};
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 const *);
char const *strdup(int /*<<< orphan*/);
const char *mntpoint(const char *devname) {
  FILE *f;
  struct mntent *mnt;
  f = setmntent("/etc/mtab", "r");
  if (f) {
    while (mnt = getmntent(f)) {
      if (strcmp(mnt->mnt_fsname, devname) == 0) {
        endmntent(f);
        return strdup(mnt->mnt_dir);
      }
    }
    endmntent(f);
  }
  return "???";
}


x86 assembly (clang, -O0):
<mntpoint>:
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     11df <mntpoint+0x8f>
jmp    1183 <mntpoint+0x33>
mov    -0x18(%rbp),%rdi
call   1050 <getmntent@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     11d6 <mntpoint+0x86>
mov    -0x20(%rbp),%rax
mov    0x4(%rax),%edi
mov    -0x10(%rbp),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    11d1 <mntpoint+0x81>
mov    -0x18(%rbp),%rdi
call   1030 <endmntent@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%edi
call   1070 <strdup@plt>
mov    %rax,-0x8(%rbp)
jmp    11ea <mntpoint+0x9a>
jmp    1183 <mntpoint+0x33>
mov    -0x18(%rbp),%rdi
call   1030 <endmntent@plt>
lea    0xe26(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mntpoint>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
lea    0xea1(%rip),%rdi
lea    0xea4(%rip),%rsi
call   1060 <setmntent@plt>
test   %rax,%rax
je     11bc <mntpoint+0x6c>
mov    %rax,%r15
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r15,%rdi
call   1050 <getmntent@plt>
test   %rax,%rax
je     11b4 <mntpoint+0x64>
mov    %rax,%rbx
mov    0x4(%rax),%edi
mov    %r14,%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
jne    1180 <mntpoint+0x30>
mov    %r15,%rdi
call   1030 <endmntent@plt>
mov    (%rbx),%edi
pop    %rbx
pop    %r14
pop    %r15
jmp    1070 <strdup@plt>
mov    %r15,%rdi
call   1030 <endmntent@plt>
lea    0xe49(%rip),%rax
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"
@.str.2 = [4 x i8] c"???\00"
define i8* @mntpoint(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 %32
9: ; preds = %1
br label %10
10: ; preds = %28, %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 %29
14: ; preds = %10
%15 = load %struct.mntent*, %struct.mntent** %5
%16 = getelementptr inbounds %struct.mntent, %struct.mntent* %15, i32 0, i32 1
%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 %21, label %28
21: ; preds = %14
%22 = load i32*, i32** %4
%23 = call i32 @endmntent(i32* %22)
%24 = load %struct.mntent*, %struct.mntent** %5
%25 = getelementptr inbounds %struct.mntent, %struct.mntent* %24, i32 0, i32 0
%26 = load i32, i32* %25
%27 = call i8* @strdup(i32 %26)
store i8* %27, i8** %2
br label %33
28: ; preds = %14
br label %10
29: ; preds = %10
%30 = load i32*, i32** %4
%31 = call i32 @endmntent(i32* %30)
br label %32
32: ; preds = %29, %1
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8** %2
br label %33
33: ; preds = %32, %21
%34 = load i8*, i8** %2
ret i8* %34
}

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