#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 pbuf(void *p, unsigned len, const void *s) {
  unsigned i;
  if (s)
    printf("%s", (char *)s);
  for (i = 0; i < len; i++) {
    printf("%02x", (unsigned)(((unsigned char *)p)[i]));
    if (((i + 1) % 4) == 0)
      printf(" ");
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<pbuf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1140 <pbuf+0x30>
mov    -0x18(%rbp),%rsi
lea    0xec7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jae    119f <pbuf+0x8f>
mov    -0x8(%rbp),%rax
mov    -0x1c(%rbp),%ecx
movzbl (%rax,%rcx,1),%esi
lea    0xe9e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
and    $0x3,%eax
cmp    $0x0,%eax
jne    118c <pbuf+0x7c>
lea    0xe83(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1191 <pbuf+0x81>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1147 <pbuf+0x37>
lea    0xe64(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pbuf>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%r15
test   %rdx,%rdx
je     1142 <pbuf+0x22>
lea    0xec8(%rip),%rdi
mov    %rdx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
test   %ebp,%ebp
je     1193 <pbuf+0x73>
mov    %ebp,%ebp
neg    %rbp
mov    $0x1,%ebx
lea    0xeac(%rip),%r14
jmp    1172 <pbuf+0x52>
nopl   0x0(%rax)
lea    (%rbx,%rbp,1),%rax
add    $0x1,%rax
add    $0x1,%rbx
cmp    $0x1,%rax
je     1193 <pbuf+0x73>
movzbl -0x1(%r15,%rbx,1),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
test   $0x3,%bl
jne    1160 <pbuf+0x40>
mov    $0x20,%edi
call   1030 <putchar@plt>
jmp    1160 <pbuf+0x40>
mov    $0xa,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <putchar@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
@.str.1 = [5 x i8] c"%02x\00"
@.str.2 = [2 x i8] c" \00"
@.str.3 = [2 x i8] c"\0A\00"
define void @pbuf(i8* %0, i32 %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%8 = load i8*, i8** %6
%9 = icmp ne i8* %8, null
br i1 %9, label %10, label %13
10: ; preds = %3
%11 = load i8*, i8** %6
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %11)
br label %13
13: ; preds = %10, %3
store i32 0, i32* %7
br label %14
14: ; preds = %33, %13
%15 = load i32, i32* %7
%16 = load i32, i32* %5
%17 = icmp ult i32 %15, %16
br i1 %17, label %18, label %36
18: ; preds = %14
%19 = load i8*, i8** %4
%20 = load i32, i32* %7
%21 = zext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %19, i64 %21
%23 = load i8, i8* %22
%24 = zext i8 %23 to i32
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %24)
%26 = load i32, i32* %7
%27 = add i32 %26, 1
%28 = urem i32 %27, 4
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %18
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %32
32: ; preds = %30, %18
br label %33
33: ; preds = %32
%34 = load i32, i32* %7
%35 = add i32 %34, 1
store i32 %35, i32* %7
br label %14
36: ; preds = %14
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
ret void
}

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