#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 */
char *decodeDisasm(unsigned char *, unsigned int, int *);
int /*<<< orphan*/ printf(char *, ...);
void Disassemble(unsigned char *memory, unsigned int address) {
  int numBytes = 0;
  int a;
  const char *retVal = decodeDisasm(memory, address, &numBytes);
  printf("%04X :", address);
  for (a = 0; a < numBytes + 1; a++) {
    printf("%02X ", memory[address + a]);
  }
  for (a = 0; a < 4 - (numBytes + 1); a++) {
    printf("   ");
  }
  printf("%s\n", retVal);
}


x86 assembly (clang, -O0):
<Disassemble>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
lea    -0x10(%rbp),%rdx
call   1040 <decodeDisasm@plt>
mov    %rax,-0x20(%rbp)
mov    -0xc(%rbp),%esi
lea    0xeac(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    -0x10(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jge    119f <Disassemble+0x7f>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
add    -0x14(%rbp),%ecx
mov    %ecx,%ecx
movzbl (%rax,%rcx,1),%esi
lea    0xe7d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1162 <Disassemble+0x42>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    -0x10(%rbp),%edx
add    $0x1,%edx
mov    $0x4,%ecx
sub    %edx,%ecx
cmp    %ecx,%eax
jge    11da <Disassemble+0xba>
lea    0xe48(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11a6 <Disassemble+0x86>
mov    -0x20(%rbp),%rsi
lea    0xe2c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Disassemble>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %esi,%ebp
mov    %rdi,%r12
movl   $0x0,0xc(%rsp)
lea    0xc(%rsp),%rdx
call   1050 <decodeDisasm@plt>
mov    %rax,%r14
lea    0xea3(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0xc(%rsp),%eax
test   %eax,%eax
js     11a3 <Disassemble+0x73>
mov    %ebp,%ebp
mov    $0xffffffffffffffff,%rbx
lea    0xe89(%rip),%r15
xchg   %ax,%ax
lea    (%rbx,%rbp,1),%eax
add    $0x1,%eax
movzbl (%r12,%rax,1),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movslq 0xc(%rsp),%rax
add    $0x1,%rbx
cmp    %rax,%rbx
jl     1180 <Disassemble+0x50>
add    $0xfffffffc,%eax
cmp    $0xfffffffe,%eax
jg     11da <Disassemble+0xaa>
lea    0xe5b(%rip),%rbx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%ebp
mov    $0x3,%eax
sub    0xc(%rsp),%eax
cmp    %eax,%ebp
jl     11c0 <Disassemble+0x90>
mov    %r14,%rdi
call   1030 <puts@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"%04X :\00"
@.str.1 = [6 x i8] c"%02X \00"
@.str.2 = [4 x i8] c" \00"
@.str.3 = [4 x i8] c"%s\0A\00"
define void @Disassemble(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
store i8* %0, i8** %3
store i32 %1, i32* %4
store i32 0, i32* %5
%8 = load i8*, i8** %3
%9 = load i32, i32* %4
%10 = call i8* @decodeDisasm(i8* %8, i32 %9, i32* %5)
store i8* %10, i8** %7
%11 = load i32, i32* %4
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %11)
store i32 0, i32* %6
br label %13
13: ; preds = %28, %2
%14 = load i32, i32* %6
%15 = load i32, i32* %5
%16 = add nsw i32 %15, 1
%17 = icmp slt i32 %14, %16
br i1 %17, label %18, label %31
18: ; preds = %13
%19 = load i8*, i8** %3
%20 = load i32, i32* %4
%21 = load i32, i32* %6
%22 = add i32 %20, %21
%23 = zext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %19, i64 %23
%25 = load i8, i8* %24
%26 = zext i8 %25 to i32
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %26)
br label %28
28: ; preds = %18
%29 = load i32, i32* %6
%30 = add nsw i32 %29, 1
store i32 %30, i32* %6
br label %13
31: ; preds = %13
store i32 0, i32* %6
br label %32
32: ; preds = %40, %31
%33 = load i32, i32* %6
%34 = load i32, i32* %5
%35 = add nsw i32 %34, 1
%36 = sub nsw i32 4, %35
%37 = icmp slt i32 %33, %36
br i1 %37, label %38, label %43
38: ; preds = %32
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
br label %40
40: ; preds = %38
%41 = load i32, i32* %6
%42 = add nsw i32 %41, 1
store i32 %42, i32* %6
br label %32
43: ; preds = %32
%44 = load i8*, i8** %7
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %44)
ret void
}

LLVM IR (-O2):
@.str = [7 x i8] c"%04X :\00"
@.str.1 = [6 x i8] c"%02X \00"
@.str.2 = [4 x i8] c" \00"
define void @Disassemble(i8* %0, i32 %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%5 = call i8* @decodeDisasm(i8* %0, i32 %1, i32* %3)
%6 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %1)
%7 = load i32, i32* %3
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %13
9: ; preds = %13, %2
%10 = phi i32 [ %7, %2 ], [ %23, %13 ]
%11 = add i32 %10, -4
%12 = icmp slt i32 %11, -1
br i1 %12, label %26, label %33
13: ; preds = %2, %13
%14 = phi i64 [ %22, %13 ], [ 0, %2 ]
%15 = trunc i64 %14 to i32
%16 = add i32 %15, %1
%17 = zext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %0, i64 %17
%19 = load i8, i8* %18
%20 = zext i8 %19 to i32
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %20)
%22 = add nuw nsw i64 %14, 1
%23 = load i32, i32* %3
%24 = sext i32 %23 to i64
%25 = icmp slt i64 %14, %24
br i1 %25, label %13, label %9
26: ; preds = %9, %26
%27 = phi i32 [ %29, %26 ], [ 0, %9 ]
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%29 = add nuw nsw i32 %27, 1
%30 = load i32, i32* %3
%31 = sub i32 3, %30
%32 = icmp slt i32 %29, %31
br i1 %32, label %26, label %33
33: ; preds = %26, %9
%34 = call i32 @puts(i8* dereferenceable(1) %5)
ret void
}