#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*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
char *readmtab(int /*<<< orphan*/ *);
scalar_t__ strcmp(char const *, char *);
char *strdup(char const *);
char *strtok(int /*<<< orphan*/ *, char *);
char *getdev(char *arg) {
  FILE *f;
  const char *dev;
  char *mntpt;
  f = fopen("/etc/mtab", "r");
  if (f) {
    while ((dev = readmtab(f)) != NULL) {
      mntpt = strtok(NULL, " \t");
      if ((strcmp(dev, arg) == 0) || (strcmp(mntpt, arg) == 0)) {
        fclose(f);
        return strdup(dev);
      }
    }
    fclose(f);
  }
  return NULL;
}


x86 assembly (clang, -O0):
<getdev>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
lea    0xe8d(%rip),%rdi
lea    0xe90(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1215 <getdev+0xb5>
jmp    1193 <getdev+0x33>
mov    -0x18(%rbp),%rdi
call   1050 <readmtab@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     120c <getdev+0xac>
xor    %eax,%eax
mov    %eax,%edi
lea    0xe57(%rip),%rsi
call   1070 <strtok@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
je     11ec <getdev+0x8c>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    1207 <getdev+0xa7>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1080 <strdup@plt>
mov    %rax,-0x8(%rbp)
jmp    121d <getdev+0xbd>
jmp    1193 <getdev+0x33>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getdev>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdi,%r12
lea    0xe8d(%rip),%rdi
lea    0xe90(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11ee <getdev+0x8e>
mov    %rax,%r14
lea    0xe7e(%rip),%r15
xchg   %ax,%ax
mov    %r14,%rdi
call   1050 <readmtab@plt>
test   %rax,%rax
je     11e6 <getdev+0x86>
mov    %rax,%r13
xor    %edi,%edi
mov    %r15,%rsi
call   1070 <strtok@plt>
mov    %rax,%rbx
mov    %r13,%rdi
mov    %r12,%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
je     11cd <getdev+0x6d>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
jne    1190 <getdev+0x30>
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    %r13,%rdi
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1080 <strdup@plt>
mov    %r14,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

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