#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*/ printf(char *, ...);
void tohexn(unsigned char *s, int len) {
  int i = 0;
  printf("\t%4.4d: ", i);
  for (i = 0; i < len; i++) {
    printf("0x%2.2x ", s[i]);
    if ((i % 16) == 15) {
      printf("\n\t%4.4d: ", i + 1);
    }
  }
  if ((i % 16) != 15) {
    printf("\n");
  }
}


x86 assembly (clang, -O0):
<tohexn>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%esi
lea    0xeda(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    119f <tohexn+0x8f>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movzbl (%rax,%rcx,1),%esi
lea    0xea3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0xf,%edx
jne    118c <tohexn+0x7c>
mov    -0x10(%rbp),%esi
add    $0x1,%esi
lea    0xe84(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1191 <tohexn+0x81>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    113e <tohexn+0x2e>
mov    -0x10(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0xf,%edx
je     11c1 <tohexn+0xb1>
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tohexn>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %rdi,%r13
lea    0xed3(%rip),%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1040 <printf@plt>
test   %ebx,%ebx
jle    11ae <tohexn+0x8e>
mov    %ebx,0x4(%rsp)
mov    %ebx,%ebx
lea    0xeaf(%rip),%r12
lea    0xeb1(%rip),%r15
xor    %ebp,%ebp
jmp    1168 <tohexn+0x48>
nopl   0x0(%rax)
mov    %r14,%rbp
cmp    %r14,%rbx
je     1195 <tohexn+0x75>
movzbl 0x0(%r13,%rbp,1),%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebp,%eax
not    %eax
lea    0x1(%rbp),%r14
test   $0xf,%al
jne    1160 <tohexn+0x40>
add    $0x1,%ebp
mov    %r15,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1160 <tohexn+0x40>
mov    0x4(%rsp),%eax
not    %eax
test   $0xf,%al
jne    11ae <tohexn+0x8e>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0xa,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <putchar@plt>

LLVM IR (-O0):
@.str = [9 x i8] c"\09%4.4d: \00"
@.str.1 = [9 x i8] c"0x%2.2x \00"
@.str.2 = [10 x i8] c"\0A\09%4.4d: \00"
@.str.3 = [2 x i8] c"\0A\00"
define void @tohexn(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
store i32 0, i32* %5
%6 = load i32, i32* %5
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %6)
store i32 0, i32* %5
br label %8
8: ; preds = %28, %2
%9 = load i32, i32* %5
%10 = load i32, i32* %4
%11 = icmp slt i32 %9, %10
br i1 %11, label %12, label %31
12: ; preds = %8
%13 = load i8*, i8** %3
%14 = load i32, i32* %5
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %13, i64 %15
%17 = load i8, i8* %16
%18 = zext i8 %17 to i32
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %18)
%20 = load i32, i32* %5
%21 = srem i32 %20, 16
%22 = icmp eq i32 %21, 15
br i1 %22, label %23, label %27
23: ; preds = %12
%24 = load i32, i32* %5
%25 = add nsw i32 %24, 1
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 %25)
br label %27
27: ; preds = %23, %12
br label %28
28: ; preds = %27
%29 = load i32, i32* %5
%30 = add nsw i32 %29, 1
store i32 %30, i32* %5
br label %8
31: ; preds = %8
%32 = load i32, i32* %5
%33 = srem i32 %32, 16
%34 = icmp ne i32 %33, 15
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.3, i64 0, i64 0))
br label %37
37: ; preds = %35, %31
ret void
}

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