#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 */

/* Variables and functions */
int EINVAL;
int ENOMEM;
char *malloc(size_t);
int /*<<< orphan*/ memcpy(char *, char *, size_t);
size_t strlen(char *);
char *strstr(char *, char *);
int get_mount_opt_value(char *mnt_opts, char *name, char **value) {
  char *name_start, *val_start, *val_stop;
  size_t name_len, val_len;
  int rc = 0;
  name_len = strlen(name);
  if (name[name_len - 1] != '=') {
    rc = EINVAL;
    goto out;
  }
  name_start = strstr(mnt_opts, name);
  if (!name_start) {
    rc = EINVAL;
    goto out;
  }
  val_start = name_start + name_len;
  val_stop = strstr(val_start, ",");
  if (!val_stop)
    val_stop = mnt_opts + strlen(mnt_opts);
  val_len = val_stop - val_start;
  *value = malloc(val_len + 1);
  if (!(*value)) {
    rc = ENOMEM;
    goto out;
  }
  memcpy(*value, val_start, val_len);
  (*value)[val_len] = '\0';
out:
  return rc;
}


x86 assembly (clang, -O0):
<get_mount_opt_value>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x44(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x38(%rbp),%rcx
sub    $0x1,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x3d,%eax
je     1192 <get_mount_opt_value+0x52>
mov    0x2e50(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
jmp    1271 <get_mount_opt_value+0x131>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <strstr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11bf <get_mount_opt_value+0x7f>
mov    0x2e23(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
jmp    1271 <get_mount_opt_value+0x131>
mov    -0x20(%rbp),%rax
add    -0x38(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
lea    0xe2a(%rip),%rsi
call   1060 <strstr@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1209 <get_mount_opt_value+0xc9>
mov    -0x8(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0x50(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    -0x28(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
add    $0x1,%rdi
call   1050 <malloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
cmpq   $0x0,(%rax)
jne    124e <get_mount_opt_value+0x10e>
mov    0x2d9c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
jmp    1271 <get_mount_opt_value+0x131>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x40(%rbp),%rdx
call   1040 <memcpy@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    -0x40(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x44(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_mount_opt_value>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%r15
mov    %rsi,%rdi
call   1030 <strlen@plt>
cmpb   $0x3d,-0x1(%rax,%rbx,1)
jne    11da <get_mount_opt_value+0x8a>
mov    %rax,%r13
mov    %r15,%rdi
mov    %rbx,%rsi
call   1070 <strstr@plt>
test   %rax,%rax
je     11da <get_mount_opt_value+0x8a>
mov    %rax,%r12
add    %r13,%r12
mov    %r12,%rdi
mov    $0x2c,%esi
call   1040 <strchr@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11ad <get_mount_opt_value+0x5d>
mov    %r15,%rdi
call   1030 <strlen@plt>
mov    %rax,%rbx
add    %r15,%rbx
sub    %r12,%rbx
lea    0x1(%rbx),%rdi
call   1060 <malloc@plt>
mov    %rax,(%r14)
test   %rax,%rax
je     11ed <get_mount_opt_value+0x9d>
mov    %rax,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1050 <memcpy@plt>
mov    (%r14),%rax
movb   $0x0,(%rax,%rbx,1)
xor    %eax,%eax
jmp    11e3 <get_mount_opt_value+0x93>
mov    0x2df7(%rip),%rax
mov    (%rax),%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
mov    0x2dec(%rip),%rax
jmp    11e1 <get_mount_opt_value+0x91>

LLVM IR (-O0):
@EINVAL = global i32 0
@.str = [2 x i8] c",\00"
@ENOMEM = global i32 0
define i32 @get_mount_opt_value(i8* %0, i8* %1, i8** %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8**
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i64
%12 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8** %2, i8*** %6
store i32 0, i32* %12
%13 = load i8*, i8** %5
%14 = call i64 @strlen(i8* %13)
store i64 %14, i64* %10
%15 = load i8*, i8** %5
%16 = load i64, i64* %10
%17 = sub i64 %16, 1
%18 = getelementptr inbounds i8, i8* %15, i64 %17
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp ne i32 %20, 61
br i1 %21, label %22, label %24
22: ; preds = %3
%23 = load i32, i32* @EINVAL
store i32 %23, i32* %12
br label %70
24: ; preds = %3
%25 = load i8*, i8** %4
%26 = load i8*, i8** %5
%27 = call i8* @strstr(i8* %25, i8* %26)
store i8* %27, i8** %7
%28 = load i8*, i8** %7
%29 = icmp ne i8* %28, null
br i1 %29, label %32, label %30
30: ; preds = %24
%31 = load i32, i32* @EINVAL
store i32 %31, i32* %12
br label %70
32: ; preds = %24
%33 = load i8*, i8** %7
%34 = load i64, i64* %10
%35 = getelementptr inbounds i8, i8* %33, i64 %34
store i8* %35, i8** %8
%36 = load i8*, i8** %8
%37 = call i8* @strstr(i8* %36, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %37, i8** %9
%38 = load i8*, i8** %9
%39 = icmp ne i8* %38, null
br i1 %39, label %45, label %40
40: ; preds = %32
%41 = load i8*, i8** %4
%42 = load i8*, i8** %4
%43 = call i64 @strlen(i8* %42)
%44 = getelementptr inbounds i8, i8* %41, i64 %43
store i8* %44, i8** %9
br label %45
45: ; preds = %40, %32
%46 = load i8*, i8** %9
%47 = load i8*, i8** %8
%48 = ptrtoint i8* %46 to i64
%49 = ptrtoint i8* %47 to i64
%50 = sub i64 %48, %49
store i64 %50, i64* %11
%51 = load i64, i64* %11
%52 = add i64 %51, 1
%53 = call i8* @malloc(i64 %52)
%54 = load i8**, i8*** %6
store i8* %53, i8** %54
%55 = load i8**, i8*** %6
%56 = load i8*, i8** %55
%57 = icmp ne i8* %56, null
br i1 %57, label %60, label %58
58: ; preds = %45
%59 = load i32, i32* @ENOMEM
store i32 %59, i32* %12
br label %70
60: ; preds = %45
%61 = load i8**, i8*** %6
%62 = load i8*, i8** %61
%63 = load i8*, i8** %8
%64 = load i64, i64* %11
%65 = call i32 @memcpy(i8* %62, i8* %63, i64 %64)
%66 = load i8**, i8*** %6
%67 = load i8*, i8** %66
%68 = load i64, i64* %11
%69 = getelementptr inbounds i8, i8* %67, i64 %68
store i8 0, i8* %69
br label %70
70: ; preds = %60, %58, %30, %22
%71 = load i32, i32* %12
ret i32 %71
}

LLVM IR (-O2):
@EINVAL = global i32 0
@ENOMEM = global i32 0
define i32 @get_mount_opt_value(i8* %0, i8* nocapture %1, i8** nocapture %2) {
%4 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%5 = add i64 %4, -1
%6 = getelementptr inbounds i8, i8* %1, i64 %5
%7 = load i8, i8* %6
%8 = icmp eq i8 %7, 61
br i1 %8, label %11, label %9
9: ; preds = %3
%10 = load i32, i32* @EINVAL
br label %37
11: ; preds = %3
%12 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) %1)
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %16
14: ; preds = %11
%15 = load i32, i32* @EINVAL
br label %37
16: ; preds = %11
%17 = getelementptr inbounds i8, i8* %12, i64 %4
%18 = tail call i8* @strchr(i8* %17, i32 44)
%19 = icmp eq i8* %18, null
br i1 %19, label %20, label %23
20: ; preds = %16
%21 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%22 = getelementptr inbounds i8, i8* %0, i64 %21
br label %23
23: ; preds = %20, %16
%24 = phi i8* [ %18, %16 ], [ %22, %20 ]
%25 = ptrtoint i8* %24 to i64
%26 = ptrtoint i8* %17 to i64
%27 = sub i64 %25, %26
%28 = add i64 %27, 1
%29 = tail call i8* @malloc(i64 %28)
store i8* %29, i8** %2
%30 = icmp eq i8* %29, null
br i1 %30, label %31, label %33
31: ; preds = %23
%32 = load i32, i32* @ENOMEM
br label %37
33: ; preds = %23
%34 = tail call i32 @memcpy(i8* %29, i8* %17, i64 %27)
%35 = load i8*, i8** %2
%36 = getelementptr inbounds i8, i8* %35, i64 %27
store i8 0, i8* %36
br label %37
37: ; preds = %33, %31, %14, %9
%38 = phi i32 [ %10, %9 ], [ 0, %33 ], [ %32, %31 ], [ %15, %14 ]
ret i32 %38
}