#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 const *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 const *);
const char *mntpoint(const char *mount) {
  FILE *fp;
  struct mntent *mnt;
  fp = setmntent("/etc/fstab", "r");
  if (fp) {
    while (mnt = getmntent(fp)) {
      if (strcmp(mnt->mnt_dir, mount) == 0) {
        endmntent(fp);
        return mnt->mnt_fsname;
      }
    }
    endmntent(fp);
  }
  return NULL;
}


x86 assembly (clang, -O0):
<mntpoint>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
lea    0xead(%rip),%rdi
lea    0xeb1(%rip),%rsi
call   1060 <setmntent@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11cb <mntpoint+0x8b>
jmp    1173 <mntpoint+0x33>
mov    -0x18(%rbp),%rdi
call   1050 <getmntent@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     11c2 <mntpoint+0x82>
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%edi
mov    -0x10(%rbp),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    11bd <mntpoint+0x7d>
mov    -0x18(%rbp),%rdi
call   1030 <endmntent@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x8(%rbp)
jmp    11d3 <mntpoint+0x93>
jmp    1173 <mntpoint+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):
<mntpoint>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
lea    0xeb1(%rip),%rdi
lea    0xeb5(%rip),%rsi
call   1060 <setmntent@plt>
test   %rax,%rax
je     11a5 <mntpoint+0x65>
mov    %rax,%r15
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r15,%rdi
call   1050 <getmntent@plt>
test   %rax,%rax
je     119d <mntpoint+0x5d>
mov    %rax,%rbx
mov    0x8(%rax),%edi
mov    %r14,%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
jne    1170 <mntpoint+0x30>
mov    %r15,%rdi
call   1030 <endmntent@plt>
mov    (%rbx),%rax
jmp    11a7 <mntpoint+0x67>
mov    %r15,%rdi
call   1030 <endmntent@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.mntent = type { i8*, i32 }
@.str = [11 x i8] c"/etc/fstab\00"
@.str.1 = [2 x i8] c"r\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 ([11 x i8], [11 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 %31
9: ; preds = %1
br label %10
10: ; preds = %27, %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 %28
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 %27
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 i8*, i8** %25
store i8* %26, i8** %2
br label %32
27: ; preds = %14
br label %10
28: ; preds = %10
%29 = load i32*, i32** %4
%30 = call i32 @endmntent(i32* %29)
br label %31
31: ; preds = %28, %1
store i8* null, i8** %2
br label %32
32: ; preds = %31, %21
%33 = load i8*, i8** %2
ret i8* %33
}

LLVM IR (-O2):
%struct.mntent = type { i8*, i32 }
@.str = [11 x i8] c"/etc/fstab\00"
@.str.1 = [2 x i8] c"r\00"
define i8* @mntpoint(i8* %0) {
%2 = tail call i32* @setmntent(i8* getelementptr inbounds ([11 x i8], [11 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 %18, 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 %16, 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 i8*, i8** %14
br label %18
16: ; preds = %4
%17 = tail call i32 @endmntent(i32* %2)
br label %18
18: ; preds = %1, %16, %12
%19 = phi i8* [ %15, %12 ], [ null, %16 ], [ null, %1 ]
ret i8* %19
}