#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 fmyinput(char *, char *, int);
int gethex(char **);
int gethexorstr(char **, char *);
int /*<<< orphan*/ hexdump(char *, int, int, int);
int /*<<< orphan*/ memcpy(char *, char *, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ skipspace(char **);
int debugit(char *buf, int sz) {
  char inbuf[100], whatbuf[100], *bp;
  int dirty = 0, to, from, l, i, j, wlen, cofs = 0;
  printf("Buffer debugger. '?' for help.\n");
  while (1) {
    l = fmyinput(".", inbuf, 90);
    bp = inbuf;
    skipspace(&bp);
    if (l > 0 && *bp) {
      switch (*bp) {
      case 'd':
        bp++;
        if (*bp) {
          from = gethex(&bp);
          to = gethex(&bp);
        } else {
          from = cofs;
          to = 0;
        }
        if (to == 0)
          to = from + 0x100;
        if (to > sz)
          to = sz;
        hexdump(buf, from, to, 1);
        cofs = to;
        break;
      case 'a':
        bp++;
        if (*bp) {
          from = gethex(&bp);
          to = gethex(&bp);
        } else {
          from = cofs;
          to = 0;
        }
        if (to == 0)
          to = from + 0x100;
        if (to > sz)
          to = sz;
        hexdump(buf, from, to, 0);
        cofs = to;
        break;
      case 'q':
        return (0);
        break;
      case 's':
        if (!dirty)
          printf("Buffer has not changed, no need to write..\n");
        return (dirty);
        break;
      case 'h':
        bp++;
        if (*bp == 'a') {
          from = 0;
          to = sz;
          bp++;
        } else {
          from = gethex(&bp);
          to = gethex(&bp);
        }
        wlen = gethexorstr(&bp, whatbuf);
        if (to > sz)
          to = sz;
        printf("from: %x, to: %x, wlen: %d\n", from, to, wlen);
        for (i = from; i < to; i++) {
          for (j = 0; j < wlen; j++) {
            if (*(buf + i + j) != *(whatbuf + j))
              break;
          }
          if (j == wlen)
            printf("%06x ", i);
        }
        printf("\n");
        break;
      case ':':
        bp++;
        if (!*bp)
          break;
        from = gethex(&bp);
        wlen = gethexorstr(&bp, whatbuf);
        printf("from: %x, wlen: %d\n", from, wlen);
        memcpy(buf + from, whatbuf, wlen);
        dirty = 1;
        break;
      case '?':
        printf("d [<from>] [<to>] - dump buffer within range\n");
        printf("a [<from>] [<to>] - same as d, but without ascii-part (for "
               "cut'n'paste)\n");
        printf(": <offset> <hexbyte> [<hexbyte> ...] - change bytes\n");
        printf("h <from> <to> <hexbyte> [<hexbyte> ...] - hunt (search) for "
               "bytes\n");
        printf("ha <hexbyte> [<hexbyte] - Hunt all (whole buffer)\n");
        printf("s - save & quit\n");
        printf("q - quit (no save)\n");
        printf("  instead of <hexbyte> etc. you may give 'string to "
               "enter/search a string\n");
        break;
      default:
        printf("?\n");
        break;
      }
    }
  }
}


x86 assembly (clang, -O0):
<debugit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movl   $0x0,-0xfc(%rbp)
movl   $0x0,-0x118(%rbp)
lea    0xf4b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x80(%rbp),%rsi
lea    0xf59(%rip),%rdi
mov    $0x5a,%edx
call   1030 <fmyinput@plt>
mov    %eax,-0x108(%rbp)
lea    -0x80(%rbp),%rax
mov    %rax,-0xf8(%rbp)
lea    -0xf8(%rbp),%rdi
call   1080 <skipspace@plt>
cmpl   $0x0,-0x108(%rbp)
jle    16a3 <debugit+0x533>
mov    -0xf8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     16a3 <debugit+0x533>
mov    -0xf8(%rbp),%rax
movsbl (%rax),%eax
add    $0xffffffc6,%eax
mov    %eax,%ecx
mov    %rcx,-0x120(%rbp)
sub    $0x39,%eax
ja     1690 <debugit+0x520>
mov    -0x120(%rbp),%rax
lea    0xddd(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0xf8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0xf8(%rbp)
mov    -0xf8(%rbp),%rax
cmpb   $0x0,(%rax)
je     1277 <debugit+0x107>
lea    -0xf8(%rbp),%rdi
call   1090 <gethex@plt>
mov    %eax,-0x104(%rbp)
lea    -0xf8(%rbp),%rdi
call   1090 <gethex@plt>
mov    %eax,-0x100(%rbp)
jmp    128d <debugit+0x11d>
mov    -0x118(%rbp),%eax
mov    %eax,-0x104(%rbp)
movl   $0x0,-0x100(%rbp)
cmpl   $0x0,-0x100(%rbp)
jne    12ab <debugit+0x13b>
mov    -0x104(%rbp),%eax
add    $0x100,%eax
mov    %eax,-0x100(%rbp)
mov    -0x100(%rbp),%eax
cmp    -0x14(%rbp),%eax
jle    12c3 <debugit+0x153>
mov    -0x14(%rbp),%eax
mov    %eax,-0x100(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x104(%rbp),%esi
mov    -0x100(%rbp),%edx
mov    $0x1,%ecx
call   1070 <hexdump@plt>
mov    -0x100(%rbp),%eax
mov    %eax,-0x118(%rbp)
jmp    169e <debugit+0x52e>
mov    -0xf8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0xf8(%rbp)
mov    -0xf8(%rbp),%rax
cmpb   $0x0,(%rax)
je     1339 <debugit+0x1c9>
lea    -0xf8(%rbp),%rdi
call   1090 <gethex@plt>
mov    %eax,-0x104(%rbp)
lea    -0xf8(%rbp),%rdi
call   1090 <gethex@plt>
mov    %eax,-0x100(%rbp)
jmp    134f <debugit+0x1df>
mov    -0x118(%rbp),%eax
mov    %eax,-0x104(%rbp)
movl   $0x0,-0x100(%rbp)
cmpl   $0x0,-0x100(%rbp)
jne    136d <debugit+0x1fd>
mov    -0x104(%rbp),%eax
add    $0x100,%eax
mov    %eax,-0x100(%rbp)
mov    -0x100(%rbp),%eax
cmp    -0x14(%rbp),%eax
jle    1385 <debugit+0x215>
mov    -0x14(%rbp),%eax
mov    %eax,-0x100(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x104(%rbp),%esi
mov    -0x100(%rbp),%edx
xor    %ecx,%ecx
call   1070 <hexdump@plt>
mov    -0x100(%rbp),%eax
mov    %eax,-0x118(%rbp)
jmp    169e <debugit+0x52e>
movl   $0x0,-0x4(%rbp)
jmp    16a8 <debugit+0x538>
cmpl   $0x0,-0xfc(%rbp)
jne    13d4 <debugit+0x264>
lea    0xd3d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0xfc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    16a8 <debugit+0x538>
mov    -0xf8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0xf8(%rbp)
mov    -0xf8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x61,%eax
jne    1431 <debugit+0x2c1>
movl   $0x0,-0x104(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x100(%rbp)
mov    -0xf8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0xf8(%rbp)
jmp    1455 <debugit+0x2e5>
lea    -0xf8(%rbp),%rdi
call   1090 <gethex@plt>
mov    %eax,-0x104(%rbp)
lea    -0xf8(%rbp),%rdi
call   1090 <gethex@plt>
mov    %eax,-0x100(%rbp)
lea    -0xf0(%rbp),%rsi
lea    -0xf8(%rbp),%rdi
call   1050 <gethexorstr@plt>
mov    %eax,-0x114(%rbp)
mov    -0x100(%rbp),%eax
cmp    -0x14(%rbp),%eax
jle    1486 <debugit+0x316>
mov    -0x14(%rbp),%eax
mov    %eax,-0x100(%rbp)
mov    -0x104(%rbp),%esi
mov    -0x100(%rbp),%edx
mov    -0x114(%rbp),%ecx
lea    0xc97(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x104(%rbp),%eax
mov    %eax,-0x10c(%rbp)
mov    -0x10c(%rbp),%eax
cmp    -0x100(%rbp),%eax
jge    156d <debugit+0x3fd>
movl   $0x0,-0x110(%rbp)
mov    -0x110(%rbp),%eax
cmp    -0x114(%rbp),%eax
jge    152e <debugit+0x3be>
mov    -0x10(%rbp),%rax
movslq -0x10c(%rbp),%rcx
add    %rcx,%rax
movslq -0x110(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
movslq -0x110(%rbp),%rcx
movsbl -0xf0(%rbp,%rcx,1),%ecx
ff
cmp    %ecx,%eax
je     1515 <debugit+0x3a5>
jmp    152e <debugit+0x3be>
jmp    151a <debugit+0x3aa>
mov    -0x110(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x110(%rbp)
jmp    14ce <debugit+0x35e>
mov    -0x110(%rbp),%eax
cmp    -0x114(%rbp),%eax
jne    1554 <debugit+0x3e4>
mov    -0x10c(%rbp),%esi
lea    0xc05(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1559 <debugit+0x3e9>
mov    -0x10c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10c(%rbp)
jmp    14b2 <debugit+0x342>
lea    0xc6d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    169e <debugit+0x52e>
mov    -0xf8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0xf8(%rbp)
mov    -0xf8(%rbp),%rax
cmpb   $0x0,(%rax)
jne    15a7 <debugit+0x437>
jmp    169e <debugit+0x52e>
lea    -0xf8(%rbp),%rdi
call   1090 <gethex@plt>
mov    %eax,-0x104(%rbp)
lea    -0xf0(%rbp),%rsi
lea    -0xf8(%rbp),%rdi
call   1050 <gethexorstr@plt>
mov    %eax,-0x114(%rbp)
mov    -0x104(%rbp),%esi
mov    -0x114(%rbp),%edx
lea    0xb73(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
movslq -0x104(%rbp),%rax
add    %rax,%rdi
lea    -0xf0(%rbp),%rsi
mov    -0x114(%rbp),%edx
call   1060 <memcpy@plt>
movl   $0x1,-0xfc(%rbp)
jmp    169e <debugit+0x52e>
lea    0xb4a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xb6a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xba5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xbcc(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xc01(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xc26(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xc29(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xc2f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    169e <debugit+0x52e>
lea    0xc67(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    16a3 <debugit+0x533>
jmp    11a4 <debugit+0x34>
mov    -0x4(%rbp),%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<debugit>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x108,%rsp
mov    %esi,%r14d
mov    %rdi,0x18(%rsp)
lea    0xf6e(%rip),%rdi
call   1040 <puts@plt>
lea    0x1134(%rip),%r15
lea    0xa0(%rsp),%r12
lea    0x8(%rsp),%rbp
lea    0xe30(%rip),%r13
movl   $0x0,0x14(%rsp)
xor    %eax,%eax
mov    %rax,0x20(%rsp)
mov    %r14d,0x2c(%rsp)
jmp    1250 <debugit+0xc0>
lea    0xf50(%rip),%rdi
call   1040 <puts@plt>
lea    0xf71(%rip),%rdi
call   1040 <puts@plt>
lea    0xfad(%rip),%rdi
call   1040 <puts@plt>
lea    0xfd5(%rip),%rdi
call   1040 <puts@plt>
lea    0x100b(%rip),%rdi
call   1040 <puts@plt>
lea    0x1031(%rip),%rdi
call   1040 <puts@plt>
lea    0x1035(%rip),%rdi
call   1040 <puts@plt>
lea    0x103c(%rip),%rdi
call   1040 <puts@plt>
cs nopw 0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %r12,%rsi
mov    $0x5a,%edx
call   1050 <fmyinput@plt>
mov    %eax,%ebx
mov    %r12,0x8(%rsp)
mov    %rbp,%rdi
call   10a0 <skipspace@plt>
test   %ebx,%ebx
jle    1250 <debugit+0xc0>
mov    0x8(%rsp),%rax
movsbl (%rax),%ecx
test   %ecx,%ecx
je     1250 <debugit+0xc0>
add    $0xffffffc6,%ecx
cmp    $0x39,%ecx
ja     12fb <debugit+0x16b>
movslq 0x0(%r13,%rcx,4),%rcx
add    %r13,%rcx
jmp    *%rcx
lea    0x1(%rax),%rcx
mov    %rcx,0x8(%rsp)
cmpb   $0x0,0x1(%rax)
je     1250 <debugit+0xc0>
mov    %rbp,%rdi
call   10b0 <gethex@plt>
mov    %eax,%ebx
mov    %rbp,%rdi
lea    0x30(%rsp),%rbp
mov    %rbp,%rsi
call   1070 <gethexorstr@plt>
mov    %eax,%r13d
lea    0xe46(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1060 <printf@plt>
movslq %ebx,%rdi
add    0x18(%rsp),%rdi
mov    %rbp,%rsi
mov    %r13d,%edx
lea    0xd1c(%rip),%r13
lea    0x8(%rsp),%rbp
call   1080 <memcpy@plt>
movl   $0x1,0x14(%rsp)
jmp    1250 <debugit+0xc0>
lea    0xff0(%rip),%rdi
call   1040 <puts@plt>
jmp    1250 <debugit+0xc0>
lea    0x1(%rax),%rcx
mov    %rcx,0x8(%rsp)
cmpb   $0x0,0x1(%rax)
mov    0x20(%rsp),%rsi
je     133b <debugit+0x1ab>
mov    %rbp,%rdi
call   10b0 <gethex@plt>
mov    %eax,%ebx
mov    %rbp,%rdi
call   10b0 <gethex@plt>
mov    %rbx,%rsi
mov    %eax,%ebx
test   %eax,%eax
jne    1341 <debugit+0x1b1>
lea    0x100(%rsi),%ebx
cmp    %r14d,%ebx
cmovg  %r14d,%ebx
mov    0x18(%rsp),%rdi
mov    %ebx,%edx
xor    %ecx,%ecx
jmp    139b <debugit+0x20b>
lea    0x1(%rax),%rcx
mov    %rcx,0x8(%rsp)
cmpb   $0x0,0x1(%rax)
mov    0x20(%rsp),%rsi
je     1382 <debugit+0x1f2>
mov    %rbp,%rdi
call   10b0 <gethex@plt>
mov    %eax,%ebx
mov    %rbp,%rdi
call   10b0 <gethex@plt>
mov    %rbx,%rsi
mov    %eax,%ebx
test   %eax,%eax
jne    1388 <debugit+0x1f8>
lea    0x100(%rsi),%ebx
cmp    %r14d,%ebx
cmovg  %r14d,%ebx
mov    0x18(%rsp),%rdi
mov    %ebx,%edx
mov    $0x1,%ecx
call   1090 <hexdump@plt>
mov    %ebx,%eax
mov    %rax,0x20(%rsp)
jmp    1250 <debugit+0xc0>
lea    0x1(%rax),%rcx
mov    %rcx,0x8(%rsp)
cmpb   $0x61,0x1(%rax)
jne    13cb <debugit+0x23b>
add    $0x2,%rax
mov    %rax,0x8(%rsp)
xor    %ebx,%ebx
mov    %r14d,%r15d
jmp    13e0 <debugit+0x250>
mov    %rbp,%rdi
call   10b0 <gethex@plt>
mov    %eax,%ebx
mov    %rbp,%rdi
call   10b0 <gethex@plt>
mov    %eax,%r15d
mov    %rbp,%rdi
lea    0x30(%rsp),%rsi
call   1070 <gethexorstr@plt>
mov    %eax,%r13d
cmp    %r14d,%r15d
cmovg  %r14d,%r15d
lea    0xcea(%rip),%rdi
mov    %ebx,%esi
mov    %r15d,%edx
mov    %eax,%ecx
xor    %eax,%eax
call   1060 <printf@plt>
cmp    %r15d,%ebx
jge    1487 <debugit+0x2f7>
movslq %ebx,%r14
mov    %r13d,%ebx
mov    0x18(%rsp),%rax
lea    (%rax,%r14,1),%rbp
jmp    144e <debugit+0x2be>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    0xccd(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x1,%r14
add    $0x1,%rbp
cmp    %r14d,%r15d
je     1487 <debugit+0x2f7>
xor    %eax,%eax
test   %r13d,%r13d
jle    1480 <debugit+0x2f0>
cs nopw 0x0(%rax,%rax,1)
nop
movzbl 0x0(%rbp,%rax,1),%ecx
cmp    0x30(%rsp,%rax,1),%cl
jne    1480 <debugit+0x2f0>
add    $0x1,%rax
cmp    %rax,%rbx
jne    1460 <debugit+0x2d0>
jmp    1430 <debugit+0x2a0>
cs nopw 0x0(%rax,%rax,1)
cmp    %r13d,%eax
je     1430 <debugit+0x2a0>
jmp    1441 <debugit+0x2b1>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0x2c(%rsp),%r14d
lea    0xe53(%rip),%r15
lea    0x8(%rsp),%rbp
lea    0xb57(%rip),%r13
jmp    1250 <debugit+0xc0>
mov    0x14(%rsp),%eax
test   %eax,%eax
jne    14c4 <debugit+0x334>
lea    0xe0a(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [32 x i8] c"Buffer debugger. '?' for help.\0A\00"
@.str.1 = [2 x i8] c".\00"
@.str.2 = [44 x i8] c"Buffer has not changed, no need to write..\0A\00"
@.str.3 = [28 x i8] c"from: %x, to: %x, wlen: %d\0A\00"
@.str.4 = [6 x i8] c"%06x \00"
@.str.5 = [2 x i8] c"\0A\00"
@.str.6 = [20 x i8] c"from: %x, wlen: %d\0A\00"
@.str.7 = [46 x i8] c"d [<from>] [<to>] - dump buffer within range\0A\00"
@.str.8 = [73 x i8] c"a [<from>] [<to>] - same as d, but without ascii-part (for cut'n'paste)\0A\00"
@.str.9 = [53 x i8] c": <offset> <hexbyte> [<hexbyte> ...] - change bytes\0A\00"
@.str.10 = [67 x i8] c"h <from> <to> <hexbyte> [<hexbyte> ...] - hunt (search) for bytes\0A\00"
@.str.11 = [51 x i8] c"ha <hexbyte> [<hexbyte] - Hunt all (whole buffer)\0A\00"
@.str.12 = [17 x i8] c"s - save & quit\0A\00"
@.str.13 = [20 x i8] c"q - quit (no save)\0A\00"
@.str.14 = [75 x i8] c" instead of <hexbyte> etc. you may give 'string to enter/search a string\0A\00"
@.str.15 = [3 x i8] c"?\0A\00"
define i32 @debugit(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca [100 x i8]
%7 = alloca [100 x i8]
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 0, i32* %9
store i32 0, i32* %16
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
br label %18
18: ; preds = %2, %205
%19 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%20 = call i32 @fmyinput(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* %19, i32 90)
store i32 %20, i32* %12
%21 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
store i8* %21, i8** %8
%22 = call i32 @skipspace(i8** %8)
%23 = load i32, i32* %12
%24 = icmp sgt i32 %23, 0
br i1 %24, label %25, label %205
25: ; preds = %18
%26 = load i8*, i8** %8
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %205
30: ; preds = %25
%31 = load i8*, i8** %8
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
switch i32 %33, label %202 [
i32 100, label %34
i32 97, label %63
i32 113, label %92
i32 115, label %93
i32 104, label %100
i32 58, label %172
i32 63, label %193
]
34: ; preds = %30
%35 = load i8*, i8** %8
%36 = getelementptr inbounds i8, i8* %35, i32 1
store i8* %36, i8** %8
%37 = load i8*, i8** %8
%38 = load i8, i8* %37
%39 = icmp ne i8 %38, 0
br i1 %39, label %40, label %43
40: ; preds = %34
%41 = call i32 @gethex(i8** %8)
store i32 %41, i32* %11
%42 = call i32 @gethex(i8** %8)
store i32 %42, i32* %10
br label %45
43: ; preds = %34
%44 = load i32, i32* %16
store i32 %44, i32* %11
store i32 0, i32* %10
br label %45
45: ; preds = %43, %40
%46 = load i32, i32* %10
%47 = icmp eq i32 %46, 0
br i1 %47, label %48, label %51
48: ; preds = %45
%49 = load i32, i32* %11
%50 = add nsw i32 %49, 256
store i32 %50, i32* %10
br label %51
51: ; preds = %48, %45
%52 = load i32, i32* %10
%53 = load i32, i32* %5
%54 = icmp sgt i32 %52, %53
br i1 %54, label %55, label %57
55: ; preds = %51
%56 = load i32, i32* %5
store i32 %56, i32* %10
br label %57
57: ; preds = %55, %51
%58 = load i8*, i8** %4
%59 = load i32, i32* %11
%60 = load i32, i32* %10
%61 = call i32 @hexdump(i8* %58, i32 %59, i32 %60, i32 1)
%62 = load i32, i32* %10
store i32 %62, i32* %16
br label %204
63: ; preds = %30
%64 = load i8*, i8** %8
%65 = getelementptr inbounds i8, i8* %64, i32 1
store i8* %65, i8** %8
%66 = load i8*, i8** %8
%67 = load i8, i8* %66
%68 = icmp ne i8 %67, 0
br i1 %68, label %69, label %72
69: ; preds = %63
%70 = call i32 @gethex(i8** %8)
store i32 %70, i32* %11
%71 = call i32 @gethex(i8** %8)
store i32 %71, i32* %10
br label %74
72: ; preds = %63
%73 = load i32, i32* %16
store i32 %73, i32* %11
store i32 0, i32* %10
br label %74
74: ; preds = %72, %69
%75 = load i32, i32* %10
%76 = icmp eq i32 %75, 0
br i1 %76, label %77, label %80
77: ; preds = %74
%78 = load i32, i32* %11
%79 = add nsw i32 %78, 256
store i32 %79, i32* %10
br label %80
80: ; preds = %77, %74
%81 = load i32, i32* %10
%82 = load i32, i32* %5
%83 = icmp sgt i32 %81, %82
br i1 %83, label %84, label %86
84: ; preds = %80
%85 = load i32, i32* %5
store i32 %85, i32* %10
br label %86
86: ; preds = %84, %80
%87 = load i8*, i8** %4
%88 = load i32, i32* %11
%89 = load i32, i32* %10
%90 = call i32 @hexdump(i8* %87, i32 %88, i32 %89, i32 0)
%91 = load i32, i32* %10
store i32 %91, i32* %16
br label %204
92: ; preds = %30
store i32 0, i32* %3
br label %206
93: ; preds = %30
%94 = load i32, i32* %9
%95 = icmp ne i32 %94, 0
br i1 %95, label %98, label %96
96: ; preds = %93
%97 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0))
br label %98
98: ; preds = %96, %93
%99 = load i32, i32* %9
store i32 %99, i32* %3
br label %206
100: ; preds = %30
%101 = load i8*, i8** %8
%102 = getelementptr inbounds i8, i8* %101, i32 1
store i8* %102, i8** %8
%103 = load i8*, i8** %8
%104 = load i8, i8* %103
%105 = sext i8 %104 to i32
%106 = icmp eq i32 %105, 97
br i1 %106, label %107, label %111
107: ; preds = %100
store i32 0, i32* %11
%108 = load i32, i32* %5
store i32 %108, i32* %10
%109 = load i8*, i8** %8
%110 = getelementptr inbounds i8, i8* %109, i32 1
store i8* %110, i8** %8
br label %114
111: ; preds = %100
%112 = call i32 @gethex(i8** %8)
store i32 %112, i32* %11
%113 = call i32 @gethex(i8** %8)
store i32 %113, i32* %10
br label %114
114: ; preds = %111, %107
%115 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%116 = call i32 @gethexorstr(i8** %8, i8* %115)
store i32 %116, i32* %15
%117 = load i32, i32* %10
%118 = load i32, i32* %5
%119 = icmp sgt i32 %117, %118
br i1 %119, label %120, label %122
120: ; preds = %114
%121 = load i32, i32* %5
store i32 %121, i32* %10
br label %122
122: ; preds = %120, %114
%123 = load i32, i32* %11
%124 = load i32, i32* %10
%125 = load i32, i32* %15
%126 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i32 %123, i32 %124, i32 %125)
%127 = load i32, i32* %11
store i32 %127, i32* %13
br label %128
128: ; preds = %167, %122
%129 = load i32, i32* %13
%130 = load i32, i32* %10
%131 = icmp slt i32 %129, %130
br i1 %131, label %132, label %170
132: ; preds = %128
store i32 0, i32* %14
br label %133
133: ; preds = %156, %132
%134 = load i32, i32* %14
%135 = load i32, i32* %15
%136 = icmp slt i32 %134, %135
br i1 %136, label %137, label %159
137: ; preds = %133
%138 = load i8*, i8** %4
%139 = load i32, i32* %13
%140 = sext i32 %139 to i64
%141 = getelementptr inbounds i8, i8* %138, i64 %140
%142 = load i32, i32* %14
%143 = sext i32 %142 to i64
%144 = getelementptr inbounds i8, i8* %141, i64 %143
%145 = load i8, i8* %144
%146 = sext i8 %145 to i32
%147 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%148 = load i32, i32* %14
%149 = sext i32 %148 to i64
%150 = getelementptr inbounds i8, i8* %147, i64 %149
%151 = load i8, i8* %150
%152 = sext i8 %151 to i32
%153 = icmp ne i32 %146, %152
br i1 %153, label %154, label %155
154: ; preds = %137
br label %159
155: ; preds = %137
br label %156
156: ; preds = %155
%157 = load i32, i32* %14
%158 = add nsw i32 %157, 1
store i32 %158, i32* %14
br label %133
159: ; preds = %154, %133
%160 = load i32, i32* %14
%161 = load i32, i32* %15
%162 = icmp eq i32 %160, %161
br i1 %162, label %163, label %166
163: ; preds = %159
%164 = load i32, i32* %13
%165 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 %164)
br label %166
166: ; preds = %163, %159
br label %167
167: ; preds = %166
%168 = load i32, i32* %13
%169 = add nsw i32 %168, 1
store i32 %169, i32* %13
br label %128
170: ; preds = %128
%171 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
br label %204
172: ; preds = %30
%173 = load i8*, i8** %8
%174 = getelementptr inbounds i8, i8* %173, i32 1
store i8* %174, i8** %8
%175 = load i8*, i8** %8
%176 = load i8, i8* %175
%177 = icmp ne i8 %176, 0
br i1 %177, label %179, label %178
178: ; preds = %172
br label %204
179: ; preds = %172
%180 = call i32 @gethex(i8** %8)
store i32 %180, i32* %11
%181 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%182 = call i32 @gethexorstr(i8** %8, i8* %181)
store i32 %182, i32* %15
%183 = load i32, i32* %11
%184 = load i32, i32* %15
%185 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0), i32 %183, i32 %184)
%186 = load i8*, i8** %4
%187 = load i32, i32* %11
%188 = sext i32 %187 to i64
%189 = getelementptr inbounds i8, i8* %186, i64 %188
%190 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%191 = load i32, i32* %15
%192 = call i32 @memcpy(i8* %189, i8* %190, i32 %191)
store i32 1, i32* %9
br label %204
193: ; preds = %30
%194 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.7, i64 0, i64 0))
%195 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([73 x i8], [73 x i8]* @.str.8, i64 0, i64 0))
%196 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.9, i64 0, i64 0))
%197 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str.10, i64 0, i64 0))
%198 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.11, i64 0, i64 0))
%199 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.12, i64 0, i64 0))
%200 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.13, i64 0, i64 0))
%201 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([75 x i8], [75 x i8]* @.str.14, i64 0, i64 0))
br label %204
202: ; preds = %30
%203 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.15, i64 0, i64 0))
br label %204
204: ; preds = %202, %193, %179, %178, %170, %86, %57
br label %205
205: ; preds = %204, %25, %18
br label %18
206: ; preds = %98, %92
%207 = load i32, i32* %3
ret i32 %207
}

