#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 *);
char *strdup(char *);
char *strtok(char *, char *);
char *getdev(char *arg) {
  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, 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    $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     1246 <getdev+0xe6>
jmp    1196 <getdev+0x36>
lea    -0xc0(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0xa0,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
je     123d <getdev+0xdd>
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
je     121a <getdev+0xba>
mov    -0xd0(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    1238 <getdev+0xd8>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0xc8(%rbp),%rdi
call   1080 <strdup@plt>
mov    %rax,-0x8(%rbp)
jmp    124e <getdev+0xee>
jmp    1196 <getdev+0x36>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0xd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getdev>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xa8,%rsp
mov    %rdi,%r13
lea    0xe85(%rip),%rdi
lea    0xe88(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     120a <getdev+0xaa>
mov    %rax,%r14
mov    %rsp,%r15
lea    0xe73(%rip),%r12
nopl   0x0(%rax)
mov    %r15,%rdi
mov    $0xa0,%esi
mov    %r14,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     1202 <getdev+0xa2>
mov    %r15,%rdi
mov    %r12,%rsi
call   1070 <strtok@plt>
mov    %rax,%rbx
xor    %edi,%edi
mov    %r12,%rsi
call   1070 <strtok@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
mov    %r13,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     11f0 <getdev+0x90>
mov    %rbp,%rdi
mov    %r13,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
jne    11a0 <getdev+0x40>
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    %rbx,%rdi
call   1080 <strdup@plt>
jmp    120c <getdev+0xac>
mov    %r14,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
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"
define i8* @getdev(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 %39
11: ; preds = %1
br label %12
12: ; preds = %35, %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 %36
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 %30, label %25
25: ; preds = %17
%26 = load i8*, i8** %7
%27 = load i8*, i8** %3
%28 = call i64 @strcmp(i8* %26, i8* %27)
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %35
30: ; preds = %25, %17
%31 = load i32*, i32** %4
%32 = call i32 @fclose(i32* %31)
%33 = load i8*, i8** %6
%34 = call i8* @strdup(i8* %33)
store i8* %34, i8** %2
br label %40
35: ; preds = %25
br label %12
36: ; preds = %12
%37 = load i32*, i32** %4
%38 = call i32 @fclose(i32* %37)
br label %39
39: ; preds = %36, %1
store i8* null, i8** %2
br label %40
40: ; preds = %39, %30
%41 = load i8*, i8** %2
ret i8* %41
}

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"
define noalias i8* @getdev(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 %22, label %6
6: ; preds = %1, %14
%7 = call i64 @fgets(i8* %3, i32 160, i32* %4)
%8 = icmp eq i64 %7, 0
br i1 %8, label %20, 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 %17, label %14
14: ; preds = %9
%15 = call i64 @strcmp(i8* %11, i8* %0)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %6
17: ; preds = %14, %9
%18 = call i32 @fclose(i32* %4)
%19 = call i8* @strdup(i8* %10)
br label %22
20: ; preds = %6
%21 = call i32 @fclose(i32* %4)
br label %22
22: ; preds = %1, %20, %17
%23 = phi i8* [ %19, %17 ], [ null, %20 ], [ null, %1 ]
ret i8* %23
}