#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_opts;
};

/* Variables and functions */
int /*<<< orphan*/ errx(int, char *);
int /*<<< orphan*/ free(char *);
scalar_t__ strcmp(char *, char const *);
char *strdup(int /*<<< orphan*/);
char *strsep(char **, char *);
char *strstr(char *, char *);
int mountedby(struct mntent *mnt, const char *user) {
  char *ds = strdup(mnt->mnt_opts);
  if (!ds)
    errx(1, "out of memory");
  char *s = ds;
  char *tok;
  int ret = 0;
  while ((tok = strsep(&s, ","))) {
    if (strstr(tok, "uname=") == tok) {
      ret = strcmp(tok + 6, user) == 0;
      break;
    }
  }
  free(ds);
  return ret;
}


x86 assembly (clang, -O0):
<mountedby>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
call   1070 <strdup@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    119b <mountedby+0x3b>
mov    $0x1,%edi
lea    0xe6a(%rip),%rsi
call   1040 <errx@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x2c(%rbp)
lea    -0x20(%rbp),%rdi
lea    0xe59(%rip),%rsi
call   1060 <strsep@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     120c <mountedby+0xac>
mov    -0x28(%rbp),%rdi
lea    0xe3d(%rip),%rsi
call   1080 <strstr@plt>
cmp    -0x28(%rbp),%rax
jne    1207 <mountedby+0xa7>
mov    -0x28(%rbp),%rdi
add    $0x6,%rdi
mov    -0x10(%rbp),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x2c(%rbp)
jmp    120c <mountedby+0xac>
jmp    11aa <mountedby+0x4a>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x2c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mountedby>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    (%rdi),%edi
call   1080 <strdup@plt>
mov    %rax,%r15
test   %rax,%rax
jne    118e <mountedby+0x2e>
lea    0xe7c(%rip),%rsi
mov    $0x1,%edi
call   1050 <errx@plt>
mov    %r15,(%rsp)
lea    0xe75(%rip),%r12
mov    %rsp,%rbx
lea    0xe6d(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
mov    %r12,%rsi
call   1070 <strsep@plt>
test   %rax,%rax
je     11f0 <mountedby+0x90>
mov    %rax,%rbp
mov    $0x6,%edx
mov    %rax,%rdi
mov    %r13,%rsi
call   1040 <strncmp@plt>
test   %eax,%eax
jne    11b0 <mountedby+0x50>
add    $0x6,%rbp
mov    %rbp,%rdi
mov    %r14,%rsi
call   1060 <strcmp@plt>
xor    %ebx,%ebx
test   %rax,%rax
sete   %bl
jmp    11f2 <mountedby+0x92>
xor    %ebx,%ebx
mov    %r15,%rdi
call   1030 <free@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.mntent = type { i32 }
@.str = [14 x i8] c"out of memory\00"
@.str.1 = [2 x i8] c",\00"
@.str.2 = [7 x i8] c"uname=\00"
define i32 @mountedby(%struct.mntent* %0, i8* %1) {
%3 = alloca %struct.mntent*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
store %struct.mntent* %0, %struct.mntent** %3
store i8* %1, i8** %4
%9 = load %struct.mntent*, %struct.mntent** %3
%10 = getelementptr inbounds %struct.mntent, %struct.mntent* %9, i32 0, i32 0
%11 = load i32, i32* %10
%12 = call i8* @strdup(i32 %11)
store i8* %12, i8** %5
%13 = load i8*, i8** %5
%14 = icmp ne i8* %13, null
br i1 %14, label %17, label %15
15: ; preds = %2
%16 = call i32 @errx(i32 1, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %17
17: ; preds = %15, %2
%18 = load i8*, i8** %5
store i8* %18, i8** %6
store i32 0, i32* %8
br label %19
19: ; preds = %34, %17
%20 = call i8* @strsep(i8** %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %20, i8** %7
%21 = icmp ne i8* %20, null
br i1 %21, label %22, label %35
22: ; preds = %19
%23 = load i8*, i8** %7
%24 = call i8* @strstr(i8* %23, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%25 = load i8*, i8** %7
%26 = icmp eq i8* %24, %25
br i1 %26, label %27, label %34
27: ; preds = %22
%28 = load i8*, i8** %7
%29 = getelementptr inbounds i8, i8* %28, i64 6
%30 = load i8*, i8** %4
%31 = call i64 @strcmp(i8* %29, i8* %30)
%32 = icmp eq i64 %31, 0
%33 = zext i1 %32 to i32
store i32 %33, i32* %8
br label %35
34: ; preds = %22
br label %19
35: ; preds = %27, %19
%36 = load i8*, i8** %5
%37 = call i32 @free(i8* %36)
%38 = load i32, i32* %8
ret i32 %38
}

LLVM IR (-O2):
%struct.mntent = type { i32 }
@.str = [14 x i8] c"out of memory\00"
@.str.1 = [2 x i8] c",\00"
@.str.2 = [7 x i8] c"uname=\00"
define i32 @mountedby(%struct.mntent* nocapture %0, i8* %1) {
%3 = alloca i8*
%4 = getelementptr inbounds %struct.mntent, %struct.mntent* %0, i64 0, i32 0
%5 = load i32, i32* %4
%6 = tail call i8* @strdup(i32 %5)
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = tail call i32 @errx(i32 1, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %8, %2
%11 = bitcast i8** %3 to i8*
store i8* %6, i8** %3
br label %12
12: ; preds = %15, %10
%13 = call i8* @strsep(i8** %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp eq i8* %13, null
br i1 %14, label %23, label %15
15: ; preds = %12
%16 = call i32 @strncmp(i8* %13, i8* dereferenceable(7) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i64 6)
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %12
18: ; preds = %15
%19 = getelementptr inbounds i8, i8* %13, i64 6
%20 = call i64 @strcmp(i8* %19, i8* %1)
%21 = icmp eq i64 %20, 0
%22 = zext i1 %21 to i32
br label %23
23: ; preds = %12, %18
%24 = phi i32 [ %22, %18 ], [ 0, %12 ]
%25 = call i32 @free(i8* %6)
ret i32 %24
}