#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 /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, ...);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ stderr;
void stk_line(int *stk, int index) {
  int val = stk[index];
  int job = 1 + (int)(val / 3);
  int lev = val % 3;
  char c;
  printf("%d ", val);
  switch (lev) {
  case 0:
    c = 'L';
    break;
  case 1:
    c = 'M';
    break;
  case 2:
    c = 'H';
    break;
  }
  if (job < 6)
    fprintf(stderr, "0x%04X: %*d%c\n", index, job * 5, job, c);
  else
    fprintf(stderr, "0x%04X: spare stack slot (for interrupts)\n", index);
}


x86 assembly (clang, -O0):
<stk_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x10(%rbp)
movslq -0x10(%rbp),%rax
imul   $0x55555556,%rax,%rax
mov    %rax,%rcx
shr    $0x20,%rcx
mov    %ecx,%edx
shr    $0x3f,%rax
mov    %eax,%ecx
mov    %edx,%eax
lea    0x1(%rax,%rcx,1),%eax
mov    %eax,-0x14(%rbp)
movslq -0x10(%rbp),%rcx
mov    %ecx,%eax
imul   $0x55555556,%rcx,%rdx
mov    %rdx,%rcx
shr    $0x3f,%rcx
shr    $0x20,%rdx
add    %ecx,%edx
mov    %edx,%ecx
lea    (%rcx,%rcx,2),%ecx
sub    %ecx,%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%esi
lea    0xe72(%rip),%rdi
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x20(%rbp)
test   %eax,%eax
je     11c8 <stk_line+0xa8>
jmp    11a6 <stk_line+0x86>
mov    -0x20(%rbp),%eax
sub    $0x1,%eax
je     11d1 <stk_line+0xb1>
jmp    11b7 <stk_line+0x97>
mov    -0x20(%rbp),%eax
sub    $0x2,%eax
je     11da <stk_line+0xba>
jmp    11de <stk_line+0xbe>
movb   $0x4c,-0x19(%rbp)
jmp    11de <stk_line+0xbe>
movb   $0x4d,-0x19(%rbp)
jmp    11de <stk_line+0xbe>
movb   $0x48,-0x19(%rbp)
cmpl   $0x6,-0x14(%rbp)
jge    1214 <stk_line+0xf4>
mov    0x2df1(%rip),%rax
mov    (%rax),%edi
mov    -0xc(%rbp),%edx
imul   $0x5,-0x14(%rbp),%ecx
mov    -0x14(%rbp),%r8d
movsbl -0x19(%rbp),%r9d
lea    0xdfc(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    122e <stk_line+0x10e>
mov    0x2dc5(%rip),%rax
mov    (%rax),%edi
mov    -0xc(%rbp),%edx
lea    0xdec(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stk_line>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%r14d
movslq %esi,%rax
movslq (%rdi,%rax,4),%r12
imul   $0x55555556,%r12,%rbp
mov    %rbp,%r15
shr    $0x3f,%r15
shr    $0x20,%rbp
lea    (%r15,%rbp,1),%eax
lea    (%rax,%rax,2),%eax
mov    %r12d,%ebx
sub    %eax,%ebx
lea    0xea9(%rip),%rdi
mov    %r12d,%esi
call   1030 <printf@plt>
xor    %r9d,%r9d
cmp    $0x2,%ebx
ja     1175 <stk_line+0x55>
movslq %ebx,%rax
lea    0xecf(%rip),%rcx
mov    (%rcx,%rax,4),%r9d
mov    0x2e64(%rip),%rax
mov    (%rax),%edi
cmp    $0xe,%r12d
jg     11a9 <stk_line+0x89>
lea    (%r15,%rbp,1),%r8d
add    $0x1,%r8d
lea    (%r8,%r8,4),%ecx
lea    0xe6d(%rip),%rsi
mov    %r14d,%edx
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <fprintf@plt>
lea    0xe63(%rip),%rsi
mov    %r14d,%edx
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <fprintf@plt>

LLVM IR (-O0):
@.str = [4 x i8] c"%d \00"
@stderr = global i32 0
@.str.1 = [15 x i8] c"0x%04X: %*d%c\0A\00"
@.str.2 = [43 x i8] c"0x%04X: spare stack slot (for interrupts)\0A\00"
define void @stk_line(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8
store i32* %0, i32** %3
store i32 %1, i32* %4
%9 = load i32*, i32** %3
%10 = load i32, i32* %4
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i32, i32* %9, i64 %11
%13 = load i32, i32* %12
store i32 %13, i32* %5
%14 = load i32, i32* %5
%15 = sdiv i32 %14, 3
%16 = add nsw i32 1, %15
store i32 %16, i32* %6
%17 = load i32, i32* %5
%18 = srem i32 %17, 3
store i32 %18, i32* %7
%19 = load i32, i32* %5
%20 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %19)
%21 = load i32, i32* %7
switch i32 %21, label %25 [
i32 0, label %22
i32 1, label %23
i32 2, label %24
]
22: ; preds = %2
store i8 76, i8* %8
br label %25
23: ; preds = %2
store i8 77, i8* %8
br label %25
24: ; preds = %2
store i8 72, i8* %8
br label %25
25: ; preds = %2, %24, %23, %22
%26 = load i32, i32* %6
%27 = icmp slt i32 %26, 6
br i1 %27, label %28, label %37
28: ; preds = %25
%29 = load i32, i32* @stderr
%30 = load i32, i32* %4
%31 = load i32, i32* %6
%32 = mul nsw i32 %31, 5
%33 = load i32, i32* %6
%34 = load i8, i8* %8
%35 = sext i8 %34 to i32
%36 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %30, i32 %32, i32 %33, i32 %35)
br label %41
37: ; preds = %25
%38 = load i32, i32* @stderr
%39 = load i32, i32* %4
%40 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %38, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0), i32 %39)
br label %41
41: ; preds = %37, %28
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"%d \00"
@stderr = global i32 0
@.str.1 = [15 x i8] c"0x%04X: %*d%c\0A\00"
@.str.2 = [43 x i8] c"0x%04X: spare stack slot (for interrupts)\0A\00"
@switch.table.stk_line = [3 x i32] [i32 76, i32 77, i32 72]
define void @stk_line(i32* nocapture %0, i32 %1) {
%3 = sext i32 %1 to i64
%4 = getelementptr inbounds i32, i32* %0, i64 %3
%5 = load i32, i32* %4
%6 = sdiv i32 %5, 3
%7 = add nsw i32 %6, 1
%8 = srem i32 %5, 3
%9 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %5)
%10 = icmp ult i32 %8, 3
br i1 %10, label %11, label %15
11: ; preds = %2
%12 = sext i32 %8 to i64
%13 = getelementptr inbounds [3 x i32], [3 x i32]* @switch.table.stk_line, i64 0, i64 %12
%14 = load i32, i32* %13
br label %15
15: ; preds = %11, %2
%16 = phi i32 [ 0, %2 ], [ %14, %11 ]
%17 = icmp slt i32 %5, 15
%18 = load i32, i32* @stderr
br i1 %17, label %19, label %22
19: ; preds = %15
%20 = mul nsw i32 %7, 5
%21 = tail call i32 (i32, i8*, i32, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %1, i32 %20, i32 %7, i32 %16)
br label %24
22: ; preds = %15
%23 = tail call i32 (i32, i8*, i32, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0), i32 %1)
br label %24
24: ; preds = %22, %19
ret void
}