#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*/ dprintf(char *, ...);
int dreadline(char *, int);
int parsenum(char **);
void debugmon(void) {
  dprintf("Entering crappy crash monitor.\n ? for help.\n");
  while (1) {
    char cmd[128];
    char *p = cmd + 1;
    int len;
    dprintf("#> ");
    len = dreadline(cmd, 128);
    switch (cmd[0]) {
    case '?':
      dprintf("?\t\thelp\n"
              "m addr len\tShow memory as words from addr for len words\n");
      break;
    case 'm': {
      unsigned int *addr;
      int mlen;
      int i;
      addr = (unsigned int *)parsenum(&p);
      mlen = parsenum(&p);
      for (i = 0; i < mlen; i++) {
        if ((i & 7) == 0)
          dprintf("\n0x%08x:", addr);
        dprintf(" 0x%08x", *addr);
        addr++;
      }
      dprintf("\n");
      break;
    }
    default:
      dprintf("%s: Unknown command or arguments\n", cmd);
      break;
    }
  }
}


x86 assembly (clang, -O0):
<debugmon>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
lea    0xebe(%rip),%rdi
mov    $0x0,%al
call   1030 <dprintf@plt>
lea    -0x7f(%rbp),%rax
mov    %rax,-0x88(%rbp)
lea    0xed2(%rip),%rdi
xor    %eax,%eax
call   1030 <dprintf@plt>
lea    -0x80(%rbp),%rdi
mov    $0x80,%esi
call   1050 <dreadline@plt>
mov    %eax,-0x8c(%rbp)
movsbl -0x80(%rbp),%eax
mov    %eax,-0xa4(%rbp)
sub    $0x3f,%eax
je     11a2 <debugmon+0x72>
jmp    118e <debugmon+0x5e>
mov    -0xa4(%rbp),%eax
sub    $0x6d,%eax
je     11b5 <debugmon+0x85>
jmp    126f <debugmon+0x13f>
lea    0xe88(%rip),%rdi
mov    $0x0,%al
call   1030 <dprintf@plt>
jmp    1281 <debugmon+0x151>
lea    -0x88(%rbp),%rdi
call   1040 <parsenum@plt>
cltq
mov    %rax,-0x98(%rbp)
lea    -0x88(%rbp),%rdi
call   1040 <parsenum@plt>
mov    %eax,-0x9c(%rbp)
movl   $0x0,-0xa0(%rbp)
mov    -0xa0(%rbp),%eax
cmp    -0x9c(%rbp),%eax
jge    125c <debugmon+0x12c>
mov    -0xa0(%rbp),%eax
and    $0x7,%eax
cmp    $0x0,%eax
jne    121f <debugmon+0xef>
mov    -0x98(%rbp),%rsi
lea    0xe5a(%rip),%rdi
mov    $0x0,%al
call   1030 <dprintf@plt>
mov    -0x98(%rbp),%rax
mov    (%rax),%esi
lea    0xe4c(%rip),%rdi
mov    $0x0,%al
call   1030 <dprintf@plt>
mov    -0x98(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x98(%rbp)
mov    -0xa0(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xa0(%rbp)
jmp    11e6 <debugmon+0xb6>
lea    0xdc8(%rip),%rdi
mov    $0x0,%al
call   1030 <dprintf@plt>
jmp    1281 <debugmon+0x151>
lea    -0x80(%rbp),%rsi
lea    0xe09(%rip),%rdi
mov    $0x0,%al
call   1030 <dprintf@plt>
jmp    1149 <debugmon+0x19>

x86 assembly (clang, -O2):
<debugmon>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x98,%rsp
lea    0xeb8(%rip),%rdi
xor    %eax,%eax
call   1030 <dprintf@plt>
lea    0x11(%rsp),%r12
lea    0xed2(%rip),%r14
lea    0x10(%rsp),%rbp
lea    0xf0b(%rip),%r13
lea    0xf0d(%rip),%rbx
jmp    118a <debugmon+0x5a>
lea    0xeb4(%rip),%rdi
xor    %eax,%eax
call   1030 <dprintf@plt>
lea    0xea8(%rip),%r14
lea    0x10(%rsp),%rbp
mov    %r12,0x8(%rsp)
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <dprintf@plt>
mov    %rbp,%rdi
mov    $0x80,%esi
call   1050 <dreadline@plt>
movsbl 0x10(%rsp),%eax
cmp    $0x6d,%eax
je     11d0 <debugmon+0xa0>
cmp    $0x3f,%eax
jne    1240 <debugmon+0x110>
lea    0xe71(%rip),%rdi
xor    %eax,%eax
call   1030 <dprintf@plt>
jmp    118a <debugmon+0x5a>
nopl   0x0(%rax)
lea    0x8(%rsp),%rbp
mov    %rbp,%rdi
call   1040 <parsenum@plt>
mov    %eax,%r14d
mov    %rbp,%rdi
call   1040 <parsenum@plt>
test   %eax,%eax
jle    1170 <debugmon+0x40>
movslq %r14d,%rbp
mov    %eax,%r15d
xor    %r14d,%r14d
jmp    121e <debugmon+0xee>
nopw   0x0(%rax,%rax,1)
mov    0x0(%rbp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <dprintf@plt>
add    $0x4,%rbp
add    $0x1,%r14
cmp    %r14d,%r15d
je     1170 <debugmon+0x40>
test   $0x7,%r14b
jne    1200 <debugmon+0xd0>
mov    %r13,%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1030 <dprintf@plt>
jmp    1200 <debugmon+0xd0>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
lea    0xe3c(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1030 <dprintf@plt>
jmp    118a <debugmon+0x5a>

LLVM IR (-O0):
@.str = [45 x i8] c"Entering crappy crash monitor.\0A ? for help.\0A\00"
@.str.1 = [4 x i8] c"#> \00"
@.str.2 = [65 x i8] c"?\09\09help\0Am addr len\09Show memory as words from addr for len words\0A\00"
@.str.3 = [9 x i8] c"\0A0x%08x:\00"
@.str.4 = [8 x i8] c" 0x%08x\00"
@.str.5 = [2 x i8] c"\0A\00"
@.str.6 = [34 x i8] c"%s: Unknown command or arguments\0A\00"
define void @debugmon() {
%1 = alloca [128 x i8]
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = call i32 (i8*, ...) @dprintf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0))
br label %8
8: ; preds = %0, %49
%9 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 0
%10 = getelementptr inbounds i8, i8* %9, i64 1
store i8* %10, i8** %2
%11 = call i32 (i8*, ...) @dprintf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%12 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 0
%13 = call i32 @dreadline(i8* %12, i32 128)
store i32 %13, i32* %3
%14 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 0
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
switch i32 %16, label %46 [
i32 63, label %17
i32 109, label %19
]
17: ; preds = %8
%18 = call i32 (i8*, ...) @dprintf(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.2, i64 0, i64 0))
br label %49
19: ; preds = %8
%20 = call i32 @parsenum(i8** %2)
%21 = sext i32 %20 to i64
%22 = inttoptr i64 %21 to i32*
store i32* %22, i32** %4
%23 = call i32 @parsenum(i8** %2)
store i32 %23, i32* %5
store i32 0, i32* %6
br label %24
24: ; preds = %41, %19
%25 = load i32, i32* %6
%26 = load i32, i32* %5
%27 = icmp slt i32 %25, %26
br i1 %27, label %28, label %44
28: ; preds = %24
%29 = load i32, i32* %6
%30 = and i32 %29, 7
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %28
%33 = load i32*, i32** %4
%34 = call i32 (i8*, ...) @dprintf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32* %33)
br label %35
35: ; preds = %32, %28
%36 = load i32*, i32** %4
%37 = load i32, i32* %36
%38 = call i32 (i8*, ...) @dprintf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i32 %37)
%39 = load i32*, i32** %4
%40 = getelementptr inbounds i32, i32* %39, i32 1
store i32* %40, i32** %4
br label %41
41: ; preds = %35
%42 = load i32, i32* %6
%43 = add nsw i32 %42, 1
store i32 %43, i32* %6
br label %24
44: ; preds = %24
%45 = call i32 (i8*, ...) @dprintf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
br label %49
46: ; preds = %8
%47 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 0
%48 = call i32 (i8*, ...) @dprintf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.6, i64 0, i64 0), i8* %47)
br label %49
49: ; preds = %46, %44, %17
br label %8
}

