#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 */
struct gdb_data {
  int dummy;
};

/* Variables and functions */
int gdb_send(struct gdb_data *, char *);
int monitor_command(struct gdb_data *, char *);
int read_memory(struct gdb_data *, char *);
int read_registers(struct gdb_data *);
int run(struct gdb_data *, char *);
int set_breakpoint(struct gdb_data *, int, char *);
int single_step(struct gdb_data *, char *);
int /*<<< orphan*/ strncmp(char *, char *, int);
int write_memory(struct gdb_data *, char *);
int write_registers(struct gdb_data *, char *);
int process_gdb_command(struct gdb_data *data, char *buf, int len) {
  switch (buf[0]) {
  case '?':
    return gdb_send(data, "T00");
  case 'z':
  case 'Z':
    return set_breakpoint(data, buf[0] == 'Z', buf + 1);
  case 'g':
    return read_registers(data);
  case 'G':
    return write_registers(data, buf + 1);
  case 'q':
    if (!strncmp(buf, "qRcmd,", 6))
      return monitor_command(data, buf + 6);
    break;
  case 'm':
    return read_memory(data, buf + 1);
  case 'M':
    return write_memory(data, buf + 1);
  case 'c':
    return run(data, buf + 1);
  case 's':
    return single_step(data, buf + 1);
  }
  return gdb_send(data, "");
}


