#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*/ IRQEnable;

/* Variables and functions */
int /*<<< orphan*/ MAP_SHARED;
int /*<<< orphan*/ O_RDWR;
int PROT_READ;
int PROT_WRITE;
int /*<<< orphan*/ _SC_PAGESIZE;
int /*<<< orphan*/ fclose(int /*<<< orphan*/);
void *mmap(int /*<<< orphan*/ *, unsigned int, int, int /*<<< orphan*/, int,
           int);
int /*<<< orphan*/ munmap(void *, unsigned int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ read(int, int *, int);
int /*<<< orphan*/ stdout;
unsigned int sysconf(int /*<<< orphan*/);
int /*<<< orphan*/ write(int, int *, int);
int main(int argc, char *argv[]) {
  int fd_src = open("/dev/uio0", O_RDWR);
  if (fd_src < 1) {
    perror("Error open /dev/uio0/");
    return -1;
  }
  int fd_dst = open("/dev/mem", O_RDWR);
  if (fd_dst < 1) {
    perror("Error open /dev/mem/");
    return -1;
  }
  unsigned pageSize = sysconf(_SC_PAGESIZE);
  void *ptr_src;
  ptr_src = mmap(NULL, pageSize, PROT_READ | PROT_WRITE, MAP_SHARED, fd_src, 0);
  void *ptr_dst;
  ptr_dst = mmap(NULL, pageSize, PROT_READ | PROT_WRITE, MAP_SHARED, fd_dst,
                 0x43C20000);
  int IRQEnable = 1;
  write(fd_src, &IRQEnable, sizeof(IRQEnable));
  while (1) {
    read(fd_src, &IRQEnable, sizeof(IRQEnable));
    *((unsigned *)(ptr_dst + 0)) = *((unsigned *)(ptr_src + 0));
    *((unsigned *)(ptr_dst + 4)) = *((unsigned *)(ptr_src + 4));
    int IRQEnable = 1;
    write(fd_src, &IRQEnable, sizeof(IRQEnable));
  }
  munmap(ptr_src, pageSize);
  munmap(ptr_dst, pageSize);
  fclose(stdout);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e5b(%rip),%rax
mov    (%rax),%esi
lea    0xe7a(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x1,-0x14(%rbp)
jge    11b0 <main+0x50>
lea    0xe6b(%rip),%rdi
call   1070 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12c2 <main+0x162>
mov    0x2e21(%rip),%rax
mov    (%rax),%esi
lea    0xe60(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x1,-0x18(%rbp)
jge    11ea <main+0x8a>
lea    0xe50(%rip),%rdi
call   1070 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12c2 <main+0x162>
mov    0x2ddf(%rip),%rax
mov    (%rax),%edi
call   1080 <sysconf@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%esi
mov    0x2df3(%rip),%rax
mov    (%rax),%edx
mov    0x2db2(%rip),%rax
or     (%rax),%edx
mov    0x2dd1(%rip),%rax
mov    (%rax),%ecx
mov    -0x14(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
xor    %r9d,%r9d
call   1040 <mmap@plt>
mov    %rax,-0x28(%rbp)
mov    -0x1c(%rbp),%esi
mov    0x2dc1(%rip),%rax
mov    (%rax),%edx
mov    0x2d80(%rip),%rax
or     (%rax),%edx
mov    0x2d9f(%rip),%rax
mov    (%rax),%ecx
mov    -0x18(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
mov    $0x43c20000,%r9d
call   1040 <mmap@plt>
mov    %rax,-0x30(%rbp)
movl   $0x1,-0x34(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x34(%rbp),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
mov    -0x14(%rbp),%edi
lea    -0x34(%rbp),%rsi
mov    $0x4,%edx
call   1050 <read@plt>
mov    -0x28(%rbp),%rax
mov    (%rax),%ecx
mov    -0x30(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x28(%rbp),%rax
mov    0x4(%rax),%ecx
mov    -0x30(%rbp),%rax
mov    %ecx,0x4(%rax)
movl   $0x1,-0x38(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x38(%rbp),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
jmp    127a <main+0x11a>
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    0x2e66(%rip),%rbx
mov    (%rbx),%esi
lea    0xe85(%rip),%rdi
call   1060 <open@plt>
test   %eax,%eax
jle    1264 <main+0x104>
mov    %eax,%r15d
mov    (%rbx),%esi
lea    0xe8c(%rip),%rdi
call   1060 <open@plt>
test   %eax,%eax
jle    126d <main+0x10d>
mov    %eax,%r14d
mov    0x2e25(%rip),%rax
mov    (%rax),%edi
call   1080 <sysconf@plt>
mov    %eax,%ebp
mov    0x2e3d(%rip),%rax
mov    0x2dfe(%rip),%r13
mov    0x0(%r13),%edx
or     (%rax),%edx
mov    0x2e19(%rip),%r12
mov    (%r12),%ecx
xor    %edi,%edi
mov    %ebp,%esi
mov    %r15d,%r8d
xor    %r9d,%r9d
call   1040 <mmap@plt>
mov    %rax,%rbx
mov    0x0(%r13),%edx
mov    0x2e08(%rip),%rax
or     (%rax),%edx
mov    (%r12),%ecx
xor    %edi,%edi
mov    %ebp,%esi
mov    %r14d,%r8d
mov    $0x43c20000,%r9d
call   1040 <mmap@plt>
mov    %rax,%rbp
movl   $0x1,0x4(%rsp)
lea    0x4(%rsp),%r14
mov    %r15d,%edi
mov    %r14,%rsi
mov    $0x4,%edx
call   1030 <write@plt>
mov    %rsp,%r12
nopl   0x0(%rax,%rax,1)
mov    %r15d,%edi
mov    %r14,%rsi
mov    $0x4,%edx
call   1050 <read@plt>
mov    (%rbx),%eax
mov    %eax,0x0(%rbp)
mov    0x4(%rbx),%eax
mov    %eax,0x4(%rbp)
movl   $0x1,(%rsp)
mov    %r15d,%edi
mov    %r12,%rsi
mov    $0x4,%edx
call   1030 <write@plt>
jmp    1230 <main+0xd0>
lea    0xd9f(%rip),%rdi
jmp    1274 <main+0x114>
lea    0xdb5(%rip),%rdi
call   1070 <perror@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"/dev/uio0\00"
@O_RDWR = global i32 0
@.str.1 = [22 x i8] c"Error open /dev/uio0/\00"
@.str.2 = [9 x i8] c"/dev/mem\00"
@.str.3 = [21 x i8] c"Error open /dev/mem/\00"
@_SC_PAGESIZE = global i32 0
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@stdout = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i32, i32* @O_RDWR
%14 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %13)
store i32 %14, i32* %6
%15 = load i32, i32* %6
%16 = icmp slt i32 %15, 1
br i1 %16, label %17, label %19
17: ; preds = %2
%18 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %64
19: ; preds = %2
%20 = load i32, i32* @O_RDWR
%21 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %20)
store i32 %21, i32* %7
%22 = load i32, i32* %7
%23 = icmp slt i32 %22, 1
br i1 %23, label %24, label %26
24: ; preds = %19
%25 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %3
br label %64
26: ; preds = %19
%27 = load i32, i32* @_SC_PAGESIZE
%28 = call i32 @sysconf(i32 %27)
store i32 %28, i32* %8
%29 = load i32, i32* %8
%30 = load i32, i32* @PROT_READ
%31 = load i32, i32* @PROT_WRITE
%32 = or i32 %30, %31
%33 = load i32, i32* @MAP_SHARED
%34 = load i32, i32* %6
%35 = call i8* @mmap(i32* null, i32 %29, i32 %32, i32 %33, i32 %34, i32 0)
store i8* %35, i8** %9
%36 = load i32, i32* %8
%37 = load i32, i32* @PROT_READ
%38 = load i32, i32* @PROT_WRITE
%39 = or i32 %37, %38
%40 = load i32, i32* @MAP_SHARED
%41 = load i32, i32* %7
%42 = call i8* @mmap(i32* null, i32 %36, i32 %39, i32 %40, i32 %41, i32 1136787456)
store i8* %42, i8** %10
store i32 1, i32* %11
%43 = load i32, i32* %6
%44 = call i32 @write(i32 %43, i32* %11, i32 4)
br label %45
45: ; preds = %26, %45
%46 = load i32, i32* %6
%47 = call i32 @read(i32 %46, i32* %11, i32 4)
%48 = load i8*, i8** %9
%49 = getelementptr i8, i8* %48, i64 0
%50 = bitcast i8* %49 to i32*
%51 = load i32, i32* %50
%52 = load i8*, i8** %10
%53 = getelementptr i8, i8* %52, i64 0
%54 = bitcast i8* %53 to i32*
store i32 %51, i32* %54
%55 = load i8*, i8** %9
%56 = getelementptr i8, i8* %55, i64 4
%57 = bitcast i8* %56 to i32*
%58 = load i32, i32* %57
%59 = load i8*, i8** %10
%60 = getelementptr i8, i8* %59, i64 4
%61 = bitcast i8* %60 to i32*
store i32 %58, i32* %61
store i32 1, i32* %12
%62 = load i32, i32* %6
%63 = call i32 @write(i32 %62, i32* %12, i32 4)
br label %45
64: ; preds = %24, %17
%65 = load i32, i32* %3
ret i32 %65
}

LLVM IR (-O2):
@.str = [10 x i8] c"/dev/uio0\00"
@O_RDWR = global i32 0
@.str.1 = [22 x i8] c"Error open /dev/uio0/\00"
@.str.2 = [9 x i8] c"/dev/mem\00"
@.str.3 = [21 x i8] c"Error open /dev/mem/\00"
@_SC_PAGESIZE = global i32 0
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@stdout = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca i32
%5 = load i32, i32* @O_RDWR
%6 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = icmp slt i32 %6, 1
br i1 %7, label %39, label %8
8: ; preds = %2
%9 = load i32, i32* @O_RDWR
%10 = tail call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %9)
%11 = icmp slt i32 %10, 1
br i1 %11, label %39, label %12
12: ; preds = %8
%13 = load i32, i32* @_SC_PAGESIZE
%14 = tail call i32 @sysconf(i32 %13)
%15 = load i32, i32* @PROT_READ
%16 = load i32, i32* @PROT_WRITE
%17 = or i32 %16, %15
%18 = load i32, i32* @MAP_SHARED
%19 = tail call i8* @mmap(i32* null, i32 %14, i32 %17, i32 %18, i32 %6, i32 0)
%20 = load i32, i32* @PROT_READ
%21 = load i32, i32* @PROT_WRITE
%22 = or i32 %21, %20
%23 = load i32, i32* @MAP_SHARED
%24 = tail call i8* @mmap(i32* null, i32 %14, i32 %22, i32 %23, i32 %10, i32 1136787456)
%25 = bitcast i32* %3 to i8*
store i32 1, i32* %3
%26 = call i32 @write(i32 %6, i32* %3, i32 4)
%27 = bitcast i8* %19 to i32*
%28 = bitcast i8* %24 to i32*
%29 = getelementptr i8, i8* %19, i64 4
%30 = bitcast i8* %29 to i32*
%31 = getelementptr i8, i8* %24, i64 4
%32 = bitcast i8* %31 to i32*
%33 = bitcast i32* %4 to i8*
br label %34
34: ; preds = %34, %12
%35 = call i32 @read(i32 %6, i32* %3, i32 4)
%36 = load i32, i32* %27
store i32 %36, i32* %28
%37 = load i32, i32* %30
store i32 %37, i32* %32
store i32 1, i32* %4
%38 = call i32 @write(i32 %6, i32* %4, i32 4)
br label %34
39: ; preds = %8, %2
%40 = phi i8* [ getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), %2 ], [ getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), %8 ]
%41 = tail call i32 @perror(i8* %40)
ret i32 -1
}