#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 printh(char *str) {
  int i = 0;
  char cur = str[0];
  while (cur != '\0') {
    cur = str[i];
    printf("%.2X ", cur);
    if (!(i % 8)) {
      printf("\n");
    }
    i++;
  }
}


x86 assembly (clang, -O0):
<printh>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%al
mov    %al,-0xd(%rbp)
movsbl -0xd(%rbp),%eax
cmp    $0x0,%eax
je     1189 <printh+0x79>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0xd(%rbp)
movsbl -0xd(%rbp),%esi
lea    0xeae(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    117b <printh+0x6b>
lea    0xe92(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    112c <printh+0x1c>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printh>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    (%rdi),%bpl
test   %bpl,%bpl
je     116e <printh+0x4e>
mov    %rdi,%r15
lea    0xec7(%rip),%r14
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
movsbl %bpl,%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
test   $0x7,%bl
jne    115d <printh+0x3d>
mov    $0xa,%edi
call   1030 <putchar@plt>
test   %bpl,%bpl
je     116e <printh+0x4e>
movzbl 0x1(%r15,%rbx,1),%ebp
add    $0x1,%rbx
jmp    1140 <printh+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%.2X \00"
@.str.1 = [2 x i8] c"\0A\00"
define void @printh(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8
store i8* %0, i8** %2
store i32 0, i32* %3
%5 = load i8*, i8** %2
%6 = getelementptr inbounds i8, i8* %5, i64 0
%7 = load i8, i8* %6
store i8 %7, i8* %4
br label %8
8: ; preds = %26, %1
%9 = load i8, i8* %4
%10 = sext i8 %9 to i32
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %29
12: ; preds = %8
%13 = load i8*, i8** %2
%14 = load i32, i32* %3
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %13, i64 %15
%17 = load i8, i8* %16
store i8 %17, i8* %4
%18 = load i8, i8* %4
%19 = sext i8 %18 to i32
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %19)
%21 = load i32, i32* %3
%22 = srem i32 %21, 8
%23 = icmp ne i32 %22, 0
br i1 %23, label %26, label %24
24: ; preds = %12
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %26
26: ; preds = %24, %12
%27 = load i32, i32* %3
%28 = add nsw i32 %27, 1
store i32 %28, i32* %3
br label %8
29: ; preds = %8
ret void
}

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