#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 */
#define KEY_DOWN 131
#define KEY_NPAGE 130
#define KEY_PPAGE 129
#define KEY_UP 128
int /*<<< orphan*/ addch(char);
int /*<<< orphan*/ get_command_argument(char *);
int hexstring_to_int(char *);
int /*<<< orphan*/ put_command_prompt(char);
int search_hex_pattern(char *, int /*<<< orphan*/, char const *, int);
int search_text_pattern(char *, int /*<<< orphan*/, char const *, int);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int proc_dumpinput(int ch, int address, int screen_size, const char *file) {
  char input[(128)];
  static int last_search_key;
  static int last_address;
  static char last_input[(128)];
  int offset, getinput;
  if (ch == ' ') {
    ch = last_search_key;
    getinput = 0;
    strcpy(input, last_input);
  } else {
    getinput = 1;
  }
  offset = last_address;
  switch (ch) {
    addch(':');
  case KEY_UP:
    address -= (32);
    if (address < 0)
      address = 0;
    break;
  case KEY_DOWN:
    address += (32);
    break;
  case KEY_NPAGE:
    address += screen_size;
    break;
  case KEY_PPAGE:
    address -= screen_size;
    if (address < 0)
      address = 0;
    break;
  case ':':
    put_command_prompt(':');
    get_command_argument(input);
    address = 0xFFFFFFF0 & hexstring_to_int(input);
    break;
  case '/':
    if (getinput) {
      put_command_prompt('/');
      get_command_argument(input);
    }
    address = search_text_pattern(input, 0, file, offset);
    last_search_key = '/';
    strcpy(last_input, input);
    break;
  case '?':
    if (getinput) {
      put_command_prompt('?');
      get_command_argument(input);
    }
    address = search_hex_pattern(input, 0, file, offset);
    last_search_key = '?';
    strcpy(last_input, input);
    break;
  default:
    break;
  }
  last_address = address + strlen(input);
  return address;
}


