#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 *, ...);
int strlen(char *);
void tohex(unsigned char *s) {
  int i = 0;
  int len = strlen((char *)s) + 1;
  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):
<tohex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%esi
lea    0xebe(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    11bb <tohex+0x9b>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movzbl (%rax,%rcx,1),%esi
lea    0xe87(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0xc(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0xf,%edx
jne    11a8 <tohex+0x88>
mov    -0xc(%rbp),%esi
add    $0x1,%esi
lea    0xe68(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11ad <tohex+0x8d>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    115a <tohex+0x3a>
mov    -0xc(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0xf,%edx
je     11dd <tohex+0xbd>
lea    0xe3d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tohex>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
call   1040 <strlen@plt>
mov    %eax,%r13d
lea    0xebd(%rip),%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1050 <printf@plt>
test   %r13d,%r13d
js     11cc <tohex+0x9c>
add    $0x1,%r13d
lea    0xe9a(%rip),%r15
lea    0xe9c(%rip),%r12
xor    %ebx,%ebx
jmp    1188 <tohex+0x58>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbp,%rbx
cmp    %rbp,%r13
je     11b4 <tohex+0x84>
movzbl (%r14,%rbx,1),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebx,%eax
not    %eax
lea    0x1(%rbx),%rbp
test   $0xf,%al
jne    1180 <tohex+0x50>
add    $0x1,%ebx
mov    %r12,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1180 <tohex+0x50>
not    %r13d
test   $0xf,%r13b
jne    11cc <tohex+0x9c>
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 @tohex(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %3
%5 = load i8*, i8** %2
%6 = call i32 @strlen(i8* %5)
%7 = add nsw i32 %6, 1
store i32 %7, i32* %4
%8 = load i32, i32* %3
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %8)
store i32 0, i32* %3
br label %10
10: ; preds = %30, %1
%11 = load i32, i32* %3
%12 = load i32, i32* %4
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %33
14: ; preds = %10
%15 = load i8*, i8** %2
%16 = load i32, i32* %3
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %15, i64 %17
%19 = load i8, i8* %18
%20 = zext i8 %19 to i32
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %20)
%22 = load i32, i32* %3
%23 = srem i32 %22, 16
%24 = icmp eq i32 %23, 15
br i1 %24, label %25, label %29
25: ; preds = %14
%26 = load i32, i32* %3
%27 = add nsw i32 %26, 1
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 %27)
br label %29
29: ; preds = %25, %14
br label %30
30: ; preds = %29
%31 = load i32, i32* %3
%32 = add nsw i32 %31, 1
store i32 %32, i32* %3
br label %10
33: ; preds = %10
%34 = load i32, i32* %3
%35 = srem i32 %34, 16
%36 = icmp ne i32 %35, 15
br i1 %36, label %37, label %39
37: ; preds = %33
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %39
39: ; preds = %37, %33
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 @tohex(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%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 slt i32 %2, 0
br i1 %4, label %25, label %5
5: ; preds = %1
%6 = add nuw i32 %2, 1
%7 = zext i32 %6 to i64
br label %8
8: ; preds = %5, %20
%9 = phi i64 [ 0, %5 ], [ %16, %20 ]
%10 = getelementptr inbounds i8, i8* %0, i64 %9
%11 = load i8, i8* %10
%12 = zext i8 %11 to i32
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %12)
%14 = and i64 %9, 15
%15 = icmp eq i64 %14, 15
%16 = add nuw nsw i64 %9, 1
br i1 %15, label %17, label %20
17: ; preds = %8
%18 = trunc i64 %16 to i32
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 %18)
br label %20
20: ; preds = %8, %17
%21 = icmp eq i64 %16, %7
br i1 %21, label %22, label %8
22: ; preds = %20
%23 = and i32 %6, 15
%24 = icmp eq i32 %23, 15
br i1 %24, label %27, label %25
25: ; preds = %1, %22
%26 = tail call i32 @putchar(i32 10)
br label %27
27: ; preds = %25, %22
ret void
}