#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 */
typedef int uint32_t;

/* Variables and functions */
int dgb_unset_trap(void *, int);
int /*<<< orphan*/ gdb_response_not_supported();
int /*<<< orphan*/ gdb_send_packet(char *, int /*<<< orphan*/);
int util_cpy_substr(char *, char *, char, int const);
int util_hex_to_word(char *);
int /*<<< orphan*/ util_str_len(char *);
void gdb_cmd_delete_breakpoint(char *gdb_in_packet, int packet_len) {
  int len;
  uint32_t addr;
  uint32_t kind;
  uint32_t errval;
  char *err = "E01";
  char *okresp = "OK";
  const int scratch_len = 16;
  char scratchpad[scratch_len];
  if (packet_len < 1) {
    gdb_send_packet(err, util_str_len(err));
    return;
  }
  if (*gdb_in_packet == ',')
    gdb_in_packet++;
  len = util_cpy_substr(scratchpad, (char *)gdb_in_packet, ',', scratch_len);
  gdb_in_packet += len + 1;
  addr = util_hex_to_word(scratchpad);
  kind = util_hex_to_word((char *)gdb_in_packet);
  if (kind == 2) {
    if ((errval = dgb_unset_trap((void *)addr, 2)) != 0) {
      if (errval == 1)
        err = "E01";
      else if (errval == 2)
        err = "E02";
      else if (errval == 3)
        err = "E03";
      else
        err = "E04";
      gdb_send_packet(err, util_str_len(err));
    } else {
      gdb_send_packet(okresp, util_str_len(okresp));
    }
  } else if (kind == 4) {
    if ((errval = dgb_unset_trap((void *)addr, 1)) != 0) {
      if (errval == 1)
        err = "E01";
      else if (errval == 2)
        err = "E02";
      else if (errval == 3)
        err = "E03";
      else
        err = "E04";
      gdb_send_packet(err, util_str_len(err));
    } else {
      gdb_send_packet(okresp, util_str_len(okresp));
    }
  } else {
    gdb_response_not_supported();
  }
}


