#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_PRIVATE;
int PROT_EXEC;
int PROT_READ;
int PROT_WRITE;
int /*<<< orphan*/ memset(void *, int /*<<< orphan*/, size_t);
void *mmap(int /*<<< orphan*/, size_t, int, int, int, int /*<<< orphan*/);
void *create_section_rwx(size_t len) {
  void *addr = mmap(0, len, PROT_READ | PROT_WRITE | PROT_EXEC,
                    MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
  memset(addr, 0, len);
  return addr;
}


x86 assembly (clang, -O0):
<create_section_rwx>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rsi
mov    0x2ec1(%rip),%rax
mov    (%rax),%edx
mov    0x2e88(%rip),%rax
or     (%rax),%edx
mov    0x2e8f(%rip),%rax
or     (%rax),%edx
mov    0x2e6e(%rip),%rax
mov    (%rax),%ecx
mov    0x2e85(%rip),%rax
or     (%rax),%ecx
xor    %r9d,%r9d
mov    $0xffffffff,%r8d
mov    %r9d,%edi
call   1030 <mmap@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rdx
xor    %esi,%esi
call   1040 <memset@plt>
mov    -0x10(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_section_rwx>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    0x2eca(%rip),%rax
mov    0x2e93(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2e98(%rip),%rax
or     (%rax),%edx
mov    0x2e77(%rip),%rax
mov    0x2e90(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
xor    %edi,%edi
mov    %r14,%rsi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,%rbx
mov    %rax,%rdi
xor    %esi,%esi
mov    %r14,%rdx
call   1040 <memset@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@PROT_EXEC = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_ANONYMOUS = global i32 0
define i8* @create_section_rwx(i64 %0) {
%2 = alloca i64
%3 = alloca i8*
store i64 %0, i64* %2
%4 = load i64, i64* %2
%5 = load i32, i32* @PROT_READ
%6 = load i32, i32* @PROT_WRITE
%7 = or i32 %5, %6
%8 = load i32, i32* @PROT_EXEC
%9 = or i32 %7, %8
%10 = load i32, i32* @MAP_PRIVATE
%11 = load i32, i32* @MAP_ANONYMOUS
%12 = or i32 %10, %11
%13 = call i8* @mmap(i32 0, i64 %4, i32 %9, i32 %12, i32 -1, i32 0)
store i8* %13, i8** %3
%14 = load i8*, i8** %3
%15 = load i64, i64* %2
%16 = call i32 @memset(i8* %14, i32 0, i64 %15)
%17 = load i8*, i8** %3
ret i8* %17
}

LLVM IR (-O2):
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@PROT_EXEC = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_ANONYMOUS = global i32 0
define i8* @create_section_rwx(i64 %0) {
%2 = load i32, i32* @PROT_READ
%3 = load i32, i32* @PROT_WRITE
%4 = or i32 %3, %2
%5 = load i32, i32* @PROT_EXEC
%6 = or i32 %4, %5
%7 = load i32, i32* @MAP_PRIVATE
%8 = load i32, i32* @MAP_ANONYMOUS
%9 = or i32 %8, %7
%10 = tail call i8* @mmap(i32 0, i64 %0, i32 %6, i32 %9, i32 -1, i32 0)
%11 = tail call i32 @memset(i8* %10, i32 0, i64 %0)
ret i8* %10
}