#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 uint8_t;

/* Variables and functions */
int /*<<< orphan*/ printf(char *, ...);
void convert_rom(const uint8_t *buf, const size_t len) {
  for (size_t i = 0; i < len; i++) {
    uint8_t ch = buf[i];
    if ((i % 16) == 0) {
      printf("\n");
    }
    printf(" 0x%02x", ch);
    if (i < len - 1) {
      printf(",");
    }
  }
}


x86 assembly (clang, -O0):
<convert_rom>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    11ae <convert_rom+0x9e>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
and    $0xf,%rax
cmp    $0x0,%rax
jne    1164 <convert_rom+0x54>
lea    0xea3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%esi
lea    0xe94(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    $0x1,%rcx
cmp    %rcx,%rax
jae    1198 <convert_rom+0x88>
lea    0xe79(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    119d <convert_rom+0x8d>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1128 <convert_rom+0x18>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<convert_rom>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %rsi,%rsi
je     1189 <convert_rom+0x69>
mov    %rsi,%r13
mov    %rdi,%r14
lea    -0x1(%rsi),%r12
lea    0xebf(%rip),%r15
xor    %ebx,%ebx
jmp    1159 <convert_rom+0x39>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%rbx
cmp    %rbx,%r13
je     1189 <convert_rom+0x69>
mov    (%r14,%rbx,4),%ebp
test   $0xf,%bl
jne    116c <convert_rom+0x4c>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %r15,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
cmp    %r12,%rbx
jae    1150 <convert_rom+0x30>
mov    $0x2c,%edi
call   1030 <putchar@plt>
jmp    1150 <convert_rom+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"\0A\00"
@.str.1 = [8 x i8] c" 0x%02x\00"
@.str.2 = [2 x i8] c",\00"
define void @convert_rom(i32* %0, i64 %1) {
%3 = alloca i32*
%4 = alloca i64
%5 = alloca i64
%6 = alloca i32
store i32* %0, i32** %3
store i64 %1, i64* %4
store i64 0, i64* %5
br label %7
7: ; preds = %31, %2
%8 = load i64, i64* %5
%9 = load i64, i64* %4
%10 = icmp ult i64 %8, %9
br i1 %10, label %11, label %34
11: ; preds = %7
%12 = load i32*, i32** %3
%13 = load i64, i64* %5
%14 = getelementptr inbounds i32, i32* %12, i64 %13
%15 = load i32, i32* %14
store i32 %15, i32* %6
%16 = load i64, i64* %5
%17 = urem i64 %16, 16
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %11
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %21
21: ; preds = %19, %11
%22 = load i32, i32* %6
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %22)
%24 = load i64, i64* %5
%25 = load i64, i64* %4
%26 = sub i64 %25, 1
%27 = icmp ult i64 %24, %26
br i1 %27, label %28, label %30
28: ; preds = %21
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %30
30: ; preds = %28, %21
br label %31
31: ; preds = %30
%32 = load i64, i64* %5
%33 = add i64 %32, 1
store i64 %33, i64* %5
br label %7
34: ; preds = %7
ret void
}

LLVM IR (-O2):
@.str.1 = [8 x i8] c" 0x%02x\00"
define void @convert_rom(i32* nocapture %0, i64 %1) {
%3 = icmp eq i64 %1, 0
br i1 %3, label %6, label %4
4: ; preds = %2
%5 = add i64 %1, -1
br label %7
6: ; preds = %20, %2
ret void
7: ; preds = %4, %20
%8 = phi i64 [ 0, %4 ], [ %21, %20 ]
%9 = getelementptr inbounds i32, i32* %0, i64 %8
%10 = load i32, i32* %9
%11 = and i64 %8, 15
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %7
%14 = tail call i32 @putchar(i32 10)
br label %15
15: ; preds = %13, %7
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %10)
%17 = icmp ult i64 %8, %5
br i1 %17, label %18, label %20
18: ; preds = %15
%19 = tail call i32 @putchar(i32 44)
br label %20
20: ; preds = %18, %15
%21 = add nuw i64 %8, 1
%22 = icmp eq i64 %21, %1
br i1 %22, label %6, label %7
}