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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ sscanf(char *, char *, char *, char *, char *, char *);
scalar_t__ strcmp(char *, char const *);
char *mntpoint(const char *devname) {
  FILE *f;
  static char tmp[256];
  static char dev[20], mntpt[20], fstype[20], rwflag[20];
  f = fopen("/etc/mtab", "r");
  if (f) {
    while (fgets(tmp, 256, f)) {
      sscanf(tmp, "%s %s %s %s\n", dev, mntpt, fstype, rwflag);
      if (strcmp(dev, devname) == 0) {
        fclose(f);
        return mntpt;
      }
    }
    fclose(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   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1212 <mntpoint+0xc2>
jmp    1183 <mntpoint+0x33>
mov    -0x18(%rbp),%rdx
lea    0x2ed2(%rip),%rdi
mov    $0x100,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
je     1209 <mntpoint+0xb9>
lea    0x2eb7(%rip),%rdi
lea    0xe5c(%rip),%rsi
lea    0x2fa9(%rip),%rdx
lea    0x2fc2(%rip),%rcx
lea    0x2fdb(%rip),%r8
lea    0x2ff4(%rip),%r9
call   1060 <sscanf@plt>
mov    -0x10(%rbp),%rsi
lea    0x2f84(%rip),%rdi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    1204 <mntpoint+0xb4>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
lea    0x2f85(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    121d <mntpoint+0xcd>
jmp    1183 <mntpoint+0x33>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
lea    0xe00(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mntpoint>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r15
lea    0xe9b(%rip),%rdi
lea    0xe9e(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11ed <mntpoint+0x9d>
mov    %rax,%rbx
lea    0x2ee0(%rip),%r12
lea    0x2fd9(%rip),%r14
lea    0x3012(%rip),%r13
lea    0x302b(%rip),%rbp
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r12,%rdi
mov    $0x100,%esi
mov    %rbx,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     11f6 <mntpoint+0xa6>
mov    %r12,%rdi
lea    0xe4d(%rip),%rsi
mov    %r14,%rdx
lea    0x2fb7(%rip),%rcx
mov    %r13,%r8
mov    %rbp,%r9
call   1060 <sscanf@plt>
mov    %r14,%rdi
mov    %r15,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
jne    11a0 <mntpoint+0x50>
lea    0x2f95(%rip),%rbp
jmp    11fd <mntpoint+0xad>
lea    0xe25(%rip),%rbp
jmp    1205 <mntpoint+0xb5>
lea    0xe1c(%rip),%rbp
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %rbp,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@mntpoint.tmp = internal global [256 x i8] zeroinitializer
@mntpoint.dev = internal global [20 x i8] zeroinitializer
@mntpoint.mntpt = internal global [20 x i8] zeroinitializer
@mntpoint.fstype = internal global [20 x i8] zeroinitializer
@mntpoint.rwflag = internal global [20 x i8] zeroinitializer
@.str = [10 x i8] c"/etc/mtab\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [13 x i8] c"%s %s %s %s\0A\00"
@.str.3 = [4 x i8] c"???\00"
define i8* @mntpoint(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32*
store i8* %0, i8** %3
%5 = call i32* @fopen(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* %5, i32** %4
%6 = load i32*, i32** %4
%7 = icmp ne i32* %6, null
br i1 %7, label %8, label %25
8: ; preds = %1
br label %9
9: ; preds = %21, %8
%10 = load i32*, i32** %4
%11 = call i64 @fgets(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @mntpoint.tmp, i64 0, i64 0), i32 256, i32* %10)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %22
13: ; preds = %9
%14 = call i32 @sscanf(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @mntpoint.tmp, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([20 x i8], [20 x i8]* @mntpoint.dev, i64 0, i64 0), i8* getelementptr inbounds ([20 x i8], [20 x i8]* @mntpoint.mntpt, i64 0, i64 0), i8* getelementptr inbounds ([20 x i8], [20 x i8]* @mntpoint.fstype, i64 0, i64 0), i8* getelementptr inbounds ([20 x i8], [20 x i8]* @mntpoint.rwflag, i64 0, i64 0))
%15 = load i8*, i8** %3
%16 = call i64 @strcmp(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @mntpoint.dev, i64 0, i64 0), i8* %15)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %13
%19 = load i32*, i32** %4
%20 = call i32 @fclose(i32* %19)
store i8* getelementptr inbounds ([20 x i8], [20 x i8]* @mntpoint.mntpt, i64 0, i64 0), i8** %2
br label %26
21: ; preds = %13
br label %9
22: ; preds = %9
%23 = load i32*, i32** %4
%24 = call i32 @fclose(i32* %23)
br label %25
25: ; preds = %22, %1
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8** %2
br label %26
26: ; preds = %25, %18
%27 = load i8*, i8** %2
ret i8* %27
}

LLVM IR (-O2):
@mntpoint.tmp = internal global [256 x i8] zeroinitializer
@mntpoint.dev = internal global [20 x i8] zeroinitializer
@mntpoint.mntpt = internal global [20 x i8] zeroinitializer
@mntpoint.fstype = internal global [20 x i8] zeroinitializer
@mntpoint.rwflag = internal global [20 x i8] zeroinitializer
@.str = [10 x i8] c"/etc/mtab\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [13 x i8] c"%s %s %s %s\0A\00"
@.str.3 = [4 x i8] c"???\00"
define i8* @mntpoint(i8* %0) {
%2 = tail call i32* @fopen(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 %14, label %4
4: ; preds = %1, %7
%5 = tail call i64 @fgets(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @mntpoint.tmp, i64 0, i64 0), i32 256, i32* %2)
%6 = icmp eq i64 %5, 0
br i1 %6, label %11, label %7
7: ; preds = %4
%8 = tail call i32 @sscanf(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @mntpoint.tmp, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([20 x i8], [20 x i8]* @mntpoint.dev, i64 0, i64 0), i8* getelementptr inbounds ([20 x i8], [20 x i8]* @mntpoint.mntpt, i64 0, i64 0), i8* getelementptr inbounds ([20 x i8], [20 x i8]* @mntpoint.fstype, i64 0, i64 0), i8* getelementptr inbounds ([20 x i8], [20 x i8]* @mntpoint.rwflag, i64 0, i64 0))
%9 = tail call i64 @strcmp(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @mntpoint.dev, i64 0, i64 0), i8* %0)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %4
11: ; preds = %4, %7
%12 = phi i8* [ getelementptr inbounds ([20 x i8], [20 x i8]* @mntpoint.mntpt, i64 0, i64 0), %7 ], [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), %4 ]
%13 = tail call i32 @fclose(i32* %2)
br label %14
14: ; preds = %11, %1
%15 = phi i8* [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), %1 ], [ %12, %11 ]
ret i8* %15
}