#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*/ firetalk_callback_subcode_reply(void *, char const *const,
                                                   char *,
                                                   int /*<<< orphan*/ *);
int /*<<< orphan*/ firetalk_callback_subcode_request(void *, char const *const,
                                                     char *,
                                                     int /*<<< orphan*/ *);
int /*<<< orphan*/ *htmlclean(char *);
int /*<<< orphan*/ memmove(char *, char *, scalar_t__);
char *strchr(char *, char);
scalar_t__ strlen(char *);
char *strstr(char *, char *);
char *aim_handle_ect(void *conn, const char *const from, char *message,
                     const int reply) {
  char *ectbegin, *ectend, *textbegin, *textend;
  while ((ectbegin = strstr(message, "<font ECT=\"")) != NULL) {
    textbegin = ectbegin + sizeof("<font ECT=\"") - 1;
    if ((textend = strstr(textbegin, "\"></font>")) != NULL) {
      char *arg;
      *textend = 0;
      ectend = textend + sizeof("\"></font>") - 1;
      if ((arg = strchr(textbegin, ' ')) != NULL) {
        *arg = '\0';
        arg++;
        if (reply == 1)
          firetalk_callback_subcode_reply(conn, from, textbegin,
                                          htmlclean(arg));
        else
          firetalk_callback_subcode_request(conn, from, textbegin,
                                            htmlclean(arg));
      } else {
        if (reply == 1)
          firetalk_callback_subcode_reply(conn, from, textbegin, NULL);
        else
          firetalk_callback_subcode_request(conn, from, textbegin, NULL);
      }
      memmove(ectbegin, ectend, strlen(ectend) + 1);
    } else
      break;
  }
  return message;
}


