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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ strcmp(char *, char const *);
char const *strdup(char *);
char *strtok(char *, char *);
const char *mntpoint(const char *devname) {
  FILE *f;
  char tmp[160];
  char *dev;
  char *mntpt;
  f = fopen("/etc/mtab", "r");
  if (f) {
    while (fgets(tmp, sizeof(tmp), f)) {
      dev = strtok(tmp, " ");
      mntpt = strtok(NULL, " ");
      if (strcmp(dev, devname) == 0) {
        fclose(f);
        return strdup(mntpt);
      }
    }
    fclose(f);
  }
  return "???";
}


x86 assembly (clang, -O0):
<mntpoint>:
push   %rbp
mov    %rsp,%rbp
sub    $0xd0,%rsp
mov    %rdi,-0x10(%rbp)
lea    0xe8a(%rip),%rdi
lea    0xe8d(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     122c <mntpoint+0xcc>
jmp    1196 <mntpoint+0x36>
lea    -0xc0(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0xa0,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
je     1223 <mntpoint+0xc3>
lea    -0xc0(%rbp),%rdi
lea    0xe49(%rip),%rsi
call   1070 <strtok@plt>
mov    %rax,-0xc8(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xe32(%rip),%rsi
call   1070 <strtok@plt>
mov    %rax,-0xd0(%rbp)
mov    -0xc8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    121e <mntpoint+0xbe>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0xd0(%rbp),%rdi
call   1080 <strdup@plt>
mov    %rax,-0x8(%rbp)
jmp    1237 <mntpoint+0xd7>
jmp    1196 <mntpoint+0x36>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
lea    0xddb(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0xd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mntpoint>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xa8,%rsp
mov    %rdi,%r15
lea    0xe85(%rip),%rdi
lea    0xe88(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
lea    0xe7d(%rip),%rax
test   %rbx,%rbx
je     1201 <mntpoint+0xa1>
mov    %rsp,%r12
lea    0xe6c(%rip),%r13
mov    %r12,%rdi
mov    $0xa0,%esi
mov    %rbx,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     11f2 <mntpoint+0x92>
mov    %r12,%rdi
mov    %r13,%rsi
call   1070 <strtok@plt>
mov    %rax,%r14
xor    %edi,%edi
mov    %r13,%rsi
call   1070 <strtok@plt>
mov    %rax,%rbp
mov    %r14,%rdi
mov    %r15,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
jne    11a0 <mntpoint+0x40>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %rbp,%rdi
call   1080 <strdup@plt>
jmp    1201 <mntpoint+0xa1>
mov    %rbx,%rdi
call   1030 <fclose@plt>
lea    0xe0d(%rip),%rax
add    $0xa8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"/etc/mtab\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [2 x i8] c" \00"
@.str.3 = [4 x i8] c"???\00"
define i8* @mntpoint(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca [160 x i8]
%6 = alloca i8*
%7 = alloca i8*
store i8* %0, i8** %3
%8 = 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* %8, i32** %4
%9 = load i32*, i32** %4
%10 = icmp ne i32* %9, null
br i1 %10, label %11, label %34
11: ; preds = %1
br label %12
12: ; preds = %30, %11
%13 = getelementptr inbounds [160 x i8], [160 x i8]* %5, i64 0, i64 0
%14 = load i32*, i32** %4
%15 = call i64 @fgets(i8* %13, i32 160, i32* %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %31
17: ; preds = %12
%18 = getelementptr inbounds [160 x i8], [160 x i8]* %5, i64 0, i64 0
%19 = call i8* @strtok(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i8* %19, i8** %6
%20 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i8* %20, i8** %7
%21 = load i8*, i8** %6
%22 = load i8*, i8** %3
%23 = call i64 @strcmp(i8* %21, i8* %22)
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %30
25: ; preds = %17
%26 = load i32*, i32** %4
%27 = call i32 @fclose(i32* %26)
%28 = load i8*, i8** %7
%29 = call i8* @strdup(i8* %28)
store i8* %29, i8** %2
br label %35
30: ; preds = %17
br label %12
31: ; preds = %12
%32 = load i32*, i32** %4
%33 = call i32 @fclose(i32* %32)
br label %34
34: ; preds = %31, %1
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8** %2
br label %35
35: ; preds = %34, %25
%36 = load i8*, i8** %2
ret i8* %36
}

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