#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 opt_to_flag(char const *, size_t);
size_t strcspn(char const *, char *);
int read_flags(const char *mnt_opts) {
  int flags = 0;
  size_t pos = strcspn(mnt_opts, ",");
  for (; mnt_opts[pos] != '\0'; pos = strcspn(mnt_opts, ",")) {
    flags |= opt_to_flag(mnt_opts, pos);
    mnt_opts += pos + 1;
  }
  return flags | opt_to_flag(mnt_opts, pos);
}


x86 assembly (clang, -O0):
<read_flags>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xec2(%rip),%rsi
call   1030 <strcspn@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     1198 <read_flags+0x78>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <opt_to_flag@plt>
or     -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
add    -0x8(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe76(%rip),%rsi
call   1030 <strcspn@plt>
mov    %rax,-0x18(%rbp)
jmp    1147 <read_flags+0x27>
mov    -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <opt_to_flag@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
or     %ecx,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_flags>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%rbx
lea    0xece(%rip),%rsi
call   1030 <strcspn@plt>
mov    %rax,%r14
cmpb   $0x0,(%rbx,%rax,1)
je     1180 <read_flags+0x60>
xor    %ebp,%ebp
lea    0xeb7(%rip),%r15
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <opt_to_flag@plt>
or     %eax,%ebp
lea    (%r14,%rbx,1),%r12
add    %r14,%rbx
add    $0x1,%rbx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1030 <strcspn@plt>
mov    %rax,%r14
cmpb   $0x0,0x1(%rax,%r12,1)
jne    1150 <read_flags+0x30>
jmp    1182 <read_flags+0x62>
xor    %ebp,%ebp
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <opt_to_flag@plt>
or     %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c",\00"
define i32 @read_flags(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i64
store i8* %0, i8** %2
store i32 0, i32* %3
%5 = load i8*, i8** %2
%6 = call i64 @strcspn(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i64 %6, i64* %4
br label %7
7: ; preds = %24, %1
%8 = load i8*, i8** %2
%9 = load i64, i64* %4
%10 = getelementptr inbounds i8, i8* %8, i64 %9
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %27
14: ; preds = %7
%15 = load i8*, i8** %2
%16 = load i64, i64* %4
%17 = call i32 @opt_to_flag(i8* %15, i64 %16)
%18 = load i32, i32* %3
%19 = or i32 %18, %17
store i32 %19, i32* %3
%20 = load i64, i64* %4
%21 = add i64 %20, 1
%22 = load i8*, i8** %2
%23 = getelementptr inbounds i8, i8* %22, i64 %21
store i8* %23, i8** %2
br label %24
24: ; preds = %14
%25 = load i8*, i8** %2
%26 = call i64 @strcspn(i8* %25, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i64 %26, i64* %4
br label %7
27: ; preds = %7
%28 = load i32, i32* %3
%29 = load i8*, i8** %2
%30 = load i64, i64* %4
%31 = call i32 @opt_to_flag(i8* %29, i64 %30)
%32 = or i32 %28, %31
ret i32 %32
}

LLVM IR (-O2):
@.str = [2 x i8] c",\00"
define i32 @read_flags(i8* %0) {
%2 = tail call i64 @strcspn(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%3 = getelementptr inbounds i8, i8* %0, i64 %2
%4 = load i8, i8* %3
%5 = icmp eq i8 %4, 0
br i1 %5, label %18, label %6
6: ; preds = %1, %6
%7 = phi i64 [ %14, %6 ], [ %2, %1 ]
%8 = phi i32 [ %11, %6 ], [ 0, %1 ]
%9 = phi i8* [ %13, %6 ], [ %0, %1 ]
%10 = tail call i32 @opt_to_flag(i8* %9, i64 %7)
%11 = or i32 %10, %8
%12 = add i64 %7, 1
%13 = getelementptr inbounds i8, i8* %9, i64 %12
%14 = tail call i64 @strcspn(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%15 = getelementptr inbounds i8, i8* %13, i64 %14
%16 = load i8, i8* %15
%17 = icmp eq i8 %16, 0
br i1 %17, label %18, label %6
18: ; preds = %6, %1
%19 = phi i8* [ %0, %1 ], [ %13, %6 ]
%20 = phi i32 [ 0, %1 ], [ %11, %6 ]
%21 = phi i64 [ %2, %1 ], [ %14, %6 ]
%22 = tail call i32 @opt_to_flag(i8* %19, i64 %21)
%23 = or i32 %22, %20
ret i32 %23
}