#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_fsname;
};
typedef int /*<<< orphan*/ regex_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ compile_regex(int /*<<< orphan*/ *, char const *);
int /*<<< orphan*/ endmntent(int /*<<< orphan*/ *);
char *freespace(char *);
struct mntent *getmntent(int /*<<< orphan*/ *);
scalar_t__ match_regex(int /*<<< orphan*/ *, char const *);
int /*<<< orphan*/ regfree(int /*<<< orphan*/ *);
int /*<<< orphan*/ *setmntent(char *, char *);
char *smprintf(char *, char *);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
char *getmounted() {
  struct mntent *ent = NULL;
  FILE *mtab = NULL;
  char *free;
  char buf[1024];
  regex_t r;
  const char *regex_text;
  const char *find_text;
  regex_text = "(/media/|/mnt/)";
  strcpy(buf, "");
  compile_regex(&r, regex_text);
  if ((mtab = setmntent("/etc/mtab", "r")) != NULL) {
    while ((ent = getmntent(mtab)) != NULL) {
      if ((ent->mnt_fsname != NULL)) {
        find_text = ent->mnt_dir;
        if ((match_regex(&r, find_text)) == 0) {
          strcat(buf, " ");
          strcat(buf, ent->mnt_dir);
          strcat(buf, " ");
          strcat(buf, free = freespace(ent->mnt_dir));
        }
      }
    }
    regfree(&r);
    endmntent(mtab);
  }
  return smprintf("%s", buf);
}


