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

/* Variables and functions */
int MS_NOATIME;
int MS_NOEXEC;
int MS_NOSUID;
int MS_RDONLY;
scalar_t__ hasmntopt(struct mntent *, char *);
int flagsof(struct mntent *mnt) {
  int f = 0;
  if (hasmntopt(mnt, "ro"))
    f |= MS_RDONLY;
  if (hasmntopt(mnt, "nosuid"))
    f |= MS_NOSUID;
  if (hasmntopt(mnt, "noexec"))
    f |= MS_NOEXEC;
  if (hasmntopt(mnt, "noatime"))
    f |= MS_NOATIME;
  return f;
}


x86 assembly (clang, -O0):
<flagsof>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xed2(%rip),%rsi
call   1030 <hasmntopt@plt>
cmp    $0x0,%rax
je     114c <flagsof+0x3c>
mov    0x2e94(%rip),%rax
mov    (%rax),%eax
or     -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xeac(%rip),%rsi
call   1030 <hasmntopt@plt>
cmp    $0x0,%rax
je     1175 <flagsof+0x65>
mov    0x2e73(%rip),%rax
mov    (%rax),%eax
or     -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe8a(%rip),%rsi
call   1030 <hasmntopt@plt>
cmp    $0x0,%rax
je     119e <flagsof+0x8e>
mov    0x2e2a(%rip),%rax
mov    (%rax),%eax
or     -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe68(%rip),%rsi
call   1030 <hasmntopt@plt>
cmp    $0x0,%rax
je     11c7 <flagsof+0xb7>
mov    0x2e31(%rip),%rax
mov    (%rax),%eax
or     -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<flagsof>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%r12
lea    0xede(%rip),%rsi
call   1030 <hasmntopt@plt>
xor    %r14d,%r14d
mov    $0x0,%r15d
test   %rax,%rax
je     113f <flagsof+0x2f>
mov    0x2e9c(%rip),%rax
mov    (%rax),%r15d
lea    0xebd(%rip),%rsi
mov    %r12,%rdi
call   1030 <hasmntopt@plt>
mov    $0x0,%ebp
test   %rax,%rax
je     1161 <flagsof+0x51>
mov    0x2e81(%rip),%rax
mov    (%rax),%ebp
lea    0xea2(%rip),%rsi
mov    %r12,%rdi
call   1030 <hasmntopt@plt>
mov    $0x0,%ebx
test   %rax,%rax
je     1183 <flagsof+0x73>
mov    0x2e3f(%rip),%rax
mov    (%rax),%ebx
or     %r15d,%ebp
lea    0xe84(%rip),%rsi
mov    %r12,%rdi
call   1030 <hasmntopt@plt>
test   %rax,%rax
je     11a4 <flagsof+0x94>
mov    0x2e4f(%rip),%rax
mov    (%rax),%r14d
or     %r14d,%ebx
or     %ebx,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.mntent = type { i32 }
@.str = [3 x i8] c"ro\00"
@MS_RDONLY = global i32 0
@.str.1 = [7 x i8] c"nosuid\00"
@MS_NOSUID = global i32 0
@.str.2 = [7 x i8] c"noexec\00"
@MS_NOEXEC = global i32 0
@.str.3 = [8 x i8] c"noatime\00"
@MS_NOATIME = global i32 0
define i32 @flagsof(%struct.mntent* %0) {
%2 = alloca %struct.mntent*
%3 = alloca i32
store %struct.mntent* %0, %struct.mntent** %2
store i32 0, i32* %3
%4 = load %struct.mntent*, %struct.mntent** %2
%5 = call i64 @hasmntopt(%struct.mntent* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%6 = icmp ne i64 %5, 0
br i1 %6, label %7, label %11
7: ; preds = %1
%8 = load i32, i32* @MS_RDONLY
%9 = load i32, i32* %3
%10 = or i32 %9, %8
store i32 %10, i32* %3
br label %11
11: ; preds = %7, %1
%12 = load %struct.mntent*, %struct.mntent** %2
%13 = call i64 @hasmntopt(%struct.mntent* %12, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %11
%16 = load i32, i32* @MS_NOSUID
%17 = load i32, i32* %3
%18 = or i32 %17, %16
store i32 %18, i32* %3
br label %19
19: ; preds = %15, %11
%20 = load %struct.mntent*, %struct.mntent** %2
%21 = call i64 @hasmntopt(%struct.mntent* %20, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %27
23: ; preds = %19
%24 = load i32, i32* @MS_NOEXEC
%25 = load i32, i32* %3
%26 = or i32 %25, %24
store i32 %26, i32* %3
br label %27
27: ; preds = %23, %19
%28 = load %struct.mntent*, %struct.mntent** %2
%29 = call i64 @hasmntopt(%struct.mntent* %28, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %35
31: ; preds = %27
%32 = load i32, i32* @MS_NOATIME
%33 = load i32, i32* %3
%34 = or i32 %33, %32
store i32 %34, i32* %3
br label %35
35: ; preds = %31, %27
%36 = load i32, i32* %3
ret i32 %36
}

LLVM IR (-O2):
%struct.mntent = type { i32 }
@.str = [3 x i8] c"ro\00"
@MS_RDONLY = global i32 0
@.str.1 = [7 x i8] c"nosuid\00"
@MS_NOSUID = global i32 0
@.str.2 = [7 x i8] c"noexec\00"
@MS_NOEXEC = global i32 0
@.str.3 = [8 x i8] c"noatime\00"
@MS_NOATIME = global i32 0
define i32 @flagsof(%struct.mntent* %0) {
%2 = tail call i64 @hasmntopt(%struct.mntent* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i64 %2, 0
%4 = load i32, i32* @MS_RDONLY
%5 = select i1 %3, i32 0, i32 %4
%6 = tail call i64 @hasmntopt(%struct.mntent* %0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%7 = icmp eq i64 %6, 0
%8 = load i32, i32* @MS_NOSUID
%9 = select i1 %7, i32 0, i32 %8
%10 = or i32 %9, %5
%11 = tail call i64 @hasmntopt(%struct.mntent* %0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%12 = icmp eq i64 %11, 0
%13 = load i32, i32* @MS_NOEXEC
%14 = select i1 %12, i32 0, i32 %13
%15 = or i32 %10, %14
%16 = tail call i64 @hasmntopt(%struct.mntent* %0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%17 = icmp eq i64 %16, 0
%18 = load i32, i32* @MS_NOATIME
%19 = select i1 %17, i32 0, i32 %18
%20 = or i32 %15, %19
ret i32 %20
}