#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 /*<<< orphan*/ uint8_t;

/* Variables and functions */
int /*<<< orphan*/ printf(char *, ...);
void display_mem(uint8_t *memory) {
  int display_counter = 0;
  int rollover_counter = 0;
  (void)printf("Memory Display:\n");
  for (int i = 0; i < 128; i++) {
    if (display_counter == 0) {
      printf("0x%04X: ", i);
    }
    printf("%02hhX ", memory[i]);
    display_counter++;
    if (display_counter == 16) {
      printf("\n");
      display_counter = 0;
      rollover_counter++;
      continue;
    }
    if (display_counter % 4 == 0) {
      printf(" ");
    }
  }
}


x86 assembly (clang, -O0):
<display_mem>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
lea    0xecf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0x80,-0x14(%rbp)
jge    11eb <display_mem+0xdb>
cmpl   $0x0,-0xc(%rbp)
jne    1167 <display_mem+0x57>
mov    -0x14(%rbp),%esi
lea    0xeb1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xea1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x10,-0xc(%rbp)
jne    11b6 <display_mem+0xa6>
lea    0xe75(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0xc(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11dd <display_mem+0xcd>
mov    -0xc(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11d8 <display_mem+0xc8>
lea    0xe47(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11dd <display_mem+0xcd>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    113f <display_mem+0x2f>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<display_mem>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r12
lea    0xecc(%rip),%rdi
call   1040 <puts@plt>
lea    0xeaf(%rip),%r14
lea    0xeb1(%rip),%r15
xor    %ebx,%ebx
xor    %ebp,%ebp
jmp    1175 <display_mem+0x45>
xchg   %ax,%ax
call   1030 <putchar@plt>
mov    %r13d,%ebp
add    $0x1,%rbx
cmp    $0x80,%rbx
je     11b3 <display_mem+0x83>
test   %ebp,%ebp
jne    1185 <display_mem+0x55>
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%r12,%rbx,4),%esi
xor    %r13d,%r13d
mov    %r15,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%ebp
mov    $0xa,%edi
cmp    $0x10,%ebp
je     1160 <display_mem+0x30>
test   $0x3,%bpl
jne    1168 <display_mem+0x38>
mov    $0x20,%edi
mov    %ebp,%r13d
jmp    1160 <display_mem+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str.1 = [9 x i8] c"0x%04X: \00"
@.str.2 = [8 x i8] c"%02hhX \00"
@str = [16 x i8] c"Memory Display:\00"
define void @display_mem(i32* nocapture %0) {
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
br label %4
3: ; preds = %24
ret void
4: ; preds = %1, %24
%5 = phi i64 [ 0, %1 ], [ %26, %24 ]
%6 = phi i32 [ 0, %1 ], [ %25, %24 ]
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %4
%9 = trunc i64 %5 to i32
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %9)
br label %11
11: ; preds = %8, %4
%12 = getelementptr inbounds i32, i32* %0, i64 %5
%13 = load i32, i32* %12
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %13)
%15 = add nsw i32 %6, 1
%16 = icmp eq i32 %15, 16
br i1 %16, label %20, label %17
17: ; preds = %11
%18 = and i32 %15, 3
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %24
20: ; preds = %17, %11
%21 = phi i32 [ 10, %11 ], [ 32, %17 ]
%22 = phi i32 [ 0, %11 ], [ %15, %17 ]
%23 = tail call i32 @putchar(i32 %21)
br label %24
24: ; preds = %20, %17
%25 = phi i32 [ %15, %17 ], [ %22, %20 ]
%26 = add nuw nsw i64 %5, 1
%27 = icmp eq i64 %26, 128
br i1 %27, label %3, label %4
}