#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) {
    if (off > 128)
      off = 128;
    memset(str, ' ', off);
    if (BIO_write(fp, str, off) <= 0)
      return 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    1313 <print_bin+0x1e3>
cmpl   $0x0,-0x2c(%rbp)
je     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    1313 <print_bin+0x1e3>
jmp    11c6 <print_bin+0x96>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe2f(%rip),%rsi
mov    $0x0,%al
call   1030 <BIO_printf@plt>
cmp    $0x0,%rax
jg     11f2 <print_bin+0xc2>
movl   $0x0,-0x4(%rbp)
jmp    1313 <print_bin+0x1e3>
movq   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%rax
cmp    -0x28(%rbp),%rax
jae    12e1 <print_bin+0x1b1>
mov    -0x38(%rbp),%rax
mov    $0xf,%ecx
xor    %edx,%edx
div    %rcx
cmp    $0x0,%rdx
jne    1276 <print_bin+0x146>
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     1271 <print_bin+0x141>
movl   $0x0,-0x4(%rbp)
jmp    1313 <print_bin+0x1e3>
jmp    1276 <print_bin+0x146>
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    0xd6e(%rip),%rcx
lea    0xd6a(%rip),%rax
cmp    %r8,%rsi
cmove  %rax,%rcx
lea    0xd52(%rip),%rsi
mov    $0x0,%al
call   1030 <BIO_printf@plt>
cmp    $0x0,%rax
jg     12cb <print_bin+0x19b>
movl   $0x0,-0x4(%rbp)
jmp    1313 <print_bin+0x1e3>
jmp    12d0 <print_bin+0x1a0>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    11fa <print_bin+0xca>
mov    -0x10(%rbp),%rdi
lea    0xd1d(%rip),%rsi
mov    $0x1,%edx
call   1050 <BIO_write@plt>
cmp    $0x0,%rax
jg     130c <print_bin+0x1dc>
movl   $0x0,-0x4(%rbp)
jmp    1313 <print_bin+0x1e3>
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
je     11a4 <print_bin+0x74>
cmp    $0x80,%r8d
mov    $0x80,%r12d
cmovl  %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    1279 <print_bin+0x149>
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 %91
17: ; preds = %5
%18 = load i32, i32* %11
%19 = icmp ne 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 %91
34: ; preds = %24
br label %35
35: ; preds = %34, %17
%36 = load i32*, i32** %7
%37 = load i8*, i8** %8
%38 = call i64 (i32*, i8*, ...) @BIO_printf(i32* %36, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %37)
%39 = icmp sle i64 %38, 0
br i1 %39, label %40, label %41
40: ; preds = %35
store i32 0, i32* %6
br label %91
41: ; preds = %35
store i64 0, i64* %12
br label %42
42: ; preds = %82, %41
%43 = load i64, i64* %12
%44 = load i64, i64* %10
%45 = icmp ult i64 %43, %44
br i1 %45, label %46, label %85
46: ; preds = %42
%47 = load i64, i64* %12
%48 = urem i64 %47, 15
%49 = icmp eq i64 %48, 0
br i1 %49, label %50, label %65
50: ; preds = %46
%51 = getelementptr inbounds [128 x i8], [128 x i8]* %13, i64 0, i64 0
store i8 10, i8* %51
%52 = getelementptr inbounds [128 x i8], [128 x i8]* %13, i64 0, i64 1
%53 = load i32, i32* %11
%54 = add nsw i32 %53, 4
%55 = call i32 @memset(i8* %52, i8 signext 32, i32 %54)
%56 = load i32*, i32** %7
%57 = getelementptr inbounds [128 x i8], [128 x i8]* %13, i64 0, i64 0
%58 = load i32, i32* %11
%59 = add nsw i32 %58, 1
%60 = add nsw i32 %59, 4
%61 = call i64 @BIO_write(i32* %56, i8* %57, i32 %60)
%62 = icmp sle i64 %61, 0
br i1 %62, label %63, label %64
63: ; preds = %50
store i32 0, i32* %6
br label %91
64: ; preds = %50
br label %65
65: ; preds = %64, %46
%66 = load i32*, i32** %7
%67 = load i8*, i8** %9
%68 = load i64, i64* %12
%69 = getelementptr inbounds i8, i8* %67, i64 %68
%70 = load i8, i8* %69
%71 = zext i8 %70 to i32
%72 = load i64, i64* %12
%73 = add i64 %72, 1
%74 = load i64, i64* %10
%75 = icmp eq i64 %73, %74
%76 = zext i1 %75 to i64
%77 = select i1 %75, 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)
%78 = call i64 (i32*, i8*, ...) @BIO_printf(i32* %66, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %71, i8* %77)
%79 = icmp sle i64 %78, 0
br i1 %79, label %80, label %81
80: ; preds = %65
store i32 0, i32* %6
br label %91
81: ; preds = %65
br label %82
82: ; preds = %81
%83 = load i64, i64* %12
%84 = add i64 %83, 1
store i64 %84, i64* %12
br label %42
85: ; preds = %42
%86 = load i32*, i32** %7
%87 = call i64 @BIO_write(i32* %86, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0), i32 1)
%88 = icmp sle i64 %87, 0
br i1 %88, label %89, label %90
89: ; preds = %85
store i32 0, i32* %6
br label %91
90: ; preds = %85
store i32 1, i32* %6
br label %91
91: ; preds = %90, %89, %80, %63, %40, %33, %16
%92 = load i32, i32* %6
ret i32 %92
}

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 eq i32 %4, 0
br i1 %10, label %17, label %11
11: ; preds = %9
%12 = icmp slt 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 = %11, %9
%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 nsw i32 %18, 4
%24 = add 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
}