x86 assembly (clang, -O0):
<getmounted>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
movq   $0x0,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
lea    0xe3e(%rip),%rax
mov    %rax,-0x430(%rbp)
lea    -0x420(%rbp),%rdi
lea    0xe46(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x430(%rbp),%rsi
lea    -0x424(%rbp),%rdi
call   10c0 <compile_regex@plt>
lea    0xe1a(%rip),%rdi
lea    0xe1d(%rip),%rsi
call   1080 <setmntent@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     12eb <getmounted+0x14b>
jmp    1215 <getmounted+0x75>
mov    -0x10(%rbp),%rdi
call   1070 <getmntent@plt>
mov    %rax,-0x8(%rbp)
cmp    $0x0,%rax
je     12d6 <getmounted+0x136>
mov    -0x8(%rbp),%rax
cmpq   $0x0,0x8(%rax)
je     12d1 <getmounted+0x131>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x438(%rbp)
mov    -0x438(%rbp),%rsi
lea    -0x424(%rbp),%rdi
call   10b0 <match_regex@plt>
cmp    $0x0,%rax
jne    12cc <getmounted+0x12c>
lea    -0x420(%rbp),%rdi
lea    0xda8(%rip),%rsi
call   10a0 <strcat@plt>
lea    -0x420(%rbp),%rdi
mov    -0x8(%rbp),%rax
mov    (%rax),%rsi
call   10a0 <strcat@plt>
lea    -0x420(%rbp),%rdi
lea    0xd82(%rip),%rsi
call   10a0 <strcat@plt>
lea    -0x420(%rbp),%rax
mov    %rax,-0x440(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1090 <freespace@plt>
mov    -0x440(%rbp),%rdi
mov    %rax,%rsi
mov    %rsi,-0x18(%rbp)
call   10a0 <strcat@plt>
jmp    12d1 <getmounted+0x131>
jmp    1215 <getmounted+0x75>
lea    -0x424(%rbp),%rdi
call   1060 <regfree@plt>
mov    -0x10(%rbp),%rdi
call   1030 <endmntent@plt>
lea    -0x420(%rbp),%rsi
lea    0xd25(%rip),%rdi
call   1050 <smprintf@plt>
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getmounted>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x410,%rsp
lea    0xe66(%rip),%rsi
lea    0x10(%rsp),%rdi
call   1040 <strcpy@plt>
lea    0xe38(%rip),%rsi
lea    0xc(%rsp),%rdi
call   10c0 <compile_regex@plt>
lea    0xe37(%rip),%rdi
lea    0xe3a(%rip),%rsi
call   1080 <setmntent@plt>
test   %rax,%rax
je     128f <getmounted+0xef>
mov    %rax,%r13
mov    %rax,%rdi
call   1070 <getmntent@plt>
test   %rax,%rax
je     127d <getmounted+0xdd>
mov    %rax,%rbx
lea    0xc(%rsp),%r14
lea    0xe0f(%rip),%r15
lea    0x10(%rsp),%r12
jmp    1230 <getmounted+0x90>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r13,%rdi
call   1070 <getmntent@plt>
mov    %rax,%rbx
test   %rax,%rax
je     127d <getmounted+0xdd>
cmpq   $0x0,0x8(%rbx)
je     1220 <getmounted+0x80>
mov    (%rbx),%rsi
mov    %r14,%rdi
call   10b0 <match_regex@plt>
test   %rax,%rax
jne    1220 <getmounted+0x80>
mov    %r12,%rdi
mov    %r15,%rsi
call   10a0 <strcat@plt>
mov    (%rbx),%rsi
mov    %r12,%rdi
call   10a0 <strcat@plt>
mov    %r12,%rdi
mov    %r15,%rsi
call   10a0 <strcat@plt>
mov    (%rbx),%rdi
call   1090 <freespace@plt>
mov    %r12,%rdi
mov    %rax,%rsi
call   10a0 <strcat@plt>
jmp    1220 <getmounted+0x80>
lea    0xc(%rsp),%rdi
call   1060 <regfree@plt>
mov    %r13,%rdi
call   1030 <endmntent@plt>
lea    0xd88(%rip),%rdi
lea    0x10(%rsp),%rsi
call   1050 <smprintf@plt>
add    $0x410,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.mntent = type { i8*, i32* }
@.str = [16 x i8] c"(/media/|/mnt/)\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [10 x i8] c"/etc/mtab\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [2 x i8] c" \00"
@.str.5 = [3 x i8] c"%s\00"
define i8* @getmounted() {
%1 = alloca %struct.mntent*
%2 = alloca i32*
%3 = alloca i8*
%4 = alloca [1024 x i8]
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
store %struct.mntent* null, %struct.mntent** %1
store i32* null, i32** %2
store i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8** %6
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%9 = call i32 @strcpy(i8* %8, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
%10 = load i8*, i8** %6
%11 = call i32 @compile_regex(i32* %5, i8* %10)
%12 = call i32* @setmntent(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %12, i32** %2
%13 = icmp ne i32* %12, null
br i1 %13, label %14, label %53
14: ; preds = %0
br label %15
15: ; preds = %48, %14
%16 = load i32*, i32** %2
%17 = call %struct.mntent* @getmntent(i32* %16)
store %struct.mntent* %17, %struct.mntent** %1
%18 = icmp ne %struct.mntent* %17, null
br i1 %18, label %19, label %49
19: ; preds = %15
%20 = load %struct.mntent*, %struct.mntent** %1
%21 = getelementptr inbounds %struct.mntent, %struct.mntent* %20, i32 0, i32 1
%22 = load i32*, i32** %21
%23 = icmp ne i32* %22, null
br i1 %23, label %24, label %48
24: ; preds = %19
%25 = load %struct.mntent*, %struct.mntent** %1
%26 = getelementptr inbounds %struct.mntent, %struct.mntent* %25, i32 0, i32 0
%27 = load i8*, i8** %26
store i8* %27, i8** %7
%28 = load i8*, i8** %7
%29 = call i64 @match_regex(i32* %5, i8* %28)
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %47
31: ; preds = %24
%32 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%33 = call i32 @strcat(i8* %32, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%34 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%35 = load %struct.mntent*, %struct.mntent** %1
%36 = getelementptr inbounds %struct.mntent, %struct.mntent* %35, i32 0, i32 0
%37 = load i8*, i8** %36
%38 = call i32 @strcat(i8* %34, i8* %37)
%39 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%40 = call i32 @strcat(i8* %39, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%41 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%42 = load %struct.mntent*, %struct.mntent** %1
%43 = getelementptr inbounds %struct.mntent, %struct.mntent* %42, i32 0, i32 0
%44 = load i8*, i8** %43
%45 = call i8* @freespace(i8* %44)
store i8* %45, i8** %3
%46 = call i32 @strcat(i8* %41, i8* %45)
br label %47
47: ; preds = %31, %24
br label %48
48: ; preds = %47, %19
br label %15
49: ; preds = %15
%50 = call i32 @regfree(i32* %5)
%51 = load i32*, i32** %2
%52 = call i32 @endmntent(i32* %51)
br label %53
53: ; preds = %49, %0
%54 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%55 = call i8* @smprintf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* %54)
ret i8* %55
}

LLVM IR (-O2):
%struct.mntent = type { i8*, i32* }
@.str = [16 x i8] c"(/media/|/mnt/)\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [10 x i8] c"/etc/mtab\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [2 x i8] c" \00"
@.str.5 = [3 x i8] c"%s\00"
define i8* @getmounted() {
%1 = alloca [1024 x i8]
%2 = alloca i32
%3 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%4 = bitcast i32* %2 to i8*
%5 = call i32 @strcpy(i8* %3, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
%6 = call i32 @compile_regex(i32* %2, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%7 = call i32* @setmntent(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %36, label %9
9: ; preds = %0
%10 = call %struct.mntent* @getmntent(i32* %7)
%11 = icmp eq %struct.mntent* %10, null
br i1 %11, label %33, label %12
12: ; preds = %9, %30
%13 = phi %struct.mntent* [ %31, %30 ], [ %10, %9 ]
%14 = getelementptr inbounds %struct.mntent, %struct.mntent* %13, i64 0, i32 1
%15 = load i32*, i32** %14
%16 = icmp eq i32* %15, null
br i1 %16, label %30, label %17
17: ; preds = %12
%18 = getelementptr inbounds %struct.mntent, %struct.mntent* %13, i64 0, i32 0
%19 = load i8*, i8** %18
%20 = call i64 @match_regex(i32* %2, i8* %19)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %30
22: ; preds = %17
%23 = call i32 @strcat(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%24 = load i8*, i8** %18
%25 = call i32 @strcat(i8* %3, i8* %24)
%26 = call i32 @strcat(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%27 = load i8*, i8** %18
%28 = call i8* @freespace(i8* %27)
%29 = call i32 @strcat(i8* %3, i8* %28)
br label %30
30: ; preds = %17, %22, %12
%31 = call %struct.mntent* @getmntent(i32* %7)
%32 = icmp eq %struct.mntent* %31, null
br i1 %32, label %33, label %12
33: ; preds = %30, %9
%34 = call i32 @regfree(i32* %2)
%35 = call i32 @endmntent(i32* %7)
br label %36
36: ; preds = %33, %0
%37 = call i8* @smprintf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* %3)
ret i8* %37
}