#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 csc_memdump_find_step(int);
int /*<<< orphan*/ csc_memdump_line(char *, int, int, char *, int);
int /*<<< orphan*/ slog_csoup_format(char *, char *);
int /*<<< orphan*/ slog_csoup_puts(int /*<<< orphan*/, int, int /*<<< orphan*/);
char *smm_alloc(int);
int /*<<< orphan*/ smm_free(char *);
int csc_memdump(void *mem, int msize, int column, int flags) {
  char *buf, *mp;
  int bsize, csize, len;
  csize = csc_memdump_find_step(flags) * column;
  bsize = csize * 6 + 32;
  if ((buf = smm_alloc(bsize)) == NULL) {
    return (0xC0000000 | (1));
  }
  mp = mem;
  while (msize) {
    len = csize < msize ? csize : msize;
    csc_memdump_line(mp, len, flags, buf, bsize);
    slog_csoup_puts(0, (8 | 0), slog_csoup_format("%s\n", buf));
    msize -= len;
    if (flags & 0x20000) {
      mp -= len;
    } else {
      mp += len;
    }
  }
  smm_free(buf);
  return 0;
}


x86 assembly (clang, -O0):
<csc_memdump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
call   1030 <csc_memdump_find_step@plt>
imul   -0x18(%rbp),%eax
mov    %eax,-0x38(%rbp)
imul   $0x6,-0x38(%rbp),%eax
add    $0x20,%eax
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%edi
call   1050 <smm_alloc@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    11b0 <csc_memdump+0x50>
movl   $0xc0000001,-0x4(%rbp)
jmp    1277 <csc_memdump+0x117>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1267 <csc_memdump+0x107>
mov    -0x38(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11d9 <csc_memdump+0x79>
mov    -0x38(%rbp),%eax
mov    %eax,-0x40(%rbp)
jmp    11df <csc_memdump+0x7f>
mov    -0x14(%rbp),%eax
mov    %eax,-0x40(%rbp)
mov    -0x40(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x3c(%rbp),%esi
mov    -0x1c(%rbp),%edx
mov    -0x28(%rbp),%rcx
mov    -0x34(%rbp),%r8d
call   1080 <csc_memdump_line@plt>
mov    -0x28(%rbp),%rsi
lea    0xdf9(%rip),%rdi
call   1070 <slog_csoup_format@plt>
mov    %eax,%edx
xor    %edi,%edi
mov    $0x8,%esi
call   1040 <slog_csoup_puts@plt>
mov    -0x3c(%rbp),%ecx
mov    -0x14(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    -0x1c(%rbp),%eax
and    $0x20000,%eax
cmp    $0x0,%eax
je     1251 <csc_memdump+0xf1>
mov    -0x3c(%rbp),%ecx
mov    -0x30(%rbp),%rax
movslq %ecx,%rdx
xor    %ecx,%ecx
sub    %rdx,%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
jmp    1262 <csc_memdump+0x102>
mov    -0x3c(%rbp),%ecx
mov    -0x30(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
jmp    11b8 <csc_memdump+0x58>
mov    -0x28(%rbp),%rdi
call   1060 <smm_free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<csc_memdump>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%r13d
mov    %edx,%r14d
mov    %esi,%r12d
mov    %rdi,%rbx
mov    %ecx,%edi
call   1030 <csc_memdump_find_step@plt>
mov    %eax,%ebp
imul   %r14d,%ebp
lea    0x0(%rbp,%rbp,2),%eax
lea    (%rax,%rax,1),%r14d
add    $0x20,%r14d
mov    %r14d,%edi
call   1050 <smm_alloc@plt>
test   %rax,%rax
je     1215 <csc_memdump+0xb5>
test   %r12d,%r12d
mov    %rax,%r15
je     1209 <csc_memdump+0xa9>
mov    %rbp,%rcx
mov    %rbp,(%rsp)
nopl   0x0(%rax)
cmp    %r12d,%ecx
mov    %r12d,%ebp
cmovl  %ecx,%ebp
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %r13d,%edx
mov    %r15,%rcx
mov    %r14d,%r8d
call   1080 <csc_memdump_line@plt>
lea    0xe2d(%rip),%rdi
mov    %r15,%rsi
call   1070 <slog_csoup_format@plt>
xor    %edi,%edi
mov    $0x8,%esi
mov    %eax,%edx
call   1040 <slog_csoup_puts@plt>
movslq %ebp,%rax
mov    %rax,%rcx
neg    %rcx
test   $0x20000,%r13d
cmove  %rax,%rcx
add    %rcx,%rbx
mov    (%rsp),%rcx
sub    %eax,%r12d
jne    11b0 <csc_memdump+0x50>
mov    %r15,%rdi
call   1060 <smm_free@plt>
xor    %eax,%eax
jmp    121a <csc_memdump+0xba>
mov    $0xc0000001,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%s\0A\00"
define i32 @csc_memdump(i8* %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
store i8* %0, i8** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
%15 = load i32, i32* %9
%16 = call i32 @csc_memdump_find_step(i32 %15)
%17 = load i32, i32* %8
%18 = mul nsw i32 %16, %17
store i32 %18, i32* %13
%19 = load i32, i32* %13
%20 = mul nsw i32 %19, 6
%21 = add nsw i32 %20, 32
store i32 %21, i32* %12
%22 = load i32, i32* %12
%23 = call i8* @smm_alloc(i32 %22)
store i8* %23, i8** %10
%24 = icmp eq i8* %23, null
br i1 %24, label %25, label %26
25: ; preds = %4
store i32 -1073741823, i32* %5
br label %71
26: ; preds = %4
%27 = load i8*, i8** %6
store i8* %27, i8** %11
br label %28
28: ; preds = %67, %26
%29 = load i32, i32* %7
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %68
31: ; preds = %28
%32 = load i32, i32* %13
%33 = load i32, i32* %7
%34 = icmp slt i32 %32, %33
br i1 %34, label %35, label %37
35: ; preds = %31
%36 = load i32, i32* %13
br label %39
37: ; preds = %31
%38 = load i32, i32* %7
br label %39
39: ; preds = %37, %35
%40 = phi i32 [ %36, %35 ], [ %38, %37 ]
store i32 %40, i32* %14
%41 = load i8*, i8** %11
%42 = load i32, i32* %14
%43 = load i32, i32* %9
%44 = load i8*, i8** %10
%45 = load i32, i32* %12
%46 = call i32 @csc_memdump_line(i8* %41, i32 %42, i32 %43, i8* %44, i32 %45)
%47 = load i8*, i8** %10
%48 = call i32 @slog_csoup_format(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %47)
%49 = call i32 @slog_csoup_puts(i32 0, i32 8, i32 %48)
%50 = load i32, i32* %14
%51 = load i32, i32* %7
%52 = sub nsw i32 %51, %50
store i32 %52, i32* %7
%53 = load i32, i32* %9
%54 = and i32 %53, 131072
%55 = icmp ne i32 %54, 0
br i1 %55, label %56, label %62
56: ; preds = %39
%57 = load i32, i32* %14
%58 = load i8*, i8** %11
%59 = sext i32 %57 to i64
%60 = sub i64 0, %59
%61 = getelementptr inbounds i8, i8* %58, i64 %60
store i8* %61, i8** %11
br label %67
62: ; preds = %39
%63 = load i32, i32* %14
%64 = load i8*, i8** %11
%65 = sext i32 %63 to i64
%66 = getelementptr inbounds i8, i8* %64, i64 %65
store i8* %66, i8** %11
br label %67
67: ; preds = %62, %56
br label %28
68: ; preds = %28
%69 = load i8*, i8** %10
%70 = call i32 @smm_free(i8* %69)
store i32 0, i32* %5
br label %71
71: ; preds = %68, %25
%72 = load i32, i32* %5
ret i32 %72
}

LLVM IR (-O2):
@.str = [4 x i8] c"%s\0A\00"
define i32 @csc_memdump(i8* %0, i32 %1, i32 %2, i32 %3) {
%5 = tail call i32 @csc_memdump_find_step(i32 %3)
%6 = mul nsw i32 %5, %2
%7 = mul nsw i32 %6, 6
%8 = add nsw i32 %7, 32
%9 = tail call i8* @smm_alloc(i32 %8)
%10 = icmp eq i8* %9, null
br i1 %10, label %32, label %11
11: ; preds = %4
%12 = icmp eq i32 %1, 0
br i1 %12, label %30, label %13
13: ; preds = %11
%14 = and i32 %3, 131072
%15 = icmp eq i32 %14, 0
br label %16
16: ; preds = %13, %16
%17 = phi i32 [ %1, %13 ], [ %24, %16 ]
%18 = phi i8* [ %0, %13 ], [ %28, %16 ]
%19 = icmp slt i32 %6, %17
%20 = select i1 %19, i32 %6, i32 %17
%21 = tail call i32 @csc_memdump_line(i8* %18, i32 %20, i32 %3, i8* %9, i32 %8)
%22 = tail call i32 @slog_csoup_format(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %9)
%23 = tail call i32 @slog_csoup_puts(i32 0, i32 8, i32 %22)
%24 = sub nsw i32 %17, %20
%25 = sext i32 %20 to i64
%26 = sub nsw i64 0, %25
%27 = select i1 %15, i64 %25, i64 %26
%28 = getelementptr inbounds i8, i8* %18, i64 %27
%29 = icmp eq i32 %24, 0
br i1 %29, label %30, label %16
30: ; preds = %16, %11
%31 = tail call i32 @smm_free(i8* %9)
br label %32
32: ; preds = %4, %30
%33 = phi i32 [ 0, %30 ], [ -1073741823, %4 ]
ret i32 %33
}