x86 assembly (clang, -O0):
<aim_handle_ect>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe6b(%rip),%rsi
call   1090 <strstr@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     131a <aim_handle_ect+0x1aa>
mov    -0x28(%rbp),%rax
add    $0xc,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
lea    0xe49(%rip),%rsi
call   1090 <strstr@plt>
mov    %rax,-0x40(%rbp)
cmp    $0x0,%rax
je     1310 <aim_handle_ect+0x1a0>
mov    -0x40(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x40(%rbp),%rax
add    $0xa,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x30(%rbp)
mov    -0x38(%rbp),%rdi
mov    $0x20,%esi
call   1050 <strchr@plt>
mov    %rax,-0x48(%rbp)
cmp    $0x0,%rax
je     129a <aim_handle_ect+0x12a>
mov    -0x48(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x48(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x48(%rbp)
cmpl   $0x1,-0x1c(%rbp)
jne    1260 <aim_handle_ect+0xf0>
mov    -0x8(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x48(%rbp),%rdi
call   1030 <htmlclean@plt>
mov    -0x60(%rbp),%rdi
mov    -0x58(%rbp),%rsi
mov    -0x50(%rbp),%rdx
mov    %rax,%rcx
call   1080 <firetalk_callback_subcode_reply@plt>
jmp    1295 <aim_handle_ect+0x125>
mov    -0x8(%rbp),%rax
mov    %rax,-0x78(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x48(%rbp),%rdi
call   1030 <htmlclean@plt>
mov    -0x78(%rbp),%rdi
mov    -0x70(%rbp),%rsi
mov    -0x68(%rbp),%rdx
mov    %rax,%rcx
call   1060 <firetalk_callback_subcode_request@plt>
jmp    12d8 <aim_handle_ect+0x168>
cmpl   $0x1,-0x1c(%rbp)
jne    12be <aim_handle_ect+0x14e>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x38(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%ecx
call   1080 <firetalk_callback_subcode_reply@plt>
jmp    12d3 <aim_handle_ect+0x163>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x38(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%ecx
call   1060 <firetalk_callback_subcode_request@plt>
jmp    12d8 <aim_handle_ect+0x168>
mov    -0x28(%rbp),%rax
mov    %rax,-0x88(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x80(%rbp)
mov    -0x30(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x88(%rbp),%rdi
mov    -0x80(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
call   1070 <memmove@plt>
jmp    1315 <aim_handle_ect+0x1a5>
jmp    131a <aim_handle_ect+0x1aa>
jmp    118a <aim_handle_ect+0x1a>
mov    -0x18(%rbp),%rax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<aim_handle_ect>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,0x4(%rsp)
mov    %rdx,%rbx
mov    %rsi,%r15
mov    %rdi,%rbp
lea    0xe71(%rip),%rsi
mov    %rdx,%rdi
call   1090 <strstr@plt>
test   %rax,%rax
je     127c <aim_handle_ect+0x10c>
mov    %rax,%r13
jmp    11f3 <aim_handle_ect+0x83>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbp,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
mov    %rax,%rcx
call   1080 <firetalk_callback_subcode_reply@plt>
mov    %r12,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%rdx
mov    %r13,%rdi
mov    %r12,%rsi
call   1070 <memmove@plt>
mov    %rbx,%rdi
lea    0xe1e(%rip),%rsi
call   1090 <strstr@plt>
mov    %rax,%r13
test   %rax,%rax
je     127c <aim_handle_ect+0x10c>
lea    0xb(%r13),%r14
mov    %r14,%rdi
lea    0xe0b(%rip),%rsi
call   1090 <strstr@plt>
test   %rax,%rax
je     127c <aim_handle_ect+0x10c>
mov    %rax,%r12
movb   $0x0,(%rax)
add    $0x9,%r12
mov    %r14,%rdi
mov    $0x20,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     1250 <aim_handle_ect+0xe0>
movb   $0x0,(%rax)
add    $0x1,%rax
mov    %rax,%rdi
call   1030 <htmlclean@plt>
cmpl   $0x1,0x4(%rsp)
je     11b0 <aim_handle_ect+0x40>
mov    %rbp,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
mov    %rax,%rcx
jmp    1272 <aim_handle_ect+0x102>
nop
cmpl   $0x1,0x4(%rsp)
jne    1267 <aim_handle_ect+0xf7>
mov    %rbp,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
xor    %ecx,%ecx
jmp    11bc <aim_handle_ect+0x4c>
mov    %rbp,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
xor    %ecx,%ecx
call   1060 <firetalk_callback_subcode_request@plt>
jmp    11c1 <aim_handle_ect+0x51>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"<font ECT=\22\00"
@.str.1 = [10 x i8] c"\22></font>\00"
define i8* @aim_handle_ect(i8* %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i32 %3, i32* %8
br label %14
14: ; preds = %76, %4
%15 = load i8*, i8** %7
%16 = call i8* @strstr(i8* %15, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
store i8* %16, i8** %9
%17 = icmp ne i8* %16, null
br i1 %17, label %18, label %77
18: ; preds = %14
%19 = load i8*, i8** %9
%20 = getelementptr inbounds i8, i8* %19, i64 12
%21 = getelementptr inbounds i8, i8* %20, i64 -1
store i8* %21, i8** %11
%22 = load i8*, i8** %11
%23 = call i8* @strstr(i8* %22, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
store i8* %23, i8** %12
%24 = icmp ne i8* %23, null
br i1 %24, label %25, label %75
25: ; preds = %18
%26 = load i8*, i8** %12
store i8 0, i8* %26
%27 = load i8*, i8** %12
%28 = getelementptr inbounds i8, i8* %27, i64 10
%29 = getelementptr inbounds i8, i8* %28, i64 -1
store i8* %29, i8** %10
%30 = load i8*, i8** %11
%31 = call i8* @strchr(i8* %30, i8 signext 32)
store i8* %31, i8** %13
%32 = icmp ne i8* %31, null
br i1 %32, label %33, label %54
33: ; preds = %25
%34 = load i8*, i8** %13
store i8 0, i8* %34
%35 = load i8*, i8** %13
%36 = getelementptr inbounds i8, i8* %35, i32 1
store i8* %36, i8** %13
%37 = load i32, i32* %8
%38 = icmp eq i32 %37, 1
br i1 %38, label %39, label %46
39: ; preds = %33
%40 = load i8*, i8** %5
%41 = load i8*, i8** %6
%42 = load i8*, i8** %11
%43 = load i8*, i8** %13
%44 = call i32* @htmlclean(i8* %43)
%45 = call i32 @firetalk_callback_subcode_reply(i8* %40, i8* %41, i8* %42, i32* %44)
br label %53
46: ; preds = %33
%47 = load i8*, i8** %5
%48 = load i8*, i8** %6
%49 = load i8*, i8** %11
%50 = load i8*, i8** %13
%51 = call i32* @htmlclean(i8* %50)
%52 = call i32 @firetalk_callback_subcode_request(i8* %47, i8* %48, i8* %49, i32* %51)
br label %53
53: ; preds = %46, %39
br label %68
54: ; preds = %25
%55 = load i32, i32* %8
%56 = icmp eq i32 %55, 1
br i1 %56, label %57, label %62
57: ; preds = %54
%58 = load i8*, i8** %5
%59 = load i8*, i8** %6
%60 = load i8*, i8** %11
%61 = call i32 @firetalk_callback_subcode_reply(i8* %58, i8* %59, i8* %60, i32* null)
br label %67
62: ; preds = %54
%63 = load i8*, i8** %5
%64 = load i8*, i8** %6
%65 = load i8*, i8** %11
%66 = call i32 @firetalk_callback_subcode_request(i8* %63, i8* %64, i8* %65, i32* null)
br label %67
67: ; preds = %62, %57
br label %68
68: ; preds = %67, %53
%69 = load i8*, i8** %9
%70 = load i8*, i8** %10
%71 = load i8*, i8** %10
%72 = call i64 @strlen(i8* %71)
%73 = add nsw i64 %72, 1
%74 = call i32 @memmove(i8* %69, i8* %70, i64 %73)
br label %76
75: ; preds = %18
br label %77
76: ; preds = %68
br label %14
77: ; preds = %75, %14
%78 = load i8*, i8** %7
ret i8* %78
}

LLVM IR (-O2):
@.str = [12 x i8] c"<font ECT=\22\00"
@.str.1 = [10 x i8] c"\22></font>\00"
define i8* @aim_handle_ect(i8* %0, i8* %1, i8* returned %2, i32 %3) {
%5 = tail call i8* @strstr(i8* dereferenceable(1) %2, i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i8* %5, null
br i1 %6, label %36, label %7
7: ; preds = %4
%8 = icmp eq i32 %3, 1
br label %9
9: ; preds = %7, %30
%10 = phi i8* [ %5, %7 ], [ %34, %30 ]
%11 = getelementptr inbounds i8, i8* %10, i64 11
%12 = tail call i8* @strstr(i8* %11, i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%13 = icmp eq i8* %12, null
br i1 %13, label %36, label %14
14: ; preds = %9
store i8 0, i8* %12
%15 = getelementptr inbounds i8, i8* %12, i64 9
%16 = tail call i8* @strchr(i8* %11, i8 signext 32)
%17 = icmp eq i8* %16, null
br i1 %17, label %25, label %18
18: ; preds = %14
store i8 0, i8* %16
%19 = getelementptr inbounds i8, i8* %16, i64 1
%20 = tail call i32* @htmlclean(i8* %19)
br i1 %8, label %21, label %23
21: ; preds = %18
%22 = tail call i32 @firetalk_callback_subcode_reply(i8* %0, i8* %1, i8* %11, i32* %20)
br label %30
23: ; preds = %18
%24 = tail call i32 @firetalk_callback_subcode_request(i8* %0, i8* %1, i8* %11, i32* %20)
br label %30
25: ; preds = %14
br i1 %8, label %26, label %28
26: ; preds = %25
%27 = tail call i32 @firetalk_callback_subcode_reply(i8* %0, i8* %1, i8* %11, i32* null)
br label %30
28: ; preds = %25
%29 = tail call i32 @firetalk_callback_subcode_request(i8* %0, i8* %1, i8* %11, i32* null)
br label %30
30: ; preds = %26, %28, %21, %23
%31 = tail call i64 @strlen(i8* %15)
%32 = add nsw i64 %31, 1
%33 = tail call i32 @memmove(i8* %10, i8* %15, i64 %32)
%34 = tail call i8* @strstr(i8* dereferenceable(1) %2, i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%35 = icmp eq i8* %34, null
br i1 %35, label %36, label %9
36: ; preds = %30, %9, %4
ret i8* %2
}