#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;
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) {
    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   1080 <getline@plt>
cmp    $0xffffffff,%eax
jne    11bf <getmntent_r+0x5f>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    1371 <getmntent_r+0x211>
mov    -0x40(%rbp),%rdi
lea    0xe4e(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x4c(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     1360 <getmntent_r+0x200>
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    1242 <getmntent_r+0xe2>
mov    0x2dd7(%rip),%rax
mov    (%rax),%ecx
mov    0x2dae(%rip),%rax
mov    %ecx,(%rax)
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    1371 <getmntent_r+0x211>
mov    -0x4c(%rbp),%eax
mov    %rax,-0x60(%rbp)
sub    $0x5,%rax
ja     130c <getmntent_r+0x1ac>
mov    -0x60(%rbp),%rax
lea    0xda2(%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    1322 <getmntent_r+0x1c2>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1040 <strcpy@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,0x20(%rax)
jmp    1322 <getmntent_r+0x1c2>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1040 <strcpy@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,0x18(%rax)
jmp    1322 <getmntent_r+0x1c2>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1040 <strcpy@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,0x10(%rax)
jmp    1322 <getmntent_r+0x1c2>
mov    -0x30(%rbp),%rdi
call   1070 <atoi@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,0x8(%rax)
jmp    1322 <getmntent_r+0x1c2>
mov    -0x30(%rbp),%rdi
call   1070 <atoi@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
jmp    1322 <getmntent_r+0x1c2>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    1371 <getmntent_r+0x211>
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    0xccf(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,-0x30(%rbp)
mov    -0x4c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4c(%rbp)
jmp    11da <getmntent_r+0x7a>
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,%ebx
mov    %rdx,%r12
mov    %rsi,%r14
mov    %rdi,%rdx
movq   $0x0,0x8(%rsp)
movq   $0x0,0x10(%rsp)
lea    0x8(%rsp),%rdi
lea    0x10(%rsp),%rsi
call   1080 <getline@plt>
mov    0x8(%rsp),%rdi
cmp    $0xffffffff,%eax
je     12bd <getmntent_r+0x15d>
lea    0xe69(%rip),%rsi
call   1060 <strtok@plt>
test   %rax,%rax
je     129f <getmntent_r+0x13f>
mov    %rax,%r13
movslq %ebx,%rbp
xor    %r15d,%r15d
mov    %r12,%rbx
jmp    120f <getmntent_r+0xaf>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1040 <strcpy@plt>
mov    %rbx,0x28(%r14)
nopw   0x0(%rax,%rax,1)
mov    %r13,%rdi
call   1050 <strlen@plt>
cltq
add    %rax,%rbx
add    $0x1,%rbx
xor    %edi,%edi
lea    0xe1e(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,%r13
add    $0x1,%r15d
test   %rax,%rax
je     129f <getmntent_r+0x13f>
mov    %r13,%rdi
call   1050 <strlen@plt>
cltq
add    %rbx,%rax
sub    %r12,%rax
add    $0x1,%rax
cmp    %rbp,%rax
jg     12a6 <getmntent_r+0x146>
cmp    $0x5,%r15d
ja     12b8 <getmntent_r+0x158>
mov    %r15d,%eax
lea    0xdc4(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    %rbx,%rdi
mov    %r13,%rsi
call   1040 <strcpy@plt>
mov    %rbx,0x20(%r14)
jmp    11e0 <getmntent_r+0x80>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1040 <strcpy@plt>
mov    %rbx,0x18(%r14)
jmp    11e0 <getmntent_r+0x80>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1040 <strcpy@plt>
mov    %rbx,0x10(%r14)
jmp    11e0 <getmntent_r+0x80>
mov    %r13,%rdi
call   1070 <atoi@plt>
mov    %rax,0x8(%r14)
jmp    11e0 <getmntent_r+0x80>
mov    %r13,%rdi
call   1070 <atoi@plt>
mov    %rax,(%r14)
jmp    11e0 <getmntent_r+0x80>
mov    0x8(%rsp),%rdi
jmp    12c0 <getmntent_r+0x160>
mov    0x2d4b(%rip),%rax
mov    (%rax),%eax
mov    0x2d22(%rip),%rcx
mov    %eax,(%rcx)
mov    0x8(%rsp),%rdi
xor    %r14d,%r14d
call   1030 <free@plt>
mov    %r14,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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
%11 = load i8*, i8** %5
br i1 %10, label %63, label %12
12: ; preds = %4
%13 = call i8* @strtok(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%14 = icmp eq i8* %13, null
br i1 %14, label %61, label %15
15: ; preds = %12
%16 = ptrtoint i8* %2 to i64
%17 = sext i32 %3 to i64
%18 = getelementptr inbounds %struct.mntent, %struct.mntent* %1, i64 0, i32 0
%19 = getelementptr inbounds %struct.mntent, %struct.mntent* %1, i64 0, i32 1
%20 = getelementptr inbounds %struct.mntent, %struct.mntent* %1, i64 0, i32 2
%21 = getelementptr inbounds %struct.mntent, %struct.mntent* %1, i64 0, i32 3
%22 = getelementptr inbounds %struct.mntent, %struct.mntent* %1, i64 0, i32 4
%23 = getelementptr inbounds %struct.mntent, %struct.mntent* %1, i64 0, i32 5
br label %24
24: ; preds = %15, %53
%25 = phi i32 [ 0, %15 ], [ %59, %53 ]
%26 = phi i8* [ %2, %15 ], [ %57, %53 ]
%27 = phi i8* [ %13, %15 ], [ %58, %53 ]
%28 = call i32 @strlen(i8* %27)
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %26, i64 1
%31 = getelementptr inbounds i8, i8* %30, i64 %29
%32 = ptrtoint i8* %31 to i64
%33 = sub i64 %32, %16
%34 = icmp sgt i64 %33, %17
br i1 %34, label %35, label %38
35: ; preds = %24
%36 = load i32, i32* @ENOBUFS
store i32 %36, i32* @errno
%37 = load i8*, i8** %5
br label %63
38: ; preds = %24
switch i32 %25, label %51 [
i32 0, label %39
i32 1, label %41
i32 2, label %43
i32 3, label %45
i32 4, label %47
i32 5, label %49
]
39: ; preds = %38
%40 = call i8* @strcpy(i8* dereferenceable(1) %26, i8* %27)
store i8* %26, i8** %23
br label %53
41: ; preds = %38
%42 = call i8* @strcpy(i8* dereferenceable(1) %26, i8* %27)
store i8* %26, i8** %22
br label %53
43: ; preds = %38
%44 = call i8* @strcpy(i8* dereferenceable(1) %26, i8* %27)
store i8* %26, i8** %21
br label %53
45: ; preds = %38
%46 = call i8* @strcpy(i8* dereferenceable(1) %26, i8* %27)
store i8* %26, i8** %20
br label %53
47: ; preds = %38
%48 = call i8* @atoi(i8* %27)
store i8* %48, i8** %19
br label %53
49: ; preds = %38
%50 = call i8* @atoi(i8* %27)
store i8* %50, i8** %18
br label %53
51: ; preds = %38
%52 = load i8*, i8** %5
br label %63
53: ; preds = %49, %47, %45, %43, %41, %39
%54 = call i32 @strlen(i8* %27)
%55 = add nsw i32 %54, 1
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i8, i8* %26, 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 %25, 1
%60 = icmp eq i8* %58, null
br i1 %60, label %61, label %24
61: ; preds = %53, %12
%62 = load i8*, i8** %5
br label %63
63: ; preds = %4, %61, %51, %35
%64 = phi i8* [ %62, %61 ], [ %52, %51 ], [ %37, %35 ], [ %11, %4 ]
%65 = phi %struct.mntent* [ %1, %61 ], [ null, %51 ], [ null, %35 ], [ null, %4 ]
%66 = call i32 @free(i8* %64)
ret %struct.mntent* %65
}