#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 *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*/ printf(char *, char const *);
int /*<<< orphan*/ *setmntent(char *, char *);
scalar_t__ strcmp(char *, int /*<<< orphan*/);
int main() {
  FILE *fstab = setmntent("/etc/mtab", "r");
  struct mntent *f;
  const char *devname = NULL;
  while (f = getmntent(fstab))
    if (strcmp("/", f->mnt_dir) == 0) {
      devname = f->mnt_fsname;
      break;
    }
  printf("/ device name: %s\n", devname);
  endmntent(fstab);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rdi
lea    0xe9d(%rip),%rsi
call   1070 <setmntent@plt>
mov    %rax,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <getmntent@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     11c7 <main+0x77>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%esi
lea    0xe69(%rip),%rdi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    11c2 <main+0x72>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
jmp    11c7 <main+0x77>
jmp    117e <main+0x2e>
mov    -0x20(%rbp),%rsi
lea    0xe3c(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <endmntent@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
lea    0xea1(%rip),%rdi
lea    0xea4(%rip),%rsi
call   1070 <setmntent@plt>
mov    %rax,%r12
xor    %r14d,%r14d
lea    0xe94(%rip),%r15
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
call   1060 <getmntent@plt>
test   %rax,%rax
je     11a3 <main+0x53>
mov    %rax,%rbx
mov    0x8(%rax),%esi
mov    %r15,%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
jne    1180 <main+0x30>
mov    (%rbx),%r14
lea    0xe64(%rip),%rdi
mov    %r14,%rsi
call   1040 <printf@plt>
mov    %r12,%rdi
call   1030 <endmntent@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.mntent = type { i8*, i32 }
@.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 = [19 x i8] c"/ device name: %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca %struct.mntent*
%4 = alloca i8*
store i32 0, i32* %1
%5 = call i32* @setmntent(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** %2
store i8* null, i8** %4
br label %6
6: ; preds = %20, %0
%7 = load i32*, i32** %2
%8 = call %struct.mntent* @getmntent(i32* %7)
store %struct.mntent* %8, %struct.mntent** %3
%9 = icmp ne %struct.mntent* %8, null
br i1 %9, label %10, label %21
10: ; preds = %6
%11 = load %struct.mntent*, %struct.mntent** %3
%12 = getelementptr inbounds %struct.mntent, %struct.mntent* %11, i32 0, i32 1
%13 = load i32, i32* %12
%14 = call i64 @strcmp(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 %13)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %10
%17 = load %struct.mntent*, %struct.mntent** %3
%18 = getelementptr inbounds %struct.mntent, %struct.mntent* %17, i32 0, i32 0
%19 = load i8*, i8** %18
store i8* %19, i8** %4
br label %21
20: ; preds = %10
br label %6
21: ; preds = %16, %6
%22 = load i8*, i8** %4
%23 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %22)
%24 = load i32*, i32** %2
%25 = call i32 @endmntent(i32* %24)
ret i32 0
}

LLVM IR (-O2):
%struct.mntent = type { i8*, i32 }
@.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 = [19 x i8] c"/ device name: %s\0A\00"
define i32 @main() {
%1 = tail call i32* @setmntent(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))
br label %2
2: ; preds = %5, %0
%3 = tail call %struct.mntent* @getmntent(i32* %1)
%4 = icmp eq %struct.mntent* %3, null
br i1 %4, label %13, label %5
5: ; preds = %2
%6 = getelementptr inbounds %struct.mntent, %struct.mntent* %3, i64 0, i32 1
%7 = load i32, i32* %6
%8 = tail call i64 @strcmp(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 %7)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %2
10: ; preds = %5
%11 = getelementptr inbounds %struct.mntent, %struct.mntent* %3, i64 0, i32 0
%12 = load i8*, i8** %11
br label %13
13: ; preds = %2, %10
%14 = phi i8* [ %12, %10 ], [ null, %2 ]
%15 = tail call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %14)
%16 = tail call i32 @endmntent(i32* %1)
ret i32 0
}