#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_dir;
  int /*<<< orphan*/ mnt_type;
};
typedef int /*<<< orphan*/ sbuf;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ endmntent(int /*<<< orphan*/ *);
struct mntent *getmntent(int /*<<< orphan*/ *);
char *malloc(int);
int /*<<< orphan*/ *setmntent(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, ...);
scalar_t__ strcmp(int /*<<< orphan*/, char *);
char *get_nfs_mounts() {
  struct mntent *ent;
  FILE *file;
  file = setmntent("/proc/mounts", "r");
  if (file == NULL)
    return NULL;
  char sbuf[512];
  char *s = sbuf;
  int length = 0;
  while (NULL != (ent = getmntent(file))) {
    if (strcmp(ent->mnt_type, "nfs4") == 0)
      s += sprintf(s, " -v %s:%s ", ent->mnt_dir, ent->mnt_dir);
  }
  endmntent(file);
  char *out = malloc(sizeof(sbuf));
  sprintf(out, "%s", sbuf);
  return out;
}


x86 assembly (clang, -O0):
<get_nfs_mounts>:
push   %rbp
mov    %rsp,%rbp
sub    $0x240,%rsp
lea    0xe8e(%rip),%rdi
lea    0xe94(%rip),%rsi
call   1070 <setmntent@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    119a <get_nfs_mounts+0x3a>
movq   $0x0,-0x8(%rbp)
jmp    1269 <get_nfs_mounts+0x109>
lea    -0x220(%rbp),%rax
mov    %rax,-0x228(%rbp)
movl   $0x0,-0x22c(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <getmntent@plt>
mov    %rax,%rcx
mov    %rcx,-0x10(%rbp)
xor    %eax,%eax
cmp    %rcx,%rax
je     1228 <get_nfs_mounts+0xc8>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%edi
lea    0xe34(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    1223 <get_nfs_mounts+0xc3>
mov    -0x228(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
lea    0xe0e(%rip),%rsi
mov    $0x0,%al
call   1080 <sprintf@plt>
mov    %eax,%ecx
mov    -0x228(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x228(%rbp)
jmp    11b2 <get_nfs_mounts+0x52>
mov    -0x18(%rbp),%rdi
call   1030 <endmntent@plt>
mov    $0x200,%edi
call   1050 <malloc@plt>
mov    %rax,-0x238(%rbp)
mov    -0x238(%rbp),%rdi
lea    -0x220(%rbp),%rdx
lea    0xdc8(%rip),%rsi
mov    $0x0,%al
call   1080 <sprintf@plt>
mov    -0x238(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x240,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_nfs_mounts>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x200,%rsp
lea    0xe79(%rip),%rdi
lea    0xe7f(%rip),%rsi
call   1080 <setmntent@plt>
test   %rax,%rax
je     122c <get_nfs_mounts+0xbc>
mov    %rax,%r14
mov    %rax,%rdi
call   1070 <getmntent@plt>
test   %rax,%rax
je     120a <get_nfs_mounts+0x9a>
mov    %rax,%rbx
mov    %rsp,%r13
lea    0xe56(%rip),%r15
lea    0xe54(%rip),%r12
jmp    11e0 <get_nfs_mounts+0x70>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14,%rdi
call   1070 <getmntent@plt>
mov    %rax,%rbx
test   %rax,%rax
je     120a <get_nfs_mounts+0x9a>
mov    0x8(%rbx),%edi
mov    %r15,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
jne    11d0 <get_nfs_mounts+0x60>
mov    (%rbx),%rcx
mov    %r13,%rdi
mov    %r12,%rsi
mov    %rcx,%rdx
xor    %eax,%eax
call   1090 <sprintf@plt>
cltq
add    %rax,%r13
jmp    11d0 <get_nfs_mounts+0x60>
mov    %r14,%rdi
call   1030 <endmntent@plt>
mov    $0x200,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    %rsp,%rsi
mov    %rax,%rdi
call   1040 <strcpy@plt>
jmp    122e <get_nfs_mounts+0xbe>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x200,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.mntent = type { i8*, i32 }
@.str = [13 x i8] c"/proc/mounts\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [5 x i8] c"nfs4\00"
@.str.3 = [11 x i8] c" -v %s:%s \00"
@.str.4 = [3 x i8] c"%s\00"
define i8* @get_nfs_mounts() {
%1 = alloca i8*
%2 = alloca %struct.mntent*
%3 = alloca i32*
%4 = alloca [512 x i8]
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = call i32* @setmntent(i8* getelementptr inbounds ([13 x i8], [13 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** %3
%9 = load i32*, i32** %3
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %12
11: ; preds = %0
store i8* null, i8** %1
br label %45
12: ; preds = %0
%13 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
store i8* %13, i8** %5
store i32 0, i32* %6
br label %14
14: ; preds = %36, %12
%15 = load i32*, i32** %3
%16 = call %struct.mntent* @getmntent(i32* %15)
store %struct.mntent* %16, %struct.mntent** %2
%17 = icmp ne %struct.mntent* null, %16
br i1 %17, label %18, label %37
18: ; preds = %14
%19 = load %struct.mntent*, %struct.mntent** %2
%20 = getelementptr inbounds %struct.mntent, %struct.mntent* %19, i32 0, i32 1
%21 = load i32, i32* %20
%22 = call i64 @strcmp(i32 %21, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %36
24: ; preds = %18
%25 = load i8*, i8** %5
%26 = load %struct.mntent*, %struct.mntent** %2
%27 = getelementptr inbounds %struct.mntent, %struct.mntent* %26, i32 0, i32 0
%28 = load i8*, i8** %27
%29 = load %struct.mntent*, %struct.mntent** %2
%30 = getelementptr inbounds %struct.mntent, %struct.mntent* %29, i32 0, i32 0
%31 = load i8*, i8** %30
%32 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %25, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i8* %28, i8* %31)
%33 = load i8*, i8** %5
%34 = sext i32 %32 to i64
%35 = getelementptr inbounds i8, i8* %33, i64 %34
store i8* %35, i8** %5
br label %36
36: ; preds = %24, %18
br label %14
37: ; preds = %14
%38 = load i32*, i32** %3
%39 = call i32 @endmntent(i32* %38)
%40 = call i8* @malloc(i32 512)
store i8* %40, i8** %7
%41 = load i8*, i8** %7
%42 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%43 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %41, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %42)
%44 = load i8*, i8** %7
store i8* %44, i8** %1
br label %45
45: ; preds = %37, %11
%46 = load i8*, i8** %1
ret i8* %46
}

LLVM IR (-O2):
%struct.mntent = type { i8*, i32 }
@.str = [13 x i8] c"/proc/mounts\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [5 x i8] c"nfs4\00"
@.str.3 = [11 x i8] c" -v %s:%s \00"
define i8* @get_nfs_mounts() {
%1 = alloca [512 x i8]
%2 = tail call i32* @setmntent(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %29, label %4
4: ; preds = %0
%5 = getelementptr inbounds [512 x i8], [512 x i8]* %1, i64 0, i64 0
%6 = tail call %struct.mntent* @getmntent(i32* %2)
%7 = icmp eq %struct.mntent* %6, null
br i1 %7, label %25, label %8
8: ; preds = %4, %21
%9 = phi %struct.mntent* [ %23, %21 ], [ %6, %4 ]
%10 = phi i8* [ %22, %21 ], [ %5, %4 ]
%11 = getelementptr inbounds %struct.mntent, %struct.mntent* %9, i64 0, i32 1
%12 = load i32, i32* %11
%13 = tail call i64 @strcmp(i32 %12, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %21
15: ; preds = %8
%16 = getelementptr inbounds %struct.mntent, %struct.mntent* %9, i64 0, i32 0
%17 = load i8*, i8** %16
%18 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %10, i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i8* %17, i8* %17)
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %10, i64 %19
br label %21
21: ; preds = %15, %8
%22 = phi i8* [ %20, %15 ], [ %10, %8 ]
%23 = tail call %struct.mntent* @getmntent(i32* %2)
%24 = icmp eq %struct.mntent* %23, null
br i1 %24, label %25, label %8
25: ; preds = %21, %4
%26 = tail call i32 @endmntent(i32* %2)
%27 = tail call dereferenceable_or_null(512) i8* @malloc(i32 512)
%28 = call i8* @strcpy(i8* dereferenceable(1) %27, i8* %5)
br label %29
29: ; preds = %0, %25
%30 = phi i8* [ %27, %25 ], [ null, %0 ]
ret i8* %30
}