#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 */
typedef unsigned long off_t;

/* Variables and functions */
int /*<<< orphan*/ MAP_SHARED;
int PROT_READ;
int PROT_WRITE;
void *mmap(int /*<<< orphan*/, unsigned long, int, int /*<<< orphan*/, int,
           unsigned long);
int /*<<< orphan*/ munmap(void *, unsigned long);
void send_m4_stop_flag(int fd, unsigned char value) {
  off_t target;
  void *map_base, *virt_addr;
  target = 0xbff0ffff;
  map_base = mmap(0, 4096UL, PROT_READ | PROT_WRITE, MAP_SHARED, fd,
                  target & ~(4096UL - 1));
  virt_addr = (unsigned char *)map_base + (target & (4096UL - 1));
  *((unsigned char *)virt_addr) = value;
  munmap(map_base, 4096UL);
}


x86 assembly (clang, -O0):
<send_m4_stop_flag>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %sil,%al
mov    %edi,-0x4(%rbp)
mov    %al,-0x5(%rbp)
mov    $0xbff0ffff,%eax
mov    %rax,-0x10(%rbp)
mov    0x2eb7(%rip),%rax
mov    (%rax),%edx
mov    0x2e86(%rip),%rax
or     (%rax),%edx
mov    0x2e95(%rip),%rax
mov    (%rax),%ecx
mov    -0x4(%rbp),%r8d
mov    -0x10(%rbp),%r9
and    $0xfffffffffffff000,%r9
xor    %edi,%edi
mov    $0x1000,%esi
call   1030 <mmap@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
and    $0xfff,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x5(%rbp),%cl
mov    -0x20(%rbp),%rax
mov    %cl,(%rax)
mov    -0x18(%rbp),%rdi
mov    $0x1000,%esi
call   1040 <munmap@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_m4_stop_flag>:
push   %rbx
mov    %esi,%ebx
mov    %edi,%r8d
mov    0x2ecb(%rip),%rax
mov    0x2e9c(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2ea9(%rip),%rax
mov    (%rax),%ecx
mov    $0x1000,%esi
mov    $0xbff0f000,%r9d
xor    %edi,%edi
call   1030 <mmap@plt>
mov    %bl,0xfff(%rax)
mov    $0x1000,%esi
mov    %rax,%rdi
pop    %rbx
jmp    1040 <munmap@plt>

LLVM IR (-O0):
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
define void @send_m4_stop_flag(i32 %0, i8 zeroext %1) {
%3 = alloca i32
%4 = alloca i8
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i8*
store i32 %0, i32* %3
store i8 %1, i8* %4
store i64 3220242431, i64* %5
%8 = load i32, i32* @PROT_READ
%9 = load i32, i32* @PROT_WRITE
%10 = or i32 %8, %9
%11 = load i32, i32* @MAP_SHARED
%12 = load i32, i32* %3
%13 = load i64, i64* %5
%14 = and i64 %13, -4096
%15 = call i8* @mmap(i32 0, i64 4096, i32 %10, i32 %11, i32 %12, i64 %14)
store i8* %15, i8** %6
%16 = load i8*, i8** %6
%17 = load i64, i64* %5
%18 = and i64 %17, 4095
%19 = getelementptr inbounds i8, i8* %16, i64 %18
store i8* %19, i8** %7
%20 = load i8, i8* %4
%21 = load i8*, i8** %7
store i8 %20, i8* %21
%22 = load i8*, i8** %6
%23 = call i32 @munmap(i8* %22, i64 4096)
ret void
}

LLVM IR (-O2):
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
define void @send_m4_stop_flag(i32 %0, i8 zeroext %1) {
%3 = load i32, i32* @PROT_READ
%4 = load i32, i32* @PROT_WRITE
%5 = or i32 %4, %3
%6 = load i32, i32* @MAP_SHARED
%7 = tail call i8* @mmap(i32 0, i64 4096, i32 %5, i32 %6, i32 %0, i64 3220238336)
%8 = getelementptr inbounds i8, i8* %7, i64 4095
store i8 %1, i8* %8
%9 = tail call i32 @munmap(i8* %7, i64 4096)
ret void
}