#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 print_hexa(int fd, char *data, int size) {
  int i, j;
  i = 0;
  j = 0;
  while (i < size) {
    if (!(i % 8)) {
      if (!(i % 16)) {
        fprintf((FILE *)fd, "\n%04d ", j);
        j = j + 16;
      } else {
        fprintf((FILE *)fd, " ");
      }
    }
    fprintf((FILE *)fd, " %02x", (unsigned char)*data++);
    i++;
  }
}


x86 assembly (clang, -O0):
<print_hexa>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11d0 <print_hexa+0xc0>
mov    -0x18(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    119e <print_hexa+0x8e>
mov    -0x18(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1187 <print_hexa+0x77>
movslq -0x4(%rbp),%rdi
mov    -0x1c(%rbp),%edx
lea    0xe8e(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x1c(%rbp),%eax
add    $0x10,%eax
mov    %eax,-0x1c(%rbp)
jmp    1199 <print_hexa+0x89>
movslq -0x4(%rbp),%rdi
lea    0xe73(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    119e <print_hexa+0x8e>
movslq -0x4(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movzbl (%rax),%edx
lea    0xe4c(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1130 <print_hexa+0x20>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_hexa>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %edx,%edx
jle    119e <print_hexa+0x7e>
mov    %rsi,%r14
movslq %edi,%rbx
mov    %edx,%ebp
lea    0xec9(%rip),%r12
xor    %r15d,%r15d
xor    %r13d,%r13d
jmp    1178 <print_hexa+0x58>
cs nopw 0x0(%rax,%rax,1)
mov    $0x20,%edi
mov    %rbx,%rsi
call   1030 <fputc@plt>
movzbl (%r14,%r15,1),%edx
mov    %rbx,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
add    $0x1,%r15
cmp    %r15d,%ebp
je     119e <print_hexa+0x7e>
test   $0x7,%r15b
jne    115d <print_hexa+0x3d>
test   $0xf,%r15b
jne    1150 <print_hexa+0x30>
mov    %rbx,%rdi
lea    0xe72(%rip),%rsi
mov    %r13d,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
add    $0x10,%r13d
jmp    115d <print_hexa+0x3d>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"\0A%04d \00"
@.str.1 = [2 x i8] c" \00"
@.str.2 = [6 x i8] c" %02x\00"
define void @print_hexa(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 = %35, %3
%10 = load i32, i32* %7
%11 = load i32, i32* %6
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %46
13: ; preds = %9
%14 = load i32, i32* %7
%15 = srem i32 %14, 8
%16 = icmp ne i32 %15, 0
br i1 %16, label %35, label %17
17: ; preds = %13
%18 = load i32, i32* %7
%19 = srem i32 %18, 16
%20 = icmp ne i32 %19, 0
br i1 %20, label %29, label %21
21: ; preds = %17
%22 = load i32, i32* %4
%23 = sext i32 %22 to i64
%24 = inttoptr i64 %23 to i32*
%25 = load i32, i32* %8
%26 = call i32 (i32*, i8*, ...) @fprintf(i32* %24, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %25)
%27 = load i32, i32* %8
%28 = add nsw i32 %27, 16
store i32 %28, i32* %8
br label %34
29: ; preds = %17
%30 = load i32, i32* %4
%31 = sext i32 %30 to i64
%32 = inttoptr i64 %31 to i32*
%33 = call i32 (i32*, i8*, ...) @fprintf(i32* %32, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %34
34: ; preds = %29, %21
br label %35
35: ; preds = %34, %13
%36 = load i32, i32* %4
%37 = sext i32 %36 to i64
%38 = inttoptr i64 %37 to i32*
%39 = load i8*, i8** %5
%40 = getelementptr inbounds i8, i8* %39, i32 1
store i8* %40, i8** %5
%41 = load i8, i8* %39
%42 = zext i8 %41 to i32
%43 = call i32 (i32*, i8*, ...) @fprintf(i32* %38, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %42)
%44 = load i32, i32* %7
%45 = add nsw i32 %44, 1
store i32 %45, i32* %7
br label %9
46: ; preds = %9
ret void
}

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