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


x86 assembly (clang, -O0):
<set_gate_m4_clk>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
movq   $0x20c4074,-0x10(%rbp)
02
mov    0x2ebe(%rip),%rax
mov    (%rax),%edx
mov    0x2e8d(%rip),%rax
or     (%rax),%edx
mov    0x2e9c(%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,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
and    $0xfff,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rcx
or     $0xc,%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rdi
mov    $0x1000,%esi
call   1040 <munmap@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_gate_m4_clk>:
push   %rax
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    $0x20c4000,%r9d
xor    %edi,%edi
call   1030 <mmap@plt>
orb    $0xc,0x74(%rax)
mov    $0x1000,%esi
mov    %rax,%rdi
pop    %rax
jmp    1040 <munmap@plt>

LLVM IR (-O0):
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
define void @set_gate_m4_clk(i32 %0) {
%2 = alloca i32
%3 = alloca i64
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i8*
store i32 %0, i32* %2
store i64 34357364, 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** %5
%15 = load i8*, i8** %5
%16 = load i64, i64* %3
%17 = and i64 %16, 4095
%18 = getelementptr inbounds i8, i8* %15, i64 %17
store i8* %18, i8** %6
%19 = load i8*, i8** %6
%20 = bitcast i8* %19 to i64*
%21 = load i64, i64* %20
store i64 %21, i64* %4
%22 = load i64, i64* %4
%23 = or i64 %22, 12
%24 = load i8*, i8** %6
%25 = bitcast i8* %24 to i64*
store i64 %23, i64* %25
%26 = load i8*, i8** %5
%27 = call i32 @munmap(i8* %26, i64 4096)
ret void
}

LLVM IR (-O2):
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
define void @set_gate_m4_clk(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 34357248)
%7 = getelementptr inbounds i8, i8* %6, i64 116
%8 = bitcast i8* %7 to i64*
%9 = load i64, i64* %8
%10 = or i64 %9, 12
store i64 %10, i64* %8
%11 = tail call i32 @munmap(i8* %6, i64 4096)
ret void
}