#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 ldm_dumpbuff(unsigned int *pBuffer, unsigned int wsize,
                  unsigned int outAddr) {
  unsigned int i;
  printf("Memory dump:\n");
  for (i = 0; i < wsize; i += 4) {
    printf("0x%x: %08x %08x %08x %08x\n", outAddr, pBuffer[i], pBuffer[i + 1],
           pBuffer[i + 2], pBuffer[i + 3]);
    outAddr += 16;
  }
  if (i < wsize) {
    printf("0x%x:", outAddr);
    for (; i < wsize; i++) {
      printf(" %08x", pBuffer[i]);
      outAddr += 4;
    }
    printf("\n");
  }
}


x86 assembly (clang, -O0):
<ldm_dumpbuff>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
lea    0xed7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jae    11a4 <ldm_dumpbuff+0x94>
mov    -0x10(%rbp),%esi
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
mov    (%rax,%rcx,4),%edx
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x1,%ecx
mov    %ecx,%ecx
mov    (%rax,%rcx,4),%ecx
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%edi
add    $0x2,%edi
mov    %edi,%edi
mov    (%rax,%rdi,4),%r8d
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%edi
add    $0x3,%edi
mov    %edi,%edi
mov    (%rax,%rdi,4),%r9d
lea    0xe88(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x10,%eax
mov    %eax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x14(%rbp)
jmp    1137 <ldm_dumpbuff+0x27>
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jae    120a <ldm_dumpbuff+0xfa>
mov    -0x10(%rbp),%esi
lea    0xe6f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jae    11fc <ldm_dumpbuff+0xec>
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
mov    (%rax,%rcx,4),%esi
lea    0xe51(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11c1 <ldm_dumpbuff+0xb1>
lea    0xe09(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ldm_dumpbuff>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%ebx
mov    %esi,%r14d
mov    %rdi,%r12
lea    0xee4(%rip),%rdi
call   1030 <puts@plt>
test   %r14d,%r14d
je     1182 <ldm_dumpbuff+0x62>
lea    0xeb8(%rip),%r15
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
mov    %ebp,%eax
mov    (%r12,%rax,4),%edx
lea    0x1(%rbp),%eax
mov    (%r12,%rax,4),%ecx
lea    0x2(%rbp),%eax
mov    (%r12,%rax,4),%r8d
lea    0x3(%rbp),%eax
mov    (%r12,%rax,4),%r9d
mov    %r15,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x10,%ebx
add    $0x4,%ebp
cmp    %r14d,%ebp
jb     1150 <ldm_dumpbuff+0x30>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str.1 = [27 x i8] c"0x%x: %08x %08x %08x %08x\0A\00"
@str = [13 x i8] c"Memory dump:\00"
define void @ldm_dumpbuff(i32* nocapture %0, i32 %1, i32 %2) {
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str, i64 0, i64 0))
%5 = icmp eq i32 %1, 0
br i1 %5, label %28, label %6
6: ; preds = %3, %6
%7 = phi i32 [ %26, %6 ], [ 0, %3 ]
%8 = phi i32 [ %25, %6 ], [ %2, %3 ]
%9 = zext i32 %7 to i64
%10 = getelementptr inbounds i32, i32* %0, i64 %9
%11 = load i32, i32* %10
%12 = or i32 %7, 1
%13 = zext i32 %12 to i64
%14 = getelementptr inbounds i32, i32* %0, i64 %13
%15 = load i32, i32* %14
%16 = or i32 %7, 2
%17 = zext i32 %16 to i64
%18 = getelementptr inbounds i32, i32* %0, i64 %17
%19 = load i32, i32* %18
%20 = or i32 %7, 3
%21 = zext i32 %20 to i64
%22 = getelementptr inbounds i32, i32* %0, i64 %21
%23 = load i32, i32* %22
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 %8, i32 %11, i32 %15, i32 %19, i32 %23)
%25 = add i32 %8, 16
%26 = add i32 %7, 4
%27 = icmp ult i32 %26, %1
br i1 %27, label %6, label %28
28: ; preds = %6, %3
ret void
}