#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*/ print_mem(unsigned long, unsigned long);
int /*<<< orphan*/ puts(char *);
scalar_t__ strtol(char *, void *, int /*<<< orphan*/);
int peek(int argc, char **argv) {
  unsigned long address, length, value, i;
  if (argc < 3) {
    puts("Usage: peek addr nwords");
    return -1;
  }
  address = (unsigned long)strtol(argv[1], ((void *)0L), 0);
  length = (unsigned long)strtol(argv[2], ((void *)0L), 0);
  for (i = 0; i < length; i++) {
    value = *((volatile unsigned long *)address);
    print_mem(address, value);
    address += 4;
  }
  return 0;
}


x86 assembly (clang, -O0):
<peek>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    1161 <peek+0x31>
lea    0xeb0(%rip),%rdi
call   1030 <puts@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e1 <peek+0xb1>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1040 <strtol@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1040 <strtol@plt>
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x20(%rbp),%rax
jae    11da <peek+0xaa>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1050 <print_mem@plt>
mov    -0x18(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x18(%rbp)
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    1197 <peek+0x67>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<peek>:
push   %r15
push   %r14
push   %rbx
cmp    $0x2,%edi
jg     114e <peek+0x1e>
lea    0xebf(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%r14d
jmp    1195 <peek+0x65>
mov    %rsi,%r15
mov    0x8(%rsi),%rdi
xor    %r14d,%r14d
xor    %esi,%esi
xor    %edx,%edx
call   1040 <strtol@plt>
mov    %rax,%rbx
mov    0x10(%r15),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1040 <strtol@plt>
test   %rax,%rax
je     1195 <peek+0x65>
mov    %rax,%r15
nopl   0x0(%rax)
mov    (%rbx),%rsi
mov    %rbx,%rdi
call   1050 <print_mem@plt>
add    $0x4,%rbx
add    $0xffffffffffffffff,%r15
jne    1180 <peek+0x50>
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [24 x i8] c"Usage: peek addr nwords\00"
define i32 @peek(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 3
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = call i32 @puts(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %40
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i64 @strtol(i8* %17, i8* null, i32 0)
store i64 %18, i64* %6
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 2
%21 = load i8*, i8** %20
%22 = call i64 @strtol(i8* %21, i8* null, i32 0)
store i64 %22, i64* %7
store i64 0, i64* %9
br label %23
23: ; preds = %36, %14
%24 = load i64, i64* %9
%25 = load i64, i64* %7
%26 = icmp ult i64 %24, %25
br i1 %26, label %27, label %39
27: ; preds = %23
%28 = load i64, i64* %6
%29 = inttoptr i64 %28 to i64*
%30 = load volatile i64, i64* %29
store i64 %30, i64* %8
%31 = load i64, i64* %6
%32 = load i64, i64* %8
%33 = call i32 @print_mem(i64 %31, i64 %32)
%34 = load i64, i64* %6
%35 = add i64 %34, 4
store i64 %35, i64* %6
br label %36
36: ; preds = %27
%37 = load i64, i64* %9
%38 = add i64 %37, 1
store i64 %38, i64* %9
br label %23
39: ; preds = %23
store i32 0, i32* %3
br label %40
40: ; preds = %39, %12
%41 = load i32, i32* %3
ret i32 %41
}

LLVM IR (-O2):
@.str = [24 x i8] c"Usage: peek addr nwords\00"
define i32 @peek(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 3
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %23
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i64 @strtol(i8* nocapture %8, i8* null, i32 0)
%10 = getelementptr inbounds i8*, i8** %1, i64 2
%11 = load i8*, i8** %10
%12 = tail call i64 @strtol(i8* nocapture %11, i8* null, i32 0)
%13 = icmp eq i64 %12, 0
br i1 %13, label %23, label %14
14: ; preds = %6, %14
%15 = phi i64 [ %21, %14 ], [ 0, %6 ]
%16 = phi i64 [ %20, %14 ], [ %9, %6 ]
%17 = inttoptr i64 %16 to i64*
%18 = load volatile i64, i64* %17
%19 = tail call i32 @print_mem(i64 %16, i64 %18)
%20 = add i64 %16, 4
%21 = add nuw i64 %15, 1
%22 = icmp eq i64 %21, %12
br i1 %22, label %23, label %14
23: ; preds = %14, %6, %4
%24 = phi i32 [ -1, %4 ], [ 0, %6 ], [ 0, %14 ]
ret i32 %24
}