LLVM IR (-O2):
@.str = [45 x i8] c"Entering crappy crash monitor.\0A ? for help.\0A\00"
@.str.1 = [4 x i8] c"#> \00"
@.str.2 = [65 x i8] c"?\09\09help\0Am addr len\09Show memory as words from addr for len words\0A\00"
@.str.3 = [9 x i8] c"\0A0x%08x:\00"
@.str.4 = [8 x i8] c" 0x%08x\00"
@.str.5 = [2 x i8] c"\0A\00"
@.str.6 = [34 x i8] c"%s: Unknown command or arguments\0A\00"
define void @debugmon() {
%1 = alloca [128 x i8]
%2 = alloca i8*
%3 = tail call i32 (i8*, ...) @dprintf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0))
%4 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 0
%5 = bitcast i8** %2 to i8*
%6 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 1
br label %7
7: ; preds = %0, %38
store i8* %6, i8** %2
%8 = call i32 (i8*, ...) @dprintf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%9 = call i32 @dreadline(i8* %4, i32 128)
%10 = load i8, i8* %4
%11 = sext i8 %10 to i32
switch i32 %11, label %36 [
i32 63, label %12
i32 109, label %14
]
12: ; preds = %7
%13 = call i32 (i8*, ...) @dprintf(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.2, i64 0, i64 0))
br label %38
14: ; preds = %7
%15 = call i32 @parsenum(i8** %2)
%16 = call i32 @parsenum(i8** %2)
%17 = icmp sgt i32 %16, 0
br i1 %17, label %18, label %34
18: ; preds = %14
%19 = sext i32 %15 to i64
%20 = inttoptr i64 %19 to i32*
br label %21
21: ; preds = %18, %28
%22 = phi i32 [ %32, %28 ], [ 0, %18 ]
%23 = phi i32* [ %31, %28 ], [ %20, %18 ]
%24 = and i32 %22, 7
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %21
%27 = call i32 (i8*, ...) @dprintf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32* %23)
br label %28
28: ; preds = %26, %21
%29 = load i32, i32* %23
%30 = call i32 (i8*, ...) @dprintf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i32 %29)
%31 = getelementptr inbounds i32, i32* %23, i64 1
%32 = add nuw nsw i32 %22, 1
%33 = icmp eq i32 %32, %16
br i1 %33, label %34, label %21
34: ; preds = %28, %14
%35 = call i32 (i8*, ...) @dprintf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
br label %38
36: ; preds = %7
%37 = call i32 (i8*, ...) @dprintf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.6, i64 0, i64 0), i8* %4)
br label %38
38: ; preds = %36, %34, %12
br label %7
}