#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 */
unsigned int dectou(char const *);
unsigned int hextou(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ read_registers(unsigned int, unsigned int, unsigned char *);
char *skipstring(char *);
void command_read(char *params) {
  unsigned base = hextou(params);
  const char *p = skipstring(params);
  unsigned count = 1;
  if (*p)
    count = dectou(p);
  for (unsigned row = base; row != base + count;) {
    unsigned amount = base + count - row;
    if (amount > 16)
      amount = 16;
    unsigned char responses[16];
    read_registers(row, amount, responses);
    printf("%02x:", row);
    for (unsigned i = 0; i != amount; ++i)
      printf(" %02x", responses[i]);
    printf("\n");
    row += amount;
  }
}


x86 assembly (clang, -O0):
<command_read>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <hextou@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <skipstring@plt>
mov    %rax,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
cmpb   $0x0,(%rax)
je     1195 <command_read+0x45>
mov    -0x18(%rbp),%rdi
call   1060 <dectou@plt>
mov    %eax,-0x1c(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    -0xc(%rbp),%ecx
add    -0x1c(%rbp),%ecx
cmp    %ecx,%eax
je     123c <command_read+0xec>
mov    -0xc(%rbp),%eax
add    -0x1c(%rbp),%eax
sub    -0x20(%rbp),%eax
mov    %eax,-0x24(%rbp)
cmpl   $0x10,-0x24(%rbp)
jbe    11c9 <command_read+0x79>
movl   $0x10,-0x24(%rbp)
mov    -0x20(%rbp),%edi
mov    -0x24(%rbp),%esi
lea    -0x40(%rbp),%rdx
call   1040 <read_registers@plt>
mov    -0x20(%rbp),%esi
lea    0xe1e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x44(%rbp)
mov    -0x44(%rbp),%eax
cmp    -0x24(%rbp),%eax
je     1220 <command_read+0xd0>
mov    -0x44(%rbp),%eax
movzbl -0x40(%rbp,%rax,1),%esi
lea    0xdfb(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    11f0 <command_read+0xa0>
lea    0xde5(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x24(%rbp),%eax
add    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
jmp    119b <command_read+0x4b>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<command_read>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%rbx
call   1080 <hextou@plt>
mov    %eax,%r13d
mov    %rbx,%rdi
call   1040 <skipstring@plt>
cmpb   $0x0,(%rax)
je     11a4 <command_read+0x44>
mov    %rax,%rdi
call   1070 <dectou@plt>
mov    %eax,%r12d
test   %eax,%eax
jne    11aa <command_read+0x4a>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x1,%r12d
add    %r13d,%r12d
lea    0xe52(%rip),%rbp
jmp    11d2 <command_read+0x72>
cs nopw 0x0(%rax,%rax,1)
mov    $0xa,%edi
call   1030 <putchar@plt>
add    %ebx,%r13d
cmp    %r13d,%r12d
je     1195 <command_read+0x35>
mov    %r12d,%ebx
sub    %r13d,%ebx
cmp    $0x10,%ebx
mov    $0x10,%eax
cmovae %eax,%ebx
mov    %r13d,%edi
mov    %ebx,%esi
mov    %rsp,%rdx
call   1050 <read_registers@plt>
lea    0xe09(%rip),%rdi
mov    %r13d,%esi
xor    %eax,%eax
call   1060 <printf@plt>
test   %ebx,%ebx
je     11c0 <command_read+0x60>
mov    %ebx,%r14d
xor    %r15d,%r15d
nopl   0x0(%rax,%rax,1)
movzbl (%rsp,%r15,1),%esi
mov    %rbp,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x1,%r15
cmp    %r15,%r14
jne    1210 <command_read+0xb0>
jmp    11c0 <command_read+0x60>

LLVM IR (-O0):
@.str = [6 x i8] c"%02x:\00"
@.str.1 = [6 x i8] c" %02x\00"
@.str.2 = [2 x i8] c"\0A\00"
define void @command_read(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca [16 x i8]
%9 = alloca i32
store i8* %0, i8** %2
%10 = load i8*, i8** %2
%11 = call i32 @hextou(i8* %10)
store i32 %11, i32* %3
%12 = load i8*, i8** %2
%13 = call i8* @skipstring(i8* %12)
store i8* %13, i8** %4
store i32 1, i32* %5
%14 = load i8*, i8** %4
%15 = load i8, i8* %14
%16 = icmp ne i8 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %1
%18 = load i8*, i8** %4
%19 = call i32 @dectou(i8* %18)
store i32 %19, i32* %5
br label %20
20: ; preds = %17, %1
%21 = load i32, i32* %3
store i32 %21, i32* %6
br label %22
22: ; preds = %58, %20
%23 = load i32, i32* %6
%24 = load i32, i32* %3
%25 = load i32, i32* %5
%26 = add i32 %24, %25
%27 = icmp ne i32 %23, %26
br i1 %27, label %28, label %63
28: ; preds = %22
%29 = load i32, i32* %3
%30 = load i32, i32* %5
%31 = add i32 %29, %30
%32 = load i32, i32* %6
%33 = sub i32 %31, %32
store i32 %33, i32* %7
%34 = load i32, i32* %7
%35 = icmp ugt i32 %34, 16
br i1 %35, label %36, label %37
36: ; preds = %28
store i32 16, i32* %7
br label %37
37: ; preds = %36, %28
%38 = load i32, i32* %6
%39 = load i32, i32* %7
%40 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 0
%41 = call i32 @read_registers(i32 %38, i32 %39, i8* %40)
%42 = load i32, i32* %6
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %42)
store i32 0, i32* %9
br label %44
44: ; preds = %55, %37
%45 = load i32, i32* %9
%46 = load i32, i32* %7
%47 = icmp ne i32 %45, %46
br i1 %47, label %48, label %58
48: ; preds = %44
%49 = load i32, i32* %9
%50 = zext i32 %49 to i64
%51 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 %50
%52 = load i8, i8* %51
%53 = zext i8 %52 to i32
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %53)
br label %55
55: ; preds = %48
%56 = load i32, i32* %9
%57 = add i32 %56, 1
store i32 %57, i32* %9
br label %44
58: ; preds = %44
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%60 = load i32, i32* %7
%61 = load i32, i32* %6
%62 = add i32 %61, %60
store i32 %62, i32* %6
br label %22
63: ; preds = %22
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c"%02x:\00"
@.str.1 = [6 x i8] c" %02x\00"
define void @command_read(i8* %0) {
%2 = alloca [16 x i8]
%3 = tail call i32 @hextou(i8* %0)
%4 = tail call i8* @skipstring(i8* %0)
%5 = load i8, i8* %4
%6 = icmp eq i8 %5, 0
br i1 %6, label %10, label %7
7: ; preds = %1
%8 = tail call i32 @dectou(i8* %4)
%9 = icmp eq i32 %8, 0
br i1 %9, label %14, label %10
10: ; preds = %1, %7
%11 = phi i32 [ %8, %7 ], [ 1, %1 ]
%12 = add i32 %11, %3
%13 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
br label %15
14: ; preds = %25, %7
ret void
15: ; preds = %10, %25
%16 = phi i32 [ %3, %10 ], [ %27, %25 ]
%17 = sub i32 %12, %16
%18 = icmp ult i32 %17, 16
%19 = select i1 %18, i32 %17, i32 16
%20 = call i32 @read_registers(i32 %16, i32 %19, i8* %13)
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %16)
%22 = icmp eq i32 %19, 0
br i1 %22, label %25, label %23
23: ; preds = %15
%24 = zext i32 %19 to i64
br label %29
25: ; preds = %29, %15
%26 = call i32 @putchar(i32 10)
%27 = add i32 %19, %16
%28 = icmp eq i32 %12, %27
br i1 %28, label %14, label %15
29: ; preds = %23, %29
%30 = phi i64 [ 0, %23 ], [ %35, %29 ]
%31 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 %30
%32 = load i8, i8* %31
%33 = zext i8 %32 to i32
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %33)
%35 = add nuw nsw i64 %30, 1
%36 = icmp eq i64 %35, %24
br i1 %36, label %25, label %29
}