#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 *, char *);
int /*<<< orphan*/ sprintf(char *, char *, ...);
void hexdump(void *addr, int size, int skip, int linechars) {
  int currline;
  int lasLine;
  int i;
  unsigned char *pc;
  char buff[256];
  char buff2[256];
  if (size - skip <= 0) {
    return;
  }
  lasLine = size / linechars;
  if (size % linechars != 0) {
    ++lasLine;
  }
  pc = (unsigned char *)addr;
  for (currline = skip / linechars; currline < lasLine; ++currline) {
    sprintf(buff, "  0x%04x ", currline * linechars);
    sprintf(buff2, "  ");
    for (i = 0; i < linechars; ++i) {
      int charno = currline * linechars + i;
      if (charno >= skip && charno < size) {
        sprintf(buff, "%s %02x", buff, pc[charno]);
        if ((pc[charno] < 0x20) || (pc[charno] > 0x7e)) {
          sprintf(buff2, "%s.", buff2);
        } else {
          sprintf(buff2, "%s%c", buff2, pc[charno]);
        }
      } else {
        sprintf(buff, "%s __", buff);
        sprintf(buff2, "%s ", buff2);
      }
    }
    printf("%s%s\n", buff, buff2);
  }
}


x86 assembly (clang, -O0):
<hexdump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x240,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    -0xc(%rbp),%eax
sub    -0x10(%rbp),%eax
cmp    $0x0,%eax
jg     114c <hexdump+0x2c>
jmp    131e <hexdump+0x1fe>
mov    -0xc(%rbp),%eax
cltd
idivl  -0x14(%rbp)
mov    %eax,-0x1c(%rbp)
mov    -0xc(%rbp),%eax
cltd
idivl  -0x14(%rbp)
cmp    $0x0,%edx
je     116f <hexdump+0x4f>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%eax
cltd
idivl  -0x14(%rbp)
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    131e <hexdump+0x1fe>
lea    -0x130(%rbp),%rdi
mov    -0x18(%rbp),%edx
imul   -0x14(%rbp),%edx
lea    0xe5e(%rip),%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
lea    -0x230(%rbp),%rdi
lea    0xe53(%rip),%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    12f6 <hexdump+0x1d6>
mov    -0x18(%rbp),%eax
imul   -0x14(%rbp),%eax
add    -0x20(%rbp),%eax
mov    %eax,-0x234(%rbp)
mov    -0x234(%rbp),%eax
cmp    -0x10(%rbp),%eax
jl     12ab <hexdump+0x18b>
mov    -0x234(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    12ab <hexdump+0x18b>
lea    -0x130(%rbp),%rdi
lea    -0x130(%rbp),%rdx
mov    -0x28(%rbp),%rax
movslq -0x234(%rbp),%rcx
movzbl (%rax,%rcx,1),%ecx
lea    0xdea(%rip),%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
mov    -0x28(%rbp),%rax
movslq -0x234(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
jl     125a <hexdump+0x13a>
mov    -0x28(%rbp),%rax
movslq -0x234(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
cmp    $0x7e,%eax
jle    127b <hexdump+0x15b>
lea    -0x230(%rbp),%rdi
lea    -0x230(%rbp),%rdx
lea    0xda6(%rip),%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
jmp    12a6 <hexdump+0x186>
lea    -0x230(%rbp),%rdi
lea    -0x230(%rbp),%rdx
mov    -0x28(%rbp),%rax
movslq -0x234(%rbp),%rcx
movzbl (%rax,%rcx,1),%ecx
lea    0xd7a(%rip),%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
jmp    12e3 <hexdump+0x1c3>
lea    -0x130(%rbp),%rdi
lea    -0x130(%rbp),%rdx
lea    0xd5e(%rip),%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
lea    -0x230(%rbp),%rdi
lea    -0x230(%rbp),%rdx
lea    0xd48(%rip),%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
jmp    12e8 <hexdump+0x1c8>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11c5 <hexdump+0xa5>
lea    -0x130(%rbp),%rsi
lea    -0x230(%rbp),%rdx
lea    0xd1d(%rip),%rdi
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1181 <hexdump+0x61>
add    $0x240,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hexdump>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x248,%rsp
mov    %ecx,0xc(%rsp)
cmp    %edx,%esi
jle    12b3 <hexdump+0x193>
mov    %edx,%ecx
mov    %rdi,%rbx
mov    %esi,%eax
cltd
mov    0xc(%rsp),%edi
idiv   %edi
mov    %eax,%ebp
cmp    $0x1,%edx
sbb    $0xffffffff,%ebp
mov    %ecx,%eax
cltd
idiv   %edi
mov    %ebp,0x1c(%rsp)
cmp    %ebp,%eax
jge    12b3 <hexdump+0x193>
movslq %ecx,%r13
movslq %esi,%rcx
mov    %rcx,0x38(%rsp)
movslq %eax,%rcx
mov    0xc(%rsp),%eax
movslq %eax,%rdx
mov    %eax,%eax
mov    %rax,0x20(%rsp)
mov    %rcx,%rax
mov    %rdx,0x28(%rsp)
imul   %rdx,%rax
mov    %rax,0x10(%rsp)
lea    0x140(%rsp),%rbp
lea    0x40(%rsp),%r14
jmp    11d4 <hexdump+0xb4>
lea    0xe81(%rip),%rdi
mov    %rbp,%rsi
mov    %r14,%rdx
call   1030 <printf@plt>
mov    0x30(%rsp),%rcx
add    $0x1,%rcx
mov    0x10(%rsp),%rax
add    0x28(%rsp),%rax
mov    %rax,0x10(%rsp)
cmp    %ecx,0x1c(%rsp)
je     12b3 <hexdump+0x193>
mov    %rcx,0x30(%rsp)
mov    %ecx,%edx
mov    0xc(%rsp),%r15d
imul   %r15d,%edx
mov    %rbp,%rdi
lea    0xe12(%rip),%rsi
xor    %eax,%eax
call   1040 <sprintf@plt>
movw   $0x2020,0x40(%rsp)
movb   $0x0,0x42(%rsp)
test   %r15d,%r15d
jle    11a0 <hexdump+0x80>
mov    0x20(%rsp),%r12
mov    0x10(%rsp),%r15
jmp    1256 <hexdump+0x136>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbp,%rdi
lea    0xdf4(%rip),%rsi
mov    %rbp,%rdx
xor    %eax,%eax
call   1040 <sprintf@plt>
mov    %r14,%rdi
lea    0xde6(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1040 <sprintf@plt>
add    $0x1,%r15
add    $0xffffffffffffffff,%r12
je     11a0 <hexdump+0x80>
cmp    %r13,%r15
jl     1220 <hexdump+0x100>
cmp    0x38(%rsp),%r15
jge    1220 <hexdump+0x100>
movzbl (%rbx,%r15,1),%ecx
mov    %rbp,%rdi
lea    0xd9c(%rip),%rsi
mov    %rbp,%rdx
xor    %eax,%eax
call   1040 <sprintf@plt>
movzbl (%rbx,%r15,1),%ecx
lea    -0x7f(%rcx),%eax
mov    %r14,%rdi
cmp    $0xa0,%al
ja     12a0 <hexdump+0x180>
lea    0xd84(%rip),%rsi
jmp    123e <hexdump+0x11e>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
lea    0xd72(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1040 <sprintf@plt>
jmp    1248 <hexdump+0x128>
add    $0x248,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [10 x i8] c" 0x%04x \00"
@.str.1 = [3 x i8] c" \00"
@.str.2 = [8 x i8] c"%s %02x\00"
@.str.3 = [4 x i8] c"%s.\00"
@.str.4 = [5 x i8] c"%s%c\00"
@.str.5 = [6 x i8] c"%s __\00"
@.str.6 = [4 x i8] c"%s \00"
@.str.7 = [6 x i8] c"%s%s\0A\00"
define void @hexdump(i8* %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i8*
%13 = alloca [256 x i8]
%14 = alloca [256 x i8]
%15 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%16 = load i32, i32* %6
%17 = load i32, i32* %7
%18 = sub nsw i32 %16, %17
%19 = icmp sle i32 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %4
br label %124
21: ; preds = %4
%22 = load i32, i32* %6
%23 = load i32, i32* %8
%24 = sdiv i32 %22, %23
store i32 %24, i32* %10
%25 = load i32, i32* %6
%26 = load i32, i32* %8
%27 = srem i32 %25, %26
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %21
%30 = load i32, i32* %10
%31 = add nsw i32 %30, 1
store i32 %31, i32* %10
br label %32
32: ; preds = %29, %21
%33 = load i8*, i8** %5
store i8* %33, i8** %12
%34 = load i32, i32* %7
%35 = load i32, i32* %8
%36 = sdiv i32 %34, %35
store i32 %36, i32* %9
br label %37
37: ; preds = %121, %32
%38 = load i32, i32* %9
%39 = load i32, i32* %10
%40 = icmp slt i32 %38, %39
br i1 %40, label %41, label %124
41: ; preds = %37
%42 = getelementptr inbounds [256 x i8], [256 x i8]* %13, i64 0, i64 0
%43 = load i32, i32* %9
%44 = load i32, i32* %8
%45 = mul nsw i32 %43, %44
%46 = call i32 (i8*, i8*, ...) @sprintf(i8* %42, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %45)
%47 = getelementptr inbounds [256 x i8], [256 x i8]* %14, i64 0, i64 0
%48 = call i32 (i8*, i8*, ...) @sprintf(i8* %47, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %11
br label %49
49: ; preds = %114, %41
%50 = load i32, i32* %11
%51 = load i32, i32* %8
%52 = icmp slt i32 %50, %51
br i1 %52, label %53, label %117
53: ; preds = %49
%54 = load i32, i32* %9
%55 = load i32, i32* %8
%56 = mul nsw i32 %54, %55
%57 = load i32, i32* %11
%58 = add nsw i32 %56, %57
store i32 %58, i32* %15
%59 = load i32, i32* %15
%60 = load i32, i32* %7
%61 = icmp sge i32 %59, %60
br i1 %61, label %62, label %106
62: ; preds = %53
%63 = load i32, i32* %15
%64 = load i32, i32* %6
%65 = icmp slt i32 %63, %64
br i1 %65, label %66, label %106
66: ; preds = %62
%67 = getelementptr inbounds [256 x i8], [256 x i8]* %13, i64 0, i64 0
%68 = getelementptr inbounds [256 x i8], [256 x i8]* %13, i64 0, i64 0
%69 = load i8*, i8** %12
%70 = load i32, i32* %15
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds i8, i8* %69, i64 %71
%73 = load i8, i8* %72
%74 = zext i8 %73 to i32
%75 = call i32 (i8*, i8*, ...) @sprintf(i8* %67, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %68, i32 %74)
%76 = load i8*, i8** %12
%77 = load i32, i32* %15
%78 = sext i32 %77 to i64
%79 = getelementptr inbounds i8, i8* %76, i64 %78
%80 = load i8, i8* %79
%81 = zext i8 %80 to i32
%82 = icmp slt i32 %81, 32
br i1 %82, label %91, label %83
83: ; preds = %66
%84 = load i8*, i8** %12
%85 = load i32, i32* %15
%86 = sext i32 %85 to i64
%87 = getelementptr inbounds i8, i8* %84, i64 %86
%88 = load i8, i8* %87
%89 = zext i8 %88 to i32
%90 = icmp sgt i32 %89, 126
br i1 %90, label %91, label %95
91: ; preds = %83, %66
%92 = getelementptr inbounds [256 x i8], [256 x i8]* %14, i64 0, i64 0
%93 = getelementptr inbounds [256 x i8], [256 x i8]* %14, i64 0, i64 0
%94 = call i32 (i8*, i8*, ...) @sprintf(i8* %92, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %93)
br label %105
95: ; preds = %83
%96 = getelementptr inbounds [256 x i8], [256 x i8]* %14, i64 0, i64 0
%97 = getelementptr inbounds [256 x i8], [256 x i8]* %14, i64 0, i64 0
%98 = load i8*, i8** %12
%99 = load i32, i32* %15
%100 = sext i32 %99 to i64
%101 = getelementptr inbounds i8, i8* %98, i64 %100
%102 = load i8, i8* %101
%103 = zext i8 %102 to i32
%104 = call i32 (i8*, i8*, ...) @sprintf(i8* %96, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8* %97, i32 %103)
br label %105
105: ; preds = %95, %91
br label %113
106: ; preds = %62, %53
%107 = getelementptr inbounds [256 x i8], [256 x i8]* %13, i64 0, i64 0
%108 = getelementptr inbounds [256 x i8], [256 x i8]* %13, i64 0, i64 0
%109 = call i32 (i8*, i8*, ...) @sprintf(i8* %107, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i8* %108)
%110 = getelementptr inbounds [256 x i8], [256 x i8]* %14, i64 0, i64 0
%111 = getelementptr inbounds [256 x i8], [256 x i8]* %14, i64 0, i64 0
%112 = call i32 (i8*, i8*, ...) @sprintf(i8* %110, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* %111)
br label %113
113: ; preds = %106, %105
br label %114
114: ; preds = %113
%115 = load i32, i32* %11
%116 = add nsw i32 %115, 1
store i32 %116, i32* %11
br label %49
117: ; preds = %49
%118 = getelementptr inbounds [256 x i8], [256 x i8]* %13, i64 0, i64 0
%119 = getelementptr inbounds [256 x i8], [256 x i8]* %14, i64 0, i64 0
%120 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0), i8* %118, i8* %119)
br label %121
121: ; preds = %117
%122 = load i32, i32* %9
%123 = add nsw i32 %122, 1
store i32 %123, i32* %9
br label %37
124: ; preds = %20, %37
ret void
}

LLVM IR (-O2):
@.str = [10 x i8] c" 0x%04x \00"
@.str.1 = [3 x i8] c" \00"
@.str.2 = [8 x i8] c"%s %02x\00"
@.str.3 = [4 x i8] c"%s.\00"
@.str.4 = [5 x i8] c"%s%c\00"
@.str.5 = [6 x i8] c"%s __\00"
@.str.6 = [4 x i8] c"%s \00"
@.str.7 = [6 x i8] c"%s%s\0A\00"
define void @hexdump(i8* nocapture %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca [256 x i8]
%6 = alloca [256 x i8]
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%8 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%9 = icmp sgt i32 %1, %2
br i1 %9, label %10, label %60
10: ; preds = %4
%11 = sdiv i32 %1, %3
%12 = srem i32 %1, %3
%13 = icmp ne i32 %12, 0
%14 = zext i1 %13 to i32
%15 = add i32 %11, %14
%16 = sdiv i32 %2, %3
%17 = icmp slt i32 %16, %15
br i1 %17, label %18, label %60
18: ; preds = %10
%19 = icmp sgt i32 %3, 0
%20 = sext i32 %2 to i64
%21 = sext i32 %1 to i64
%22 = sext i32 %16 to i64
%23 = sext i32 %3 to i64
%24 = zext i32 %3 to i64
br label %25
25: ; preds = %18, %55
%26 = phi i64 [ %22, %18 ], [ %57, %55 ]
%27 = mul nsw i64 %26, %23
%28 = trunc i64 %27 to i32
%29 = call i32 (i8*, i8*, ...) @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %28)
br i1 %19, label %30, label %55
30: ; preds = %25, %52
%31 = phi i64 [ %53, %52 ], [ 0, %25 ]
%32 = add nsw i64 %31, %27
%33 = icmp sge i64 %32, %20
%34 = icmp slt i64 %32, %21
%35 = and i1 %33, %34
br i1 %35, label %36, label %49
36: ; preds = %30
%37 = getelementptr inbounds i8, i8* %0, i64 %32
%38 = load i8, i8* %37
%39 = zext i8 %38 to i32
%40 = call i32 (i8*, i8*, ...) @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %7, i32 %39)
%41 = load i8, i8* %37
%42 = add i8 %41, -127
%43 = icmp ult i8 %42, -95
br i1 %43, label %44, label %46
44: ; preds = %36
%45 = call i32 (i8*, i8*, ...) @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %8)
br label %52
46: ; preds = %36
%47 = zext i8 %41 to i32
%48 = call i32 (i8*, i8*, ...) @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8* %8, i32 %47)
br label %52
49: ; preds = %30
%50 = call i32 (i8*, i8*, ...) @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i8* %7)
%51 = call i32 (i8*, i8*, ...) @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* %8)
br label %52
52: ; preds = %44, %46, %49
%53 = add nuw nsw i64 %31, 1
%54 = icmp eq i64 %53, %24
br i1 %54, label %55, label %30
55: ; preds = %52, %25
%56 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0), i8* %7, i8* %8)
%57 = add nsw i64 %26, 1
%58 = trunc i64 %57 to i32
%59 = icmp eq i32 %15, %58
br i1 %59, label %60, label %25
60: ; preds = %55, %10, %4
ret void
}