#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*/ DBG(int, char *, ...);
void DBG_buf(int level, unsigned char *buf, int len, int cols) {
  int i;
  for (i = 0; i < len; i++) {
    DBG(level, "%02x ", buf[i]);
    if (i % cols == cols - 1 || i == len - 1)
      DBG(level, "\n");
  }
}


x86 assembly (clang, -O0):
<DBG_buf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    119f <DBG_buf+0x8f>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movzbl (%rax,%rcx,1),%edx
lea    0xeb2(%rip),%rsi
mov    $0x0,%al
call   1030 <DBG@plt>
mov    -0x1c(%rbp),%eax
cltd
idivl  -0x18(%rbp)
mov    -0x18(%rbp),%eax
sub    $0x1,%eax
cmp    %eax,%edx
je     117b <DBG_buf+0x6b>
mov    -0x1c(%rbp),%eax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jne    118c <DBG_buf+0x7c>
mov    -0x4(%rbp),%edi
lea    0xe81(%rip),%rsi
mov    $0x0,%al
call   1030 <DBG@plt>
jmp    1191 <DBG_buf+0x81>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    112c <DBG_buf+0x1c>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<DBG_buf>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %edx,%edx
jle    1181 <DBG_buf+0x71>
mov    %ecx,%r13d
mov    %rsi,%r14
mov    %edi,%ebp
lea    -0x1(%r13),%r12d
lea    -0x1(%rdx),%eax
mov    %rax,(%rsp)
mov    %edx,%r15d
xor    %ebx,%ebx
jmp    1159 <DBG_buf+0x49>
nopl   0x0(%rax)
mov    %ebp,%edi
lea    0xebd(%rip),%rsi
xor    %eax,%eax
call   1030 <DBG@plt>
add    $0x1,%rbx
cmp    %rbx,%r15
je     1181 <DBG_buf+0x71>
movzbl (%r14,%rbx,1),%edx
mov    %ebp,%edi
lea    0xe99(%rip),%rsi
xor    %eax,%eax
call   1030 <DBG@plt>
mov    %ebx,%eax
cltd
idiv   %r13d
cmp    %r12d,%edx
je     1140 <DBG_buf+0x30>
cmp    %rbx,(%rsp)
jne    1150 <DBG_buf+0x40>
jmp    1140 <DBG_buf+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [6 x i8] c"%02x \00"
@.str.1 = [2 x i8] c"\0A\00"
define void @DBG_buf(i32 %0, i8* nocapture %1, i32 %2, i32 %3) {
%5 = icmp sgt i32 %2, 0
br i1 %5, label %6, label %27
6: ; preds = %4
%7 = add nsw i32 %3, -1
%8 = add nsw i32 %2, -1
%9 = zext i32 %8 to i64
%10 = zext i32 %2 to i64
br label %11
11: ; preds = %6, %24
%12 = phi i64 [ 0, %6 ], [ %25, %24 ]
%13 = getelementptr inbounds i8, i8* %1, i64 %12
%14 = load i8, i8* %13
%15 = zext i8 %14 to i32
%16 = tail call i32 (i32, i8*, ...) @DBG(i32 %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %15)
%17 = trunc i64 %12 to i32
%18 = srem i32 %17, %3
%19 = icmp eq i32 %18, %7
%20 = icmp eq i64 %12, %9
%21 = select i1 %19, i1 true, i1 %20
br i1 %21, label %22, label %24
22: ; preds = %11
%23 = tail call i32 (i32, i8*, ...) @DBG(i32 %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %24
24: ; preds = %11, %22
%25 = add nuw nsw i64 %12, 1
%26 = icmp eq i64 %25, %10
br i1 %26, label %27, label %11
27: ; preds = %24, %4
ret void
}