#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 */
typedef scalar_t__ u_char;

/* Variables and functions */
int /*<<< orphan*/ sprintf(char *, char *, int);
const char *print_bin(u_char *bin, char *txt, size_t sz_bin) {
  char *ptr = txt;
  size_t i;
  for (i = 0; i < sz_bin; ++i) {
    sprintf(ptr, "%02x ", (int)bin[i]);
    ptr += 3;
  }
  txt[sz_bin * 3] = '\0';
  return txt;
}


x86 assembly (clang, -O0):
<print_bin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    117d <print_bin+0x6d>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %eax,%edx
lea    0xea5(%rip),%rsi
call   1030 <sprintf@plt>
mov    -0x20(%rbp),%rax
add    $0x3,%rax
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1134 <print_bin+0x24>
mov    -0x10(%rbp),%rax
imul   $0x3,-0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_bin>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r13
mov    %rsi,%r14
test   %rdx,%rdx
je     115c <print_bin+0x4c>
mov    %rdi,%r15
xor    %ebp,%ebp
lea    0xece(%rip),%r12
mov    %r14,%rbx
cs nopw 0x0(%rax,%rax,1)
nop
mov    (%r15,%rbp,8),%edx
mov    %rbx,%rdi
mov    %r12,%rsi
call   1030 <sprintf@plt>
add    $0x3,%rbx
add    $0x1,%rbp
cmp    %rbp,%r13
jne    1140 <print_bin+0x30>
lea    0x0(,%r13,2),%rax
add    %r13,%rax
movb   $0x0,(%r14,%rax,1)
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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