#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*/ fprintf(int /*<<< orphan*/, char *, char const *);
int /*<<< orphan*/ socket_write(int, char const *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
scalar_t__ strcasecmp(char *, void *);
int /*<<< orphan*/ strlen(char const *);
void server_on_read_cb(int fd, void *buffer, int length) {
  const char message[] = "pong";
  if ((length > 0) && (buffer != NULL)) {
    if (strcasecmp("ping", buffer) == 0) {
      fprintf(stderr, "server::%s\n", message);
      socket_write(fd, message, strlen(message));
    }
  }
}


x86 assembly (clang, -O0):
<server_on_read_cb>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    0xea8(%rip),%eax
mov    %eax,-0x19(%rbp)
mov    0xea3(%rip),%al
mov    %al,-0x15(%rbp)
cmpl   $0x0,-0x14(%rbp)
jle    11d6 <server_on_read_cb+0x96>
cmpq   $0x0,-0x10(%rbp)
je     11d6 <server_on_read_cb+0x96>
mov    -0x10(%rbp),%rsi
lea    0xe81(%rip),%rdi
call   1030 <strcasecmp@plt>
cmp    $0x0,%rax
jne    11d1 <server_on_read_cb+0x91>
mov    0x2e46(%rip),%rax
mov    (%rax),%edi
lea    -0x19(%rbp),%rdx
lea    0xe63(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x2c(%rbp)
lea    -0x19(%rbp),%rax
mov    %rax,-0x28(%rbp)
lea    -0x19(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    %eax,%edx
call   1050 <socket_write@plt>
jmp    11d6 <server_on_read_cb+0x96>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<server_on_read_cb>:
push   %r14
push   %rbx
push   %rax
movb   $0x0,0x4(%rsp)
movl   $0x676e6f70,(%rsp)
test   %rsi,%rsi
je     119b <server_on_read_cb+0x5b>
test   %edx,%edx
jle    119b <server_on_read_cb+0x5b>
mov    %edi,%ebx
lea    0xea3(%rip),%rdi
call   1030 <strcasecmp@plt>
test   %rax,%rax
jne    119b <server_on_read_cb+0x5b>
mov    0x2e6d(%rip),%rax
mov    (%rax),%edi
lea    0xe8e(%rip),%rsi
mov    %rsp,%r14
mov    %r14,%rdx
call   1060 <fprintf@plt>
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1050 <socket_write@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__const.server_on_read_cb.message = [5 x i8] c"pong\00"
@.str = [5 x i8] c"ping\00"
@stderr = global i32 0
@.str.1 = [12 x i8] c"server::%s\0A\00"
define void @server_on_read_cb(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca [5 x i8]
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%8 = bitcast [5 x i8]* %7 to i8*
%9 = load i32, i32* %6
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %28
11: ; preds = %3
%12 = load i8*, i8** %5
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %28
14: ; preds = %11
%15 = load i8*, i8** %5
%16 = call i64 @strcasecmp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %27
18: ; preds = %14
%19 = load i32, i32* @stderr
%20 = getelementptr inbounds [5 x i8], [5 x i8]* %7, i64 0, i64 0
%21 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %20)
%22 = load i32, i32* %4
%23 = getelementptr inbounds [5 x i8], [5 x i8]* %7, i64 0, i64 0
%24 = getelementptr inbounds [5 x i8], [5 x i8]* %7, i64 0, i64 0
%25 = call i32 @strlen(i8* %24)
%26 = call i32 @socket_write(i32 %22, i8* %23, i32 %25)
br label %27
27: ; preds = %18, %14
br label %28
28: ; preds = %27, %11, %3
ret void
}

LLVM IR (-O2):
@__const.server_on_read_cb.message = [5 x i8] c"pong\00"
@.str = [5 x i8] c"ping\00"
@stderr = global i32 0
@.str.1 = [12 x i8] c"server::%s\0A\00"
define void @server_on_read_cb(i32 %0, i8* %1, i32 %2) {
%4 = alloca [5 x i8]
%5 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 0
%6 = icmp sgt i32 %2, 0
%7 = icmp ne i8* %1, null
%8 = and i1 %7, %6
br i1 %8, label %9, label %17
9: ; preds = %3
%10 = tail call i64 @strcasecmp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %1)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %17
12: ; preds = %9
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %5)
%15 = call i32 @strlen(i8* %5)
%16 = call i32 @socket_write(i32 %0, i8* %5, i32 %15)
br label %17
17: ; preds = %9, %12, %3
ret void
}