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

/* Variables and functions */
char *strchr(char *, char);
size_t strlen(char const *);
char *strstr(char *, char const *);
char *hasmntopt(const struct mntent *mnt, const char *opt) {
  const size_t optlen = strlen(opt);
  char *rest = mnt->mnt_opts, *p;
  while ((p = strstr(rest, opt))) {
    if ((p == rest || p[-1] == ',') &&
        (p[optlen] == '\0' || p[optlen] == '=' || p[optlen] == ','))
      return p;
    rest = strchr(p, ',');
    if (!rest)
      break;
    ++rest;
  }
  return NULL;
}


x86 assembly (clang, -O0):
<hasmntopt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <strstr@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
je     1211 <hasmntopt+0xe1>
mov    -0x30(%rbp),%rax
cmp    -0x28(%rbp),%rax
je     1192 <hasmntopt+0x62>
mov    -0x30(%rbp),%rax
movsbl -0x1(%rax),%eax
cmp    $0x2c,%eax
jne    11de <hasmntopt+0xae>
mov    -0x30(%rbp),%rax
mov    -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     11d1 <hasmntopt+0xa1>
mov    -0x30(%rbp),%rax
mov    -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x3d,%eax
je     11d1 <hasmntopt+0xa1>
mov    -0x30(%rbp),%rax
mov    -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2c,%eax
jne    11de <hasmntopt+0xae>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1219 <hasmntopt+0xe9>
mov    -0x30(%rbp),%rdi
mov    $0x2c,%esi
call   1040 <strchr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1200 <hasmntopt+0xd0>
jmp    1211 <hasmntopt+0xe1>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1158 <hasmntopt+0x28>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hasmntopt>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%rbx
mov    %rsi,%rdi
call   1030 <strlen@plt>
mov    %rax,%r14
mov    (%rbx),%rbx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1050 <strstr@plt>
test   %rax,%rax
je     11b5 <hasmntopt+0x85>
movabs $0x2000100000000001,%r12
cs nopw 0x0(%rax,%rax,1)
cmp    %rbx,%rax
je     117b <hasmntopt+0x4b>
cmpb   $0x2c,-0x1(%rax)
jne    118c <hasmntopt+0x5c>
movzbl (%rax,%r14,1),%ecx
cmp    $0x3d,%rcx
ja     118c <hasmntopt+0x5c>
bt     %rcx,%r12
jb     11b7 <hasmntopt+0x87>
mov    %rax,%rdi
mov    $0x2c,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     11b5 <hasmntopt+0x85>
mov    %rax,%rbx
add    $0x1,%rbx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1050 <strstr@plt>
test   %rax,%rax
jne    1170 <hasmntopt+0x40>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.mntent = type { i8* }
define i8* @hasmntopt(%struct.mntent* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca %struct.mntent*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i8*
store %struct.mntent* %0, %struct.mntent** %4
store i8* %1, i8** %5
%9 = load i8*, i8** %5
%10 = call i64 @strlen(i8* %9)
store i64 %10, i64* %6
%11 = load %struct.mntent*, %struct.mntent** %4
%12 = getelementptr inbounds %struct.mntent, %struct.mntent* %11, i32 0, i32 0
%13 = load i8*, i8** %12
store i8* %13, i8** %7
br label %14
14: ; preds = %58, %2
%15 = load i8*, i8** %7
%16 = load i8*, i8** %5
%17 = call i8* @strstr(i8* %15, i8* %16)
store i8* %17, i8** %8
%18 = icmp ne i8* %17, null
br i1 %18, label %19, label %61
19: ; preds = %14
%20 = load i8*, i8** %8
%21 = load i8*, i8** %7
%22 = icmp eq i8* %20, %21
br i1 %22, label %29, label %23
23: ; preds = %19
%24 = load i8*, i8** %8
%25 = getelementptr inbounds i8, i8* %24, i64 -1
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp eq i32 %27, 44
br i1 %28, label %29, label %52
29: ; preds = %23, %19
%30 = load i8*, i8** %8
%31 = load i64, i64* %6
%32 = getelementptr inbounds i8, i8* %30, i64 %31
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = icmp eq i32 %34, 0
br i1 %35, label %50, label %36
36: ; preds = %29
%37 = load i8*, i8** %8
%38 = load i64, i64* %6
%39 = getelementptr inbounds i8, i8* %37, i64 %38
%40 = load i8, i8* %39
%41 = sext i8 %40 to i32
%42 = icmp eq i32 %41, 61
br i1 %42, label %50, label %43
43: ; preds = %36
%44 = load i8*, i8** %8
%45 = load i64, i64* %6
%46 = getelementptr inbounds i8, i8* %44, i64 %45
%47 = load i8, i8* %46
%48 = sext i8 %47 to i32
%49 = icmp eq i32 %48, 44
br i1 %49, label %50, label %52
50: ; preds = %43, %36, %29
%51 = load i8*, i8** %8
store i8* %51, i8** %3
br label %62
52: ; preds = %43, %23
%53 = load i8*, i8** %8
%54 = call i8* @strchr(i8* %53, i8 signext 44)
store i8* %54, i8** %7
%55 = load i8*, i8** %7
%56 = icmp ne i8* %55, null
br i1 %56, label %58, label %57
57: ; preds = %52
br label %61
58: ; preds = %52
%59 = load i8*, i8** %7
%60 = getelementptr inbounds i8, i8* %59, i32 1
store i8* %60, i8** %7
br label %14
61: ; preds = %57, %14
store i8* null, i8** %3
br label %62
62: ; preds = %61, %50
%63 = load i8*, i8** %3
ret i8* %63
}

LLVM IR (-O2):
%struct.mntent = type { i8* }
define i8* @hasmntopt(%struct.mntent* nocapture %0, i8* nocapture %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%4 = getelementptr inbounds %struct.mntent, %struct.mntent* %0, i64 0, i32 0
%5 = load i8*, i8** %4
%6 = tail call i8* @strstr(i8* dereferenceable(1) %5, i8* dereferenceable(1) %1)
%7 = icmp eq i8* %6, null
br i1 %7, label %26, label %11
8: ; preds = %22
%9 = tail call i8* @strstr(i8* dereferenceable(1) %25, i8* dereferenceable(1) %1)
%10 = icmp eq i8* %9, null
br i1 %10, label %26, label %11
11: ; preds = %2, %8
%12 = phi i8* [ %9, %8 ], [ %6, %2 ]
%13 = phi i8* [ %25, %8 ], [ %5, %2 ]
%14 = icmp eq i8* %12, %13
br i1 %14, label %19, label %15
15: ; preds = %11
%16 = getelementptr inbounds i8, i8* %12, i64 -1
%17 = load i8, i8* %16
%18 = icmp eq i8 %17, 44
br i1 %18, label %19, label %22
19: ; preds = %15, %11
%20 = getelementptr inbounds i8, i8* %12, i64 %3
%21 = load i8, i8* %20
switch i8 %21, label %22 [
i8 0, label %26
i8 61, label %26
i8 44, label %26
]
22: ; preds = %19, %15
%23 = tail call i8* @strchr(i8* %12, i8 signext 44)
%24 = icmp eq i8* %23, null
%25 = getelementptr inbounds i8, i8* %23, i64 1
br i1 %24, label %26, label %8
26: ; preds = %19, %19, %19, %22, %8, %2
%27 = phi i8* [ null, %2 ], [ null, %8 ], [ null, %22 ], [ %12, %19 ], [ %12, %19 ], [ %12, %19 ]
ret i8* %27
}