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

/* Variables and functions */
int /*<<< orphan*/ printf(char *, int const, char);
int /*<<< orphan*/ putchar(char);
void show_stack_state(const int8_t *stack, size_t stack_size) {
  for (size_t i = 0; i < stack_size; ++i)
    printf("%4d%c", stack[i], (i + 1) % (2 << 3) == 0 ? '\n' : ' ');
  putchar('\n');
}


x86 assembly (clang, -O0):
<show_stack_state>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    118e <show_stack_state+0x6e>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
mov    -0x18(%rbp),%rdx
add    $0x1,%rdx
and    $0xf,%rdx
mov    $0x20,%eax
mov    $0xa,%ecx
cmp    $0x0,%rdx
cmove  %ecx,%eax
lea    0xe8b(%rip),%rdi
movsbl %al,%edx
call   1040 <printf@plt>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1138 <show_stack_state+0x18>
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<show_stack_state>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
test   %rsi,%rsi
je     117a <show_stack_state+0x5a>
mov    %rsi,%r12
mov    %rdi,%r14
neg    %r12
mov    $0x1,%ebx
mov    $0xa,%ebp
lea    0xeb9(%rip),%r15
nopw   0x0(%rax,%rax,1)
mov    -0x4(%r14,%rbx,4),%esi
test   $0xf,%bl
mov    $0x20,%edx
cmove  %ebp,%edx
mov    %r15,%rdi
call   1040 <printf@plt>
lea    (%r12,%rbx,1),%rax
add    $0x1,%rax
add    $0x1,%rbx
cmp    $0x1,%rax
jne    1150 <show_stack_state+0x30>
mov    $0xa,%edi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <putchar@plt>

LLVM IR (-O0):
@.str = [6 x i8] c"%4d%c\00"
define void @show_stack_state(i32* %0, i64 %1) {
%3 = alloca i32*
%4 = alloca i64
%5 = alloca i64
store i32* %0, i32** %3
store i64 %1, i64* %4
store i64 0, i64* %5
br label %6
6: ; preds = %23, %2
%7 = load i64, i64* %5
%8 = load i64, i64* %4
%9 = icmp ult i64 %7, %8
br i1 %9, label %10, label %26
10: ; preds = %6
%11 = load i32*, i32** %3
%12 = load i64, i64* %5
%13 = getelementptr inbounds i32, i32* %11, i64 %12
%14 = load i32, i32* %13
%15 = load i64, i64* %5
%16 = add i64 %15, 1
%17 = urem i64 %16, 16
%18 = icmp eq i64 %17, 0
%19 = zext i1 %18 to i64
%20 = select i1 %18, i32 10, i32 32
%21 = trunc i32 %20 to i8
%22 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %14, i8 signext %21)
br label %23
23: ; preds = %10
%24 = load i64, i64* %5
%25 = add i64 %24, 1
store i64 %25, i64* %5
br label %6
26: ; preds = %6
%27 = call i32 @putchar(i8 signext 10)
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c"%4d%c\00"
define void @show_stack_state(i32* nocapture %0, i64 %1) {
%3 = icmp eq i64 %1, 0
br i1 %3, label %4, label %6
4: ; preds = %6, %2
%5 = tail call i32 @putchar(i8 signext 10)
ret void
6: ; preds = %2, %6
%7 = phi i64 [ %10, %6 ], [ 0, %2 ]
%8 = getelementptr inbounds i32, i32* %0, i64 %7
%9 = load i32, i32* %8
%10 = add nuw i64 %7, 1
%11 = and i64 %10, 15
%12 = icmp eq i64 %11, 0
%13 = select i1 %12, i8 10, i8 32
%14 = tail call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %9, i8 signext %13)
%15 = icmp eq i64 %10, %1
br i1 %15, label %4, label %6
}