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

/* Variables and functions */
int /*<<< orphan*/ ENOBUFS;
void *atoi(char *);
int /*<<< orphan*/ errno;
scalar_t__ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
int getline(char **, size_t *, int /*<<< orphan*/ *);
void *strcpy(char *, char *);
int strlen(char *);
char *strtok(char *, char *);
struct mntent *getmntent_r(FILE *fp, struct mntent *result, char *buffer,
                           int bufsize) {
  char *token, *buff_ptr;
  char *line = NULL;
  size_t size = 0;
  int i;
  buff_ptr = buffer;
  if (getline(&line, &size, fp) == -1 || feof(fp)) {
    free(line);
    return NULL;
  }
  for (token = strtok(line, " "), i = 0; token != NULL;
       token = strtok(NULL, " "), ++i) {
    if (((buff_ptr + strlen(token) + 1) - buffer) > bufsize) {
      errno = ENOBUFS;
      free(line);
      return NULL;
    }
    switch (i) {
    case 0:
      result->mnt_fsname = strcpy(buff_ptr, token);
      break;
    case 1:
      result->mnt_dir = strcpy(buff_ptr, token);
      break;
    case 2:
      result->mnt_type = strcpy(buff_ptr, token);
      break;
    case 3:
      result->mnt_opts = strcpy(buff_ptr, token);
      break;
    case 4:
      result->mnt_freq = atoi(token);
      break;
    case 5:
      result->mnt_passno = atoi(token);
      break;
    default:
      free(line);
      return NULL;
    }
    buff_ptr += strlen(token) + 1;
  }
  free(line);
  return result;
}


