#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;
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);
unsigned int sysconf(int /*<<< orphan*/);
int /*<<< orphan*/ write(int, int *, int);
void *copy_thread() {
  int fd_src = open("/dev/uio0", O_RDWR);
  if (fd_src < 1) {
    perror("Error open /dev/uio0/");
  }
  int fd_dst1 = open("/dev/mem", O_RDWR);
  if (fd_dst1 < 1) {
    perror("Error open /dev/mem/");
  }
  unsigned pageSize = sysconf(_SC_PAGESIZE);
  void *ptr_src;
  ptr_src = mmap(NULL, pageSize, PROT_READ | PROT_WRITE, MAP_SHARED, fd_src, 0);
  void *ptr_dst1;
  ptr_dst1 = mmap(NULL, pageSize, PROT_READ | PROT_WRITE, MAP_SHARED, fd_dst1,
                  0x43C20000);
  int IRQEnable = 1;
  write(fd_src, &IRQEnable, sizeof(IRQEnable));
  while (1) {
    read(fd_src, &IRQEnable, sizeof(IRQEnable));
    *((unsigned *)(ptr_dst1 + 0)) = *((unsigned *)(ptr_src + 0));
    *((unsigned *)(ptr_dst1 + 4)) = *((unsigned *)(ptr_src + 4));
    int IRQEnable = 1;
    write(fd_src, &IRQEnable, sizeof(IRQEnable));
  }
  munmap(ptr_src, pageSize);
  munmap(ptr_dst1, pageSize);
}


