#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*/ sw_printf(char *, ...);
scalar_t__ sw_strtoul(char *, void *, int);
int cmd_mem_read(char *arg_list[], int n) {
  volatile int *addr;
  if (n < 2) {
    sw_printf("usage: %s <memaddr>\n\r", arg_list[0]);
    return -1;
  }
  addr = (int *)sw_strtoul(arg_list[1], ((void *)0), 16);
  sw_printf("addr[%x]: %x\n\r", addr, *addr);
  return 0;
}


x86 assembly (clang, -O0):
<cmd_mem_read>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpl   $0x2,-0x14(%rbp)
jge    115a <cmd_mem_read+0x3a>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xeb9(%rip),%rdi
mov    $0x0,%al
call   1030 <sw_printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1193 <cmd_mem_read+0x73>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   1040 <sw_strtoul@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rsi
mov    -0x20(%rbp),%rax
mov    (%rax),%edx
lea    0xe91(%rip),%rdi
mov    $0x0,%al
call   1030 <sw_printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cmd_mem_read>:
push   %rbx
cmp    $0x1,%esi
jg     113e <cmd_mem_read+0x1e>
mov    (%rdi),%rsi
lea    0xed0(%rip),%rdi
xor    %eax,%eax
call   1030 <sw_printf@plt>
mov    $0xffffffff,%ebx
jmp    1163 <cmd_mem_read+0x43>
mov    0x8(%rdi),%rdi
xor    %ebx,%ebx
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <sw_strtoul@plt>
mov    (%rax),%edx
lea    0xebd(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1030 <sw_printf@plt>
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [22 x i8] c"usage: %s <memaddr>\0A\0D\00"
@.str.1 = [15 x i8] c"addr[%x]: %x\0A\0D\00"
define i32 @cmd_mem_read(i8** %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i32*
store i8** %0, i8*** %4
store i32 %1, i32* %5
%7 = load i32, i32* %5
%8 = icmp slt i32 %7, 2
br i1 %8, label %9, label %14
9: ; preds = %2
%10 = load i8**, i8*** %4
%11 = getelementptr inbounds i8*, i8** %10, i64 0
%12 = load i8*, i8** %11
%13 = call i32 (i8*, ...) @sw_printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %12)
store i32 -1, i32* %3
br label %24
14: ; preds = %2
%15 = load i8**, i8*** %4
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i64 @sw_strtoul(i8* %17, i8* null, i32 16)
%19 = inttoptr i64 %18 to i32*
store i32* %19, i32** %6
%20 = load i32*, i32** %6
%21 = load i32*, i32** %6
%22 = load volatile i32, i32* %21
%23 = call i32 (i8*, ...) @sw_printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32* %20, i32 %22)
store i32 0, i32* %3
br label %24
24: ; preds = %14, %9
%25 = load i32, i32* %3
ret i32 %25
}

LLVM IR (-O2):
@.str = [22 x i8] c"usage: %s <memaddr>\0A\0D\00"
@.str.1 = [15 x i8] c"addr[%x]: %x\0A\0D\00"
define i32 @cmd_mem_read(i8** nocapture %0, i32 %1) {
%3 = icmp slt i32 %1, 2
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = load i8*, i8** %0
%6 = tail call i32 (i8*, ...) @sw_printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %5)
br label %14
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %0, i64 1
%9 = load i8*, i8** %8
%10 = tail call i64 @sw_strtoul(i8* %9, i8* null, i32 16)
%11 = inttoptr i64 %10 to i32*
%12 = load volatile i32, i32* %11
%13 = tail call i32 (i8*, ...) @sw_printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32* %11, i32 %12)
br label %14
14: ; preds = %7, %4
%15 = phi i32 [ -1, %4 ], [ 0, %7 ]
ret i32 %15
}