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


x86 assembly (clang, -O0):
<cmd_mem_write>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpl   $0x3,-0x14(%rbp)
jge    1158 <cmd_mem_write+0x38>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xeb9(%rip),%rdi
call   1030 <sw_printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1197 <cmd_mem_write+0x77>
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    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   1040 <sw_strtoul@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cmd_mem_write>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%rbx
cmp    $0x2,%esi
jg     1144 <cmd_mem_write+0x24>
mov    (%rbx),%rsi
lea    0xec9(%rip),%rdi
call   1030 <sw_printf@plt>
mov    $0xffffffff,%r14d
jmp    116d <cmd_mem_write+0x4d>
mov    0x8(%rbx),%rdi
xor    %r14d,%r14d
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <sw_strtoul@plt>
mov    %rax,%r15
mov    0x10(%rbx),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <sw_strtoul@plt>
mov    %eax,(%r15)
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [29 x i8] c"usage: %s <memaddr> <data>\0A\0D\00"
define i32 @cmd_mem_write(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, 3
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 @sw_printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %12)
store i32 -1, i32* %3
br label %26
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 i8**, i8*** %4
%21 = getelementptr inbounds i8*, i8** %20, i64 2
%22 = load i8*, i8** %21
%23 = call i64 @sw_strtoul(i8* %22, i8* null, i32 16)
%24 = trunc i64 %23 to i32
%25 = load i32*, i32** %6
store volatile i32 %24, i32* %25
store i32 0, i32* %3
br label %26
26: ; preds = %14, %9
%27 = load i32, i32* %3
ret i32 %27
}

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