#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 *, ...);
void print_buf(void *data, unsigned int len, unsigned int width) {
  unsigned int i;
  unsigned int *uip = (unsigned int *)data;
  unsigned short *usp = (unsigned short *)data;
  unsigned char *ucp = (unsigned char *)data;
  printf("\n");
  for (i = 0; i < len / width; i++) {
    if ((i % (16 / width)) == 0)
      printf("0x%04x:", i);
    if (width == 4)
      printf(" %08x", uip[i]);
    else if (width == 2)
      printf(" %04x", usp[i]);
    else
      printf(" %02x", ucp[i]);
    if (((i + 1) % (16 / width)) == 0)
      printf("\n");
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<print_buf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
lea    0xebf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0xc(%rbp),%eax
xor    %edx,%edx
divl   -0x10(%rbp)
mov    %eax,%ecx
mov    -0x34(%rbp),%eax
cmp    %ecx,%eax
jae    1250 <print_buf+0x140>
mov    -0x14(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    $0x10,%eax
xor    %edx,%edx
divl   -0x10(%rbp)
mov    %eax,%ecx
mov    -0x38(%rbp),%eax
xor    %edx,%edx
div    %ecx
cmp    $0x0,%edx
jne    119d <print_buf+0x8d>
mov    -0x14(%rbp),%esi
lea    0xe6c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x4,-0x10(%rbp)
jne    11c4 <print_buf+0xb4>
mov    -0x20(%rbp),%rax
mov    -0x14(%rbp),%ecx
mov    (%rax,%rcx,4),%esi
lea    0xe52(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    120a <print_buf+0xfa>
cmpl   $0x2,-0x10(%rbp)
jne    11ec <print_buf+0xdc>
mov    -0x28(%rbp),%rax
mov    -0x14(%rbp),%ecx
movzwl (%rax,%rcx,2),%esi
lea    0xe30(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1205 <print_buf+0xf5>
mov    -0x30(%rbp),%rax
mov    -0x14(%rbp),%ecx
movzbl (%rax,%rcx,1),%esi
lea    0xe18(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    120a <print_buf+0xfa>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
mov    $0x10,%eax
xor    %edx,%edx
divl   -0x10(%rbp)
mov    %eax,%ecx
mov    -0x3c(%rbp),%eax
xor    %edx,%edx
div    %ecx
cmp    $0x0,%edx
jne    123d <print_buf+0x12d>
lea    0xdca(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1242 <print_buf+0x132>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    114f <print_buf+0x3f>
lea    0xda9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_buf>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%ebx
mov    %esi,%ebp
mov    %rdi,%r14
mov    $0xa,%edi
call   1030 <putchar@plt>
cmp    %ebp,%ebx
jbe    1158 <print_buf+0x38>
mov    $0xa,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <putchar@plt>
mov    %ebp,%eax
xor    %edx,%edx
div    %ebx
mov    %eax,%ecx
mov    $0x10,%eax
xor    %edx,%edx
div    %ebx
mov    %eax,%ebp
cmp    $0x2,%ecx
mov    $0x1,%r12d
cmovae %ecx,%r12d
lea    0xe81(%rip),%r15
xor    %r13d,%r13d
jmp    1195 <print_buf+0x75>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
cmp    %r12,%r13
je     1140 <print_buf+0x20>
mov    %r13d,%eax
xor    %edx,%edx
div    %ebp
test   %edx,%edx
je     11c0 <print_buf+0xa0>
cmp    $0x2,%ebx
je     11d2 <print_buf+0xb2>
cmp    $0x4,%ebx
jne    11e0 <print_buf+0xc0>
mov    (%r14,%r13,4),%esi
lea    0xe53(%rip),%rdi
jmp    11ec <print_buf+0xcc>
nopw   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %r13d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
cmp    $0x2,%ebx
jne    11a5 <print_buf+0x85>
movzwl (%r14,%r13,2),%esi
lea    0xe30(%rip),%rdi
jmp    11ec <print_buf+0xcc>
movzbl (%r14,%r13,1),%esi
lea    0xe28(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%r13
mov    %r13d,%eax
xor    %edx,%edx
div    %ebp
test   %edx,%edx
jne    1190 <print_buf+0x70>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    1190 <print_buf+0x70>

LLVM IR (-O0):
@.str = [2 x i8] c"\0A\00"
@.str.1 = [8 x i8] c"0x%04x:\00"
@.str.2 = [6 x i8] c" %08x\00"
@.str.3 = [6 x i8] c" %04x\00"
@.str.4 = [6 x i8] c" %02x\00"
define void @print_buf(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i16*
%10 = alloca i8*
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%11 = load i8*, i8** %4
%12 = bitcast i8* %11 to i32*
store i32* %12, i32** %8
%13 = load i8*, i8** %4
%14 = bitcast i8* %13 to i16*
store i16* %14, i16** %9
%15 = load i8*, i8** %4
store i8* %15, i8** %10
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %7
br label %17
17: ; preds = %72, %3
%18 = load i32, i32* %7
%19 = load i32, i32* %5
%20 = load i32, i32* %6
%21 = udiv i32 %19, %20
%22 = icmp ult i32 %18, %21
br i1 %22, label %23, label %75
23: ; preds = %17
%24 = load i32, i32* %7
%25 = load i32, i32* %6
%26 = udiv i32 16, %25
%27 = urem i32 %24, %26
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %23
%30 = load i32, i32* %7
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %30)
br label %32
32: ; preds = %29, %23
%33 = load i32, i32* %6
%34 = icmp eq i32 %33, 4
br i1 %34, label %35, label %42
35: ; preds = %32
%36 = load i32*, i32** %8
%37 = load i32, i32* %7
%38 = zext i32 %37 to i64
%39 = getelementptr inbounds i32, i32* %36, i64 %38
%40 = load i32, i32* %39
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %40)
br label %62
42: ; preds = %32
%43 = load i32, i32* %6
%44 = icmp eq i32 %43, 2
br i1 %44, label %45, label %53
45: ; preds = %42
%46 = load i16*, i16** %9
%47 = load i32, i32* %7
%48 = zext i32 %47 to i64
%49 = getelementptr inbounds i16, i16* %46, i64 %48
%50 = load i16, i16* %49
%51 = zext i16 %50 to i32
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %51)
br label %61
53: ; preds = %42
%54 = load i8*, i8** %10
%55 = load i32, i32* %7
%56 = zext i32 %55 to i64
%57 = getelementptr inbounds i8, i8* %54, i64 %56
%58 = load i8, i8* %57
%59 = zext i8 %58 to i32
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 %59)
br label %61
61: ; preds = %53, %45
br label %62
62: ; preds = %61, %35
%63 = load i32, i32* %7
%64 = add i32 %63, 1
%65 = load i32, i32* %6
%66 = udiv i32 16, %65
%67 = urem i32 %64, %66
%68 = icmp eq i32 %67, 0
br i1 %68, label %69, label %71
69: ; preds = %62
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %71
71: ; preds = %69, %62
br label %72
72: ; preds = %71
%73 = load i32, i32* %7
%74 = add i32 %73, 1
store i32 %74, i32* %7
br label %17
75: ; preds = %17
%76 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str.1 = [8 x i8] c"0x%04x:\00"
@.str.2 = [6 x i8] c" %08x\00"
@.str.3 = [6 x i8] c" %04x\00"
@.str.4 = [6 x i8] c" %02x\00"
define void @print_buf(i8* nocapture %0, i32 %1, i32 %2) {
%4 = bitcast i8* %0 to i32*
%5 = bitcast i8* %0 to i16*
%6 = tail call i32 @putchar(i32 10)
%7 = icmp ugt i32 %2, %1
br i1 %7, label %44, label %8
8: ; preds = %3
%9 = udiv i32 %1, %2
%10 = udiv i32 16, %2
%11 = call i32 @llvm.umax.i32(i32 %9, i32 1)
%12 = zext i32 %11 to i64
br label %13
13: ; preds = %8, %42
%14 = phi i64 [ 0, %8 ], [ %36, %42 ]
%15 = trunc i64 %14 to i32
%16 = urem i32 %15, %10
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %13
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %15)
br label %20
20: ; preds = %18, %13
switch i32 %2, label %30 [
i32 4, label %21
i32 2, label %25
]
21: ; preds = %20
%22 = getelementptr inbounds i32, i32* %4, i64 %14
%23 = load i32, i32* %22
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %23)
br label %35
25: ; preds = %20
%26 = getelementptr inbounds i16, i16* %5, i64 %14
%27 = load i16, i16* %26
%28 = zext i16 %27 to i32
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %28)
br label %35
30: ; preds = %20
%31 = getelementptr inbounds i8, i8* %0, i64 %14
%32 = load i8, i8* %31
%33 = zext i8 %32 to i32
%34 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 %33)
br label %35
35: ; preds = %25, %30, %21
%36 = add nuw nsw i64 %14, 1
%37 = trunc i64 %36 to i32
%38 = urem i32 %37, %10
%39 = icmp eq i32 %38, 0
br i1 %39, label %40, label %42
40: ; preds = %35
%41 = tail call i32 @putchar(i32 10)
br label %42
42: ; preds = %35, %40
%43 = icmp eq i64 %36, %12
br i1 %43, label %44, label %13
44: ; preds = %42, %3
%45 = tail call i32 @putchar(i32 10)
ret void
}