x86 assembly (clang, -O0):
<getmntent_r>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
movq   $0x0,-0x40(%rbp)
movq   $0x0,-0x48(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdx
lea    -0x40(%rbp),%rdi
lea    -0x48(%rbp),%rsi
call   1090 <getline@plt>
cmp    $0xffffffff,%eax
je     11cc <getmntent_r+0x5c>
mov    -0x10(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%rax
je     11e2 <getmntent_r+0x72>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    1394 <getmntent_r+0x224>
mov    -0x40(%rbp),%rdi
lea    0xe2b(%rip),%rsi
call   1070 <strtok@plt>
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x4c(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     1383 <getmntent_r+0x213>
mov    -0x38(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x30(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x58(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
add    $0x1,%rax
mov    -0x20(%rbp),%rcx
sub    %rcx,%rax
movslq -0x24(%rbp),%rcx
cmp    %rcx,%rax
jle    1265 <getmntent_r+0xf5>
mov    0x2db4(%rip),%rax
mov    (%rax),%ecx
mov    0x2d8b(%rip),%rax
mov    %ecx,(%rax)
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    1394 <getmntent_r+0x224>
mov    -0x4c(%rbp),%eax
mov    %rax,-0x60(%rbp)
sub    $0x5,%rax
ja     132f <getmntent_r+0x1bf>
mov    -0x60(%rbp),%rax
lea    0xd7f(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1040 <strcpy@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,0x28(%rax)
jmp    1345 <getmntent_r+0x1d5>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1040 <strcpy@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,0x20(%rax)
jmp    1345 <getmntent_r+0x1d5>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1040 <strcpy@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,0x18(%rax)
jmp    1345 <getmntent_r+0x1d5>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1040 <strcpy@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,0x10(%rax)
jmp    1345 <getmntent_r+0x1d5>
mov    -0x30(%rbp),%rdi
call   1080 <atoi@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,0x8(%rax)
jmp    1345 <getmntent_r+0x1d5>
mov    -0x30(%rbp),%rdi
call   1080 <atoi@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
jmp    1345 <getmntent_r+0x1d5>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    1394 <getmntent_r+0x224>
mov    -0x30(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
add    $0x1,%ecx
mov    -0x38(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x38(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xcac(%rip),%rsi
call   1070 <strtok@plt>
mov    %rax,-0x30(%rbp)
mov    -0x4c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4c(%rbp)
jmp    11fd <getmntent_r+0x8d>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getmntent_r>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %ecx,%ebp
mov    %rdx,%r14
mov    %rsi,%r12
mov    %rdi,%rbx
movq   $0x0,0x8(%rsp)
movq   $0x0,0x10(%rsp)
lea    0x8(%rsp),%rdi
lea    0x10(%rsp),%rsi
mov    %rbx,%rdx
call   1090 <getline@plt>
cmp    $0xffffffff,%eax
je     11bf <getmntent_r+0x4f>
mov    %rbx,%rdi
call   1060 <feof@plt>
test   %rax,%rax
je     11de <getmntent_r+0x6e>
xor    %r12d,%r12d
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
mov    %r12,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x8(%rsp),%rdi
lea    0xe2e(%rip),%rsi
call   1070 <strtok@plt>
test   %rax,%rax
je     11c2 <getmntent_r+0x52>
mov    %rax,%r13
movslq %ebp,%rbp
xor    %r15d,%r15d
mov    %r14,%rbx
jmp    123b <getmntent_r+0xcb>
mov    %r13,%rdi
call   1080 <atoi@plt>
mov    %rax,(%r12)
xchg   %ax,%ax
mov    %r13,%rdi
call   1050 <strlen@plt>
cltq
add    %rax,%rbx
add    $0x1,%rbx
xor    %edi,%edi
lea    0xdee(%rip),%rsi
call   1070 <strtok@plt>
mov    %rax,%r13
add    $0x1,%r15d
test   %rax,%rax
je     11c2 <getmntent_r+0x52>
mov    %r13,%rdi
call   1050 <strlen@plt>
cltq
add    %rbx,%rax
sub    %r14,%rax
add    $0x1,%rax
cmp    %rbp,%rax
jg     12d8 <getmntent_r+0x168>
cmp    $0x5,%r15d
ja     11bf <getmntent_r+0x4f>
mov    %r15d,%eax
lea    0xd94(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    %rbx,%rdi
mov    %r13,%rsi
call   1040 <strcpy@plt>
mov    %rbx,0x28(%r12)
jmp    1210 <getmntent_r+0xa0>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1040 <strcpy@plt>
mov    %rbx,0x20(%r12)
jmp    1210 <getmntent_r+0xa0>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1040 <strcpy@plt>
mov    %rbx,0x18(%r12)
jmp    1210 <getmntent_r+0xa0>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1040 <strcpy@plt>
mov    %rbx,0x10(%r12)
jmp    1210 <getmntent_r+0xa0>
mov    %r13,%rdi
call   1080 <atoi@plt>
mov    %rax,0x8(%r12)
jmp    1210 <getmntent_r+0xa0>
mov    0x2d19(%rip),%rax
mov    (%rax),%eax
mov    0x2cf0(%rip),%rcx
mov    %eax,(%rcx)
jmp    11bf <getmntent_r+0x4f>

LLVM IR (-O0):
%struct.mntent = type { i8*, i8*, i8*, i8*, i8*, i8* }
@.str = [2 x i8] c" \00"
@ENOBUFS = global i32 0
@errno = global i32 0
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*
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i64
%14 = alloca i32
store i32* %0, i32** %6
store %struct.mntent* %1, %struct.mntent** %7
store i8* %2, i8** %8
store i32 %3, i32* %9
store i8* null, i8** %12
store i64 0, i64* %13
%15 = load i8*, i8** %8
store i8* %15, i8** %11
%16 = load i32*, i32** %6
%17 = call i32 @getline(i8** %12, i64* %13, i32* %16)
%18 = icmp eq i32 %17, -1
br i1 %18, label %23, label %19
19: ; preds = %4
%20 = load i32*, i32** %6
%21 = call i64 @feof(i32* %20)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %19, %4
%24 = load i8*, i8** %12
%25 = call i32 @free(i8* %24)
store %struct.mntent* null, %struct.mntent** %5
br label %104
26: ; preds = %19
%27 = load i8*, i8** %12
%28 = call i8* @strtok(i8* %27, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %28, i8** %10
store i32 0, i32* %14
br label %29
29: ; preds = %96, %26
%30 = load i8*, i8** %10
%31 = icmp ne i8* %30, null
br i1 %31, label %32, label %100
32: ; preds = %29
%33 = load i8*, i8** %11
%34 = load i8*, i8** %10
%35 = call i32 @strlen(i8* %34)
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %33, i64 %36
%38 = getelementptr inbounds i8, i8* %37, i64 1
%39 = load i8*, i8** %8
%40 = ptrtoint i8* %38 to i64
%41 = ptrtoint i8* %39 to i64
%42 = sub i64 %40, %41
%43 = load i32, i32* %9
%44 = sext i32 %43 to i64
%45 = icmp sgt i64 %42, %44
br i1 %45, label %46, label %50
46: ; preds = %32
%47 = load i32, i32* @ENOBUFS
store i32 %47, i32* @errno
%48 = load i8*, i8** %12
%49 = call i32 @free(i8* %48)
store %struct.mntent* null, %struct.mntent** %5
br label %104
50: ; preds = %32
%51 = load i32, i32* %14
switch i32 %51, label %86 [
i32 0, label %52
i32 1, label %58
i32 2, label %64
i32 3, label %70
i32 4, label %76
i32 5, label %81
]
52: ; preds = %50
%53 = load i8*, i8** %11
%54 = load i8*, i8** %10
%55 = call i8* @strcpy(i8* %53, i8* %54)
%56 = load %struct.mntent*, %struct.mntent** %7
%57 = getelementptr inbounds %struct.mntent, %struct.mntent* %56, i32 0, i32 5
store i8* %55, i8** %57
br label %89
58: ; preds = %50
%59 = load i8*, i8** %11
%60 = load i8*, i8** %10
%61 = call i8* @strcpy(i8* %59, i8* %60)
%62 = load %struct.mntent*, %struct.mntent** %7
%63 = getelementptr inbounds %struct.mntent, %struct.mntent* %62, i32 0, i32 4
store i8* %61, i8** %63
br label %89
64: ; preds = %50
%65 = load i8*, i8** %11
%66 = load i8*, i8** %10
%67 = call i8* @strcpy(i8* %65, i8* %66)
%68 = load %struct.mntent*, %struct.mntent** %7
%69 = getelementptr inbounds %struct.mntent, %struct.mntent* %68, i32 0, i32 3
store i8* %67, i8** %69
br label %89
70: ; preds = %50
%71 = load i8*, i8** %11
%72 = load i8*, i8** %10
%73 = call i8* @strcpy(i8* %71, i8* %72)
%74 = load %struct.mntent*, %struct.mntent** %7
%75 = getelementptr inbounds %struct.mntent, %struct.mntent* %74, i32 0, i32 2
store i8* %73, i8** %75
br label %89
76: ; preds = %50
%77 = load i8*, i8** %10
%78 = call i8* @atoi(i8* %77)
%79 = load %struct.mntent*, %struct.mntent** %7
%80 = getelementptr inbounds %struct.mntent, %struct.mntent* %79, i32 0, i32 1
store i8* %78, i8** %80
br label %89
81: ; preds = %50
%82 = load i8*, i8** %10
%83 = call i8* @atoi(i8* %82)
%84 = load %struct.mntent*, %struct.mntent** %7
%85 = getelementptr inbounds %struct.mntent, %struct.mntent* %84, i32 0, i32 0
store i8* %83, i8** %85
br label %89
86: ; preds = %50
%87 = load i8*, i8** %12
%88 = call i32 @free(i8* %87)
store %struct.mntent* null, %struct.mntent** %5
br label %104
89: ; preds = %81, %76, %70, %64, %58, %52
%90 = load i8*, i8** %10
%91 = call i32 @strlen(i8* %90)
%92 = add nsw i32 %91, 1
%93 = load i8*, i8** %11
%94 = sext i32 %92 to i64
%95 = getelementptr inbounds i8, i8* %93, i64 %94
store i8* %95, i8** %11
br label %96
96: ; preds = %89
%97 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %97, i8** %10
%98 = load i32, i32* %14
%99 = add nsw i32 %98, 1
store i32 %99, i32* %14
br label %29
100: ; preds = %29
%101 = load i8*, i8** %12
%102 = call i32 @free(i8* %101)
%103 = load %struct.mntent*, %struct.mntent** %7
store %struct.mntent* %103, %struct.mntent** %5
br label %104
104: ; preds = %100, %86, %46, %23
%105 = load %struct.mntent*, %struct.mntent** %5
ret %struct.mntent* %105
}

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