#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 int /*<<< orphan*/ BIO;

/* Variables and functions */
scalar_t__ BIO_printf(int /*<<< orphan*/ *, char *, ...);
scalar_t__ BIO_write(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ memset(char *, char, int);
int print_bin(BIO *fp, const char *name, const unsigned char *buf, size_t len,
              int off) {
  size_t i;
  char str[128];
  if (buf == NULL)
    return 1;
  if (off > 0) {
    if (off > 128)
      off = 128;
    memset(str, ' ', off);
    if (BIO_write(fp, str, off) <= 0)
      return 0;
  } else {
    off = 0;
  }
  if (BIO_printf(fp, "%s", name) <= 0)
    return 0;
  for (i = 0; i < len; i++) {
    if ((i % 15) == 0) {
      str[0] = '\n';
      memset(&(str[1]), ' ', off + 4);
      if (BIO_write(fp, str, off + 1 + 4) <= 0)
        return 0;
    }
    if (BIO_printf(fp, "%02x%s", buf[i], ((i + 1) == len) ? "" : ":") <= 0)
      return 0;
  }
  if (BIO_write(fp, "\n", 1) <= 0)
    return 0;
  return 1;
}


x86 assembly (clang, -O0):
<print_bin>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8d,-0x2c(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1166 <print_bin+0x36>
movl   $0x1,-0x4(%rbp)
jmp    131a <print_bin+0x1ea>
cmpl   $0x0,-0x2c(%rbp)
jle    11c6 <print_bin+0x96>
cmpl   $0x80,-0x2c(%rbp)
jle    1184 <print_bin+0x54>
movl   $0x80,-0x2c(%rbp)
lea    -0xc0(%rbp),%rdi
mov    -0x2c(%rbp),%edx
mov    $0x20,%esi
call   1040 <memset@plt>
mov    -0x10(%rbp),%rdi
lea    -0xc0(%rbp),%rsi
mov    -0x2c(%rbp),%edx
call   1050 <BIO_write@plt>
cmp    $0x0,%rax
jg     11c1 <print_bin+0x91>
movl   $0x0,-0x4(%rbp)
jmp    131a <print_bin+0x1ea>
jmp    11cd <print_bin+0x9d>
movl   $0x0,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe28(%rip),%rsi
mov    $0x0,%al
call   1030 <BIO_printf@plt>
cmp    $0x0,%rax
jg     11f9 <print_bin+0xc9>
movl   $0x0,-0x4(%rbp)
jmp    131a <print_bin+0x1ea>
movq   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%rax
cmp    -0x28(%rbp),%rax
jae    12e8 <print_bin+0x1b8>
mov    -0x38(%rbp),%rax
mov    $0xf,%ecx
xor    %edx,%edx
div    %rcx
cmp    $0x0,%rdx
jne    127d <print_bin+0x14d>
movb   $0xa,-0xc0(%rbp)
lea    -0xc0(%rbp),%rdi
add    $0x1,%rdi
mov    -0x2c(%rbp),%edx
add    $0x4,%edx
mov    $0x20,%esi
call   1040 <memset@plt>
mov    -0x10(%rbp),%rdi
lea    -0xc0(%rbp),%rsi
mov    -0x2c(%rbp),%edx
add    $0x1,%edx
add    $0x4,%edx
call   1050 <BIO_write@plt>
cmp    $0x0,%rax
jg     1278 <print_bin+0x148>
movl   $0x0,-0x4(%rbp)
jmp    131a <print_bin+0x1ea>
jmp    127d <print_bin+0x14d>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    -0x38(%rbp),%rcx
movzbl (%rax,%rcx,1),%edx
mov    -0x38(%rbp),%rsi
add    $0x1,%rsi
mov    -0x28(%rbp),%r8
lea    0xd67(%rip),%rcx
lea    0xd63(%rip),%rax
cmp    %r8,%rsi
cmove  %rax,%rcx
lea    0xd4b(%rip),%rsi
mov    $0x0,%al
call   1030 <BIO_printf@plt>
cmp    $0x0,%rax
jg     12d2 <print_bin+0x1a2>
movl   $0x0,-0x4(%rbp)
jmp    131a <print_bin+0x1ea>
jmp    12d7 <print_bin+0x1a7>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    1201 <print_bin+0xd1>
mov    -0x10(%rbp),%rdi
lea    0xd16(%rip),%rsi
mov    $0x1,%edx
call   1050 <BIO_write@plt>
cmp    $0x0,%rax
jg     1313 <print_bin+0x1e3>
movl   $0x0,-0x4(%rbp)
jmp    131a <print_bin+0x1ea>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_bin>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xa8,%rsp
mov    %rcx,0x10(%rsp)
mov    %rdx,0x18(%rsp)
test   %rdx,%rdx
je     127d <print_bin+0x14d>
mov    %rsi,%r13
mov    %rdi,%rbx
xor    %ebp,%ebp
mov    $0x0,%r12d
test   %r8d,%r8d
jle    11a4 <print_bin+0x74>
cmp    $0x80,%r8d
mov    $0x80,%r12d
cmovb  %r8d,%r12d
lea    0x20(%rsp),%r14
mov    %r14,%rdi
mov    $0x20,%esi
mov    %r12d,%edx
call   1040 <memset@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r12d,%edx
call   1050 <BIO_write@plt>
test   %rax,%rax
jle    12a1 <print_bin+0x171>
lea    0xe59(%rip),%rsi
mov    %rbx,%rdi
mov    %r13,%rdx
xor    %eax,%eax
call   1030 <BIO_printf@plt>
test   %rax,%rax
jle    12a1 <print_bin+0x171>
lea    0x4(%r12),%eax
mov    %eax,0xc(%rsp)
add    $0x5,%r12d
mov    0x10(%rsp),%rax
lea    -0x1(%rax),%r14
xor    %r13d,%r13d
xor    %ebp,%ebp
jmp    1220 <print_bin+0xf0>
xchg   %ax,%ax
mov    0x18(%rsp),%rax
movzbl (%rax,%r13,1),%edx
lea    0x1(%r13),%r15
cmp    %r13,%r14
lea    0xe0f(%rip),%rcx
lea    0xe0b(%rip),%rax
cmove  %rax,%rcx
mov    %rbx,%rdi
lea    0xdf3(%rip),%rsi
xor    %eax,%eax
call   1030 <BIO_printf@plt>
mov    %r15,%r13
test   %rax,%rax
jle    12a1 <print_bin+0x171>
mov    %r13,%rax
movabs $0x8888888888888889,%rcx
88 88 88
mul    %rcx
cmp    %r13,0x10(%rsp)
je     1284 <print_bin+0x154>
shr    $0x3,%rdx
lea    (%rdx,%rdx,4),%rax
lea    (%rax,%rax,2),%rax
cmp    %r13,%rax
jne    11e0 <print_bin+0xb0>
movb   $0xa,0x20(%rsp)
lea    0x21(%rsp),%rdi
mov    $0x20,%esi
mov    0xc(%rsp),%edx
call   1040 <memset@plt>
mov    %rbx,%rdi
lea    0x20(%rsp),%rsi
mov    %r12d,%edx
call   1050 <BIO_write@plt>
test   %rax,%rax
jg     11e0 <print_bin+0xb0>
xor    %ebp,%ebp
jmp    12a1 <print_bin+0x171>
mov    $0x1,%ebp
jmp    12a1 <print_bin+0x171>
lea    0xd7e(%rip),%rsi
mov    %rbx,%rdi
mov    $0x1,%edx
call   1050 <BIO_write@plt>
xor    %ebp,%ebp
test   %rax,%rax
setg   %bpl
mov    %ebp,%eax
add    $0xa8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
@.str.1 = [7 x i8] c"%02x%s\00"
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [2 x i8] c":\00"
@.str.4 = [2 x i8] c"\0A\00"
define i32 @print_bin(i32* %0, i8* %1, i8* %2, i64 %3, i32 %4) {
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i32
%12 = alloca i64
%13 = alloca [128 x i8]
store i32* %0, i32** %7
store i8* %1, i8** %8
store i8* %2, i8** %9
store i64 %3, i64* %10
store i32 %4, i32* %11
%14 = load i8*, i8** %9
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %17
16: ; preds = %5
store i32 1, i32* %6
br label %92
17: ; preds = %5
%18 = load i32, i32* %11
%19 = icmp sgt i32 %18, 0
br i1 %19, label %20, label %35
20: ; preds = %17
%21 = load i32, i32* %11
%22 = icmp sgt i32 %21, 128
br i1 %22, label %23, label %24
23: ; preds = %20
store i32 128, i32* %11
br label %24
24: ; preds = %23, %20
%25 = getelementptr inbounds [128 x i8], [128 x i8]* %13, i64 0, i64 0
%26 = load i32, i32* %11
%27 = call i32 @memset(i8* %25, i8 signext 32, i32 %26)
%28 = load i32*, i32** %7
%29 = getelementptr inbounds [128 x i8], [128 x i8]* %13, i64 0, i64 0
%30 = load i32, i32* %11
%31 = call i64 @BIO_write(i32* %28, i8* %29, i32 %30)
%32 = icmp sle i64 %31, 0
br i1 %32, label %33, label %34
33: ; preds = %24
store i32 0, i32* %6
br label %92
34: ; preds = %24
br label %36
35: ; preds = %17
store i32 0, i32* %11
br label %36
36: ; preds = %35, %34
%37 = load i32*, i32** %7
%38 = load i8*, i8** %8
%39 = call i64 (i32*, i8*, ...) @BIO_printf(i32* %37, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %38)
%40 = icmp sle i64 %39, 0
br i1 %40, label %41, label %42
41: ; preds = %36
store i32 0, i32* %6
br label %92
42: ; preds = %36
store i64 0, i64* %12
br label %43
43: ; preds = %83, %42
%44 = load i64, i64* %12
%45 = load i64, i64* %10
%46 = icmp ult i64 %44, %45
br i1 %46, label %47, label %86
47: ; preds = %43
%48 = load i64, i64* %12
%49 = urem i64 %48, 15
%50 = icmp eq i64 %49, 0
br i1 %50, label %51, label %66
51: ; preds = %47
%52 = getelementptr inbounds [128 x i8], [128 x i8]* %13, i64 0, i64 0
store i8 10, i8* %52
%53 = getelementptr inbounds [128 x i8], [128 x i8]* %13, i64 0, i64 1
%54 = load i32, i32* %11
%55 = add nsw i32 %54, 4
%56 = call i32 @memset(i8* %53, i8 signext 32, i32 %55)
%57 = load i32*, i32** %7
%58 = getelementptr inbounds [128 x i8], [128 x i8]* %13, i64 0, i64 0
%59 = load i32, i32* %11
%60 = add nsw i32 %59, 1
%61 = add nsw i32 %60, 4
%62 = call i64 @BIO_write(i32* %57, i8* %58, i32 %61)
%63 = icmp sle i64 %62, 0
br i1 %63, label %64, label %65
64: ; preds = %51
store i32 0, i32* %6
br label %92
65: ; preds = %51
br label %66
66: ; preds = %65, %47
%67 = load i32*, i32** %7
%68 = load i8*, i8** %9
%69 = load i64, i64* %12
%70 = getelementptr inbounds i8, i8* %68, i64 %69
%71 = load i8, i8* %70
%72 = zext i8 %71 to i32
%73 = load i64, i64* %12
%74 = add i64 %73, 1
%75 = load i64, i64* %10
%76 = icmp eq i64 %74, %75
%77 = zext i1 %76 to i64
%78 = select i1 %76, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0)
%79 = call i64 (i32*, i8*, ...) @BIO_printf(i32* %67, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %72, i8* %78)
%80 = icmp sle i64 %79, 0
br i1 %80, label %81, label %82
81: ; preds = %66
store i32 0, i32* %6
br label %92
82: ; preds = %66
br label %83
83: ; preds = %82
%84 = load i64, i64* %12
%85 = add i64 %84, 1
store i64 %85, i64* %12
br label %43
86: ; preds = %43
%87 = load i32*, i32** %7
%88 = call i64 @BIO_write(i32* %87, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0), i32 1)
%89 = icmp sle i64 %88, 0
br i1 %89, label %90, label %91
90: ; preds = %86
store i32 0, i32* %6
br label %92
91: ; preds = %86
store i32 1, i32* %6
br label %92
92: ; preds = %91, %90, %81, %64, %41, %33, %16
%93 = load i32, i32* %6
ret i32 %93
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
@.str.1 = [7 x i8] c"%02x%s\00"
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [2 x i8] c":\00"
@.str.4 = [2 x i8] c"\0A\00"
define i32 @print_bin(i32* %0, i8* %1, i8* %2, i64 %3, i32 %4) {
%6 = alloca [128 x i8]
%7 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%8 = icmp eq i8* %2, null
br i1 %8, label %48, label %9
9: ; preds = %5
%10 = icmp sgt i32 %4, 0
br i1 %10, label %11, label %17
11: ; preds = %9
%12 = icmp ult i32 %4, 128
%13 = select i1 %12, i32 %4, i32 128
%14 = call i32 @memset(i8* %7, i8 signext 32, i32 %13)
%15 = call i64 @BIO_write(i32* %0, i8* %7, i32 %13)
%16 = icmp slt i64 %15, 1
br i1 %16, label %48, label %17
17: ; preds = %9, %11
%18 = phi i32 [ %13, %11 ], [ 0, %9 ]
%19 = call i64 (i32*, i8*, ...) @BIO_printf(i32* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %1)
%20 = icmp slt i64 %19, 1
br i1 %20, label %48, label %21
21: ; preds = %17
%22 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 1
%23 = add nuw nsw i32 %18, 4
%24 = add nuw nsw i32 %18, 5
br label %25
25: ; preds = %21, %35
%26 = phi i64 [ %39, %35 ], [ 0, %21 ]
%27 = icmp eq i64 %26, %3
br i1 %27, label %44, label %28
28: ; preds = %25
%29 = urem i64 %26, 15
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %35
31: ; preds = %28
store i8 10, i8* %7
%32 = call i32 @memset(i8* %22, i8 signext 32, i32 %23)
%33 = call i64 @BIO_write(i32* %0, i8* %7, i32 %24)
%34 = icmp slt i64 %33, 1
br i1 %34, label %48, label %35
35: ; preds = %31, %28
%36 = getelementptr inbounds i8, i8* %2, i64 %26
%37 = load i8, i8* %36
%38 = zext i8 %37 to i32
%39 = add i64 %26, 1
%40 = icmp eq i64 %39, %3
%41 = select i1 %40, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0)
%42 = call i64 (i32*, i8*, ...) @BIO_printf(i32* %0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %38, i8* %41)
%43 = icmp slt i64 %42, 1
br i1 %43, label %48, label %25
44: ; preds = %25
%45 = call i64 @BIO_write(i32* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0), i32 1)
%46 = icmp sgt i64 %45, 0
%47 = zext i1 %46 to i32
br label %48
48: ; preds = %35, %31, %44, %17, %11, %5
%49 = phi i32 [ 1, %5 ], [ 0, %11 ], [ 0, %17 ], [ %47, %44 ], [ 0, %31 ], [ 0, %35 ]
ret i32 %49
}