#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 */
int /*<<< orphan*/ _SC_PAGESIZE;
int /*<<< orphan*/ printf(char *, int, char *);
long sysconf(int /*<<< orphan*/);
void peek(char *mem) {
  int i, j;
  char buf[(10) + 1];
  long pagesize = sysconf(_SC_PAGESIZE);
  for (i = 0; i < (3); i++) {
    for (j = 0; j < (10); j++) {
      buf[j] = mem[i * pagesize + j];
    }
    buf[(10)] = '\0';
    printf("-> Page %d: %s...\n", i + 1, buf);
  }
}


x86 assembly (clang, -O0):
<peek>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2eb5(%rip),%rax
mov    (%rax),%edi
call   1040 <sysconf@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x3,-0xc(%rbp)
jge    11b5 <peek+0x95>
movl   $0x0,-0x10(%rbp)
cmpl   $0xa,-0x10(%rbp)
jge    118d <peek+0x6d>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
imul   -0x28(%rbp),%rcx
movslq -0x10(%rbp),%rdx
add    %rdx,%rcx
mov    (%rax,%rcx,1),%cl
movslq -0x10(%rbp),%rax
mov    %cl,-0x1b(%rbp,%rax,1)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1156 <peek+0x36>
movb   $0x0,-0x11(%rbp)
mov    -0xc(%rbp),%esi
add    $0x1,%esi
lea    -0x1b(%rbp),%rdx
lea    0xe5e(%rip),%rdi
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1145 <peek+0x25>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<peek>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%rbx
mov    0x2eb3(%rip),%rax
mov    (%rax),%edi
call   1040 <sysconf@plt>
mov    %rax,%r14
mov    (%rbx),%rax
mov    %rax,0x8(%rsp)
movzwl 0x8(%rbx),%eax
mov    %ax,0x10(%rsp)
movb   $0x0,0x12(%rsp)
lea    0xea4(%rip),%r15
lea    0x8(%rsp),%r12
mov    %r15,%rdi
mov    $0x1,%esi
mov    %r12,%rdx
call   1030 <printf@plt>
mov    (%rbx,%r14,1),%rax
mov    %rax,0x8(%rsp)
movzwl 0x8(%rbx,%r14,1),%eax
mov    %ax,0x10(%rsp)
movb   $0x0,0x12(%rsp)
mov    %r15,%rdi
mov    $0x2,%esi
mov    %r12,%rdx
call   1030 <printf@plt>
mov    (%rbx,%r14,2),%rax
mov    %rax,0x8(%rsp)
movzwl 0x8(%rbx,%r14,2),%eax
mov    %ax,0x10(%rsp)
movb   $0x0,0x12(%rsp)
mov    %r15,%rdi
mov    $0x3,%esi
mov    %r12,%rdx
call   1030 <printf@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@_SC_PAGESIZE = global i32 0
@.str = [19 x i8] c"-> Page %d: %s...\0A\00"
define void @peek(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca [11 x i8]
%6 = alloca i64
store i8* %0, i8** %2
%7 = load i32, i32* @_SC_PAGESIZE
%8 = call i64 @sysconf(i32 %7)
store i64 %8, i64* %6
store i32 0, i32* %3
br label %9
9: ; preds = %39, %1
%10 = load i32, i32* %3
%11 = icmp slt i32 %10, 3
br i1 %11, label %12, label %42
12: ; preds = %9
store i32 0, i32* %4
br label %13
13: ; preds = %30, %12
%14 = load i32, i32* %4
%15 = icmp slt i32 %14, 10
br i1 %15, label %16, label %33
16: ; preds = %13
%17 = load i8*, i8** %2
%18 = load i32, i32* %3
%19 = sext i32 %18 to i64
%20 = load i64, i64* %6
%21 = mul nsw i64 %19, %20
%22 = load i32, i32* %4
%23 = sext i32 %22 to i64
%24 = add nsw i64 %21, %23
%25 = getelementptr inbounds i8, i8* %17, i64 %24
%26 = load i8, i8* %25
%27 = load i32, i32* %4
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [11 x i8], [11 x i8]* %5, i64 0, i64 %28
store i8 %26, i8* %29
br label %30
30: ; preds = %16
%31 = load i32, i32* %4
%32 = add nsw i32 %31, 1
store i32 %32, i32* %4
br label %13
33: ; preds = %13
%34 = getelementptr inbounds [11 x i8], [11 x i8]* %5, i64 0, i64 10
store i8 0, i8* %34
%35 = load i32, i32* %3
%36 = add nsw i32 %35, 1
%37 = getelementptr inbounds [11 x i8], [11 x i8]* %5, i64 0, i64 0
%38 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %36, i8* %37)
br label %39
39: ; preds = %33
%40 = load i32, i32* %3
%41 = add nsw i32 %40, 1
store i32 %41, i32* %3
br label %9
42: ; preds = %9
ret void
}

LLVM IR (-O2):
@_SC_PAGESIZE = global i32 0
@.str = [19 x i8] c"-> Page %d: %s...\0A\00"
define void @peek(i8* nocapture %0) {
%2 = alloca [11 x i8]
%3 = getelementptr inbounds [11 x i8], [11 x i8]* %2, i64 0, i64 0
%4 = getelementptr inbounds [11 x i8], [11 x i8]* %2, i64 0, i64 0
%5 = load i32, i32* @_SC_PAGESIZE
%6 = tail call i64 @sysconf(i32 %5)
%7 = getelementptr inbounds [11 x i8], [11 x i8]* %2, i64 0, i64 10
store i8 0, i8* %7
%8 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 1, i8* %4)
%9 = getelementptr i8, i8* %0, i64 %6
store i8 0, i8* %7
%10 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 2, i8* %4)
%11 = shl nsw i64 %6, 1
%12 = getelementptr i8, i8* %0, i64 %11
store i8 0, i8* %7
%13 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 3, i8* %4)
ret void
}