#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 print_buffer(char *name, unsigned char *pbuffer, int len) {
  int i;
  int num = len;
  if (num > 256)
    num = 256;
  printf("%s\n", name);
  for (i = 0; i < num; i++) {
    printf(" %02X", pbuffer[i]);
    if (i > 0 && (i & 0xFF) == 0)
      printf("\n");
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<print_buffer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x100,-0x1c(%rbp)
jle    113d <print_buffer+0x2d>
movl   $0x100,-0x1c(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xeb8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11b8 <print_buffer+0xa8>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movzbl (%rax,%rcx,1),%esi
lea    0xe8f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x0,-0x18(%rbp)
jle    11a5 <print_buffer+0x95>
mov    -0x18(%rbp),%eax
and    $0xff,%eax
cmp    $0x0,%eax
jne    11a5 <print_buffer+0x95>
lea    0xe64(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11aa <print_buffer+0x9a>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1156 <print_buffer+0x46>
lea    0xe43(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_buffer>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %rsi,%r15
call   1040 <puts@plt>
test   %r14d,%r14d
jle    1178 <print_buffer+0x48>
cmp    $0x100,%r14d
mov    $0x100,%ebp
cmovb  %r14d,%ebp
lea    0xea2(%rip),%r14
xor    %ebx,%ebx
movzbl (%r15,%rbx,1),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1160 <print_buffer+0x30>
mov    $0xa,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <putchar@plt>

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

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