#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
void export_bin(int type, char *value, int len, int col, FILE *file) {
  int byte;
  if (type == 3) {
    fprintf(file, "hex:");
    col += 4;
  } else {
    fprintf(file, "hex(%x):", type);
    col += 7;
  }
  byte = 0;
  int start = (col - 2) / 3;
  while (byte + 1 < len) {
    fprintf(file, "%02x,", (unsigned char)value[byte]);
    byte++;
    if (!((byte + start) % 25))
      fprintf(file, "\\\r\n  ");
  }
  if (len)
    fprintf(file, "%02x\r\n", (unsigned char)value[len - 1]);
}


x86 assembly (clang, -O0):
<export_bin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
cmpl   $0x3,-0x4(%rbp)
jne    1153 <export_bin+0x43>
mov    -0x20(%rbp),%rdi
lea    0xec2(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x18(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x18(%rbp)
jmp    1171 <export_bin+0x61>
mov    -0x20(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xea4(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x18(%rbp),%eax
add    $0x7,%eax
mov    %eax,-0x18(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x18(%rbp),%eax
sub    $0x2,%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
cmp    -0x14(%rbp),%eax
jge    11ed <export_bin+0xdd>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
movzbl (%rax,%rcx,1),%edx
lea    0xe5f(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
add    -0x28(%rbp),%eax
mov    $0x19,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11e8 <export_bin+0xd8>
mov    -0x20(%rbp),%rdi
lea    0xe33(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    1189 <export_bin+0x79>
cmpl   $0x0,-0x14(%rbp)
je     121a <export_bin+0x10a>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movzbl (%rax,%rcx,1),%edx
lea    0xe07(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<export_bin>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8,%rbx
mov    %ecx,%r12d
mov    %edx,%ebp
mov    %rsi,%r14
cmp    $0x3,%edi
jne    115b <export_bin+0x3b>
lea    0xebe(%rip),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1040 <fwrite@plt>
mov    $0x4,%eax
jmp    1173 <export_bin+0x53>
mov    %edi,%edx
lea    0xea1(%rip),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    $0x7,%eax
mov    %rbp,(%rsp)
cmp    $0x2,%ebp
jl     1203 <export_bin+0xe3>
add    %r12d,%eax
add    $0xfffffffe,%eax
cltq
imul   $0x55555556,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
shr    $0x20,%rax
add    %ecx,%eax
mov    (%rsp),%rcx
lea    -0x1(%rcx),%ebp
movslq %eax,%r15
add    $0x1,%r15
xor    %r12d,%r12d
jmp    11b5 <export_bin+0x95>
nop
cmp    %r12,%rbp
je     1203 <export_bin+0xe3>
mov    %r12,%r13
add    $0x1,%r12
movzbl (%r14,%r13,1),%edx
mov    %rbx,%rdi
lea    0xe43(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
add    %r15d,%r13d
imul   $0xc28f5c29,%r13d,%eax
add    $0x51eb851,%eax
cmp    $0xa3d70a2,%eax
ja     11b0 <export_bin+0x90>
mov    $0x5,%esi
mov    $0x1,%edx
lea    0xe1b(%rip),%rdi
mov    %rbx,%rcx
call   1040 <fwrite@plt>
jmp    11b0 <export_bin+0x90>
mov    (%rsp),%rax
test   %eax,%eax
je     1232 <export_bin+0x112>
cltq
movzbl -0x1(%rax,%r14,1),%edx
lea    0xe00(%rip),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fprintf@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"hex:\00"
@.str.1 = [9 x i8] c"hex(%x):\00"
@.str.2 = [6 x i8] c"%02x,\00"
@.str.3 = [6 x i8] c"\\\0D\0A \00"
@.str.4 = [7 x i8] c"%02x\0D\0A\00"
define void @export_bin(i32 %0, i8* %1, i32 %2, i32 %3, i32* %4) {
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32*
%11 = alloca i32
%12 = alloca i32
store i32 %0, i32* %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i32* %4, i32** %10
%13 = load i32, i32* %6
%14 = icmp eq i32 %13, 3
br i1 %14, label %15, label %20
15: ; preds = %5
%16 = load i32*, i32** %10
%17 = call i32 (i32*, i8*, ...) @fprintf(i32* %16, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%18 = load i32, i32* %9
%19 = add nsw i32 %18, 4
store i32 %19, i32* %9
br label %26
20: ; preds = %5
%21 = load i32*, i32** %10
%22 = load i32, i32* %6
%23 = call i32 (i32*, i8*, ...) @fprintf(i32* %21, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %22)
%24 = load i32, i32* %9
%25 = add nsw i32 %24, 7
store i32 %25, i32* %9
br label %26
26: ; preds = %20, %15
store i32 0, i32* %11
%27 = load i32, i32* %9
%28 = sub nsw i32 %27, 2
%29 = sdiv i32 %28, 3
store i32 %29, i32* %12
br label %30
30: ; preds = %54, %26
%31 = load i32, i32* %11
%32 = add nsw i32 %31, 1
%33 = load i32, i32* %8
%34 = icmp slt i32 %32, %33
br i1 %34, label %35, label %55
35: ; preds = %30
%36 = load i32*, i32** %10
%37 = load i8*, i8** %7
%38 = load i32, i32* %11
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %37, i64 %39
%41 = load i8, i8* %40
%42 = zext i8 %41 to i32
%43 = call i32 (i32*, i8*, ...) @fprintf(i32* %36, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %42)
%44 = load i32, i32* %11
%45 = add nsw i32 %44, 1
store i32 %45, i32* %11
%46 = load i32, i32* %11
%47 = load i32, i32* %12
%48 = add nsw i32 %46, %47
%49 = srem i32 %48, 25
%50 = icmp ne i32 %49, 0
br i1 %50, label %54, label %51
51: ; preds = %35
%52 = load i32*, i32** %10
%53 = call i32 (i32*, i8*, ...) @fprintf(i32* %52, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
br label %54
54: ; preds = %51, %35
br label %30
55: ; preds = %30
%56 = load i32, i32* %8
%57 = icmp ne i32 %56, 0
br i1 %57, label %58, label %68
58: ; preds = %55
%59 = load i32*, i32** %10
%60 = load i8*, i8** %7
%61 = load i32, i32* %8
%62 = sub nsw i32 %61, 1
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds i8, i8* %60, i64 %63
%65 = load i8, i8* %64
%66 = zext i8 %65 to i32
%67 = call i32 (i32*, i8*, ...) @fprintf(i32* %59, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32 %66)
br label %68
68: ; preds = %58, %55
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"hex:\00"
@.str.1 = [9 x i8] c"hex(%x):\00"
@.str.2 = [6 x i8] c"%02x,\00"
@.str.3 = [6 x i8] c"\\\0D\0A \00"
@.str.4 = [7 x i8] c"%02x\0D\0A\00"
define void @export_bin(i32 %0, i8* nocapture %1, i32 %2, i32 %3, i32* nocapture %4) {
%6 = icmp eq i32 %0, 3
br i1 %6, label %7, label %9
7: ; preds = %5
%8 = tail call i64 @fwrite(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64 4, i64 1, i32* %4)
br label %11
9: ; preds = %5
%10 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %4, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %0)
br label %11
11: ; preds = %9, %7
%12 = phi i32 [ 7, %9 ], [ 4, %7 ]
%13 = add nsw i32 %12, %3
%14 = add nsw i32 %13, -2
%15 = sdiv i32 %14, 3
%16 = icmp sgt i32 %2, 1
br i1 %16, label %17, label %37
17: ; preds = %11
%18 = add nsw i32 %2, -1
%19 = zext i32 %18 to i64
br label %20
20: ; preds = %17, %34
%21 = phi i64 [ 0, %17 ], [ %23, %34 ]
%22 = phi i64 [ 1, %17 ], [ %35, %34 ]
%23 = add nuw nsw i64 %21, 1
%24 = getelementptr inbounds i8, i8* %1, i64 %21
%25 = load i8, i8* %24
%26 = zext i8 %25 to i32
%27 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %4, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %26)
%28 = trunc i64 %22 to i32
%29 = add nsw i32 %15, %28
%30 = srem i32 %29, 25
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %20
%33 = tail call i64 @fwrite(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i64 5, i64 1, i32* %4)
br label %34
34: ; preds = %32, %20
%35 = add nuw nsw i64 %22, 1
%36 = icmp eq i64 %23, %19
br i1 %36, label %37, label %20
37: ; preds = %34, %11
%38 = icmp eq i32 %2, 0
br i1 %38, label %46, label %39
39: ; preds = %37
%40 = add nsw i32 %2, -1
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %1, i64 %41
%43 = load i8, i8* %42
%44 = zext i8 %43 to i32
%45 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %4, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32 %44)
br label %46
46: ; preds = %39, %37
ret void
}