LLVM IR (-O2):
@.str.1 = [2 x i8] c".\00"
@.str.3 = [28 x i8] c"from: %x, to: %x, wlen: %d\0A\00"
@.str.4 = [6 x i8] c"%06x \00"
@.str.6 = [20 x i8] c"from: %x, wlen: %d\0A\00"
@str = [31 x i8] c"Buffer debugger. '?' for help.\00"
@str.16 = [45 x i8] c"d [<from>] [<to>] - dump buffer within range\00"
@str.17 = [72 x i8] c"a [<from>] [<to>] - same as d, but without ascii-part (for cut'n'paste)\00"
@str.18 = [52 x i8] c": <offset> <hexbyte> [<hexbyte> ...] - change bytes\00"
@str.19 = [66 x i8] c"h <from> <to> <hexbyte> [<hexbyte> ...] - hunt (search) for bytes\00"
@str.20 = [50 x i8] c"ha <hexbyte> [<hexbyte] - Hunt all (whole buffer)\00"
@str.21 = [16 x i8] c"s - save & quit\00"
@str.22 = [19 x i8] c"q - quit (no save)\00"
@str.23 = [74 x i8] c" instead of <hexbyte> etc. you may give 'string to enter/search a string\00"
@str.24 = [43 x i8] c"Buffer has not changed, no need to write..\00"
@str.25 = [2 x i8] c"?\00"
define i32 @debugit(i8* %0, i32 %1) {
%3 = alloca [100 x i8]
%4 = alloca [100 x i8]
%5 = alloca i8*
%6 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%8 = bitcast i8** %5 to i8*
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str, i64 0, i64 0))
br label %10
10: ; preds = %39, %2
%11 = phi i32 [ 0, %2 ], [ %40, %39 ]
%12 = phi i32 [ 0, %2 ], [ %41, %39 ]
%13 = call i32 @fmyinput(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* %6, i32 90)
store i8* %6, i8** %5
%14 = call i32 @skipspace(i8** %5)
%15 = icmp sgt i32 %13, 0
br i1 %15, label %16, label %39
16: ; preds = %10
%17 = load i8*, i8** %5
%18 = load i8, i8* %17
%19 = icmp eq i8 %18, 0
br i1 %19, label %39, label %20
20: ; preds = %16
%21 = sext i8 %18 to i32
switch i32 %21, label %131 [
i32 100, label %22
i32 97, label %42
i32 113, label %133
i32 115, label %59
i32 104, label %63
i32 58, label %111
i32 63, label %122
]
22: ; preds = %20
%23 = getelementptr inbounds i8, i8* %17, i64 1
store i8* %23, i8** %5
%24 = load i8, i8* %23
%25 = icmp eq i8 %24, 0
br i1 %25, label %30, label %26
26: ; preds = %22
%27 = call i32 @gethex(i8** %5)
%28 = call i32 @gethex(i8** %5)
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %22, %26
%31 = phi i32 [ %27, %26 ], [ %12, %22 ]
%32 = add nsw i32 %31, 256
br label %33
33: ; preds = %26, %30
%34 = phi i32 [ %31, %30 ], [ %27, %26 ]
%35 = phi i32 [ %32, %30 ], [ %28, %26 ]
%36 = icmp sgt i32 %35, %1
%37 = select i1 %36, i32 %1, i32 %35
%38 = call i32 @hexdump(i8* %0, i32 %34, i32 %37, i32 1)
br label %39
39: ; preds = %33, %53, %109, %115, %122, %131, %111, %16, %10
%40 = phi i32 [ %11, %131 ], [ %11, %122 ], [ 1, %115 ], [ %11, %111 ], [ %11, %109 ], [ %11, %53 ], [ %11, %33 ], [ %11, %16 ], [ %11, %10 ]
%41 = phi i32 [ %12, %131 ], [ %12, %122 ], [ %12, %115 ], [ %12, %111 ], [ %12, %109 ], [ %57, %53 ], [ %37, %33 ], [ %12, %16 ], [ %12, %10 ]
br label %10
42: ; preds = %20
%43 = getelementptr inbounds i8, i8* %17, i64 1
store i8* %43, i8** %5
%44 = load i8, i8* %43
%45 = icmp eq i8 %44, 0
br i1 %45, label %50, label %46
46: ; preds = %42
%47 = call i32 @gethex(i8** %5)
%48 = call i32 @gethex(i8** %5)
%49 = icmp eq i32 %48, 0
br i1 %49, label %50, label %53
50: ; preds = %42, %46
%51 = phi i32 [ %47, %46 ], [ %12, %42 ]
%52 = add nsw i32 %51, 256
br label %53
53: ; preds = %46, %50
%54 = phi i32 [ %51, %50 ], [ %47, %46 ]
%55 = phi i32 [ %52, %50 ], [ %48, %46 ]
%56 = icmp sgt i32 %55, %1
%57 = select i1 %56, i32 %1, i32 %55
%58 = call i32 @hexdump(i8* %0, i32 %54, i32 %57, i32 0)
br label %39
59: ; preds = %20
%60 = icmp eq i32 %11, 0
br i1 %60, label %61, label %133
61: ; preds = %59
%62 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @str.24, i64 0, i64 0))
br label %133
63: ; preds = %20
%64 = getelementptr inbounds i8, i8* %17, i64 1
store i8* %64, i8** %5
%65 = load i8, i8* %64
%66 = icmp eq i8 %65, 97
br i1 %66, label %67, label %69
67: ; preds = %63
%68 = getelementptr inbounds i8, i8* %17, i64 2
store i8* %68, i8** %5
br label %72
69: ; preds = %63
%70 = call i32 @gethex(i8** %5)
%71 = call i32 @gethex(i8** %5)
br label %72
72: ; preds = %69, %67
%73 = phi i32 [ %1, %67 ], [ %71, %69 ]
%74 = phi i32 [ 0, %67 ], [ %70, %69 ]
%75 = call i32 @gethexorstr(i8** %5, i8* %7)
%76 = icmp sgt i32 %73, %1
%77 = select i1 %76, i32 %1, i32 %73
%78 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i32 %74, i32 %77, i32 %75)
%79 = icmp slt i32 %74, %77
br i1 %79, label %80, label %109
80: ; preds = %72
%81 = icmp sgt i32 %75, 0
%82 = sext i32 %74 to i64
%83 = zext i32 %75 to i64
br label %84
84: ; preds = %80, %105
%85 = phi i64 [ %82, %80 ], [ %106, %105 ]
%86 = getelementptr inbounds i8, i8* %0, i64 %85
br i1 %81, label %87, label %99
87: ; preds = %84, %94
%88 = phi i64 [ %95, %94 ], [ 0, %84 ]
%89 = getelementptr inbounds i8, i8* %86, i64 %88
%90 = load i8, i8* %89
%91 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 %88
%92 = load i8, i8* %91
%93 = icmp eq i8 %90, %92
br i1 %93, label %94, label %97
94: ; preds = %87
%95 = add nuw nsw i64 %88, 1
%96 = icmp eq i64 %95, %83
br i1 %96, label %102, label %87
97: ; preds = %87
%98 = trunc i64 %88 to i32
br label %99
99: ; preds = %97, %84
%100 = phi i32 [ 0, %84 ], [ %98, %97 ]
%101 = icmp eq i32 %100, %75
br i1 %101, label %102, label %105
102: ; preds = %94, %99
%103 = trunc i64 %85 to i32
%104 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 %103)
br label %105
105: ; preds = %99, %102
%106 = add nsw i64 %85, 1
%107 = trunc i64 %106 to i32
%108 = icmp eq i32 %77, %107
br i1 %108, label %109, label %84
109: ; preds = %105, %72
%110 = call i32 @putchar(i32 10)
br label %39
111: ; preds = %20
%112 = getelementptr inbounds i8, i8* %17, i64 1
store i8* %112, i8** %5
%113 = load i8, i8* %112
%114 = icmp eq i8 %113, 0
br i1 %114, label %39, label %115
115: ; preds = %111
%116 = call i32 @gethex(i8** %5)
%117 = call i32 @gethexorstr(i8** %5, i8* %7)
%118 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0), i32 %116, i32 %117)
%119 = sext i32 %116 to i64
%120 = getelementptr inbounds i8, i8* %0, i64 %119
%121 = call i32 @memcpy(i8* %120, i8* %7, i32 %117)
br label %39
122: ; preds = %20
%123 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @str.16, i64 0, i64 0))
%124 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([72 x i8], [72 x i8]* @str.17, i64 0, i64 0))
%125 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @str.18, i64 0, i64 0))
%126 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([66 x i8], [66 x i8]* @str.19, i64 0, i64 0))
%127 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @str.20, i64 0, i64 0))
%128 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.21, i64 0, i64 0))
%129 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.22, i64 0, i64 0))
%130 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([74 x i8], [74 x i8]* @str.23, i64 0, i64 0))
br label %39
131: ; preds = %20
%132 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str.25, i64 0, i64 0))
br label %39
133: ; preds = %20, %59, %61
%134 = phi i32 [ 0, %61 ], [ %11, %59 ], [ 0, %20 ]
ret i32 %134
}