x86 assembly (clang, -O0):
<proc_dumpinput>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %rcx,-0x18(%rbp)
cmpl   $0x20,-0x4(%rbp)
jne    11bd <proc_dumpinput+0x4d>
mov    0x2ed8(%rip),%eax
mov    %eax,-0x4(%rbp)
movl   $0x0,-0xa8(%rbp)
lea    -0xa0(%rbp),%rdi
lea    0x2ecd(%rip),%rsi
call   1030 <strcpy@plt>
jmp    11c7 <proc_dumpinput+0x57>
movl   $0x1,-0xa8(%rbp)
mov    0x2ea7(%rip),%eax
mov    %eax,-0xa4(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0xac(%rbp)
sub    $0x2f,%eax
je     12f5 <proc_dumpinput+0x185>
jmp    11ea <proc_dumpinput+0x7a>
mov    -0xac(%rbp),%eax
sub    $0x3a,%eax
je     12c6 <proc_dumpinput+0x156>
jmp    11fe <proc_dumpinput+0x8e>
mov    -0xac(%rbp),%eax
sub    $0x3f,%eax
je     1355 <proc_dumpinput+0x1e5>
jmp    1212 <proc_dumpinput+0xa2>
mov    -0xac(%rbp),%eax
sub    $0x80,%eax
je     126a <proc_dumpinput+0xfa>
jmp    1228 <proc_dumpinput+0xb8>
mov    -0xac(%rbp),%eax
sub    $0x81,%eax
je     12a5 <proc_dumpinput+0x135>
jmp    123e <proc_dumpinput+0xce>
mov    -0xac(%rbp),%eax
sub    $0x82,%eax
je     1297 <proc_dumpinput+0x127>
jmp    1254 <proc_dumpinput+0xe4>
mov    -0xac(%rbp),%eax
sub    $0x83,%eax
je     1289 <proc_dumpinput+0x119>
jmp    13b5 <proc_dumpinput+0x245>
mov    -0x8(%rbp),%eax
sub    $0x20,%eax
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    1284 <proc_dumpinput+0x114>
movl   $0x0,-0x8(%rbp)
jmp    13ba <proc_dumpinput+0x24a>
mov    -0x8(%rbp),%eax
add    $0x20,%eax
mov    %eax,-0x8(%rbp)
jmp    13ba <proc_dumpinput+0x24a>
mov    -0xc(%rbp),%eax
add    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
jmp    13ba <proc_dumpinput+0x24a>
mov    -0xc(%rbp),%ecx
mov    -0x8(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    12c1 <proc_dumpinput+0x151>
movl   $0x0,-0x8(%rbp)
jmp    13ba <proc_dumpinput+0x24a>
mov    $0x3a,%edi
call   1090 <put_command_prompt@plt>
lea    -0xa0(%rbp),%rdi
call   1080 <get_command_argument@plt>
lea    -0xa0(%rbp),%rdi
call   1040 <hexstring_to_int@plt>
and    $0xfffffff0,%eax
mov    %eax,-0x8(%rbp)
jmp    13ba <proc_dumpinput+0x24a>
cmpl   $0x0,-0xa8(%rbp)
je     1318 <proc_dumpinput+0x1a8>
mov    $0x2f,%edi
call   1090 <put_command_prompt@plt>
lea    -0xa0(%rbp),%rdi
call   1080 <get_command_argument@plt>
lea    -0xa0(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0xa4(%rbp),%ecx
xor    %esi,%esi
call   1060 <search_text_pattern@plt>
mov    %eax,-0x8(%rbp)
movl   $0x2f,0x2d33(%rip)
lea    -0xa0(%rbp),%rsi
lea    0x2d35(%rip),%rdi
call   1030 <strcpy@plt>
jmp    13ba <proc_dumpinput+0x24a>
cmpl   $0x0,-0xa8(%rbp)
je     1378 <proc_dumpinput+0x208>
mov    $0x3f,%edi
call   1090 <put_command_prompt@plt>
lea    -0xa0(%rbp),%rdi
call   1080 <get_command_argument@plt>
lea    -0xa0(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0xa4(%rbp),%ecx
xor    %esi,%esi
call   1050 <search_hex_pattern@plt>
mov    %eax,-0x8(%rbp)
movl   $0x3f,0x2cd3(%rip)
lea    -0xa0(%rbp),%rsi
lea    0x2cd5(%rip),%rdi
call   1030 <strcpy@plt>
jmp    13ba <proc_dumpinput+0x24a>
jmp    13ba <proc_dumpinput+0x24a>
mov    -0x8(%rbp),%eax
mov    %eax,-0xb0(%rbp)
lea    -0xa0(%rbp),%rdi
call   1070 <strlen@plt>
mov    %eax,%ecx
mov    -0xb0(%rbp),%eax
add    %ecx,%eax
mov    %eax,0x2c95(%rip)
mov    -0x8(%rbp),%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<proc_dumpinput>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x80,%rsp
mov    %rcx,%r14
mov    %edx,%r15d
mov    %esi,%r12d
mov    %edi,%ebp
mov    %edi,%ebx
cmp    $0x20,%edi
jne    11a6 <proc_dumpinput+0x36>
mov    0x2ed9(%rip),%ebx
lea    0x2ee2(%rip),%rsi
mov    %rsp,%rdi
call   1030 <strcpy@plt>
cmp    $0x7f,%ebx
jle    11df <proc_dumpinput+0x6f>
add    $0xffffff80,%ebx
cmp    $0x3,%ebx
ja     12b8 <proc_dumpinput+0x148>
lea    0xe42(%rip),%rax
movslq (%rax,%rbx,4),%rcx
add    %rax,%rcx
jmp    *%rcx
cmp    $0x21,%r12d
mov    $0x20,%eax
cmovge %r12d,%eax
add    $0xffffffe0,%eax
mov    %eax,%r12d
jmp    12b8 <proc_dumpinput+0x148>
mov    0x2e8e(%rip),%r15d
cmp    $0x2f,%ebx
je     124c <proc_dumpinput+0xdc>
cmp    $0x3a,%ebx
je     1294 <proc_dumpinput+0x124>
cmp    $0x3f,%ebx
jne    12b8 <proc_dumpinput+0x148>
cmp    $0x20,%ebp
je     1214 <proc_dumpinput+0xa4>
mov    $0x3f,%edi
call   1090 <put_command_prompt@plt>
mov    %rsp,%rdi
call   1080 <get_command_argument@plt>
mov    %rsp,%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    %r14,%rdx
mov    %r15d,%ecx
call   1050 <search_hex_pattern@plt>
mov    %eax,%r12d
movl   $0x3f,0x2e3c(%rip)
jmp    1283 <proc_dumpinput+0x113>
xor    %eax,%eax
sub    %r15d,%r12d
cmovs  %eax,%r12d
jmp    12b8 <proc_dumpinput+0x148>
add    %r15d,%r12d
jmp    12b8 <proc_dumpinput+0x148>
add    $0x20,%r12d
jmp    12b8 <proc_dumpinput+0x148>
cmp    $0x20,%ebp
je     1263 <proc_dumpinput+0xf3>
mov    $0x2f,%edi
call   1090 <put_command_prompt@plt>
mov    %rsp,%rdi
call   1080 <get_command_argument@plt>
mov    %rsp,%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    %r14,%rdx
mov    %r15d,%ecx
call   1060 <search_text_pattern@plt>
mov    %eax,%r12d
movl   $0x2f,0x2ded(%rip)
lea    0x2df6(%rip),%rdi
mov    %rbp,%rsi
call   1030 <strcpy@plt>
jmp    12b8 <proc_dumpinput+0x148>
mov    $0x3a,%edi
call   1090 <put_command_prompt@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1080 <get_command_argument@plt>
mov    %rbx,%rdi
call   1040 <hexstring_to_int@plt>
mov    %eax,%r12d
and    $0xfffffff0,%r12d
mov    %rsp,%rdi
call   1070 <strlen@plt>
add    %r12d,%eax
mov    %eax,0x2dab(%rip)
mov    %r12d,%eax
add    $0x80,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@proc_dumpinput.last_search_key = internal global i32 0
@proc_dumpinput.last_address = internal global i32 0
@proc_dumpinput.last_input = internal global [128 x i8] zeroinitializer
define i32 @proc_dumpinput(i32 %0, i32 %1, i32 %2, i8* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca [128 x i8]
%10 = alloca i32
%11 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i8* %3, i8** %8
%12 = load i32, i32* %5
%13 = icmp eq i32 %12, 32
br i1 %13, label %14, label %18
14: ; preds = %4
%15 = load i32, i32* @proc_dumpinput.last_search_key
store i32 %15, i32* %5
store i32 0, i32* %11
%16 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
%17 = call i32 @strcpy(i8* %16, i8* getelementptr inbounds ([128 x i8], [128 x i8]* @proc_dumpinput.last_input, i64 0, i64 0))
br label %19
18: ; preds = %4
store i32 1, i32* %11
br label %19
19: ; preds = %18, %14
%20 = load i32, i32* @proc_dumpinput.last_address
store i32 %20, i32* %10
%21 = load i32, i32* %5
switch i32 %21, label %79 [
i32 128, label %22
i32 131, label %29
i32 130, label %32
i32 129, label %36
i32 58, label %44
i32 47, label %51
i32 63, label %65
]
22: ; preds = %19
%23 = load i32, i32* %6
%24 = sub nsw i32 %23, 32
store i32 %24, i32* %6
%25 = load i32, i32* %6
%26 = icmp slt i32 %25, 0
br i1 %26, label %27, label %28
27: ; preds = %22
store i32 0, i32* %6
br label %28
28: ; preds = %27, %22
br label %80
29: ; preds = %19
%30 = load i32, i32* %6
%31 = add nsw i32 %30, 32
store i32 %31, i32* %6
br label %80
32: ; preds = %19
%33 = load i32, i32* %7
%34 = load i32, i32* %6
%35 = add nsw i32 %34, %33
store i32 %35, i32* %6
br label %80
36: ; preds = %19
%37 = load i32, i32* %7
%38 = load i32, i32* %6
%39 = sub nsw i32 %38, %37
store i32 %39, i32* %6
%40 = load i32, i32* %6
%41 = icmp slt i32 %40, 0
br i1 %41, label %42, label %43
42: ; preds = %36
store i32 0, i32* %6
br label %43
43: ; preds = %42, %36
br label %80
44: ; preds = %19
%45 = call i32 @put_command_prompt(i8 signext 58)
%46 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
%47 = call i32 @get_command_argument(i8* %46)
%48 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
%49 = call i32 @hexstring_to_int(i8* %48)
%50 = and i32 -16, %49
store i32 %50, i32* %6
br label %80
51: ; preds = %19
%52 = load i32, i32* %11
%53 = icmp ne i32 %52, 0
br i1 %53, label %54, label %58
54: ; preds = %51
%55 = call i32 @put_command_prompt(i8 signext 47)
%56 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
%57 = call i32 @get_command_argument(i8* %56)
br label %58
58: ; preds = %54, %51
%59 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
%60 = load i8*, i8** %8
%61 = load i32, i32* %10
%62 = call i32 @search_text_pattern(i8* %59, i32 0, i8* %60, i32 %61)
store i32 %62, i32* %6
store i32 47, i32* @proc_dumpinput.last_search_key
%63 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
%64 = call i32 @strcpy(i8* getelementptr inbounds ([128 x i8], [128 x i8]* @proc_dumpinput.last_input, i64 0, i64 0), i8* %63)
br label %80
65: ; preds = %19
%66 = load i32, i32* %11
%67 = icmp ne i32 %66, 0
br i1 %67, label %68, label %72
68: ; preds = %65
%69 = call i32 @put_command_prompt(i8 signext 63)
%70 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
%71 = call i32 @get_command_argument(i8* %70)
br label %72
72: ; preds = %68, %65
%73 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
%74 = load i8*, i8** %8
%75 = load i32, i32* %10
%76 = call i32 @search_hex_pattern(i8* %73, i32 0, i8* %74, i32 %75)
store i32 %76, i32* %6
store i32 63, i32* @proc_dumpinput.last_search_key
%77 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
%78 = call i32 @strcpy(i8* getelementptr inbounds ([128 x i8], [128 x i8]* @proc_dumpinput.last_input, i64 0, i64 0), i8* %77)
br label %80
79: ; preds = %19
br label %80
80: ; preds = %79, %72, %58, %44, %43, %32, %29, %28
%81 = load i32, i32* %6
%82 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
%83 = call i32 @strlen(i8* %82)
%84 = add nsw i32 %81, %83
store i32 %84, i32* @proc_dumpinput.last_address
%85 = load i32, i32* %6
ret i32 %85
}

LLVM IR (-O2):
@proc_dumpinput.last_search_key = internal unnamed_addr global i32 0
@proc_dumpinput.last_address = internal unnamed_addr global i32 0
@proc_dumpinput.last_input = internal global [128 x i8] zeroinitializer
define i32 @proc_dumpinput(i32 %0, i32 %1, i32 %2, i8* %3) {
%5 = alloca [128 x i8]
%6 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%7 = icmp eq i32 %0, 32
br i1 %7, label %8, label %11
8: ; preds = %4
%9 = load i32, i32* @proc_dumpinput.last_search_key
%10 = call i32 @strcpy(i8* %6, i8* getelementptr inbounds ([128 x i8], [128 x i8]* @proc_dumpinput.last_input, i64 0, i64 0))
br label %11
11: ; preds = %4, %8
%12 = phi i32 [ %9, %8 ], [ %0, %4 ]
%13 = load i32, i32* @proc_dumpinput.last_address
switch i32 %12, label %45 [
i32 128, label %14
i32 131, label %18
i32 130, label %20
i32 129, label %22
i32 58, label %26
i32 47, label %31
i32 63, label %38
]
14: ; preds = %11
%15 = icmp sgt i32 %1, 32
%16 = select i1 %15, i32 %1, i32 32
%17 = add nsw i32 %16, -32
br label %45
18: ; preds = %11
%19 = add nsw i32 %1, 32
br label %45
20: ; preds = %11
%21 = add nsw i32 %2, %1
br label %45
22: ; preds = %11
%23 = sub nsw i32 %1, %2
%24 = icmp sgt i32 %23, 0
%25 = select i1 %24, i32 %23, i32 0
br label %45
26: ; preds = %11
%27 = call i32 @put_command_prompt(i8 signext 58)
%28 = call i32 @get_command_argument(i8* %6)
%29 = call i32 @hexstring_to_int(i8* %6)
%30 = and i32 %29, -16
br label %45
31: ; preds = %11
br i1 %7, label %35, label %32
32: ; preds = %31
%33 = call i32 @put_command_prompt(i8 signext 47)
%34 = call i32 @get_command_argument(i8* %6)
br label %35
35: ; preds = %32, %31
%36 = call i32 @search_text_pattern(i8* %6, i32 0, i8* %3, i32 %13)
store i32 47, i32* @proc_dumpinput.last_search_key
%37 = call i32 @strcpy(i8* getelementptr inbounds ([128 x i8], [128 x i8]* @proc_dumpinput.last_input, i64 0, i64 0), i8* %6)
br label %45
38: ; preds = %11
br i1 %7, label %42, label %39
39: ; preds = %38
%40 = call i32 @put_command_prompt(i8 signext 63)
%41 = call i32 @get_command_argument(i8* %6)
br label %42
42: ; preds = %39, %38
%43 = call i32 @search_hex_pattern(i8* %6, i32 0, i8* %3, i32 %13)
store i32 63, i32* @proc_dumpinput.last_search_key
%44 = call i32 @strcpy(i8* getelementptr inbounds ([128 x i8], [128 x i8]* @proc_dumpinput.last_input, i64 0, i64 0), i8* %6)
br label %45
45: ; preds = %11, %42, %35, %26, %22, %20, %18, %14
%46 = phi i32 [ %1, %11 ], [ %43, %42 ], [ %36, %35 ], [ %30, %26 ], [ %25, %22 ], [ %21, %20 ], [ %19, %18 ], [ %17, %14 ]
%47 = call i32 @strlen(i8* %6)
%48 = add nsw i32 %47, %46
store i32 %48, i32* @proc_dumpinput.last_address
ret i32 %46
}