x86 assembly (clang, -O0):
<gdb_cmd_delete_breakpoint>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    0xe87(%rip),%rax
mov    %rax,-0x28(%rbp)
lea    0xe80(%rip),%rax
mov    %rax,-0x30(%rbp)
movl   $0x10,-0x34(%rbp)
mov    %rsp,%rax
mov    %rax,-0x40(%rbp)
cmpl   $0x1,-0xc(%rbp)
jge    11c8 <gdb_cmd_delete_breakpoint+0x68>
mov    -0x28(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <util_str_len@plt>
mov    -0x68(%rbp),%rdi
mov    %eax,%esi
call   1060 <gdb_send_packet@plt>
movl   $0x1,-0x44(%rbp)
jmp    13d5 <gdb_cmd_delete_breakpoint+0x275>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2c,%eax
jne    11e4 <gdb_cmd_delete_breakpoint+0x84>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rsi
lea    -0x60(%rbp),%rdi
mov    $0x2c,%edx
mov    $0x10,%ecx
call   1050 <util_cpy_substr@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%ecx
add    $0x1,%ecx
mov    -0x8(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
lea    -0x60(%rbp),%rdi
call   1070 <util_hex_to_word@plt>
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <util_hex_to_word@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x2,-0x18(%rbp)
jne    12f3 <gdb_cmd_delete_breakpoint+0x193>
movslq -0x14(%rbp),%rdi
mov    $0x2,%esi
call   1080 <dgb_unset_trap@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
je     12d2 <gdb_cmd_delete_breakpoint+0x172>
cmpl   $0x1,-0x1c(%rbp)
jne    1268 <gdb_cmd_delete_breakpoint+0x108>
lea    0xda1(%rip),%rax
mov    %rax,-0x28(%rbp)
jmp    12b1 <gdb_cmd_delete_breakpoint+0x151>
cmpl   $0x2,-0x1c(%rbp)
jne    1282 <gdb_cmd_delete_breakpoint+0x122>
lea    0xd8e(%rip),%rax
mov    %rax,-0x28(%rbp)
jmp    12ac <gdb_cmd_delete_breakpoint+0x14c>
cmpl   $0x3,-0x1c(%rbp)
jne    129c <gdb_cmd_delete_breakpoint+0x13c>
lea    0xd78(%rip),%rax
mov    %rax,-0x28(%rbp)
jmp    12a7 <gdb_cmd_delete_breakpoint+0x147>
lea    0xd6c(%rip),%rax
mov    %rax,-0x28(%rbp)
jmp    12ac <gdb_cmd_delete_breakpoint+0x14c>
jmp    12b1 <gdb_cmd_delete_breakpoint+0x151>
mov    -0x28(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <util_str_len@plt>
mov    -0x70(%rbp),%rdi
mov    %eax,%esi
call   1060 <gdb_send_packet@plt>
jmp    12ee <gdb_cmd_delete_breakpoint+0x18e>
mov    -0x30(%rbp),%rax
mov    %rax,-0x78(%rbp)
mov    -0x30(%rbp),%rdi
call   1030 <util_str_len@plt>
mov    -0x78(%rbp),%rdi
mov    %eax,%esi
call   1060 <gdb_send_packet@plt>
jmp    13ce <gdb_cmd_delete_breakpoint+0x26e>
cmpl   $0x4,-0x18(%rbp)
jne    13c2 <gdb_cmd_delete_breakpoint+0x262>
movslq -0x14(%rbp),%rdi
mov    $0x1,%esi
call   1080 <dgb_unset_trap@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
je     139b <gdb_cmd_delete_breakpoint+0x23b>
cmpl   $0x1,-0x1c(%rbp)
jne    1331 <gdb_cmd_delete_breakpoint+0x1d1>
lea    0xcd8(%rip),%rax
mov    %rax,-0x28(%rbp)
jmp    137a <gdb_cmd_delete_breakpoint+0x21a>
cmpl   $0x2,-0x1c(%rbp)
jne    134b <gdb_cmd_delete_breakpoint+0x1eb>
lea    0xcc5(%rip),%rax
mov    %rax,-0x28(%rbp)
jmp    1375 <gdb_cmd_delete_breakpoint+0x215>
cmpl   $0x3,-0x1c(%rbp)
jne    1365 <gdb_cmd_delete_breakpoint+0x205>
lea    0xcaf(%rip),%rax
mov    %rax,-0x28(%rbp)
jmp    1370 <gdb_cmd_delete_breakpoint+0x210>
lea    0xca3(%rip),%rax
mov    %rax,-0x28(%rbp)
jmp    1375 <gdb_cmd_delete_breakpoint+0x215>
jmp    137a <gdb_cmd_delete_breakpoint+0x21a>
mov    -0x28(%rbp),%rax
mov    %rax,-0x80(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <util_str_len@plt>
mov    -0x80(%rbp),%rdi
mov    %eax,%esi
call   1060 <gdb_send_packet@plt>
jmp    13bd <gdb_cmd_delete_breakpoint+0x25d>
mov    -0x30(%rbp),%rax
mov    %rax,-0x88(%rbp)
mov    -0x30(%rbp),%rdi
call   1030 <util_str_len@plt>
mov    -0x88(%rbp),%rdi
mov    %eax,%esi
call   1060 <gdb_send_packet@plt>
jmp    13c9 <gdb_cmd_delete_breakpoint+0x269>
mov    $0x0,%al
call   1040 <gdb_response_not_supported@plt>
jmp    13ce <gdb_cmd_delete_breakpoint+0x26e>
movl   $0x0,-0x44(%rbp)
mov    -0x40(%rbp),%rax
mov    %rax,%rsp
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gdb_cmd_delete_breakpoint>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
test   %esi,%esi
jle    11e7 <gdb_cmd_delete_breakpoint+0x87>
xor    %ebx,%ebx
cmpb   $0x2c,(%rdi)
sete   %bl
add    %rdi,%rbx
mov    %rsp,%r14
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x2c,%edx
mov    $0x10,%ecx
call   1050 <util_cpy_substr@plt>
cltq
add    %rax,%rbx
add    $0x1,%rbx
mov    %r14,%rdi
call   1070 <util_hex_to_word@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1070 <util_hex_to_word@plt>
cmp    $0x4,%eax
je     1208 <gdb_cmd_delete_breakpoint+0xa8>
cmp    $0x2,%eax
jne    123c <gdb_cmd_delete_breakpoint+0xdc>
movslq %ebp,%rdi
mov    $0x2,%esi
call   1080 <dgb_unset_trap@plt>
cmp    $0x3,%eax
ja     1257 <gdb_cmd_delete_breakpoint+0xf7>
lea    0xe4b(%rip),%rbx
mov    %eax,%eax
lea    0xe32(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xe32(%rip),%rbx
mov    %rbx,%rdi
call   1030 <util_str_len@plt>
mov    %rbx,%rdi
mov    %eax,%esi
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
jmp    1060 <gdb_send_packet@plt>
movslq %ebp,%rdi
mov    $0x1,%esi
call   1080 <dgb_unset_trap@plt>
cmp    $0x3,%eax
ja     1257 <gdb_cmd_delete_breakpoint+0xf7>
lea    0xdff(%rip),%rbx
mov    %eax,%eax
lea    0xdd6(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xdea(%rip),%rbx
jmp    125e <gdb_cmd_delete_breakpoint+0xfe>
xor    %eax,%eax
call   1040 <gdb_response_not_supported@plt>
jmp    1270 <gdb_cmd_delete_breakpoint+0x110>
lea    0xddb(%rip),%rbx
jmp    125e <gdb_cmd_delete_breakpoint+0xfe>
lea    0xdd6(%rip),%rbx
jmp    125e <gdb_cmd_delete_breakpoint+0xfe>
lea    0xdd1(%rip),%rbx
mov    %rbx,%rdi
call   1030 <util_str_len@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1060 <gdb_send_packet@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"E01\00"
@.str.1 = [3 x i8] c"OK\00"
@.str.2 = [4 x i8] c"E02\00"
@.str.3 = [4 x i8] c"E03\00"
@.str.4 = [4 x i8] c"E04\00"
define void @gdb_cmd_delete_breakpoint(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8** %9
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8** %10
store i32 16, i32* %11
%14 = call i8* @llvm.stacksave()
store i8* %14, i8** %12
%15 = alloca i8, i64 16
%16 = load i32, i32* %4
%17 = icmp slt i32 %16, 1
br i1 %17, label %18, label %23
18: ; preds = %2
%19 = load i8*, i8** %9
%20 = load i8*, i8** %9
%21 = call i32 @util_str_len(i8* %20)
%22 = call i32 @gdb_send_packet(i8* %19, i32 %21)
store i32 1, i32* %13
br label %115
23: ; preds = %2
%24 = load i8*, i8** %3
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp eq i32 %26, 44
br i1 %27, label %28, label %31
28: ; preds = %23
%29 = load i8*, i8** %3
%30 = getelementptr inbounds i8, i8* %29, i32 1
store i8* %30, i8** %3
br label %31
31: ; preds = %28, %23
%32 = load i8*, i8** %3
%33 = call i32 @util_cpy_substr(i8* %15, i8* %32, i8 signext 44, i32 16)
store i32 %33, i32* %5
%34 = load i32, i32* %5
%35 = add nsw i32 %34, 1
%36 = load i8*, i8** %3
%37 = sext i32 %35 to i64
%38 = getelementptr inbounds i8, i8* %36, i64 %37
store i8* %38, i8** %3
%39 = call i32 @util_hex_to_word(i8* %15)
store i32 %39, i32* %6
%40 = load i8*, i8** %3
%41 = call i32 @util_hex_to_word(i8* %40)
store i32 %41, i32* %7
%42 = load i32, i32* %7
%43 = icmp eq i32 %42, 2
br i1 %43, label %44, label %76
44: ; preds = %31
%45 = load i32, i32* %6
%46 = sext i32 %45 to i64
%47 = inttoptr i64 %46 to i8*
%48 = call i32 @dgb_unset_trap(i8* %47, i32 2)
store i32 %48, i32* %8
%49 = icmp ne i32 %48, 0
br i1 %49, label %50, label %70
50: ; preds = %44
%51 = load i32, i32* %8
%52 = icmp eq i32 %51, 1
br i1 %52, label %53, label %54
53: ; preds = %50
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8** %9
br label %65
54: ; preds = %50
%55 = load i32, i32* %8
%56 = icmp eq i32 %55, 2
br i1 %56, label %57, label %58
57: ; preds = %54
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8** %9
br label %64
58: ; preds = %54
%59 = load i32, i32* %8
%60 = icmp eq i32 %59, 3
br i1 %60, label %61, label %62
61: ; preds = %58
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8** %9
br label %63
62: ; preds = %58
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8** %9
br label %63
63: ; preds = %62, %61
br label %64
64: ; preds = %63, %57
br label %65
65: ; preds = %64, %53
%66 = load i8*, i8** %9
%67 = load i8*, i8** %9
%68 = call i32 @util_str_len(i8* %67)
%69 = call i32 @gdb_send_packet(i8* %66, i32 %68)
br label %75
70: ; preds = %44
%71 = load i8*, i8** %10
%72 = load i8*, i8** %10
%73 = call i32 @util_str_len(i8* %72)
%74 = call i32 @gdb_send_packet(i8* %71, i32 %73)
br label %75
75: ; preds = %70, %65
br label %114
76: ; preds = %31
%77 = load i32, i32* %7
%78 = icmp eq i32 %77, 4
br i1 %78, label %79, label %111
79: ; preds = %76
%80 = load i32, i32* %6
%81 = sext i32 %80 to i64
%82 = inttoptr i64 %81 to i8*
%83 = call i32 @dgb_unset_trap(i8* %82, i32 1)
store i32 %83, i32* %8
%84 = icmp ne i32 %83, 0
br i1 %84, label %85, label %105
85: ; preds = %79
%86 = load i32, i32* %8
%87 = icmp eq i32 %86, 1
br i1 %87, label %88, label %89
88: ; preds = %85
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8** %9
br label %100
89: ; preds = %85
%90 = load i32, i32* %8
%91 = icmp eq i32 %90, 2
br i1 %91, label %92, label %93
92: ; preds = %89
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8** %9
br label %99
93: ; preds = %89
%94 = load i32, i32* %8
%95 = icmp eq i32 %94, 3
br i1 %95, label %96, label %97
96: ; preds = %93
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8** %9
br label %98
97: ; preds = %93
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8** %9
br label %98
98: ; preds = %97, %96
br label %99
99: ; preds = %98, %92
br label %100
100: ; preds = %99, %88
%101 = load i8*, i8** %9
%102 = load i8*, i8** %9
%103 = call i32 @util_str_len(i8* %102)
%104 = call i32 @gdb_send_packet(i8* %101, i32 %103)
br label %110
105: ; preds = %79
%106 = load i8*, i8** %10
%107 = load i8*, i8** %10
%108 = call i32 @util_str_len(i8* %107)
%109 = call i32 @gdb_send_packet(i8* %106, i32 %108)
br label %110
110: ; preds = %105, %100
br label %113
111: ; preds = %76
%112 = call i32 (...) @gdb_response_not_supported()
br label %113
113: ; preds = %111, %110
br label %114
114: ; preds = %113, %75
store i32 0, i32* %13
br label %115
115: ; preds = %114, %18
%116 = load i8*, i8** %12
%117 = load i32, i32* %13
switch i32 %117, label %119 [
i32 0, label %118
i32 1, label %118
]
118: ; preds = %115, %115
ret void
119: ; preds = %115
unreachable
}

LLVM IR (-O2):
@.str = [4 x i8] c"E01\00"
@.str.1 = [3 x i8] c"OK\00"
@.str.2 = [4 x i8] c"E02\00"
@.str.3 = [4 x i8] c"E03\00"
@.str.4 = [4 x i8] c"E04\00"
define void @gdb_cmd_delete_breakpoint(i8* %0, i32 %1) {
%3 = alloca [16 x i8]
%4 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 0
%5 = icmp slt i32 %1, 1
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = tail call i32 @util_str_len(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%8 = tail call i32 @gdb_send_packet(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %7)
br label %50
9: ; preds = %2
%10 = load i8, i8* %0
%11 = icmp eq i8 %10, 44
%12 = zext i1 %11 to i64
%13 = getelementptr i8, i8* %0, i64 %12
%14 = call i32 @util_cpy_substr(i8* %4, i8* %13, i8 signext 44, i32 16)
%15 = add nsw i32 %14, 1
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %13, i64 %16
%18 = call i32 @util_hex_to_word(i8* %4)
%19 = call i32 @util_hex_to_word(i8* %17)
switch i32 %19, label %48 [
i32 2, label %20
i32 4, label %34
]
20: ; preds = %9
%21 = sext i32 %18 to i64
%22 = inttoptr i64 %21 to i8*
%23 = call i32 @dgb_unset_trap(i8* %22, i32 2)
switch i32 %23, label %26 [
i32 0, label %31
i32 1, label %27
i32 2, label %24
i32 3, label %25
]
24: ; preds = %20
br label %27
25: ; preds = %20
br label %27
26: ; preds = %20
br label %27
27: ; preds = %20, %24, %26, %25
%28 = phi i8* [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), %24 ], [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), %25 ], [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), %26 ], [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), %20 ]
%29 = call i32 @util_str_len(i8* %28)
%30 = call i32 @gdb_send_packet(i8* %28, i32 %29)
br label %50
31: ; preds = %20
%32 = call i32 @util_str_len(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%33 = call i32 @gdb_send_packet(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %32)
br label %50
34: ; preds = %9
%35 = sext i32 %18 to i64
%36 = inttoptr i64 %35 to i8*
%37 = call i32 @dgb_unset_trap(i8* %36, i32 1)
switch i32 %37, label %40 [
i32 0, label %45
i32 1, label %41
i32 2, label %38
i32 3, label %39
]
38: ; preds = %34
br label %41
39: ; preds = %34
br label %41
40: ; preds = %34
br label %41
41: ; preds = %34, %38, %40, %39
%42 = phi i8* [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), %38 ], [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), %39 ], [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), %40 ], [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), %34 ]
%43 = call i32 @util_str_len(i8* %42)
%44 = call i32 @gdb_send_packet(i8* %42, i32 %43)
br label %50
45: ; preds = %34
%46 = call i32 @util_str_len(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%47 = call i32 @gdb_send_packet(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %46)
br label %50
48: ; preds = %9
%49 = call i32 (...) @gdb_response_not_supported()
br label %50
50: ; preds = %31, %27, %41, %45, %48, %6
ret void
}