#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_bin_func(const char *name, size_t len, const void *s,
                    const char *func) {
  printf("%s:%s:len=%d:[", func, name, (int)len);
  size_t i;
  for (i = 0; i < len; i++) {
    printf("%02x", (int)((const unsigned char *)s)[i]);
  }
  printf("]\n");
}


x86 assembly (clang, -O0):
<print_bin_func>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x20(%rbp),%rsi
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rax
mov    %eax,%ecx
lea    0xec3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    1185 <print_bin_func+0x75>
mov    -0x18(%rbp),%rax
mov    -0x28(%rbp),%rcx
movzbl (%rax,%rcx,1),%esi
lea    0xea2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    114c <print_bin_func+0x3c>
lea    0xe88(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_bin_func>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r12
mov    %rdi,%rdx
lea    0xec8(%rip),%rdi
mov    %rcx,%rsi
mov    %r12d,%ecx
xor    %eax,%eax
call   1040 <printf@plt>
test   %r12,%r12
je     1178 <print_bin_func+0x58>
lea    0xebe(%rip),%r15
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movzbl (%r14,%rbx,1),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1160 <print_bin_func+0x40>
lea    0xe95(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <puts@plt>

LLVM IR (-O0):
@.str = [15 x i8] c"%s:%s:len=%d:[\00"
@.str.1 = [5 x i8] c"%02x\00"
@.str.2 = [3 x i8] c"]\0A\00"
define void @print_bin_func(i8* %0, i64 %1, i8* %2, i8* %3) {
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i64
store i8* %0, i8** %5
store i64 %1, i64* %6
store i8* %2, i8** %7
store i8* %3, i8** %8
%10 = load i8*, i8** %8
%11 = load i8*, i8** %5
%12 = load i64, i64* %6
%13 = trunc i64 %12 to i32
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %10, i8* %11, i32 %13)
store i64 0, i64* %9
br label %15
15: ; preds = %26, %4
%16 = load i64, i64* %9
%17 = load i64, i64* %6
%18 = icmp ult i64 %16, %17
br i1 %18, label %19, label %29
19: ; preds = %15
%20 = load i8*, i8** %7
%21 = load i64, i64* %9
%22 = getelementptr inbounds i8, i8* %20, 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)
br label %26
26: ; preds = %19
%27 = load i64, i64* %9
%28 = add i64 %27, 1
store i64 %28, i64* %9
br label %15
29: ; preds = %15
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
ret void
}

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