#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 */
scalar_t__ fprintf(int /*<<< orphan*/ *, char *, ...);
int io_hexdump(FILE *f, const char *data, int dlen) {
  int r = 0, i;
  for (i = 0; i < dlen; i++) {
    r += fprintf(f, "%02hhx", data[i]);
    if (!(r % 78))
      fprintf(f, "\n");
  }
  return r + (dlen / 78);
}


x86 assembly (clang, -O0):
<io_hexdump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11a1 <io_hexdump+0x91>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%edx
lea    0xeac(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    %rax,%rcx
movslq -0x18(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    $0x4e,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    118e <io_hexdump+0x7e>
mov    -0x8(%rbp),%rdi
lea    0xe80(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    1193 <io_hexdump+0x83>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1131 <io_hexdump+0x21>
mov    -0x18(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x4e,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
add    %ecx,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<io_hexdump>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %edx,%edx
mov    %edx,0x4(%rsp)
jle    119b <io_hexdump+0x7b>
mov    %rsi,%r15
mov    %rdi,%rbp
mov    %edx,%r13d
xor    %r14d,%r14d
xor    %ebx,%ebx
jmp    1159 <io_hexdump+0x39>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%r14
cmp    %r14,%r13
je     119d <io_hexdump+0x7d>
mov    %ebx,%r12d
movsbl (%r15,%r14,1),%edx
mov    %rbp,%rdi
lea    0xe95(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    %rax,%rbx
add    %r12d,%ebx
imul   $0x96f96f97,%ebx,%eax
add    $0x3483482,%eax
ror    %eax
cmp    $0x3483482,%eax
ja     1150 <io_hexdump+0x30>
mov    $0xa,%edi
mov    %rbp,%rsi
call   1030 <fputc@plt>
jmp    1150 <io_hexdump+0x30>
xor    %ebx,%ebx
mov    0x4(%rsp),%ecx
movslq %ecx,%rax
imul   $0xffffffffd20d20d3,%rax,%rax
shr    $0x20,%rax
add    %ecx,%eax
mov    %eax,%ecx
shr    $0x1f,%ecx
sar    $0x6,%eax
add    %ecx,%eax
add    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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