#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 MS_ASYNC;
int MS_INVALIDATE;
int MS_SYNC;
int msync(void *, size_t, int);
int system_io_msync(void *ptr, size_t size, int hs_flags) {
  int flags = 0;
  if (hs_flags & 1) {
    flags |= MS_SYNC;
  }
  if (hs_flags & 2) {
    flags |= MS_ASYNC;
  }
  if (hs_flags & 4) {
    flags |= MS_INVALIDATE;
  }
  return msync(ptr, size, flags);
}


x86 assembly (clang, -O0):
<system_io_msync>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x14(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     1148 <system_io_msync+0x38>
mov    0x2e90(%rip),%rax
mov    (%rax),%eax
or     -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
and    $0x2,%eax
cmp    $0x0,%eax
je     1166 <system_io_msync+0x56>
mov    0x2e82(%rip),%rax
mov    (%rax),%eax
or     -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
and    $0x4,%eax
cmp    $0x0,%eax
je     1184 <system_io_msync+0x74>
mov    0x2e6c(%rip),%rax
mov    (%rax),%eax
or     -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   1030 <msync@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<system_io_msync>:
mov    %edx,%r8d
and    $0x1,%r8d
neg    %r8d
mov    0x2eaf(%rip),%rcx
and    (%rcx),%r8d
mov    %edx,%ecx
shl    $0x1e,%ecx
sar    $0x1f,%ecx
mov    0x2ead(%rip),%rax
and    (%rax),%ecx
or     %r8d,%ecx
shl    $0x1d,%edx
sar    $0x1f,%edx
mov    0x2ea3(%rip),%rax
and    (%rax),%edx
or     %ecx,%edx
jmp    1030 <msync@plt>

LLVM IR (-O0):
@MS_SYNC = global i32 0
@MS_ASYNC = global i32 0
@MS_INVALIDATE = global i32 0
define i32 @system_io_msync(i8* %0, i64 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %4
store i64 %1, i64* %5
store i32 %2, i32* %6
store i32 0, i32* %7
%8 = load i32, i32* %6
%9 = and i32 %8, 1
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %15
11: ; preds = %3
%12 = load i32, i32* @MS_SYNC
%13 = load i32, i32* %7
%14 = or i32 %13, %12
store i32 %14, i32* %7
br label %15
15: ; preds = %11, %3
%16 = load i32, i32* %6
%17 = and i32 %16, 2
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %23
19: ; preds = %15
%20 = load i32, i32* @MS_ASYNC
%21 = load i32, i32* %7
%22 = or i32 %21, %20
store i32 %22, i32* %7
br label %23
23: ; preds = %19, %15
%24 = load i32, i32* %6
%25 = and i32 %24, 4
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %31
27: ; preds = %23
%28 = load i32, i32* @MS_INVALIDATE
%29 = load i32, i32* %7
%30 = or i32 %29, %28
store i32 %30, i32* %7
br label %31
31: ; preds = %27, %23
%32 = load i8*, i8** %4
%33 = load i64, i64* %5
%34 = load i32, i32* %7
%35 = call i32 @msync(i8* %32, i64 %33, i32 %34)
ret i32 %35
}

LLVM IR (-O2):
@MS_SYNC = global i32 0
@MS_ASYNC = global i32 0
@MS_INVALIDATE = global i32 0
define i32 @system_io_msync(i8* %0, i64 %1, i32 %2) {
%4 = and i32 %2, 1
%5 = icmp eq i32 %4, 0
%6 = load i32, i32* @MS_SYNC
%7 = select i1 %5, i32 0, i32 %6
%8 = and i32 %2, 2
%9 = icmp eq i32 %8, 0
%10 = load i32, i32* @MS_ASYNC
%11 = select i1 %9, i32 0, i32 %10
%12 = or i32 %11, %7
%13 = and i32 %2, 4
%14 = icmp eq i32 %13, 0
%15 = load i32, i32* @MS_INVALIDATE
%16 = select i1 %14, i32 0, i32 %15
%17 = or i32 %12, %16
%18 = tail call i32 @msync(i8* %0, i64 %1, i32 %17)
ret i32 %18
}