#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 fromhex(char);
int /*<<< orphan*/ select_frame_buffer_by_fn(unsigned int *, unsigned int);
int /*<<< orphan*/ select_frame_buffer_by_tpn(unsigned int, unsigned int *);
int /*<<< orphan*/ sprintf(char *, char *, ...);
int /*<<< orphan*/ start_trace_focusing();
int /*<<< orphan*/ stop_trace_focusing();
void decode_Frame_packet(char *buffer, char *response) {
  int i;
  char ch;
  unsigned int frame_number;
  unsigned int tracepoint_number;
  start_trace_focusing();
  switch (buffer[0]) {
  case 'p': {
    i = 3;
  } break;
  case 't': {
    i = 4;
    tracepoint_number = 0;
    while ((ch = buffer[i]) != '\0') {
      tracepoint_number = tracepoint_number << 4;
      tracepoint_number |= fromhex(ch) & 0x0f;
      i++;
    }
    if (select_frame_buffer_by_tpn(tracepoint_number, &frame_number)) {
      sprintf(response, "F%xT%x", frame_number, tracepoint_number);
    } else {
      sprintf(response, "F-1");
    }
  } break;
  case 'r': {
    i = 6;
  } break;
  case 'o': {
    i = 8;
  } break;
  default: {
    i = 0;
    frame_number = 0;
    while ((ch = buffer[i]) != '\0') {
      frame_number = frame_number << 4;
      frame_number |= fromhex(ch) & 0x0f;
      i++;
    }
    if (frame_number == 0xFFFFFFFF) {
      stop_trace_focusing();
      sprintf(response, "OK");
    } else {
      if (select_frame_buffer_by_fn(&tracepoint_number, frame_number)) {
        sprintf(response, "F%xT%x", frame_number, tracepoint_number);
      } else {
        sprintf(response, "F-1");
      }
    }
  }
  }
}


