#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*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
void print_bin(char *value, int value_length) {
  int i;
  char j;
  char k;
  char l;
  if (value == NULL) {
    fprintf(stderr, "[error] print_bin: value == NULL\n");
    return;
  }
  for (i = 0; i < value_length; i++) {
    j = value[i];
    if (j >= 32 && j < 127) {
      printf("%c", j);
    } else if (j == 9) {
      printf("\\t");
    } else if (j == 10) {
      printf("\\n");
    } else if (j == 13) {
      printf("\\r");
    } else {
      printf("\\x");
      k = ((unsigned char)j) / 16;
      l = ((unsigned char)j) % 16;
      k = (k >= 10) ? ('a' + (k - 10)) : ('0' + k);
      l = (l >= 10) ? ('a' + (l - 10)) : ('0' + l);
      printf("%c%c", k, l);
    }
  }
}


x86 assembly (clang, -O0):
<print_bin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1154 <print_bin+0x34>
mov    0x2e9f(%rip),%rax
mov    (%rax),%edi
lea    0xeb6(%rip),%rsi
call   1040 <fprintf@plt>
jmp    12ca <print_bin+0x1aa>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    12ca <print_bin+0x1aa>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x11(%rbp)
movsbl -0x11(%rbp),%eax
cmp    $0x20,%eax
jl     11a6 <print_bin+0x86>
movsbl -0x11(%rbp),%eax
cmp    $0x7f,%eax
jge    11a6 <print_bin+0x86>
movsbl -0x11(%rbp),%esi
lea    0xe96(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12b7 <print_bin+0x197>
movsbl -0x11(%rbp),%eax
cmp    $0x9,%eax
jne    11c6 <print_bin+0xa6>
lea    0xe68(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12b2 <print_bin+0x192>
movsbl -0x11(%rbp),%eax
cmp    $0xa,%eax
jne    11e6 <print_bin+0xc6>
lea    0xe4b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12ad <print_bin+0x18d>
movsbl -0x11(%rbp),%eax
cmp    $0xd,%eax
jne    1206 <print_bin+0xe6>
lea    0xe2e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12a8 <print_bin+0x188>
lea    0xe1e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movzbl -0x11(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
mov    %al,-0x12(%rbp)
movzbl -0x11(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
mov    %dl,%al
mov    %al,-0x13(%rbp)
movsbl -0x12(%rbp),%eax
cmp    $0xa,%eax
jl     1253 <print_bin+0x133>
movsbl -0x12(%rbp),%eax
sub    $0xa,%eax
add    $0x61,%eax
mov    %eax,-0x18(%rbp)
jmp    125d <print_bin+0x13d>
movsbl -0x12(%rbp),%eax
add    $0x30,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %al,-0x12(%rbp)
movsbl -0x13(%rbp),%eax
cmp    $0xa,%eax
jl     1282 <print_bin+0x162>
movsbl -0x13(%rbp),%eax
sub    $0xa,%eax
add    $0x61,%eax
mov    %eax,-0x1c(%rbp)
jmp    128c <print_bin+0x16c>
movsbl -0x13(%rbp),%eax
add    $0x30,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %al,-0x13(%rbp)
movsbl -0x12(%rbp),%esi
movsbl -0x13(%rbp),%edx
lea    0xd8d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12ad <print_bin+0x18d>
jmp    12b2 <print_bin+0x192>
jmp    12b7 <print_bin+0x197>
jmp    12bc <print_bin+0x19c>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    115b <print_bin+0x3b>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_bin>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %rdi,%rdi
je     1225 <print_bin+0xf5>
test   %esi,%esi
jle    1216 <print_bin+0xe6>
mov    %rdi,%rbx
mov    %esi,%r15d
lea    0xed2(%rip),%r13
lea    0xece(%rip),%rbp
xor    %r12d,%r12d
jmp    1185 <print_bin+0x55>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r14d,%edi
call   1030 <putchar@plt>
add    $0x1,%r12
cmp    %r12,%r15
je     1216 <print_bin+0xe6>
movzbl (%rbx,%r12,1),%r14d
lea    -0x20(%r14),%eax
cmp    $0x5e,%al
jbe    1170 <print_bin+0x40>
cmp    $0xd,%r14b
je     11ad <print_bin+0x7d>
cmp    $0xa,%r14b
je     11b6 <print_bin+0x86>
cmp    $0x9,%r14b
jne    11c6 <print_bin+0x96>
lea    0xe77(%rip),%rdi
jmp    11bd <print_bin+0x8d>
lea    0xe74(%rip),%rdi
jmp    11bd <print_bin+0x8d>
lea    0xe68(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1178 <print_bin+0x48>
mov    %r13,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14d,%eax
shr    $0x4,%al
mov    %r14d,%ecx
and    $0xf,%cl
lea    0x57(%rax),%edx
or     $0x30,%al
cmp    $0xa0,%r14b
movzbl %dl,%edx
movzbl %al,%eax
cmovae %edx,%eax
lea    0x57(%rcx),%edx
lea    0x30(%rcx),%esi
cmp    $0xa,%cl
movzbl %dl,%ecx
movzbl %sil,%edx
cmovae %ecx,%edx
movzbl %al,%esi
movzbl %dl,%edx
mov    %rbp,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1178 <print_bin+0x48>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2db4(%rip),%rax
mov    (%rax),%edi
lea    0xdcb(%rip),%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <fprintf@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [34 x i8] c"[error] print_bin: value == NULL\0A\00"
@.str.1 = [3 x i8] c"%c\00"
@.str.2 = [3 x i8] c"\\t\00"
@.str.3 = [3 x i8] c"\\n\00"
@.str.4 = [3 x i8] c"\\r\00"
@.str.5 = [3 x i8] c"\\x\00"
@.str.6 = [5 x i8] c"%c%c\00"
define void @print_bin(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8
%7 = alloca i8
%8 = alloca i8
store i8* %0, i8** %3
store i32 %1, i32* %4
%9 = load i8*, i8** %3
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
br label %106
14: ; preds = %2
store i32 0, i32* %5
br label %15
15: ; preds = %103, %14
%16 = load i32, i32* %5
%17 = load i32, i32* %4
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %106
19: ; preds = %15
%20 = load i8*, i8** %3
%21 = load i32, i32* %5
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %20, i64 %22
%24 = load i8, i8* %23
store i8 %24, i8* %6
%25 = load i8, i8* %6
%26 = sext i8 %25 to i32
%27 = icmp sge i32 %26, 32
br i1 %27, label %28, label %36
28: ; preds = %19
%29 = load i8, i8* %6
%30 = sext i8 %29 to i32
%31 = icmp slt i32 %30, 127
br i1 %31, label %32, label %36
32: ; preds = %28
%33 = load i8, i8* %6
%34 = sext i8 %33 to i32
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %34)
br label %102
36: ; preds = %28, %19
%37 = load i8, i8* %6
%38 = sext i8 %37 to i32
%39 = icmp eq i32 %38, 9
br i1 %39, label %40, label %42
40: ; preds = %36
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %101
42: ; preds = %36
%43 = load i8, i8* %6
%44 = sext i8 %43 to i32
%45 = icmp eq i32 %44, 10
br i1 %45, label %46, label %48
46: ; preds = %42
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
br label %100
48: ; preds = %42
%49 = load i8, i8* %6
%50 = sext i8 %49 to i32
%51 = icmp eq i32 %50, 13
br i1 %51, label %52, label %54
52: ; preds = %48
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
br label %99
54: ; preds = %48
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%56 = load i8, i8* %6
%57 = zext i8 %56 to i32
%58 = sdiv i32 %57, 16
%59 = trunc i32 %58 to i8
store i8 %59, i8* %7
%60 = load i8, i8* %6
%61 = zext i8 %60 to i32
%62 = srem i32 %61, 16
%63 = trunc i32 %62 to i8
store i8 %63, i8* %8
%64 = load i8, i8* %7
%65 = sext i8 %64 to i32
%66 = icmp sge i32 %65, 10
br i1 %66, label %67, label %72
67: ; preds = %54
%68 = load i8, i8* %7
%69 = sext i8 %68 to i32
%70 = sub nsw i32 %69, 10
%71 = add nsw i32 97, %70
br label %76
72: ; preds = %54
%73 = load i8, i8* %7
%74 = sext i8 %73 to i32
%75 = add nsw i32 48, %74
br label %76
76: ; preds = %72, %67
%77 = phi i32 [ %71, %67 ], [ %75, %72 ]
%78 = trunc i32 %77 to i8
store i8 %78, i8* %7
%79 = load i8, i8* %8
%80 = sext i8 %79 to i32
%81 = icmp sge i32 %80, 10
br i1 %81, label %82, label %87
82: ; preds = %76
%83 = load i8, i8* %8
%84 = sext i8 %83 to i32
%85 = sub nsw i32 %84, 10
%86 = add nsw i32 97, %85
br label %91
87: ; preds = %76
%88 = load i8, i8* %8
%89 = sext i8 %88 to i32
%90 = add nsw i32 48, %89
br label %91
91: ; preds = %87, %82
%92 = phi i32 [ %86, %82 ], [ %90, %87 ]
%93 = trunc i32 %92 to i8
store i8 %93, i8* %8
%94 = load i8, i8* %7
%95 = sext i8 %94 to i32
%96 = load i8, i8* %8
%97 = sext i8 %96 to i32
%98 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i32 %95, i32 %97)
br label %99
99: ; preds = %91, %52
br label %100
100: ; preds = %99, %46
br label %101
101: ; preds = %100, %40
br label %102
102: ; preds = %101, %32
br label %103
103: ; preds = %102
%104 = load i32, i32* %5
%105 = add nsw i32 %104, 1
store i32 %105, i32* %5
br label %15
106: ; preds = %11, %15
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [34 x i8] c"[error] print_bin: value == NULL\0A\00"
@.str.2 = [3 x i8] c"\\t\00"
@.str.3 = [3 x i8] c"\\n\00"
@.str.4 = [3 x i8] c"\\r\00"
@.str.5 = [3 x i8] c"\\x\00"
@.str.6 = [5 x i8] c"%c%c\00"
define void @print_bin(i8* %0, i32 %1) {
%3 = icmp eq i8* %0, null
br i1 %3, label %8, label %4
4: ; preds = %2
%5 = icmp sgt i32 %1, 0
br i1 %5, label %6, label %45
6: ; preds = %4
%7 = zext i32 %1 to i64
br label %11
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
br label %45
11: ; preds = %6, %42
%12 = phi i64 [ 0, %6 ], [ %43, %42 ]
%13 = getelementptr inbounds i8, i8* %0, i64 %12
%14 = load i8, i8* %13
%15 = add i8 %14, -32
%16 = icmp ult i8 %15, 95
br i1 %16, label %17, label %20
17: ; preds = %11
%18 = zext i8 %14 to i32
%19 = tail call i32 @putchar(i32 %18)
br label %42
20: ; preds = %11
switch i8 %14, label %27 [
i8 9, label %21
i8 10, label %23
i8 13, label %25
]
21: ; preds = %20
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %42
23: ; preds = %20
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
br label %42
25: ; preds = %20
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
br label %42
27: ; preds = %20
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%29 = lshr i8 %14, 4
%30 = and i8 %14, 15
%31 = icmp ugt i8 %14, -97
%32 = add nuw nsw i8 %29, 87
%33 = or i8 %29, 48
%34 = select i1 %31, i8 %32, i8 %33
%35 = icmp ugt i8 %30, 9
%36 = add nuw nsw i8 %30, 87
%37 = or i8 %30, 48
%38 = select i1 %35, i8 %36, i8 %37
%39 = zext i8 %34 to i32
%40 = zext i8 %38 to i32
%41 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i32 %39, i32 %40)
br label %42
42: ; preds = %17, %23, %27, %25, %21
%43 = add nuw nsw i64 %12, 1
%44 = icmp eq i64 %43, %7
br i1 %44, label %45, label %11
45: ; preds = %42, %4, %8
ret void
}