#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*/ printf(char *, char);
int hexdump(char *buff, int size) {
  printf("Buff size: %i\n", size);
  int i;
  for (i = 0; i <= size; i++) {
    if (((i % 16) == 0)) {
      printf("\n%4.4x ", i);
    }
    printf("%2.2x ", buff[i]);
  }
  return 0;
}


x86 assembly (clang, -O0):
<hexdump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
lea    0xed7(%rip),%rdi
movsbl %al,%esi
call   1030 <printf@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jg     1190 <hexdump+0x80>
mov    -0x10(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    116a <hexdump+0x5a>
mov    -0x10(%rbp),%eax
lea    0xead(%rip),%rdi
movsbl %al,%esi
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
lea    0xe9e(%rip),%rdi
movsbl (%rax,%rcx,1),%esi
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1138 <hexdump+0x28>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hexdump>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %esi,%r13d
mov    %rdi,%r14
movsbl %r13b,%esi
lea    0xed6(%rip),%rdi
call   1030 <printf@plt>
test   %r13d,%r13d
js     1178 <hexdump+0x68>
add    $0x1,%r13d
xor    %ebx,%ebx
lea    0xece(%rip),%r15
lea    0xecf(%rip),%r12
jmp    1166 <hexdump+0x56>
nopw   0x0(%rax,%rax,1)
movsbl (%r14,%rbx,1),%esi
mov    %r12,%rdi
call   1030 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r13
je     1178 <hexdump+0x68>
test   $0xf,%bl
jne    1150 <hexdump+0x40>
movsbl %bl,%esi
mov    %r15,%rdi
call   1030 <printf@plt>
jmp    1150 <hexdump+0x40>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [15 x i8] c"Buff size: %i\0A\00"
@.str.1 = [8 x i8] c"\0A%4.4x \00"
@.str.2 = [7 x i8] c"%2.2x \00"
define i32 @hexdump(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%6 = load i32, i32* %4
%7 = trunc i32 %6 to i8
%8 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8 signext %7)
store i32 0, i32* %5
br label %9
9: ; preds = %28, %2
%10 = load i32, i32* %5
%11 = load i32, i32* %4
%12 = icmp sle i32 %10, %11
br i1 %12, label %13, label %31
13: ; preds = %9
%14 = load i32, i32* %5
%15 = srem i32 %14, 16
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %13
%18 = load i32, i32* %5
%19 = trunc i32 %18 to i8
%20 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8 signext %19)
br label %21
21: ; preds = %17, %13
%22 = load i8*, i8** %3
%23 = load i32, i32* %5
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %22, i64 %24
%26 = load i8, i8* %25
%27 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8 signext %26)
br label %28
28: ; preds = %21
%29 = load i32, i32* %5
%30 = add nsw i32 %29, 1
store i32 %30, i32* %5
br label %9
31: ; preds = %9
ret i32 0
}

LLVM IR (-O2):
@.str = [15 x i8] c"Buff size: %i\0A\00"
@.str.1 = [8 x i8] c"\0A%4.4x \00"
@.str.2 = [7 x i8] c"%2.2x \00"
define i32 @hexdump(i8* nocapture %0, i32 %1) {
%3 = trunc i32 %1 to i8
%4 = tail call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8 signext %3)
%5 = icmp slt i32 %1, 0
br i1 %5, label %22, label %6
6: ; preds = %2
%7 = add nuw i32 %1, 1
%8 = zext i32 %7 to i64
br label %9
9: ; preds = %6, %16
%10 = phi i64 [ 0, %6 ], [ %20, %16 ]
%11 = and i64 %10, 15
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %9
%14 = trunc i64 %10 to i8
%15 = tail call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8 signext %14)
br label %16
16: ; preds = %13, %9
%17 = getelementptr inbounds i8, i8* %0, i64 %10
%18 = load i8, i8* %17
%19 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8 signext %18)
%20 = add nuw nsw i64 %10, 1
%21 = icmp eq i64 %20, %8
br i1 %21, label %22, label %9
22: ; preds = %16, %2
ret i32 0
}