void show_context(char *str, int str_length, int err_pos_in_str,
                  int faulty_bytes) {
  int chars_before_error = (((err_pos_in_str) < (8)) ? (err_pos_in_str) : (8));
  int chars_after_error =
      (((str_length - err_pos_in_str) < (8)) ? (str_length - err_pos_in_str)
                                             : (8));
  int printed = 0;
  printed = show_hex_str(str + err_pos_in_str - chars_before_error,
                         chars_before_error + chars_after_error);
  printf("%*s | ", 3 * 16 - printed, "");
  show_str(str + err_pos_in_str - chars_before_error,
           chars_before_error + chars_after_error);
  printf("\n");
  printed = printf("%*s", (3 * chars_before_error), "");
  printed +=
      printf("%.*s", faulty_bytes * 2 + faulty_bytes - 1, "^^^^^^^^^^^^^^^^");
  printf("%*s | ", 3 * 16 - printed, "");
  printf("%*s", (chars_before_error), "");
  printf("%.*s", faulty_bytes, "^^^^");
  printf("\n\n");
}


x86 assembly (clang, -O0):
<show_context>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
cmpl   $0x8,-0x10(%rbp)
jge    115a <show_context+0x2a>
mov    -0x10(%rbp),%eax
mov    %eax,-0x24(%rbp)
jmp    1167 <show_context+0x37>
mov    $0x8,%eax
mov    %eax,-0x24(%rbp)
jmp    1167 <show_context+0x37>
mov    -0x24(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0xc(%rbp),%eax
sub    -0x10(%rbp),%eax
cmp    $0x8,%eax
jge    118a <show_context+0x5a>
mov    -0xc(%rbp),%eax
sub    -0x10(%rbp),%eax
mov    %eax,-0x28(%rbp)
jmp    1197 <show_context+0x67>
mov    $0x8,%eax
mov    %eax,-0x28(%rbp)
jmp    1197 <show_context+0x67>
mov    -0x28(%rbp),%eax
mov    %eax,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
movslq -0x10(%rbp),%rax
add    %rax,%rdi
movslq -0x18(%rbp),%rcx
xor    %eax,%eax
sub    %rcx,%rax
add    %rax,%rdi
mov    -0x18(%rbp),%esi
add    -0x1c(%rbp),%esi
mov    $0x0,%al
call   1030 <show_hex_str@plt>
mov    %eax,-0x20(%rbp)
mov    $0x30,%esi
sub    -0x20(%rbp),%esi
lea    0xe26(%rip),%rdi
lea    0xe42(%rip),%rdx
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
movslq -0x10(%rbp),%rax
add    %rax,%rdi
movslq -0x18(%rbp),%rcx
xor    %eax,%eax
sub    %rcx,%rax
add    %rax,%rdi
mov    -0x18(%rbp),%esi
add    -0x1c(%rbp),%esi
mov    $0x0,%al
call   1050 <show_str@plt>
lea    0xe0f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
imul   $0x3,-0x18(%rbp),%esi
lea    0xde2(%rip),%rdi
lea    0xdf7(%rip),%rdx
mov    $0x0,%al
call   1040 <printf@plt>
mov    %eax,-0x20(%rbp)
mov    -0x14(%rbp),%esi
shl    $0x1,%esi
add    -0x14(%rbp),%esi
sub    $0x1,%esi
lea    0xdc2(%rip),%rdi
lea    0xdc0(%rip),%rdx
mov    $0x0,%al
call   1040 <printf@plt>
add    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    $0x30,%esi
sub    -0x20(%rbp),%esi
lea    0xd94(%rip),%rdi
lea    0xdb0(%rip),%rdx
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%esi
lea    0xd83(%rip),%rdi
lea    0xd98(%rip),%rdx
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%esi
lea    0xd6f(%rip),%rdi
lea    0xd79(%rip),%rdx
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xd70(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<show_context>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%r14d
mov    %esi,%ebx
mov    %rdi,%r12
cmp    $0x8,%edx
mov    $0x8,%eax
mov    $0x8,%ecx
cmovl  %edx,%ecx
sub    %edx,%ebx
cmp    $0x8,%ebx
cmovge %eax,%ebx
movslq %edx,%rax
add    %rax,%r12
movslq %ecx,%r13
sub    %r13,%r12
add    %r13d,%ebx
mov    %r12,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <show_hex_str@plt>
mov    $0x30,%ebp
mov    $0x30,%esi
sub    %eax,%esi
lea    0xe57(%rip),%rdi
lea    0xe72(%rip),%r15
mov    %r15,%rdx
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r12,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1070 <show_str@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0x0(%r13,%r13,2),%esi
lea    0xe2b(%rip),%rdi
mov    %r15,%rdx
xor    %eax,%eax
call   1060 <printf@plt>
mov    %eax,%ebx
lea    (%r14,%r14,2),%esi
add    $0xffffffff,%esi
lea    0xe15(%rip),%r12
lea    0xe13(%rip),%rdx
mov    %r12,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
add    %ebx,%eax
sub    %eax,%ebp
lea    0xdee(%rip),%rdi
mov    %ebp,%esi
mov    %r15,%rdx
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xde2(%rip),%rdi
mov    %r13d,%esi
mov    %r15,%rdx
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xde3(%rip),%rdx
mov    %r12,%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xdd4(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <puts@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"%*s | \00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [2 x i8] c"\0A\00"
@.str.3 = [4 x i8] c"%*s\00"
@.str.4 = [5 x i8] c"%.*s\00"
@.str.5 = [17 x i8] c"^^^^^^^^^^^^^^^^\00"
@.str.6 = [5 x i8] c"^^^^\00"
@.str.7 = [3 x i8] c"\0A\0A\00"
define void @show_context(i8* %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%12 = load i32, i32* %7
%13 = icmp slt i32 %12, 8
br i1 %13, label %14, label %16
14: ; preds = %4
%15 = load i32, i32* %7
br label %17
16: ; preds = %4
br label %17
17: ; preds = %16, %14
%18 = phi i32 [ %15, %14 ], [ 8, %16 ]
store i32 %18, i32* %9
%19 = load i32, i32* %6
%20 = load i32, i32* %7
%21 = sub nsw i32 %19, %20
%22 = icmp slt i32 %21, 8
br i1 %22, label %23, label %27
23: ; preds = %17
%24 = load i32, i32* %6
%25 = load i32, i32* %7
%26 = sub nsw i32 %24, %25
br label %28
27: ; preds = %17
br label %28
28: ; preds = %27, %23
%29 = phi i32 [ %26, %23 ], [ 8, %27 ]
store i32 %29, i32* %10
store i32 0, i32* %11
%30 = load i8*, i8** %5
%31 = load i32, i32* %7
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %30, i64 %32
%34 = load i32, i32* %9
%35 = sext i32 %34 to i64
%36 = sub i64 0, %35
%37 = getelementptr inbounds i8, i8* %33, i64 %36
%38 = load i32, i32* %9
%39 = load i32, i32* %10
%40 = add nsw i32 %38, %39
%41 = call i32 (i8*, i32, ...) bitcast (i32 (...)* @show_hex_str to i32 (i8*, i32, ...)*)(i8* %37, i32 %40)
store i32 %41, i32* %11
%42 = load i32, i32* %11
%43 = sub nsw i32 48, %42
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %43, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
%45 = load i8*, i8** %5
%46 = load i32, i32* %7
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i8, i8* %45, i64 %47
%49 = load i32, i32* %9
%50 = sext i32 %49 to i64
%51 = sub i64 0, %50
%52 = getelementptr inbounds i8, i8* %48, i64 %51
%53 = load i32, i32* %9
%54 = load i32, i32* %10
%55 = add nsw i32 %53, %54
%56 = call i32 (i8*, i32, ...) bitcast (i32 (...)* @show_str to i32 (i8*, i32, ...)*)(i8* %52, i32 %55)
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%58 = load i32, i32* %9
%59 = mul nsw i32 3, %58
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %59, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
store i32 %60, i32* %11
%61 = load i32, i32* %8
%62 = mul nsw i32 %61, 2
%63 = load i32, i32* %8
%64 = add nsw i32 %62, %63
%65 = sub nsw i32 %64, 1
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %65, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0))
%67 = load i32, i32* %11
%68 = add nsw i32 %67, %66
store i32 %68, i32* %11
%69 = load i32, i32* %11
%70 = sub nsw i32 48, %69
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %70, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
%72 = load i32, i32* %9
%73 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %72, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
%74 = load i32, i32* %8
%75 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %74, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
%76 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [7 x i8] c"%*s | \00"
@.str.1 = [1 x i8] zeroinitializer
@.str.3 = [4 x i8] c"%*s\00"
@.str.4 = [5 x i8] c"%.*s\00"
@.str.5 = [17 x i8] c"^^^^^^^^^^^^^^^^\00"
@.str.6 = [5 x i8] c"^^^^\00"
@str = [2 x i8] c"\0A\00"
define void @show_context(i8* %0, i32 %1, i32 %2, i32 %3) {
%5 = icmp slt i32 %2, 8
%6 = select i1 %5, i32 %2, i32 8
%7 = sub nsw i32 %1, %2
%8 = icmp slt i32 %7, 8
%9 = select i1 %8, i32 %7, i32 8
%10 = sext i32 %2 to i64
%11 = getelementptr inbounds i8, i8* %0, i64 %10
%12 = sext i32 %6 to i64
%13 = sub nsw i64 0, %12
%14 = getelementptr inbounds i8, i8* %11, i64 %13
%15 = add nsw i32 %9, %6
%16 = tail call i32 (i8*, i32, ...) bitcast (i32 (...)* @show_hex_str to i32 (i8*, i32, ...)*)(i8* %14, i32 %15)
%17 = sub nsw i32 48, %16
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %17, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
%19 = tail call i32 (i8*, i32, ...) bitcast (i32 (...)* @show_str to i32 (i8*, i32, ...)*)(i8* %14, i32 %15)
%20 = tail call i32 @putchar(i32 10)
%21 = mul nsw i32 %6, 3
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %21, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
%23 = mul nsw i32 %3, 3
%24 = add nsw i32 %23, -1
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %24, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0))
%26 = add i32 %22, %25
%27 = sub i32 48, %26
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %27, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %6, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
%30 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
%31 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0))
ret void
}