#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 */
typedef int uint8_t;
typedef int /*<<< orphan*/ uint32_t;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ error_reply(int);
int read_registers(int /*<<< orphan*/, int *, int);
int /*<<< orphan*/ reply(char *, int);
int /*<<< orphan*/ sprintf(char *, char *, int);
void cmd_g_get_registers(int cog) {
  uint8_t buf[19 * sizeof(uint32_t)];
  char response[1024];
  int j;
  int err;
  if ((err = read_registers(0, buf, sizeof(buf))) != 0) {
    error_reply(err);
    return;
  }
  for (j = 0; j < sizeof(buf); j++) {
    sprintf(response + 2 * j, "%02x", buf[j]);
  }
  reply(response, sizeof(buf) * 2);
}


x86 assembly (clang, -O0):
<cmd_g_get_registers>:
push   %rbp
mov    %rsp,%rbp
sub    $0x550,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x140(%rbp),%rsi
xor    %edi,%edi
mov    $0x130,%edx
call   1030 <read_registers@plt>
mov    %eax,-0x548(%rbp)
cmp    $0x0,%eax
je     1180 <cmd_g_get_registers+0x40>
mov    -0x548(%rbp),%edi
call   1050 <error_reply@plt>
jmp    11f1 <cmd_g_get_registers+0xb1>
movl   $0x0,-0x544(%rbp)
movslq -0x544(%rbp),%rax
cmp    $0x130,%rax
jae    11e0 <cmd_g_get_registers+0xa0>
lea    -0x540(%rbp),%rdi
mov    -0x544(%rbp),%eax
shl    $0x1,%eax
cltq
add    %rax,%rdi
movslq -0x544(%rbp),%rax
mov    -0x140(%rbp,%rax,4),%edx
lea    0xe39(%rip),%rsi
call   1060 <sprintf@plt>
mov    -0x544(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x544(%rbp)
jmp    118a <cmd_g_get_registers+0x4a>
lea    -0x540(%rbp),%rdi
mov    $0x260,%esi
call   1040 <reply@plt>
add    $0x550,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cmd_g_get_registers>:
push   %r14
push   %rbx
sub    $0x538,%rsp
mov    %rsp,%rsi
xor    %edi,%edi
mov    $0x130,%edx
call   1030 <read_registers@plt>
test   %eax,%eax
je     1166 <cmd_g_get_registers+0x26>
mov    %eax,%edi
call   1050 <error_reply@plt>
jmp    11a5 <cmd_g_get_registers+0x65>
xor    %ebx,%ebx
lea    0xe91(%rip),%r14
nop
lea    (%rsp,%rbx,1),%rdi
add    $0x130,%rdi
mov    (%rsp,%rbx,2),%edx
mov    %r14,%rsi
call   1060 <sprintf@plt>
add    $0x2,%rbx
cmp    $0x260,%rbx
jne    1170 <cmd_g_get_registers+0x30>
lea    0x130(%rsp),%rdi
mov    $0x260,%esi
call   1040 <reply@plt>
add    $0x538,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%02x\00"
define void @cmd_g_get_registers(i32 %0) {
%2 = alloca i32
%3 = alloca [76 x i32]
%4 = alloca [1024 x i8]
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %2
%7 = getelementptr inbounds [76 x i32], [76 x i32]* %3, i64 0, i64 0
%8 = call i32 @read_registers(i32 0, i32* %7, i32 304)
store i32 %8, i32* %6
%9 = icmp ne i32 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %1
%11 = load i32, i32* %6
%12 = call i32 @error_reply(i32 %11)
br label %35
13: ; preds = %1
store i32 0, i32* %5
br label %14
14: ; preds = %29, %13
%15 = load i32, i32* %5
%16 = sext i32 %15 to i64
%17 = icmp ult i64 %16, 304
br i1 %17, label %18, label %32
18: ; preds = %14
%19 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%20 = load i32, i32* %5
%21 = mul nsw i32 2, %20
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %19, i64 %22
%24 = load i32, i32* %5
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [76 x i32], [76 x i32]* %3, i64 0, i64 %25
%27 = load i32, i32* %26
%28 = call i32 @sprintf(i8* %23, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %27)
br label %29
29: ; preds = %18
%30 = load i32, i32* %5
%31 = add nsw i32 %30, 1
store i32 %31, i32* %5
br label %14
32: ; preds = %14
%33 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%34 = call i32 @reply(i8* %33, i32 608)
br label %35
35: ; preds = %32, %10
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"%02x\00"
define void @cmd_g_get_registers(i32 %0) {
%2 = alloca [76 x i32]
%3 = alloca [1024 x i8]
%4 = bitcast [76 x i32]* %2 to i8*
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [76 x i32], [76 x i32]* %2, i64 0, i64 0
%7 = call i32 @read_registers(i32 0, i32* %6, i32 304)
%8 = icmp eq i32 %7, 0
br i1 %8, label %11, label %9
9: ; preds = %1
%10 = call i32 @error_reply(i32 %7)
br label %22
11: ; preds = %1, %11
%12 = phi i64 [ %18, %11 ], [ 0, %1 ]
%13 = shl nuw nsw i64 %12, 1
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %13
%15 = getelementptr inbounds [76 x i32], [76 x i32]* %2, i64 0, i64 %12
%16 = load i32, i32* %15
%17 = call i32 @sprintf(i8* %14, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %16)
%18 = add nuw nsw i64 %12, 1
%19 = icmp eq i64 %18, 304
br i1 %19, label %20, label %11
20: ; preds = %11
%21 = call i32 @reply(i8* %5, i32 608)
br label %22
22: ; preds = %20, %9
ret void
}