#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 unsigned int ssize_t;
typedef int __u8;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
scalar_t__ fprintf(int /*<<< orphan*/ *, char *, ...);
int hexdump(FILE *stream, __u8 *addr, ssize_t size) {
  unsigned i, j, c = 0;
  for (i = 0; i < size; i += 4) {
    for (j = i; j < size && j < i + 4; j++)
      c += fprintf(stream, "%.2x", addr[j]);
    c += fprintf(stream, " ");
  }
  c += fprintf(stream, "\n");
  return c;
}


x86 assembly (clang, -O0):
<hexdump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jae    11d7 <hexdump+0xc7>
mov    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%ecx
xor    %eax,%eax
cmp    -0x14(%rbp),%ecx
mov    %al,-0x21(%rbp)
jae    1165 <hexdump+0x55>
mov    -0x1c(%rbp),%eax
mov    -0x18(%rbp),%ecx
add    $0x4,%ecx
cmp    %ecx,%eax
setb   %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    1175 <hexdump+0x65>
jmp    11ab <hexdump+0x9b>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
mov    (%rax,%rcx,4),%edx
lea    0xe76(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%eax
add    %rcx,%rax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1143 <hexdump+0x33>
mov    -0x8(%rbp),%rdi
lea    0xe4f(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%eax
add    %rcx,%rax
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x18(%rbp)
jmp    1131 <hexdump+0x21>
mov    -0x8(%rbp),%rdi
lea    0xe25(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%eax
add    %rcx,%rax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hexdump>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,0x8(%rsp)
test   %edx,%edx
je     11b4 <hexdump+0xa4>
mov    %rsi,%r12
mov    %edx,%r14d
xor    %ebx,%ebx
xor    %eax,%eax
mov    %edx,0x10(%rsp)
jmp    1166 <hexdump+0x56>
nopl   0x0(%rax,%rax,1)
mov    0x8(%rsp),%rdi
lea    0xeb9(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    %rax,%r15
add    %ebx,%r15d
mov    %r15d,%ebx
mov    0x14(%rsp),%eax
cmp    0x10(%rsp),%eax
jae    11b7 <hexdump+0xa7>
lea    0x4(%rax),%ecx
cmp    $0xfffffffc,%eax
mov    %ecx,0x14(%rsp)
je     1140 <hexdump+0x30>
mov    %eax,%ebp
add    $0x1,%rbp
mov    %ecx,%r15d
nopl   0x0(%rax,%rax,1)
mov    %ebx,%r13d
mov    -0x4(%r12,%rbp,4),%edx
mov    0x8(%rsp),%rdi
lea    0xe6c(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    %rax,%rbx
add    %r13d,%ebx
cmp    %r14,%rbp
jae    1140 <hexdump+0x30>
lea    0x1(%rbp),%rax
cmp    %r15,%rbp
mov    %rax,%rbp
jb     1180 <hexdump+0x70>
jmp    1140 <hexdump+0x30>
xor    %r15d,%r15d
lea    0xe49(%rip),%rsi
mov    0x8(%rsp),%rdi
xor    %eax,%eax
call   1030 <fprintf@plt>
add    %r15d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%.2x\00"
@.str.1 = [2 x i8] c" \00"
@.str.2 = [2 x i8] c"\0A\00"
define i32 @hexdump(i32* %0, i32* %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32* %0, i32** %4
store i32* %1, i32** %5
store i32 %2, i32* %6
store i32 0, i32* %9
store i32 0, i32* %7
br label %10
10: ; preds = %49, %3
%11 = load i32, i32* %7
%12 = load i32, i32* %6
%13 = icmp ult i32 %11, %12
br i1 %13, label %14, label %52
14: ; preds = %10
%15 = load i32, i32* %7
store i32 %15, i32* %8
br label %16
16: ; preds = %39, %14
%17 = load i32, i32* %8
%18 = load i32, i32* %6
%19 = icmp ult i32 %17, %18
br i1 %19, label %20, label %25
20: ; preds = %16
%21 = load i32, i32* %8
%22 = load i32, i32* %7
%23 = add i32 %22, 4
%24 = icmp ult i32 %21, %23
br label %25
25: ; preds = %20, %16
%26 = phi i1 [ false, %16 ], [ %24, %20 ]
br i1 %26, label %27, label %42
27: ; preds = %25
%28 = load i32*, i32** %4
%29 = load i32*, i32** %5
%30 = load i32, i32* %8
%31 = zext i32 %30 to i64
%32 = getelementptr inbounds i32, i32* %29, i64 %31
%33 = load i32, i32* %32
%34 = call i64 (i32*, i8*, ...) @fprintf(i32* %28, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %33)
%35 = load i32, i32* %9
%36 = zext i32 %35 to i64
%37 = add nsw i64 %36, %34
%38 = trunc i64 %37 to i32
store i32 %38, i32* %9
br label %39
39: ; preds = %27
%40 = load i32, i32* %8
%41 = add i32 %40, 1
store i32 %41, i32* %8
br label %16
42: ; preds = %25
%43 = load i32*, i32** %4
%44 = call i64 (i32*, i8*, ...) @fprintf(i32* %43, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%45 = load i32, i32* %9
%46 = zext i32 %45 to i64
%47 = add nsw i64 %46, %44
%48 = trunc i64 %47 to i32
store i32 %48, i32* %9
br label %49
49: ; preds = %42
%50 = load i32, i32* %7
%51 = add i32 %50, 4
store i32 %51, i32* %7
br label %10
52: ; preds = %10
%53 = load i32*, i32** %4
%54 = call i64 (i32*, i8*, ...) @fprintf(i32* %53, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%55 = load i32, i32* %9
%56 = zext i32 %55 to i64
%57 = add nsw i64 %56, %54
%58 = trunc i64 %57 to i32
store i32 %58, i32* %9
%59 = load i32, i32* %9
ret i32 %59
}

LLVM IR (-O2):
@.str = [5 x i8] c"%.2x\00"
@.str.1 = [2 x i8] c" \00"
@.str.2 = [2 x i8] c"\0A\00"
define i32 @hexdump(i32* nocapture %0, i32* nocapture %1, i32 %2) {
%4 = icmp eq i32 %2, 0
br i1 %4, label %33, label %5
5: ; preds = %3
%6 = zext i32 %2 to i64
br label %7
7: ; preds = %5, %27
%8 = phi i32 [ %31, %27 ], [ 0, %5 ]
%9 = phi i32 [ %10, %27 ], [ 0, %5 ]
%10 = add i32 %9, 4
%11 = icmp eq i32 %9, -4
br i1 %11, label %27, label %12
12: ; preds = %7
%13 = zext i32 %9 to i64
%14 = zext i32 %10 to i64
br label %15
15: ; preds = %12, %15
%16 = phi i64 [ %13, %12 ], [ %23, %15 ]
%17 = phi i32 [ %8, %12 ], [ %22, %15 ]
%18 = getelementptr inbounds i32, i32* %1, i64 %16
%19 = load i32, i32* %18
%20 = tail call i64 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %19)
%21 = trunc i64 %20 to i32
%22 = add i32 %17, %21
%23 = add nuw nsw i64 %16, 1
%24 = icmp ult i64 %23, %6
%25 = icmp ult i64 %23, %14
%26 = select i1 %24, i1 %25, i1 false
br i1 %26, label %15, label %27
27: ; preds = %15, %7
%28 = phi i32 [ %8, %7 ], [ %22, %15 ]
%29 = tail call i64 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%30 = trunc i64 %29 to i32
%31 = add i32 %28, %30
%32 = icmp ult i32 %10, %2
br i1 %32, label %7, label %33
33: ; preds = %27, %3
%34 = phi i32 [ 0, %3 ], [ %31, %27 ]
%35 = tail call i64 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%36 = trunc i64 %35 to i32
%37 = add i32 %34, %36
ret i32 %37
}