#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 uint32_t;

/* Variables and functions */
int cpu_read_word_dasm(int);
int /*<<< orphan*/ sprintf(char *, char *, int);
void make_hex(char *buff, uint32_t pc, uint32_t length) {
  char *ptr = buff;
  for (; length > 0; length -= 2) {
    sprintf(ptr, "%04x", cpu_read_word_dasm(pc));
    pc += 2;
    ptr += 4;
    if (length > 2)
      *ptr++ = ' ';
  }
}


x86 assembly (clang, -O0):
<make_hex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
cmpl   $0x0,-0x10(%rbp)
jle    11aa <make_hex+0x8a>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0xc(%rbp),%edi
call   1030 <cpu_read_word_dasm@plt>
mov    -0x20(%rbp),%rdi
mov    %eax,%edx
lea    0xe9f(%rip),%rsi
call   1040 <sprintf@plt>
mov    -0xc(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0xc(%rbp)
mov    -0x18(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x18(%rbp)
cmpl   $0x2,-0x10(%rbp)
jle    1197 <make_hex+0x77>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x20,(%rax)
jmp    119c <make_hex+0x7c>
mov    -0x10(%rbp),%eax
sub    $0x2,%eax
mov    %eax,-0x10(%rbp)
jmp    113a <make_hex+0x1a>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<make_hex>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %edx,%edx
jle    1189 <make_hex+0x69>
mov    %edx,%r14d
mov    %esi,%ebp
mov    %rdi,%rbx
mov    %esi,%edi
call   1030 <cpu_read_word_dasm@plt>
lea    0xebf(%rip),%rsi
mov    %rbx,%rdi
mov    %eax,%edx
call   1040 <sprintf@plt>
cmp    $0x3,%r14d
jb     1189 <make_hex+0x69>
add    $0x2,%ebp
add    $0x5,%rbx
lea    0xea1(%rip),%r15
nop
movb   $0x20,-0x1(%rbx)
add    $0xfffffffe,%r14d
mov    %ebp,%edi
call   1030 <cpu_read_word_dasm@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %eax,%edx
call   1040 <sprintf@plt>
add    $0x2,%ebp
add    $0x5,%rbx
cmp    $0x2,%r14d
ja     1160 <make_hex+0x40>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%04x\00"
define void @make_hex(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%8 = load i8*, i8** %4
store i8* %8, i8** %7
br label %9
9: ; preds = %27, %3
%10 = load i32, i32* %6
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %30
12: ; preds = %9
%13 = load i8*, i8** %7
%14 = load i32, i32* %5
%15 = call i32 @cpu_read_word_dasm(i32 %14)
%16 = call i32 @sprintf(i8* %13, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %15)
%17 = load i32, i32* %5
%18 = add nsw i32 %17, 2
store i32 %18, i32* %5
%19 = load i8*, i8** %7
%20 = getelementptr inbounds i8, i8* %19, i64 4
store i8* %20, i8** %7
%21 = load i32, i32* %6
%22 = icmp sgt i32 %21, 2
br i1 %22, label %23, label %26
23: ; preds = %12
%24 = load i8*, i8** %7
%25 = getelementptr inbounds i8, i8* %24, i32 1
store i8* %25, i8** %7
store i8 32, i8* %24
br label %26
26: ; preds = %23, %12
br label %27
27: ; preds = %26
%28 = load i32, i32* %6
%29 = sub nsw i32 %28, 2
store i32 %29, i32* %6
br label %9
30: ; preds = %9
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"%04x\00"
define void @make_hex(i8* nocapture writeonly %0, i32 %1, i32 %2) {
%4 = icmp sgt i32 %2, 0
br i1 %4, label %5, label %20
5: ; preds = %3
%6 = tail call i32 @cpu_read_word_dasm(i32 %1)
%7 = tail call i32 @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = icmp ugt i32 %2, 2
br i1 %8, label %9, label %20
9: ; preds = %5, %9
%10 = phi i32 [ %14, %9 ], [ %1, %5 ]
%11 = phi i32 [ %16, %9 ], [ %2, %5 ]
%12 = phi i8* [ %15, %9 ], [ %0, %5 ]
%13 = getelementptr inbounds i8, i8* %12, i64 4
%14 = add nsw i32 %10, 2
%15 = getelementptr inbounds i8, i8* %12, i64 5
store i8 32, i8* %13
%16 = add nsw i32 %11, -2
%17 = tail call i32 @cpu_read_word_dasm(i32 %14)
%18 = tail call i32 @sprintf(i8* dereferenceable(1) %15, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %17)
%19 = icmp ugt i32 %16, 2
br i1 %19, label %9, label %20
20: ; preds = %9, %5, %3
ret void
}