#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 int /*<<< orphan*/ uint8_t;
typedef int uint32_t;

/* Variables and functions */
int /*<<< orphan*/ *MAP_FAILED;
int /*<<< orphan*/ MAP_SHARED;
int PROT_READ;
int PROT_WRITE;
int /*<<< orphan*/ *mmap(int /*<<< orphan*/ *, int, int, int /*<<< orphan*/,
                         int, int);
int munmap(int /*<<< orphan*/ *, int);
int pwm_iclken_clock(int mem_fd) {
  int page_addr = 0x48004A10 & 0xfffff000;
  int offset = 0x48004A10 & 0xfff;
  uint8_t *registers =
      mmap(NULL, 4096, PROT_READ | PROT_WRITE, MAP_SHARED, mem_fd, page_addr);
  if (registers == MAP_FAILED)
    return -1;
  uint32_t value = *((volatile uint32_t *)(registers + offset));
  *((volatile uint32_t *)(registers + offset)) = value | (1 << 16);
  return munmap(registers, 4096);
}


x86 assembly (clang, -O0):
<pwm_iclken_clock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
movl   $0x48004000,-0xc(%rbp)
movl   $0xa10,-0x10(%rbp)
mov    0x2eb8(%rip),%rax
mov    (%rax),%edx
mov    0x2e87(%rip),%rax
or     (%rax),%edx
mov    0x2e96(%rip),%rax
mov    (%rax),%ecx
mov    -0x8(%rbp),%r8d
mov    -0xc(%rbp),%r9d
xor    %eax,%eax
mov    %eax,%edi
mov    $0x1000,%esi
call   1030 <mmap@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    0x2e4f(%rip),%rcx
cmp    (%rcx),%rax
jne    118e <pwm_iclken_clock+0x6e>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c1 <pwm_iclken_clock+0xa1>
mov    -0x18(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edx
or     $0x10000,%edx
mov    -0x18(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x18(%rbp),%rdi
mov    $0x1000,%esi
call   1040 <munmap@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pwm_iclken_clock>:
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
xor    %edi,%edi
mov    $0x1000,%esi
mov    $0x48004000,%r9d
call   1030 <mmap@plt>
mov    0x2e70(%rip),%rcx
cmp    (%rcx),%rax
je     1175 <pwm_iclken_clock+0x55>
orl    $0x10000,0x2840(%rax)
mov    %rax,%rdi
mov    $0x1000,%esi
pop    %rax
jmp    1040 <munmap@plt>
mov    $0xffffffff,%eax
pop    %rcx
ret

LLVM IR (-O0):
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i32* null
define i32 @pwm_iclken_clock(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
store i32 %0, i32* %3
store i32 1207975936, i32* %4
store i32 2576, i32* %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 i32, i32* %4
%14 = call i32* @mmap(i32* null, i32 4096, i32 %10, i32 %11, i32 %12, i32 %13)
store i32* %14, i32** %6
%15 = load i32*, i32** %6
%16 = load i32*, i32** @MAP_FAILED
%17 = icmp eq i32* %15, %16
br i1 %17, label %18, label %19
18: ; preds = %1
store i32 -1, i32* %2
br label %33
19: ; preds = %1
%20 = load i32*, i32** %6
%21 = load i32, i32* %5
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i32, i32* %20, i64 %22
%24 = load volatile i32, i32* %23
store i32 %24, i32* %7
%25 = load i32, i32* %7
%26 = or i32 %25, 65536
%27 = load i32*, i32** %6
%28 = load i32, i32* %5
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i32, i32* %27, i64 %29
store volatile i32 %26, i32* %30
%31 = load i32*, i32** %6
%32 = call i32 @munmap(i32* %31, i32 4096)
store i32 %32, i32* %2
br label %33
33: ; preds = %19, %18
%34 = load i32, i32* %2
ret i32 %34
}

LLVM IR (-O2):
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i32* null
define i32 @pwm_iclken_clock(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 i32* @mmap(i32* null, i32 4096, i32 %4, i32 %5, i32 %0, i32 1207975936)
%7 = load i32*, i32** @MAP_FAILED
%8 = icmp eq i32* %6, %7
br i1 %8, label %14, label %9
9: ; preds = %1
%10 = getelementptr inbounds i32, i32* %6, i64 2576
%11 = load volatile i32, i32* %10
%12 = or i32 %11, 65536
store volatile i32 %12, i32* %10
%13 = tail call i32 @munmap(i32* %6, i32 4096)
br label %14
14: ; preds = %1, %9
%15 = phi i32 [ %13, %9 ], [ -1, %1 ]
ret i32 %15
}