x86 assembly (clang, -O0):
<copy_thread>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    0x2e69(%rip),%rax
mov    (%rax),%esi
lea    0xe88(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x1,-0x4(%rbp)
jge    1196 <copy_thread+0x36>
lea    0xe79(%rip),%rdi
call   1070 <perror@plt>
mov    0x2e3b(%rip),%rax
mov    (%rax),%esi
lea    0xe7a(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x1,-0x8(%rbp)
jge    11c4 <copy_thread+0x64>
lea    0xe6a(%rip),%rdi
call   1070 <perror@plt>
mov    0x2e05(%rip),%rax
mov    (%rax),%edi
call   1080 <sysconf@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%esi
mov    0x2e19(%rip),%rax
mov    (%rax),%edx
mov    0x2dd8(%rip),%rax
or     (%rax),%edx
mov    0x2df7(%rip),%rax
mov    (%rax),%ecx
mov    -0x4(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
xor    %r9d,%r9d
call   1040 <mmap@plt>
mov    %rax,-0x18(%rbp)
mov    -0xc(%rbp),%esi
mov    0x2de7(%rip),%rax
mov    (%rax),%edx
mov    0x2da6(%rip),%rax
or     (%rax),%edx
mov    0x2dc5(%rip),%rax
mov    (%rax),%ecx
mov    -0x8(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
mov    $0x43c20000,%r9d
call   1040 <mmap@plt>
mov    %rax,-0x20(%rbp)
movl   $0x1,-0x24(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x24(%rbp),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
mov    -0x4(%rbp),%edi
lea    -0x24(%rbp),%rsi
mov    $0x4,%edx
call   1050 <read@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
mov    0x4(%rax),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,0x4(%rax)
movl   $0x1,-0x28(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
jmp    1254 <copy_thread+0xf4>

x86 assembly (clang, -O2):
<copy_thread>:
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>
mov    %eax,%r15d
test   %eax,%eax
jle    1264 <copy_thread+0x104>
mov    (%rbx),%esi
lea    0xe8c(%rip),%rdi
call   1060 <open@plt>
mov    %eax,%r14d
test   %eax,%eax
jle    1275 <copy_thread+0x115>
mov    0x2e25(%rip),%rax
mov    (%rax),%edi
call   1080 <sysconf@plt>
mov    %eax,%ebx
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    %ebx,%esi
mov    %r15d,%r8d
xor    %r9d,%r9d
call   1040 <mmap@plt>
mov    %rax,%rbp
mov    0x0(%r13),%edx
mov    0x2e08(%rip),%rax
or     (%rax),%edx
mov    (%r12),%ecx
xor    %edi,%edi
mov    %ebx,%esi
mov    %r14d,%r8d
mov    $0x43c20000,%r9d
call   1040 <mmap@plt>
mov    %rax,%rbx
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    0x0(%rbp),%eax
mov    %eax,(%rbx)
mov    0x4(%rbp),%eax
mov    %eax,0x4(%rbx)
movl   $0x1,(%rsp)
mov    %r15d,%edi
mov    %r12,%rsi
mov    $0x4,%edx
call   1030 <write@plt>
jmp    1230 <copy_thread+0xd0>
lea    0xd9f(%rip),%rdi
call   1070 <perror@plt>
jmp    118b <copy_thread+0x2b>
lea    0xdad(%rip),%rdi
call   1070 <perror@plt>
jmp    11a4 <copy_thread+0x44>

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
define i8* @copy_thread() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = load i32, i32* @O_RDWR
%9 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %8)
store i32 %9, i32* %1
%10 = load i32, i32* %1
%11 = icmp slt i32 %10, 1
br i1 %11, label %12, label %14
12: ; preds = %0
%13 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
br label %14
14: ; preds = %12, %0
%15 = load i32, i32* @O_RDWR
%16 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %15)
store i32 %16, i32* %2
%17 = load i32, i32* %2
%18 = icmp slt i32 %17, 1
br i1 %18, label %19, label %21
19: ; preds = %14
%20 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
br label %21
21: ; preds = %19, %14
%22 = load i32, i32* @_SC_PAGESIZE
%23 = call i32 @sysconf(i32 %22)
store i32 %23, i32* %3
%24 = load i32, i32* %3
%25 = load i32, i32* @PROT_READ
%26 = load i32, i32* @PROT_WRITE
%27 = or i32 %25, %26
%28 = load i32, i32* @MAP_SHARED
%29 = load i32, i32* %1
%30 = call i8* @mmap(i32* null, i32 %24, i32 %27, i32 %28, i32 %29, i32 0)
store i8* %30, i8** %4
%31 = load i32, i32* %3
%32 = load i32, i32* @PROT_READ
%33 = load i32, i32* @PROT_WRITE
%34 = or i32 %32, %33
%35 = load i32, i32* @MAP_SHARED
%36 = load i32, i32* %2
%37 = call i8* @mmap(i32* null, i32 %31, i32 %34, i32 %35, i32 %36, i32 1136787456)
store i8* %37, i8** %5
store i32 1, i32* %6
%38 = load i32, i32* %1
%39 = call i32 @write(i32 %38, i32* %6, i32 4)
br label %40
40: ; preds = %21, %40
%41 = load i32, i32* %1
%42 = call i32 @read(i32 %41, i32* %6, i32 4)
%43 = load i8*, i8** %4
%44 = getelementptr i8, i8* %43, i64 0
%45 = bitcast i8* %44 to i32*
%46 = load i32, i32* %45
%47 = load i8*, i8** %5
%48 = getelementptr i8, i8* %47, i64 0
%49 = bitcast i8* %48 to i32*
store i32 %46, i32* %49
%50 = load i8*, i8** %4
%51 = getelementptr i8, i8* %50, i64 4
%52 = bitcast i8* %51 to i32*
%53 = load i32, i32* %52
%54 = load i8*, i8** %5
%55 = getelementptr i8, i8* %54, i64 4
%56 = bitcast i8* %55 to i32*
store i32 %53, i32* %56
store i32 1, i32* %7
%57 = load i32, i32* %1
%58 = call i32 @write(i32 %57, i32* %7, i32 4)
br label %40
}

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
define noalias i8* @copy_thread() {
%1 = alloca i32
%2 = alloca i32
%3 = load i32, i32* @O_RDWR
%4 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp slt i32 %4, 1
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = tail call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
br label %8
8: ; preds = %6, %0
%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 %12, label %14
12: ; preds = %8
%13 = tail call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
br label %14
14: ; preds = %12, %8
%15 = load i32, i32* @_SC_PAGESIZE
%16 = tail call i32 @sysconf(i32 %15)
%17 = load i32, i32* @PROT_READ
%18 = load i32, i32* @PROT_WRITE
%19 = or i32 %18, %17
%20 = load i32, i32* @MAP_SHARED
%21 = tail call i8* @mmap(i32* null, i32 %16, i32 %19, i32 %20, i32 %4, i32 0)
%22 = load i32, i32* @PROT_READ
%23 = load i32, i32* @PROT_WRITE
%24 = or i32 %23, %22
%25 = load i32, i32* @MAP_SHARED
%26 = tail call i8* @mmap(i32* null, i32 %16, i32 %24, i32 %25, i32 %10, i32 1136787456)
%27 = bitcast i32* %1 to i8*
store i32 1, i32* %1
%28 = call i32 @write(i32 %4, i32* %1, i32 4)
%29 = bitcast i8* %21 to i32*
%30 = bitcast i8* %26 to i32*
%31 = getelementptr i8, i8* %21, i64 4
%32 = bitcast i8* %31 to i32*
%33 = getelementptr i8, i8* %26, i64 4
%34 = bitcast i8* %33 to i32*
%35 = bitcast i32* %2 to i8*
br label %36
36: ; preds = %36, %14
%37 = call i32 @read(i32 %4, i32* %1, i32 4)
%38 = load i32, i32* %29
store i32 %38, i32* %30
%39 = load i32, i32* %32
store i32 %39, i32* %34
store i32 1, i32* %2
%40 = call i32 @write(i32 %4, i32* %2, i32 4)
br label %36
}