#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*/ free(char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ send(int, char *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strcasecmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ strlen(char *);
void on_write(int sock, short event, void *arg) {
  char *buffer = (char *)arg;
  char response[1024];
  if (!strcasecmp(buffer, "hello")) {
    strcpy(response, "how do you do");
  } else {
    strcpy(response, "sorry");
  }
  printf("send:%s\n", response);
  send(sock, response, strlen(response), 0);
  free(buffer);
}


x86 assembly (clang, -O0):
<on_write>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %si,%ax
mov    %edi,-0x4(%rbp)
mov    %ax,-0x6(%rbp)
mov    %rdx,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe74(%rip),%rsi
call   1040 <strcasecmp@plt>
cmp    $0x0,%eax
jne    11b2 <on_write+0x52>
lea    -0x420(%rbp),%rdi
lea    0xe5e(%rip),%rsi
call   1050 <strcpy@plt>
jmp    11c5 <on_write+0x65>
lea    -0x420(%rbp),%rdi
lea    0xe54(%rip),%rsi
call   1050 <strcpy@plt>
lea    -0x420(%rbp),%rsi
lea    0xe47(%rip),%rdi
call   1080 <printf@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x42c(%rbp)
lea    -0x420(%rbp),%rax
mov    %rax,-0x428(%rbp)
lea    -0x420(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x42c(%rbp),%edi
mov    -0x428(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1070 <send@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<on_write>:
push   %rbp
push   %r14
push   %rbx
sub    $0x400,%rsp
mov    %rdx,%rbx
mov    %edi,%r14d
lea    0xe88(%rip),%rsi
mov    %rdx,%rdi
call   1040 <strcasecmp@plt>
test   %eax,%eax
lea    0xe7d(%rip),%rax
lea    0xe84(%rip),%rsi
cmove  %rax,%rsi
mov    %rsp,%rbp
mov    %rbp,%rdi
call   1050 <strcpy@plt>
lea    0xe74(%rip),%rdi
mov    %rbp,%rsi
call   1080 <printf@plt>
mov    %rbp,%rdi
call   1060 <strlen@plt>
mov    %r14d,%edi
mov    %rbp,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1070 <send@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"hello\00"
@.str.1 = [14 x i8] c"how do you do\00"
@.str.2 = [6 x i8] c"sorry\00"
@.str.3 = [9 x i8] c"send:%s\0A\00"
define void @on_write(i32 %0, i16 signext %1, i8* %2) {
%4 = alloca i32
%5 = alloca i16
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca [1024 x i8]
store i32 %0, i32* %4
store i16 %1, i16* %5
store i8* %2, i8** %6
%9 = load i8*, i8** %6
store i8* %9, i8** %7
%10 = load i8*, i8** %7
%11 = call i32 @strcasecmp(i8* %10, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%12 = icmp ne i32 %11, 0
br i1 %12, label %16, label %13
13: ; preds = %3
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%15 = call i32 @strcpy(i8* %14, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %19
16: ; preds = %3
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%18 = call i32 @strcpy(i8* %17, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %19
19: ; preds = %16, %13
%20 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%21 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* %20)
%22 = load i32, i32* %4
%23 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%24 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%25 = call i32 @strlen(i8* %24)
%26 = call i32 @send(i32 %22, i8* %23, i32 %25, i32 0)
%27 = load i8*, i8** %7
%28 = call i32 @free(i8* %27)
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c"hello\00"
@.str.1 = [14 x i8] c"how do you do\00"
@.str.2 = [6 x i8] c"sorry\00"
@.str.3 = [9 x i8] c"send:%s\0A\00"
define void @on_write(i32 %0, i16 signext %1, i8* nocapture %2) {
%4 = alloca [1024 x i8]
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%6 = tail call i32 @strcasecmp(i8* %2, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32 %6, 0
%8 = select i1 %7, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0)
%9 = call i32 @strcpy(i8* %5, i8* %8)
%10 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* %5)
%11 = call i32 @strlen(i8* %5)
%12 = call i32 @send(i32 %0, i8* %5, i32 %11, i32 0)
%13 = call i32 @free(i8* %2)
ret void
}