x86 assembly (clang, -O0):
<decode_Frame_packet>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xor    %eax,%eax
call   1070 <start_trace_focusing@plt>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
add    $0xffffff91,%eax
mov    %eax,%ecx
mov    %rcx,-0x28(%rbp)
sub    $0x5,%eax
ja     1262 <decode_Frame_packet+0x102>
mov    -0x28(%rbp),%rax
lea    0xe65(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0x3,-0x14(%rbp)
jmp    1329 <decode_Frame_packet+0x1c9>
movl   $0x4,-0x14(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x15(%rbp)
movsbl %al,%eax
cmp    $0x0,%eax
je     1201 <decode_Frame_packet+0xa1>
mov    -0x20(%rbp),%eax
shl    $0x4,%eax
mov    %eax,-0x20(%rbp)
movsbl -0x15(%rbp),%edi
call   1050 <fromhex@plt>
and    $0xf,%eax
or     -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11be <decode_Frame_packet+0x5e>
mov    -0x20(%rbp),%edi
lea    -0x1c(%rbp),%rsi
call   1040 <select_frame_buffer_by_tpn@plt>
cmp    $0x0,%eax
je     1233 <decode_Frame_packet+0xd3>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%edx
mov    -0x20(%rbp),%ecx
lea    0xdf1(%rip),%rsi
mov    $0x0,%al
call   1080 <sprintf@plt>
jmp    1245 <decode_Frame_packet+0xe5>
mov    -0x10(%rbp),%rdi
lea    0xde1(%rip),%rsi
mov    $0x0,%al
call   1080 <sprintf@plt>
jmp    1329 <decode_Frame_packet+0x1c9>
movl   $0x6,-0x14(%rbp)
jmp    1329 <decode_Frame_packet+0x1c9>
movl   $0x8,-0x14(%rbp)
jmp    1329 <decode_Frame_packet+0x1c9>
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x15(%rbp)
movsbl %al,%eax
cmp    $0x0,%eax
je     12b3 <decode_Frame_packet+0x153>
mov    -0x1c(%rbp),%eax
shl    $0x4,%eax
mov    %eax,-0x1c(%rbp)
movsbl -0x15(%rbp),%edi
call   1050 <fromhex@plt>
and    $0xf,%eax
or     -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1270 <decode_Frame_packet+0x110>
cmpl   $0xffffffff,-0x1c(%rbp)
jne    12db <decode_Frame_packet+0x17b>
mov    $0x0,%al
call   1030 <stop_trace_focusing@plt>
mov    -0x10(%rbp),%rdi
lea    0xd54(%rip),%rsi
mov    $0x0,%al
call   1080 <sprintf@plt>
jmp    1324 <decode_Frame_packet+0x1c4>
mov    -0x1c(%rbp),%esi
lea    -0x20(%rbp),%rdi
call   1060 <select_frame_buffer_by_fn@plt>
cmp    $0x0,%eax
je     130d <decode_Frame_packet+0x1ad>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%edx
mov    -0x20(%rbp),%ecx
lea    0xd17(%rip),%rsi
mov    $0x0,%al
call   1080 <sprintf@plt>
jmp    131f <decode_Frame_packet+0x1bf>
mov    -0x10(%rbp),%rdi
lea    0xd07(%rip),%rsi
mov    $0x0,%al
call   1080 <sprintf@plt>
jmp    1324 <decode_Frame_packet+0x1c4>
jmp    1329 <decode_Frame_packet+0x1c9>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<decode_Frame_packet>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
xor    %eax,%eax
call   1070 <start_trace_focusing@plt>
mov    (%rbx),%al
movsbl %al,%ecx
lea    -0x6f(%rcx),%edx
cmp    $0x2,%edx
jb     1276 <decode_Frame_packet+0x116>
cmp    $0x72,%ecx
je     1276 <decode_Frame_packet+0x116>
cmp    $0x74,%ecx
jne    11cd <decode_Frame_packet+0x6d>
movl   $0x0,(%rsp)
mov    0x4(%rbx),%al
test   %al,%al
je     121b <decode_Frame_packet+0xbb>
add    $0x5,%rbx
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
shl    $0x4,%ebp
movsbl %al,%edi
call   1050 <fromhex@plt>
and    $0xf,%eax
or     %eax,%ebp
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
jne    11b0 <decode_Frame_packet+0x50>
jmp    121d <decode_Frame_packet+0xbd>
test   %al,%al
je     123f <decode_Frame_packet+0xdf>
add    $0x1,%rbx
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
mov    %ebp,%r15d
shl    $0x4,%r15d
movsbl %al,%edi
call   1050 <fromhex@plt>
mov    %eax,%ebp
and    $0xf,%ebp
or     %r15d,%ebp
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
jne    11e0 <decode_Frame_packet+0x80>
cmp    $0xffffffff,%ebp
jne    1249 <decode_Frame_packet+0xe9>
xor    %eax,%eax
call   1030 <stop_trace_focusing@plt>
movw   $0x4b4f,(%r14)
movb   $0x0,0x2(%r14)
jmp    1276 <decode_Frame_packet+0x116>
xor    %ebp,%ebp
lea    0x4(%rsp),%rsi
mov    %ebp,%edi
call   1040 <select_frame_buffer_by_tpn@plt>
test   %eax,%eax
je     126f <decode_Frame_packet+0x10f>
mov    0x4(%rsp),%edx
lea    0xdc8(%rip),%rsi
mov    %r14,%rdi
mov    %ebp,%ecx
jmp    1266 <decode_Frame_packet+0x106>
movl   $0x0,0x4(%rsp)
xor    %ebp,%ebp
mov    %rsp,%rdi
mov    %ebp,%esi
call   1060 <select_frame_buffer_by_fn@plt>
test   %eax,%eax
je     126f <decode_Frame_packet+0x10f>
mov    (%rsp),%ecx
lea    0xd9f(%rip),%rsi
mov    %r14,%rdi
mov    %ebp,%edx
xor    %eax,%eax
call   1080 <sprintf@plt>
jmp    1276 <decode_Frame_packet+0x116>
movl   $0x312d46,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"F%xT%x\00"
@.str.1 = [4 x i8] c"F-1\00"
@.str.2 = [3 x i8] c"OK\00"
define void @decode_Frame_packet(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%9 = call i32 (...) @start_trace_focusing()
%10 = load i8*, i8** %3
%11 = getelementptr inbounds i8, i8* %10, i64 0
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
switch i32 %13, label %49 [
i32 112, label %14
i32 116, label %15
i32 114, label %47
i32 111, label %48
]
14: ; preds = %2
store i32 3, i32* %5
br label %89
15: ; preds = %2
store i32 4, i32* %5
store i32 0, i32* %8
br label %16
16: ; preds = %24, %15
%17 = load i8*, i8** %3
%18 = load i32, i32* %5
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %17, i64 %19
%21 = load i8, i8* %20
store i8 %21, i8* %6
%22 = sext i8 %21 to i32
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %34
24: ; preds = %16
%25 = load i32, i32* %8
%26 = shl i32 %25, 4
store i32 %26, i32* %8
%27 = load i8, i8* %6
%28 = call i32 @fromhex(i8 signext %27)
%29 = and i32 %28, 15
%30 = load i32, i32* %8
%31 = or i32 %30, %29
store i32 %31, i32* %8
%32 = load i32, i32* %5
%33 = add nsw i32 %32, 1
store i32 %33, i32* %5
br label %16
34: ; preds = %16
%35 = load i32, i32* %8
%36 = call i32 @select_frame_buffer_by_tpn(i32 %35, i32* %7)
%37 = icmp ne i32 %36, 0
br i1 %37, label %38, label %43
38: ; preds = %34
%39 = load i8*, i8** %4
%40 = load i32, i32* %7
%41 = load i32, i32* %8
%42 = call i32 (i8*, i8*, ...) @sprintf(i8* %39, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %40, i32 %41)
br label %46
43: ; preds = %34
%44 = load i8*, i8** %4
%45 = call i32 (i8*, i8*, ...) @sprintf(i8* %44, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
br label %46
46: ; preds = %43, %38
br label %89
47: ; preds = %2
store i32 6, i32* %5
br label %89
48: ; preds = %2
store i32 8, i32* %5
br label %89
49: ; preds = %2
store i32 0, i32* %5
store i32 0, i32* %7
br label %50
50: ; preds = %58, %49
%51 = load i8*, i8** %3
%52 = load i32, i32* %5
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i8, i8* %51, i64 %53
%55 = load i8, i8* %54
store i8 %55, i8* %6
%56 = sext i8 %55 to i32
%57 = icmp ne i32 %56, 0
br i1 %57, label %58, label %68
58: ; preds = %50
%59 = load i32, i32* %7
%60 = shl i32 %59, 4
store i32 %60, i32* %7
%61 = load i8, i8* %6
%62 = call i32 @fromhex(i8 signext %61)
%63 = and i32 %62, 15
%64 = load i32, i32* %7
%65 = or i32 %64, %63
store i32 %65, i32* %7
%66 = load i32, i32* %5
%67 = add nsw i32 %66, 1
store i32 %67, i32* %5
br label %50
68: ; preds = %50
%69 = load i32, i32* %7
%70 = icmp eq i32 %69, -1
br i1 %70, label %71, label %75
71: ; preds = %68
%72 = call i32 (...) @stop_trace_focusing()
%73 = load i8*, i8** %4
%74 = call i32 (i8*, i8*, ...) @sprintf(i8* %73, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %88
75: ; preds = %68
%76 = load i32, i32* %7
%77 = call i32 @select_frame_buffer_by_fn(i32* %8, i32 %76)
%78 = icmp ne i32 %77, 0
br i1 %78, label %79, label %84
79: ; preds = %75
%80 = load i8*, i8** %4
%81 = load i32, i32* %7
%82 = load i32, i32* %8
%83 = call i32 (i8*, i8*, ...) @sprintf(i8* %80, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %81, i32 %82)
br label %87
84: ; preds = %75
%85 = load i8*, i8** %4
%86 = call i32 (i8*, i8*, ...) @sprintf(i8* %85, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
br label %87
87: ; preds = %84, %79
br label %88
88: ; preds = %87, %71
br label %89
89: ; preds = %88, %48, %47, %46, %14
ret void
}

LLVM IR (-O2):
@.str = [7 x i8] c"F%xT%x\00"
@.str.2 = [3 x i8] c"OK\00"
define void @decode_Frame_packet(i8* nocapture %0, i8* nocapture writeonly %1) {
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %3 to i8*
%6 = bitcast i32* %4 to i8*
%7 = tail call i32 (...) @start_trace_focusing()
%8 = load i8, i8* %0
%9 = sext i8 %8 to i32
switch i32 %9, label %35 [
i32 112, label %63
i32 116, label %10
i32 114, label %63
i32 111, label %63
]
10: ; preds = %2
store i32 0, i32* %4
%11 = getelementptr inbounds i8, i8* %0, i64 4
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, 0
br i1 %13, label %26, label %14
14: ; preds = %10, %14
%15 = phi i64 [ %22, %14 ], [ 4, %10 ]
%16 = phi i8 [ %24, %14 ], [ %12, %10 ]
%17 = phi i32 [ %21, %14 ], [ 0, %10 ]
%18 = shl i32 %17, 4
%19 = tail call i32 @fromhex(i8 signext %16)
%20 = and i32 %19, 15
%21 = or i32 %18, %20
%22 = add nuw i64 %15, 1
%23 = getelementptr inbounds i8, i8* %0, i64 %22
%24 = load i8, i8* %23
%25 = icmp eq i8 %24, 0
br i1 %25, label %26, label %14
26: ; preds = %14, %10
%27 = phi i32 [ 0, %10 ], [ %21, %14 ]
%28 = call i32 @select_frame_buffer_by_tpn(i32 %27, i32* %3)
%29 = icmp eq i32 %28, 0
br i1 %29, label %33, label %30
30: ; preds = %26
%31 = load i32, i32* %3
%32 = call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %31, i32 %27)
br label %63
33: ; preds = %26
%34 = bitcast i8* %1 to i32*
store i32 3222854, i32* %34
br label %63
35: ; preds = %2
%36 = icmp eq i8 %8, 0
br i1 %36, label %37, label %38
37: ; preds = %35
store i32 0, i32* %3
br label %54
38: ; preds = %35, %38
%39 = phi i64 [ %46, %38 ], [ 0, %35 ]
%40 = phi i8 [ %48, %38 ], [ %8, %35 ]
%41 = phi i32 [ %45, %38 ], [ 0, %35 ]
%42 = shl i32 %41, 4
%43 = tail call i32 @fromhex(i8 signext %40)
%44 = and i32 %43, 15
%45 = or i32 %42, %44
%46 = add nuw i64 %39, 1
%47 = getelementptr inbounds i8, i8* %0, i64 %46
%48 = load i8, i8* %47
%49 = icmp eq i8 %48, 0
br i1 %49, label %50, label %38
50: ; preds = %38
%51 = icmp eq i32 %45, -1
br i1 %51, label %52, label %54
52: ; preds = %50
%53 = tail call i32 (...) @stop_trace_focusing()
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 dereferenceable(3) %1, i8* align 1 dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i64 3, i1 false)
br label %63
54: ; preds = %37, %50
%55 = phi i32 [ 0, %37 ], [ %45, %50 ]
%56 = call i32 @select_frame_buffer_by_fn(i32* %4, i32 %55)
%57 = icmp eq i32 %56, 0
br i1 %57, label %61, label %58
58: ; preds = %54
%59 = load i32, i32* %4
%60 = call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %55, i32 %59)
br label %63
61: ; preds = %54
%62 = bitcast i8* %1 to i32*
store i32 3222854, i32* %62
br label %63
63: ; preds = %2, %2, %2, %52, %61, %58, %30, %33
ret void
}