#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 cpu_read_word_dasm(unsigned int);
int /*<<< orphan*/ sprintf(char *, char *, int);
void make_hex(char *buff, unsigned int pc, unsigned int 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)
jbe    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)
jbe    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
je     1170 <make_hex+0x50>
mov    %edx,%ebx
mov    %esi,%ebp
mov    %rdi,%r14
lea    0xec7(%rip),%r15
jmp    1151 <make_hex+0x31>
nopl   0x0(%rax,%rax,1)
movb   $0x20,0x4(%r14)
add    $0x5,%r14
add    $0x2,%ebp
add    $0xfffffffe,%ebx
je     1170 <make_hex+0x50>
mov    %ebp,%edi
call   1030 <cpu_read_word_dasm@plt>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %eax,%edx
call   1040 <sprintf@plt>
cmp    $0x3,%ebx
jae    1140 <make_hex+0x20>
add    $0x4,%r14
jmp    1149 <make_hex+0x29>
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 ugt 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 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 ugt 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 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 eq i32 %2, 0
br i1 %4, label %20, label %5
5: ; preds = %3, %16
%6 = phi i8* [ %17, %16 ], [ %0, %3 ]
%7 = phi i32 [ %18, %16 ], [ %2, %3 ]
%8 = phi i32 [ %11, %16 ], [ %1, %3 ]
%9 = tail call i32 @cpu_read_word_dasm(i32 %8)
%10 = tail call i32 @sprintf(i8* dereferenceable(1) %6, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = add i32 %8, 2
%12 = getelementptr inbounds i8, i8* %6, i64 4
%13 = icmp ugt i32 %7, 2
br i1 %13, label %14, label %16
14: ; preds = %5
%15 = getelementptr inbounds i8, i8* %6, i64 5
store i8 32, i8* %12
br label %16
16: ; preds = %5, %14
%17 = phi i8* [ %15, %14 ], [ %12, %5 ]
%18 = add i32 %7, -2
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %5
20: ; preds = %16, %3
ret void
}