#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 {
  int /*<<< orphan*/ *mnt_dir;
  int /*<<< orphan*/ *mnt_fsname;
  void *mnt_passno;
  void *mnt_freq;
  int /*<<< orphan*/ *mnt_opts;
  int /*<<< orphan*/ *mnt_type;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
void *mntparse(char *, int /*<<< orphan*/ **, char *);
struct mntent *getmntent_r(FILE *fp, struct mntent *me, char *buf, int len) {
  char *p = buf;
  do {
    if (fgets(buf, len, fp) == NULL)
      return NULL;
  } while (*p == '\n' || *p == '#');
  mntparse(buf, &me->mnt_fsname, NULL);
  mntparse(NULL, &me->mnt_dir, NULL);
  mntparse(NULL, &me->mnt_type, "fuzix");
  mntparse(NULL, &me->mnt_opts, "");
  me->mnt_freq = mntparse(NULL, NULL, "0");
  me->mnt_passno = mntparse(NULL, NULL, "0");
  if (me->mnt_fsname == NULL || me->mnt_dir == NULL)
    return NULL;
  return me;
}


x86 assembly (clang, -O0):
<getmntent_r>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    -0x10(%rbp),%rdx
call   1040 <fgets@plt>
cmp    $0x0,%rax
jne    1166 <getmntent_r+0x46>
movq   $0x0,-0x8(%rbp)
jmp    125e <getmntent_r+0x13e>
jmp    116b <getmntent_r+0x4b>
mov    -0x30(%rbp),%rax
movsbl (%rax),%ecx
mov    $0x1,%al
cmp    $0xa,%ecx
mov    %al,-0x31(%rbp)
je     1190 <getmntent_r+0x70>
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x23,%eax
sete   %al
mov    %al,-0x31(%rbp)
mov    -0x31(%rbp),%al
test   $0x1,%al
jne    113f <getmntent_r+0x1f>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
add    $0x8,%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <mntparse@plt>
mov    -0x18(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
mov    %rdx,%rdi
call   1030 <mntparse@plt>
mov    -0x18(%rbp),%rsi
add    $0x28,%rsi
xor    %eax,%eax
mov    %eax,%edi
lea    0xe2d(%rip),%rdx
call   1030 <mntparse@plt>
mov    -0x18(%rbp),%rsi
add    $0x20,%rsi
xor    %eax,%eax
mov    %eax,%edi
lea    0xe1c(%rip),%rdx
call   1030 <mntparse@plt>
xor    %eax,%eax
mov    %eax,%esi
lea    0xe0b(%rip),%rdx
mov    %rsi,%rdi
call   1030 <mntparse@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,0x18(%rax)
xor    %eax,%eax
mov    %eax,%esi
lea    0xded(%rip),%rdx
mov    %rsi,%rdi
call   1030 <mntparse@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,0x10(%rax)
mov    -0x18(%rbp),%rax
cmpq   $0x0,0x8(%rax)
je     1249 <getmntent_r+0x129>
mov    -0x18(%rbp),%rax
cmpq   $0x0,(%rax)
jne    1256 <getmntent_r+0x136>
movq   $0x0,-0x8(%rbp)
jmp    125e <getmntent_r+0x13e>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getmntent_r>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %ecx,%r12d
mov    %rdx,%rbx
mov    %rsi,%r15
mov    %rdi,%rbp
mov    %rdx,%rdi
mov    %ecx,%esi
mov    %rbp,%rdx
call   1040 <fgets@plt>
xor    %r14d,%r14d
jmp    115e <getmntent_r+0x3e>
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r12d,%esi
mov    %rbp,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     11ee <getmntent_r+0xce>
movzbl (%rbx),%eax
cmp    $0x23,%al
je     1150 <getmntent_r+0x30>
cmp    $0xa,%al
je     1150 <getmntent_r+0x30>
lea    0x8(%r15),%rsi
xor    %r14d,%r14d
mov    %rbx,%rdi
xor    %edx,%edx
call   1030 <mntparse@plt>
xor    %edi,%edi
mov    %r15,%rsi
xor    %edx,%edx
call   1030 <mntparse@plt>
lea    0x28(%r15),%rsi
lea    0xe66(%rip),%rdx
xor    %edi,%edi
call   1030 <mntparse@plt>
lea    0x20(%r15),%rsi
lea    0xe5b(%rip),%rdx
xor    %edi,%edi
call   1030 <mntparse@plt>
lea    0xe4c(%rip),%rbx
xor    %edi,%edi
xor    %esi,%esi
mov    %rbx,%rdx
call   1030 <mntparse@plt>
mov    %rax,0x18(%r15)
xor    %edi,%edi
xor    %esi,%esi
mov    %rbx,%rdx
call   1030 <mntparse@plt>
mov    %rax,0x10(%r15)
cmpq   $0x0,0x8(%r15)
je     11ee <getmntent_r+0xce>
mov    (%r15),%rax
test   %rax,%rax
cmove  %rax,%r15
mov    %r15,%r14
mov    %r14,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.mntent = type { i32*, i32*, i8*, i8*, i32*, i32* }
@.str = [6 x i8] c"fuzix\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [2 x i8] c"0\00"
define %struct.mntent* @getmntent_r(i32* %0, %struct.mntent* %1, i8* %2, i32 %3) {
%5 = alloca %struct.mntent*
%6 = alloca i32*
%7 = alloca %struct.mntent*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i8*
store i32* %0, i32** %6
store %struct.mntent* %1, %struct.mntent** %7
store i8* %2, i8** %8
store i32 %3, i32* %9
%11 = load i8*, i8** %8
store i8* %11, i8** %10
br label %12
12: ; preds = %30, %4
%13 = load i8*, i8** %8
%14 = load i32, i32* %9
%15 = load i32*, i32** %6
%16 = call i32* @fgets(i8* %13, i32 %14, i32* %15)
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %19
18: ; preds = %12
store %struct.mntent* null, %struct.mntent** %5
br label %64
19: ; preds = %12
br label %20
20: ; preds = %19
%21 = load i8*, i8** %10
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp eq i32 %23, 10
br i1 %24, label %30, label %25
25: ; preds = %20
%26 = load i8*, i8** %10
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp eq i32 %28, 35
br label %30
30: ; preds = %25, %20
%31 = phi i1 [ true, %20 ], [ %29, %25 ]
br i1 %31, label %12, label %32
32: ; preds = %30
%33 = load i8*, i8** %8
%34 = load %struct.mntent*, %struct.mntent** %7
%35 = getelementptr inbounds %struct.mntent, %struct.mntent* %34, i32 0, i32 1
%36 = call i8* @mntparse(i8* %33, i32** %35, i8* null)
%37 = load %struct.mntent*, %struct.mntent** %7
%38 = getelementptr inbounds %struct.mntent, %struct.mntent* %37, i32 0, i32 0
%39 = call i8* @mntparse(i8* null, i32** %38, i8* null)
%40 = load %struct.mntent*, %struct.mntent** %7
%41 = getelementptr inbounds %struct.mntent, %struct.mntent* %40, i32 0, i32 5
%42 = call i8* @mntparse(i8* null, i32** %41, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%43 = load %struct.mntent*, %struct.mntent** %7
%44 = getelementptr inbounds %struct.mntent, %struct.mntent* %43, i32 0, i32 4
%45 = call i8* @mntparse(i8* null, i32** %44, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
%46 = call i8* @mntparse(i8* null, i32** null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%47 = load %struct.mntent*, %struct.mntent** %7
%48 = getelementptr inbounds %struct.mntent, %struct.mntent* %47, i32 0, i32 3
store i8* %46, i8** %48
%49 = call i8* @mntparse(i8* null, i32** null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%50 = load %struct.mntent*, %struct.mntent** %7
%51 = getelementptr inbounds %struct.mntent, %struct.mntent* %50, i32 0, i32 2
store i8* %49, i8** %51
%52 = load %struct.mntent*, %struct.mntent** %7
%53 = getelementptr inbounds %struct.mntent, %struct.mntent* %52, i32 0, i32 1
%54 = load i32*, i32** %53
%55 = icmp eq i32* %54, null
br i1 %55, label %61, label %56
56: ; preds = %32
%57 = load %struct.mntent*, %struct.mntent** %7
%58 = getelementptr inbounds %struct.mntent, %struct.mntent* %57, i32 0, i32 0
%59 = load i32*, i32** %58
%60 = icmp eq i32* %59, null
br i1 %60, label %61, label %62
61: ; preds = %56, %32
store %struct.mntent* null, %struct.mntent** %5
br label %64
62: ; preds = %56
%63 = load %struct.mntent*, %struct.mntent** %7
store %struct.mntent* %63, %struct.mntent** %5
br label %64
64: ; preds = %62, %61, %18
%65 = load %struct.mntent*, %struct.mntent** %5
ret %struct.mntent* %65
}

LLVM IR (-O2):
%struct.mntent = type { i32*, i32*, i8*, i8*, i32*, i32* }
@.str = [6 x i8] c"fuzix\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [2 x i8] c"0\00"
define %struct.mntent* @getmntent_r(i32* nocapture %0, %struct.mntent* %1, i8* %2, i32 %3) {
%5 = tail call i32* @fgets(i8* %2, i32 %3, i32* %0)
%6 = icmp eq i32* %5, null
br i1 %6, label %31, label %7
7: ; preds = %4, %9
%8 = load i8, i8* %2
switch i8 %8, label %12 [
i8 10, label %9
i8 35, label %9
]
9: ; preds = %7, %7
%10 = tail call i32* @fgets(i8* %2, i32 %3, i32* %0)
%11 = icmp eq i32* %10, null
br i1 %11, label %31, label %7
12: ; preds = %7
%13 = getelementptr inbounds %struct.mntent, %struct.mntent* %1, i64 0, i32 1
%14 = tail call i8* @mntparse(i8* %2, i32** %13, i8* null)
%15 = getelementptr inbounds %struct.mntent, %struct.mntent* %1, i64 0, i32 0
%16 = tail call i8* @mntparse(i8* null, i32** %15, i8* null)
%17 = getelementptr inbounds %struct.mntent, %struct.mntent* %1, i64 0, i32 5
%18 = tail call i8* @mntparse(i8* null, i32** %17, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%19 = getelementptr inbounds %struct.mntent, %struct.mntent* %1, i64 0, i32 4
%20 = tail call i8* @mntparse(i8* null, i32** %19, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
%21 = tail call i8* @mntparse(i8* null, i32** null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%22 = getelementptr inbounds %struct.mntent, %struct.mntent* %1, i64 0, i32 3
store i8* %21, i8** %22
%23 = tail call i8* @mntparse(i8* null, i32** null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%24 = getelementptr inbounds %struct.mntent, %struct.mntent* %1, i64 0, i32 2
store i8* %23, i8** %24
%25 = load i32*, i32** %13
%26 = icmp eq i32* %25, null
br i1 %26, label %31, label %27
27: ; preds = %12
%28 = load i32*, i32** %15
%29 = icmp eq i32* %28, null
%30 = select i1 %29, %struct.mntent* null, %struct.mntent* %1
br label %31
31: ; preds = %9, %4, %27, %12
%32 = phi %struct.mntent* [ null, %12 ], [ %30, %27 ], [ null, %4 ], [ null, %9 ]
ret %struct.mntent* %32
}