#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;
typedef int /*<<< orphan*/ WINDOW;

/* Variables and functions */
int /*<<< orphan*/ mvwprintw(int /*<<< orphan*/ *, int, int, char *, ...);
int /*<<< orphan*/ wprintw(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ wrefresh(int /*<<< orphan*/ *);
void curses_display_mem(WINDOW *win, uint8_t *memory) {
  int display_counter = 0;
  int rollover_counter = 0;
  (void)mvwprintw(win, 1, 2, "Memory Display:");
  for (int i = 0; i < 128; i++) {
    if (display_counter == 0)
      (void)mvwprintw(win, rollover_counter + 2, 2, "0x%04hhX: ", i);
    (void)wprintw(win, "%02hhX ", memory[i]);
    display_counter++;
    if (display_counter == 16) {
      display_counter = 0;
      rollover_counter++;
      (void)wrefresh(win);
    }
    if (display_counter % 4 == 0)
      (void)wprintw(win, " ");
  }
}


x86 assembly (clang, -O0):
<curses_display_mem>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x1,%esi
mov    $0x2,%edx
lea    0xe9d(%rip),%rcx
mov    $0x0,%al
call   1050 <mvwprintw@plt>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x80,-0x1c(%rbp)
jge    122b <curses_display_mem+0xfb>
cmpl   $0x0,-0x14(%rbp)
jne    11a9 <curses_display_mem+0x79>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%esi
add    $0x2,%esi
mov    -0x1c(%rbp),%r8d
mov    $0x2,%edx
lea    0xe6e(%rip),%rcx
mov    $0x0,%al
call   1050 <mvwprintw@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xe5c(%rip),%rsi
mov    $0x0,%al
call   1040 <wprintw@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x10,-0x14(%rbp)
jne    11f2 <curses_display_mem+0xc2>
movl   $0x0,-0x14(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <wrefresh@plt>
mov    -0x14(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1218 <curses_display_mem+0xe8>
mov    -0x8(%rbp),%rdi
lea    0xe08(%rip),%rsi
mov    $0x0,%al
call   1040 <wprintw@plt>
jmp    121d <curses_display_mem+0xed>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1171 <curses_display_mem+0x41>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<curses_display_mem>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xeb8(%rip),%rcx
mov    $0x1,%esi
mov    $0x2,%edx
xor    %eax,%eax
call   1050 <mvwprintw@plt>
lea    0xebb(%rip),%r12
xor    %ebp,%ebp
xor    %r15d,%r15d
xor    %r13d,%r13d
jmp    119d <curses_display_mem+0x6d>
nopw   0x0(%rax,%rax,1)
add    $0x1,%r15d
mov    %rbx,%rdi
call   1030 <wrefresh@plt>
xor    %r13d,%r13d
mov    %rbx,%rdi
lea    0xe90(%rip),%rsi
xor    %eax,%eax
call   1040 <wprintw@plt>
add    $0x1,%rbp
cmp    $0x80,%rbp
je     11e2 <curses_display_mem+0xb2>
test   %r13d,%r13d
jne    11bf <curses_display_mem+0x8f>
lea    0x2(%r15),%esi
mov    %rbx,%rdi
mov    $0x2,%edx
lea    0xe5b(%rip),%rcx
mov    %ebp,%r8d
xor    %eax,%eax
call   1050 <mvwprintw@plt>
mov    (%r14,%rbp,4),%edx
mov    %rbx,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1040 <wprintw@plt>
add    $0x1,%r13d
cmp    $0x10,%r13d
je     1170 <curses_display_mem+0x40>
test   $0x3,%r13b
jne    1190 <curses_display_mem+0x60>
jmp    117f <curses_display_mem+0x4f>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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