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

/* Variables and functions */
void *MAP_FAILED;
int /*<<< orphan*/ MAP_SHARED;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ PROT_READ;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ memcpy(unsigned char *, void *, int);
void *mmap(int /*<<< orphan*/ *, int, int /*<<< orphan*/, int /*<<< orphan*/,
           int, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  int fdin, fdout;
  void *src, *dst;
  unsigned char sz[1024] = {0};
  if ((fdin = open("/dev/simple", O_RDONLY)) < 0)
    printf("can't open /dev/simple for reading");
  if ((src = mmap(NULL, 4096 * 2, PROT_READ, MAP_SHARED, fdin, 0)) ==
      MAP_FAILED)
    printf("mmap error for simplen");
  memcpy(sz, src, 11);
  sz[10] = '\0';
  printf("%x\n", src);
  printf("%s\n\n", sz);
  memcpy(sz, src + 4096, 11);
  printf("%x\n", src + 4096);
  printf("%s\n", sz);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x430(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1050 <memset@plt>
mov    0x2e45(%rip),%rax
mov    (%rax),%esi
lea    0xe64(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    11bb <main+0x5b>
lea    0xe58(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2e36(%rip),%rax
mov    (%rax),%edx
mov    0x2e1d(%rip),%rax
mov    (%rax),%ecx
mov    -0x14(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
mov    $0x2000,%esi
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,-0x20(%rbp)
mov    0x2ddb(%rip),%rcx
cmp    (%rcx),%rax
jne    1204 <main+0xa4>
lea    0xe32(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x430(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    $0xb,%edx
call   1060 <memcpy@plt>
movb   $0x0,-0x426(%rbp)
mov    -0x20(%rbp),%rsi
lea    0xe1b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x430(%rbp),%rsi
lea    0xe0a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x430(%rbp),%rdi
mov    -0x20(%rbp),%rsi
add    $0x1000,%rsi
mov    $0xb,%edx
call   1060 <memcpy@plt>
mov    -0x20(%rbp),%rsi
add    $0x1000,%rsi
lea    0xdd1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x430(%rbp),%rsi
lea    0xdc5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %edi,%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x400,%rsp
mov    %rsp,%rdi
mov    $0x400,%edx
xor    %esi,%esi
call   1060 <memset@plt>
mov    0x2e46(%rip),%rax
mov    (%rax),%esi
lea    0xe65(%rip),%rdi
call   1080 <open@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    11b4 <main+0x44>
lea    0xe5f(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2e3d(%rip),%rax
mov    (%rax),%edx
mov    0x2e24(%rip),%rax
mov    (%rax),%ecx
xor    %edi,%edi
mov    $0x2000,%esi
mov    %ebx,%r8d
xor    %r9d,%r9d
call   1040 <mmap@plt>
mov    %rax,%rbx
mov    0x2de6(%rip),%rax
cmp    (%rax),%rbx
jne    11f5 <main+0x85>
lea    0xe41(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rsp,%r14
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0xb,%edx
call   1070 <memcpy@plt>
movb   $0x0,0xa(%rsp)
lea    0xe32(%rip),%r15
mov    %r15,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe22(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1000,%rbx
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0xb,%edx
call   1070 <memcpy@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14,%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"/dev/simple\00"
@O_RDONLY = global i32 0
@.str.1 = [35 x i8] c"can't open /dev/simple for reading\00"
@PROT_READ = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i8* null
@.str.2 = [23 x i8] c"mmap error for simplen\00"
@.str.3 = [4 x i8] c"%x\0A\00"
@.str.4 = [5 x i8] c"%s\0A\0A\00"
@.str.5 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca [1024 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = bitcast [1024 x i8]* %10 to i8*
%12 = load i32, i32* @O_RDONLY
%13 = call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %12)
store i32 %13, i32* %6
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %2
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0))
br label %17
17: ; preds = %15, %2
%18 = load i32, i32* @PROT_READ
%19 = load i32, i32* @MAP_SHARED
%20 = load i32, i32* %6
%21 = call i8* @mmap(i32* null, i32 8192, i32 %18, i32 %19, i32 %20, i32 0)
store i8* %21, i8** %8
%22 = load i8*, i8** @MAP_FAILED
%23 = icmp eq i8* %21, %22
br i1 %23, label %24, label %26
24: ; preds = %17
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
br label %26
26: ; preds = %24, %17
%27 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%28 = load i8*, i8** %8
%29 = call i32 @memcpy(i8* %27, i8* %28, i32 11)
%30 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 10
store i8 0, i8* %30
%31 = load i8*, i8** %8
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %31)
%33 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8* %33)
%35 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%36 = load i8*, i8** %8
%37 = getelementptr i8, i8* %36, i64 4096
%38 = call i32 @memcpy(i8* %35, i8* %37, i32 11)
%39 = load i8*, i8** %8
%40 = getelementptr i8, i8* %39, i64 4096
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %40)
%42 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* %42)
%44 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [12 x i8] c"/dev/simple\00"
@O_RDONLY = global i32 0
@.str.1 = [35 x i8] c"can't open /dev/simple for reading\00"
@PROT_READ = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i8* null
@.str.2 = [23 x i8] c"mmap error for simplen\00"
@.str.3 = [4 x i8] c"%x\0A\00"
@.str.4 = [5 x i8] c"%s\0A\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = load i32, i32* @O_RDONLY
%6 = tail call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0))
br label %10
10: ; preds = %8, %2
%11 = load i32, i32* @PROT_READ
%12 = load i32, i32* @MAP_SHARED
%13 = tail call i8* @mmap(i32* null, i32 8192, i32 %11, i32 %12, i32 %6, i32 0)
%14 = load i8*, i8** @MAP_FAILED
%15 = icmp eq i8* %13, %14
br i1 %15, label %16, label %18
16: ; preds = %10
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
br label %18
18: ; preds = %16, %10
%19 = call i32 @memcpy(i8* %4, i8* %13, i32 11)
%20 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 10
store i8 0, i8* %20
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %13)
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8* %4)
%23 = getelementptr i8, i8* %13, i64 4096
%24 = call i32 @memcpy(i8* %4, i8* %23, i32 11)
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %23)
%26 = call i32 @puts(i8* %4)
%27 = call i32 @exit(i32 0)
unreachable
}