#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 *, unsigned char, char *);
void write_bytes(void *p, char size, FILE *file, int *count) {
  char i;
  for (i = 0; i < size; i++)
    fprintf(file, "0x%02X,%s", *(((unsigned char *)p) + i),
            ++(*count) % 16 ? "" : "\n");
}


x86 assembly (clang, -O0):
<write_bytes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movb   $0x0,-0x21(%rbp)
movsbl -0x21(%rbp),%eax
movsbl -0x9(%rbp),%ecx
cmp    %ecx,%eax
jge    119c <write_bytes+0x8c>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rax
movsbl -0x21(%rbp),%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x22(%rbp)
mov    -0x20(%rbp),%rcx
mov    (%rcx),%eax
add    $0x1,%eax
mov    %eax,(%rcx)
mov    $0x10,%ecx
cltd
idiv   %ecx
mov    -0x22(%rbp),%al
mov    %edx,%esi
lea    0xe98(%rip),%rcx
lea    0xe92(%rip),%rdx
cmp    $0x0,%esi
cmovne %rdx,%rcx
lea    0xe79(%rip),%rsi
movzbl %al,%edx
call   1030 <fprintf@plt>
mov    -0x21(%rbp),%al
add    $0x1,%al
mov    %al,-0x21(%rbp)
jmp    112e <write_bytes+0x1e>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_bytes>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %sil,%sil
jle    1174 <write_bytes+0x64>
mov    %rcx,%rbx
mov    %rdx,%r14
mov    %rdi,%r15
movzbl %sil,%r13d
xor    %ebp,%ebp
lea    0xeca(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
movzbl (%r15,%rbp,1),%edx
mov    (%rbx),%eax
add    $0x1,%eax
mov    %eax,(%rbx)
test   $0xf,%al
lea    0xeb6(%rip),%rcx
lea    0xeae(%rip),%rax
cmove  %rax,%rcx
mov    %r14,%rdi
mov    %r12,%rsi
call   1030 <fprintf@plt>
add    $0x1,%rbp
cmp    %rbp,%r13
jne    1140 <write_bytes+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"0x%02X,%s\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [2 x i8] c"\0A\00"
define void @write_bytes(i8* %0, i8 signext %1, i32* %2, i32* %3) {
%5 = alloca i8*
%6 = alloca i8
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i8
store i8* %0, i8** %5
store i8 %1, i8* %6
store i32* %2, i32** %7
store i32* %3, i32** %8
store i8 0, i8* %9
br label %10
10: ; preds = %32, %4
%11 = load i8, i8* %9
%12 = sext i8 %11 to i32
%13 = load i8, i8* %6
%14 = sext i8 %13 to i32
%15 = icmp slt i32 %12, %14
br i1 %15, label %16, label %35
16: ; preds = %10
%17 = load i32*, i32** %7
%18 = load i8*, i8** %5
%19 = load i8, i8* %9
%20 = sext i8 %19 to i32
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %18, i64 %21
%23 = load i8, i8* %22
%24 = load i32*, i32** %8
%25 = load i32, i32* %24
%26 = add nsw i32 %25, 1
store i32 %26, i32* %24
%27 = srem i32 %26, 16
%28 = icmp ne i32 %27, 0
%29 = zext i1 %28 to i64
%30 = select i1 %28, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0)
%31 = call i32 @fprintf(i32* %17, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8 zeroext %23, i8* %30)
br label %32
32: ; preds = %16
%33 = load i8, i8* %9
%34 = add i8 %33, 1
store i8 %34, i8* %9
br label %10
35: ; preds = %10
ret void
}

LLVM IR (-O2):
@.str = [10 x i8] c"0x%02X,%s\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [2 x i8] c"\0A\00"
define void @write_bytes(i8* nocapture %0, i8 signext %1, i32* nocapture %2, i32* nocapture %3) {
%5 = icmp sgt i8 %1, 0
br i1 %5, label %6, label %20
6: ; preds = %4
%7 = zext i8 %1 to i64
br label %8
8: ; preds = %6, %8
%9 = phi i64 [ 0, %6 ], [ %18, %8 ]
%10 = getelementptr inbounds i8, i8* %0, i64 %9
%11 = load i8, i8* %10
%12 = load i32, i32* %3
%13 = add nsw i32 %12, 1
store i32 %13, i32* %3
%14 = and i32 %13, 15
%15 = icmp eq i32 %14, 0
%16 = select i1 %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0)
%17 = tail call i32 @fprintf(i32* %2, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8 zeroext %11, i8* %16)
%18 = add nuw nsw i64 %9, 1
%19 = icmp eq i64 %18, %7
br i1 %19, label %20, label %8
20: ; preds = %8, %4
ret void
}