#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);
int get_m4_trace_flag(int fd) {
  off_t target;
  void *map_base, *virt_addr;
  int value;
  target = 0xbff0fff4;
  map_base = mmap(0, 4096UL, PROT_READ | PROT_WRITE, MAP_SHARED, fd,
                  target & ~(4096UL - 1));
  virt_addr = (unsigned char *)map_base + (target & (4096UL - 1));
  value = *((int *)virt_addr);
  munmap(map_base, 4096UL);
  return (value);
}


x86 assembly (clang, -O0):
<get_m4_trace_flag>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    $0xbff0fff4,%eax
mov    %rax,-0x10(%rbp)
mov    0x2ebd(%rip),%rax
mov    (%rax),%edx
mov    0x2e8c(%rip),%rax
or     (%rax),%edx
mov    0x2e9b(%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    -0x20(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x1000,%esi
call   1040 <munmap@plt>
mov    -0x24(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_m4_trace_flag>:
push   %rbx
mov    %edi,%r8d
mov    0x2ecd(%rip),%rax
mov    0x2e9e(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2eab(%rip),%rax
mov    (%rax),%ecx
mov    $0x1000,%esi
mov    $0xbff0f000,%r9d
xor    %edi,%edi
call   1030 <mmap@plt>
mov    0xff4(%rax),%ebx
mov    $0x1000,%esi
mov    %rax,%rdi
call   1040 <munmap@plt>
mov    %ebx,%eax
pop    %rbx
ret

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

LLVM IR (-O2):
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
define i32 @get_m4_trace_flag(i32 %0) {
%2 = load i32, i32* @PROT_READ
%3 = load i32, i32* @PROT_WRITE
%4 = or i32 %3, %2
%5 = load i32, i32* @MAP_SHARED
%6 = tail call i8* @mmap(i32 0, i64 4096, i32 %4, i32 %5, i32 %0, i64 3220238336)
%7 = getelementptr inbounds i8, i8* %6, i64 4084
%8 = bitcast i8* %7 to i32*
%9 = load i32, i32* %8
%10 = tail call i32 @munmap(i8* %6, i64 4096)
ret i32 %9
}