#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 MAP_ANONYMOUS;
int MAP_FIXED;
int MAP_GROWSDOWN;
int MAP_LOCKED;
int MAP_NONBLOCK;
int MAP_NORESERVE;
int MAP_POPULATE;
int MAP_PRIVATE;
int MAP_SHARED;
int mips_change_flags(int flags) {
  int mipsflags = 0;
  if (flags & 0x01)
    mipsflags |= MAP_SHARED;
  if (flags & 0x02)
    mipsflags |= MAP_PRIVATE;
  if (flags & 0x20)
    mipsflags |= MAP_ANONYMOUS;
  if (flags & 0x10)
    mipsflags |= MAP_FIXED;
  if (flags & 0x0100)
    mipsflags |= MAP_GROWSDOWN;
  if (flags & 0x2000)
    mipsflags |= MAP_LOCKED;
  if (flags & 0x10000)
    mipsflags |= MAP_NONBLOCK;
  if (flags & 0x4000)
    mipsflags |= MAP_NORESERVE;
  if (flags & 0x8000)
    mipsflags |= MAP_POPULATE;
  return mipsflags;
}


x86 assembly (clang, -O0):
<mips_change_flags>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x4(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     112c <mips_change_flags+0x2c>
mov    0x2ec4(%rip),%rax
mov    (%rax),%eax
or     -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%eax
and    $0x2,%eax
cmp    $0x0,%eax
je     114a <mips_change_flags+0x4a>
mov    0x2e6e(%rip),%rax
mov    (%rax),%eax
or     -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%eax
and    $0x20,%eax
cmp    $0x0,%eax
je     1168 <mips_change_flags+0x68>
mov    0x2e70(%rip),%rax
mov    (%rax),%eax
or     -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%eax
and    $0x10,%eax
cmp    $0x0,%eax
je     1186 <mips_change_flags+0x86>
mov    0x2e2a(%rip),%rax
mov    (%rax),%eax
or     -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%eax
and    $0x100,%eax
cmp    $0x0,%eax
je     11a6 <mips_change_flags+0xa6>
mov    0x2e02(%rip),%rax
mov    (%rax),%eax
or     -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%eax
and    $0x2000,%eax
cmp    $0x0,%eax
je     11c6 <mips_change_flags+0xc6>
mov    0x2dfa(%rip),%rax
mov    (%rax),%eax
or     -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%eax
and    $0x10000,%eax
cmp    $0x0,%eax
je     11e6 <mips_change_flags+0xe6>
mov    0x2e12(%rip),%rax
mov    (%rax),%eax
or     -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%eax
and    $0x4000,%eax
cmp    $0x0,%eax
je     1206 <mips_change_flags+0x106>
mov    0x2dda(%rip),%rax
mov    (%rax),%eax
or     -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%eax
and    $0x8000,%eax
cmp    $0x0,%eax
je     1226 <mips_change_flags+0x126>
mov    0x2daa(%rip),%rax
mov    (%rax),%eax
or     -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<mips_change_flags>:
movd   %edi,%xmm0
pshufd $0x0,%xmm0,%xmm0
movdqa 0xeef(%rip),%xmm1
pand   %xmm0,%xmm1
pand   0xef3(%rip),%xmm0
pxor   %xmm2,%xmm2
pcmpeqd %xmm2,%xmm0
pcmpeqd %xmm2,%xmm1
packssdw %xmm0,%xmm1
packsswb %xmm1,%xmm1
pmovmskb %xmm1,%edx
xor    %r8d,%r8d
mov    $0x0,%eax
test   $0x80,%dl
jne    114b <mips_change_flags+0x4b>
mov    0x2e67(%rip),%rax
mov    (%rax),%eax
mov    $0x0,%r11d
test   $0x40,%dl
jne    1160 <mips_change_flags+0x60>
mov    0x2e73(%rip),%rcx
mov    (%rcx),%r11d
and    $0x1,%edi
mov    $0x0,%r9d
test   $0x20,%dl
jne    1178 <mips_change_flags+0x78>
mov    0x2e33(%rip),%rcx
mov    (%rcx),%r9d
neg    %edi
mov    0x2e67(%rip),%r10
mov    $0x0,%ecx
test   $0x10,%dl
jne    1194 <mips_change_flags+0x94>
mov    0x2e0e(%rip),%rcx
mov    (%rcx),%ecx
and    (%r10),%edi
mov    $0x0,%esi
test   $0x8,%dl
jne    11aa <mips_change_flags+0xaa>
mov    0x2e10(%rip),%rsi
mov    (%rsi),%esi
or     %esi,%ecx
or     %edi,%eax
or     %r9d,%r11d
mov    $0x0,%esi
test   $0x4,%dl
jne    11c4 <mips_change_flags+0xc4>
mov    0x2e2e(%rip),%rsi
mov    (%rsi),%esi
or     %esi,%ecx
or     %r11d,%eax
mov    $0x0,%esi
test   $0x2,%dl
jne    11dc <mips_change_flags+0xdc>
mov    0x2dfe(%rip),%rsi
mov    (%rsi),%esi
or     %ecx,%eax
test   $0x1,%dl
jne    11ed <mips_change_flags+0xed>
mov    0x2dde(%rip),%rcx
mov    (%rcx),%r8d
or     %r8d,%esi
or     %esi,%eax
ret

LLVM IR (-O0):
@MAP_SHARED = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_ANONYMOUS = global i32 0
@MAP_FIXED = global i32 0
@MAP_GROWSDOWN = global i32 0
@MAP_LOCKED = global i32 0
@MAP_NONBLOCK = global i32 0
@MAP_NORESERVE = global i32 0
@MAP_POPULATE = global i32 0
define i32 @mips_change_flags(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %3
%4 = load i32, i32* %2
%5 = and i32 %4, 1
%6 = icmp ne i32 %5, 0
br i1 %6, label %7, label %11
7: ; preds = %1
%8 = load i32, i32* @MAP_SHARED
%9 = load i32, i32* %3
%10 = or i32 %9, %8
store i32 %10, i32* %3
br label %11
11: ; preds = %7, %1
%12 = load i32, i32* %2
%13 = and i32 %12, 2
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %11
%16 = load i32, i32* @MAP_PRIVATE
%17 = load i32, i32* %3
%18 = or i32 %17, %16
store i32 %18, i32* %3
br label %19
19: ; preds = %15, %11
%20 = load i32, i32* %2
%21 = and i32 %20, 32
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %27
23: ; preds = %19
%24 = load i32, i32* @MAP_ANONYMOUS
%25 = load i32, i32* %3
%26 = or i32 %25, %24
store i32 %26, i32* %3
br label %27
27: ; preds = %23, %19
%28 = load i32, i32* %2
%29 = and i32 %28, 16
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %35
31: ; preds = %27
%32 = load i32, i32* @MAP_FIXED
%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* %2
%37 = and i32 %36, 256
%38 = icmp ne i32 %37, 0
br i1 %38, label %39, label %43
39: ; preds = %35
%40 = load i32, i32* @MAP_GROWSDOWN
%41 = load i32, i32* %3
%42 = or i32 %41, %40
store i32 %42, i32* %3
br label %43
43: ; preds = %39, %35
%44 = load i32, i32* %2
%45 = and i32 %44, 8192
%46 = icmp ne i32 %45, 0
br i1 %46, label %47, label %51
47: ; preds = %43
%48 = load i32, i32* @MAP_LOCKED
%49 = load i32, i32* %3
%50 = or i32 %49, %48
store i32 %50, i32* %3
br label %51
51: ; preds = %47, %43
%52 = load i32, i32* %2
%53 = and i32 %52, 65536
%54 = icmp ne i32 %53, 0
br i1 %54, label %55, label %59
55: ; preds = %51
%56 = load i32, i32* @MAP_NONBLOCK
%57 = load i32, i32* %3
%58 = or i32 %57, %56
store i32 %58, i32* %3
br label %59
59: ; preds = %55, %51
%60 = load i32, i32* %2
%61 = and i32 %60, 16384
%62 = icmp ne i32 %61, 0
br i1 %62, label %63, label %67
63: ; preds = %59
%64 = load i32, i32* @MAP_NORESERVE
%65 = load i32, i32* %3
%66 = or i32 %65, %64
store i32 %66, i32* %3
br label %67
67: ; preds = %63, %59
%68 = load i32, i32* %2
%69 = and i32 %68, 32768
%70 = icmp ne i32 %69, 0
br i1 %70, label %71, label %75
71: ; preds = %67
%72 = load i32, i32* @MAP_POPULATE
%73 = load i32, i32* %3
%74 = or i32 %73, %72
store i32 %74, i32* %3
br label %75
75: ; preds = %71, %67
%76 = load i32, i32* %3
ret i32 %76
}

LLVM IR (-O2):
@MAP_SHARED = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_ANONYMOUS = global i32 0
@MAP_FIXED = global i32 0
@MAP_GROWSDOWN = global i32 0
@MAP_LOCKED = global i32 0
@MAP_NONBLOCK = global i32 0
@MAP_NORESERVE = global i32 0
@MAP_POPULATE = global i32 0
define i32 @mips_change_flags(i32 %0) {
%2 = and i32 %0, 1
%3 = icmp eq i32 %2, 0
%4 = load i32, i32* @MAP_SHARED
%5 = select i1 %3, i32 0, i32 %4
%6 = load i32, i32* @MAP_PRIVATE
%7 = insertelement <8 x i32> poison, i32 %0, i64 0
%8 = shufflevector <8 x i32> %7, <8 x i32> poison, <8 x i32> zeroinitializer
%9 = and <8 x i32> %8, <i32 32768, i32 16384, i32 65536, i32 8192, i32 256, i32 16, i32 32, i32 2>
%10 = icmp eq <8 x i32> %9, zeroinitializer
%11 = extractelement <8 x i1> %10, i64 7
%12 = select i1 %11, i32 0, i32 %6
%13 = or i32 %12, %5
%14 = load i32, i32* @MAP_ANONYMOUS
%15 = extractelement <8 x i1> %10, i64 6
%16 = select i1 %15, i32 0, i32 %14
%17 = or i32 %13, %16
%18 = load i32, i32* @MAP_FIXED
%19 = extractelement <8 x i1> %10, i64 5
%20 = select i1 %19, i32 0, i32 %18
%21 = or i32 %17, %20
%22 = load i32, i32* @MAP_GROWSDOWN
%23 = extractelement <8 x i1> %10, i64 4
%24 = select i1 %23, i32 0, i32 %22
%25 = or i32 %21, %24
%26 = load i32, i32* @MAP_LOCKED
%27 = extractelement <8 x i1> %10, i64 3
%28 = select i1 %27, i32 0, i32 %26
%29 = or i32 %25, %28
%30 = load i32, i32* @MAP_NONBLOCK
%31 = extractelement <8 x i1> %10, i64 2
%32 = select i1 %31, i32 0, i32 %30
%33 = or i32 %29, %32
%34 = load i32, i32* @MAP_NORESERVE
%35 = extractelement <8 x i1> %10, i64 1
%36 = select i1 %35, i32 0, i32 %34
%37 = or i32 %33, %36
%38 = load i32, i32* @MAP_POPULATE
%39 = extractelement <8 x i1> %10, i64 0
%40 = select i1 %39, i32 0, i32 %38
%41 = or i32 %37, %40
ret i32 %41
}