x86 assembly (clang, -O0):
<process_gdb_command>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
add    $0xffffffc1,%eax
mov    %eax,%ecx
mov    %rcx,-0x28(%rbp)
sub    $0x3b,%eax
ja     12ed <process_gdb_command+0x14d>
mov    -0x28(%rbp),%rax
lea    0xe29(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x10(%rbp),%rdi
lea    0xf05(%rip),%rsi
call   10c0 <gdb_send@plt>
mov    %eax,-0x4(%rbp)
jmp    1300 <process_gdb_command+0x160>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5a,%eax
sete   %al
and    $0x1,%al
movzbl %al,%esi
mov    -0x18(%rbp),%rdx
add    $0x1,%rdx
call   1090 <set_breakpoint@plt>
mov    %eax,-0x4(%rbp)
jmp    1300 <process_gdb_command+0x160>
mov    -0x10(%rbp),%rdi
call   1040 <read_registers@plt>
mov    %eax,-0x4(%rbp)
jmp    1300 <process_gdb_command+0x160>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
add    $0x1,%rsi
call   1070 <write_registers@plt>
mov    %eax,-0x4(%rbp)
jmp    1300 <process_gdb_command+0x160>
mov    -0x18(%rbp),%rdi
lea    0xe9c(%rip),%rsi
mov    $0x6,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    1284 <process_gdb_command+0xe4>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
add    $0x6,%rsi
call   10b0 <monitor_command@plt>
mov    %eax,-0x4(%rbp)
jmp    1300 <process_gdb_command+0x160>
jmp    12ed <process_gdb_command+0x14d>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
add    $0x1,%rsi
call   10a0 <read_memory@plt>
mov    %eax,-0x4(%rbp)
jmp    1300 <process_gdb_command+0x160>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
add    $0x1,%rsi
call   1080 <write_memory@plt>
mov    %eax,-0x4(%rbp)
jmp    1300 <process_gdb_command+0x160>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
add    $0x1,%rsi
call   1050 <run@plt>
mov    %eax,-0x4(%rbp)
jmp    1300 <process_gdb_command+0x160>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
add    $0x1,%rsi
call   1060 <single_step@plt>
mov    %eax,-0x4(%rbp)
jmp    1300 <process_gdb_command+0x160>
mov    -0x10(%rbp),%rdi
lea    0xe02(%rip),%rsi
call   10c0 <gdb_send@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<process_gdb_command>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
movsbl (%rsi),%eax
lea    -0x3f(%rax),%ecx
cmp    $0x3b,%ecx
ja     1272 <process_gdb_command+0xd2>
mov    %rsi,%rbx
lea    0xe40(%rip),%rdx
movslq (%rdx,%rcx,4),%rcx
add    %rdx,%rcx
jmp    *%rcx
xor    %esi,%esi
cmp    $0x5a,%al
sete   %sil
add    $0x1,%rbx
mov    %r14,%rdi
mov    %rbx,%rdx
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1090 <set_breakpoint@plt>
lea    0xf02(%rip),%rsi
jmp    1279 <process_gdb_command+0xd9>
add    $0x1,%rbx
mov    %r14,%rdi
mov    %rbx,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1070 <write_registers@plt>
add    $0x1,%rbx
mov    %r14,%rdi
mov    %rbx,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1080 <write_memory@plt>
add    $0x1,%rbx
mov    %r14,%rdi
mov    %rbx,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <run@plt>
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <read_registers@plt>
add    $0x1,%rbx
mov    %r14,%rdi
mov    %rbx,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    10a0 <read_memory@plt>
lea    0xe93(%rip),%rsi
mov    %rbx,%rdi
mov    $0x6,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
je     129e <process_gdb_command+0xfe>
lea    0xe81(%rip),%rsi
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    10c0 <gdb_send@plt>
add    $0x1,%rbx
mov    %r14,%rdi
mov    %rbx,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1060 <single_step@plt>
add    $0x6,%rbx
mov    %r14,%rdi
mov    %rbx,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    10b0 <monitor_command@plt>

LLVM IR (-O0):
%struct.gdb_data = type { i32 }
@.str = [4 x i8] c"T00\00"
@.str.1 = [7 x i8] c"qRcmd,\00"
@.str.2 = [1 x i8] zeroinitializer
define i32 @process_gdb_command(%struct.gdb_data* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca %struct.gdb_data*
%6 = alloca i8*
%7 = alloca i32
store %struct.gdb_data* %0, %struct.gdb_data** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%8 = load i8*, i8** %6
%9 = getelementptr inbounds i8, i8* %8, i64 0
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
switch i32 %11, label %64 [
i32 63, label %12
i32 122, label %15
i32 90, label %15
i32 103, label %26
i32 71, label %29
i32 113, label %34
i32 109, label %44
i32 77, label %49
i32 99, label %54
i32 115, label %59
]
12: ; preds = %3
%13 = load %struct.gdb_data*, %struct.gdb_data** %5
%14 = call i32 @gdb_send(%struct.gdb_data* %13, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i32 %14, i32* %4
br label %67
15: ; preds = %3, %3
%16 = load %struct.gdb_data*, %struct.gdb_data** %5
%17 = load i8*, i8** %6
%18 = getelementptr inbounds i8, i8* %17, i64 0
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp eq i32 %20, 90
%22 = zext i1 %21 to i32
%23 = load i8*, i8** %6
%24 = getelementptr inbounds i8, i8* %23, i64 1
%25 = call i32 @set_breakpoint(%struct.gdb_data* %16, i32 %22, i8* %24)
store i32 %25, i32* %4
br label %67
26: ; preds = %3
%27 = load %struct.gdb_data*, %struct.gdb_data** %5
%28 = call i32 @read_registers(%struct.gdb_data* %27)
store i32 %28, i32* %4
br label %67
29: ; preds = %3
%30 = load %struct.gdb_data*, %struct.gdb_data** %5
%31 = load i8*, i8** %6
%32 = getelementptr inbounds i8, i8* %31, i64 1
%33 = call i32 @write_registers(%struct.gdb_data* %30, i8* %32)
store i32 %33, i32* %4
br label %67
34: ; preds = %3
%35 = load i8*, i8** %6
%36 = call i32 @strncmp(i8* %35, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 6)
%37 = icmp ne i32 %36, 0
br i1 %37, label %43, label %38
38: ; preds = %34
%39 = load %struct.gdb_data*, %struct.gdb_data** %5
%40 = load i8*, i8** %6
%41 = getelementptr inbounds i8, i8* %40, i64 6
%42 = call i32 @monitor_command(%struct.gdb_data* %39, i8* %41)
store i32 %42, i32* %4
br label %67
43: ; preds = %34
br label %64
44: ; preds = %3
%45 = load %struct.gdb_data*, %struct.gdb_data** %5
%46 = load i8*, i8** %6
%47 = getelementptr inbounds i8, i8* %46, i64 1
%48 = call i32 @read_memory(%struct.gdb_data* %45, i8* %47)
store i32 %48, i32* %4
br label %67
49: ; preds = %3
%50 = load %struct.gdb_data*, %struct.gdb_data** %5
%51 = load i8*, i8** %6
%52 = getelementptr inbounds i8, i8* %51, i64 1
%53 = call i32 @write_memory(%struct.gdb_data* %50, i8* %52)
store i32 %53, i32* %4
br label %67
54: ; preds = %3
%55 = load %struct.gdb_data*, %struct.gdb_data** %5
%56 = load i8*, i8** %6
%57 = getelementptr inbounds i8, i8* %56, i64 1
%58 = call i32 @run(%struct.gdb_data* %55, i8* %57)
store i32 %58, i32* %4
br label %67
59: ; preds = %3
%60 = load %struct.gdb_data*, %struct.gdb_data** %5
%61 = load i8*, i8** %6
%62 = getelementptr inbounds i8, i8* %61, i64 1
%63 = call i32 @single_step(%struct.gdb_data* %60, i8* %62)
store i32 %63, i32* %4
br label %67
64: ; preds = %3, %43
%65 = load %struct.gdb_data*, %struct.gdb_data** %5
%66 = call i32 @gdb_send(%struct.gdb_data* %65, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0))
store i32 %66, i32* %4
br label %67
67: ; preds = %64, %59, %54, %49, %44, %38, %29, %26, %15, %12
%68 = load i32, i32* %4
ret i32 %68
}

LLVM IR (-O2):
%struct.gdb_data = type { i32 }
@.str = [4 x i8] c"T00\00"
@.str.1 = [7 x i8] c"qRcmd,\00"
@.str.2 = [1 x i8] zeroinitializer
define i32 @process_gdb_command(%struct.gdb_data* %0, i8* %1, i32 %2) {
%4 = load i8, i8* %1
%5 = sext i8 %4 to i32
switch i32 %5, label %36 [
i32 63, label %6
i32 122, label %8
i32 90, label %8
i32 103, label %13
i32 71, label %15
i32 113, label %18
i32 109, label %24
i32 77, label %27
i32 99, label %30
i32 115, label %33
]
6: ; preds = %3
%7 = tail call i32 @gdb_send(%struct.gdb_data* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
br label %38
8: ; preds = %3, %3
%9 = icmp eq i8 %4, 90
%10 = zext i1 %9 to i32
%11 = getelementptr inbounds i8, i8* %1, i64 1
%12 = tail call i32 @set_breakpoint(%struct.gdb_data* %0, i32 %10, i8* %11)
br label %38
13: ; preds = %3
%14 = tail call i32 @read_registers(%struct.gdb_data* %0)
br label %38
15: ; preds = %3
%16 = getelementptr inbounds i8, i8* %1, i64 1
%17 = tail call i32 @write_registers(%struct.gdb_data* %0, i8* %16)
br label %38
18: ; preds = %3
%19 = tail call i32 @strncmp(i8* %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 6)
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %36
21: ; preds = %18
%22 = getelementptr inbounds i8, i8* %1, i64 6
%23 = tail call i32 @monitor_command(%struct.gdb_data* %0, i8* %22)
br label %38
24: ; preds = %3
%25 = getelementptr inbounds i8, i8* %1, i64 1
%26 = tail call i32 @read_memory(%struct.gdb_data* %0, i8* %25)
br label %38
27: ; preds = %3
%28 = getelementptr inbounds i8, i8* %1, i64 1
%29 = tail call i32 @write_memory(%struct.gdb_data* %0, i8* %28)
br label %38
30: ; preds = %3
%31 = getelementptr inbounds i8, i8* %1, i64 1
%32 = tail call i32 @run(%struct.gdb_data* %0, i8* %31)
br label %38
33: ; preds = %3
%34 = getelementptr inbounds i8, i8* %1, i64 1
%35 = tail call i32 @single_step(%struct.gdb_data* %0, i8* %34)
br label %38
36: ; preds = %18, %3
%37 = tail call i32 @gdb_send(%struct.gdb_data* %0, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0))
br label %38
38: ; preds = %36, %33, %30, %27, %24, %21, %15, %13, %8, %6
%39 = phi i32 [ %37, %36 ], [ %35, %33 ], [ %32, %30 ], [ %29, %27 ], [ %26, %24 ], [ %23, %21 ], [ %17, %15 ], [ %14, %13 ], [ %12, %8 ], [ %7, %6 ]
ret i32 %39
}