#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 */
struct evbuffer {
  int dummy;
};
struct bufferevent {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ LOG_DEBUG;
int /*<<< orphan*/ _debug(char *, int, int /*<<< orphan*/, char *, int);
struct evbuffer *bufferevent_get_input(struct bufferevent *);
int evbuffer_get_length(struct evbuffer *);
scalar_t__ evbuffer_remove(struct evbuffer *, char *, int);
char *malloc(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ process_user_cmd(struct bufferevent *, char *, void *);
char *strrchr(char *, char);
void xkcp_mon_read_cb(struct bufferevent *bev, void *ctx) {
  struct evbuffer *input = bufferevent_get_input(bev);
  int len = evbuffer_get_length(input);
  _debug((strrchr("/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                  "outputs/2022-01-22/02-19-57/repos/liudf0716/xkcptun/refs/"
                  "heads/master/xkcp_mon.c",
                  '/')
              ? strrchr("/scratch/repos/new/home/jordi_armengol_estape/"
                        "c-scraper/outputs/2022-01-22/02-19-57/repos/liudf0716/"
                        "xkcptun/refs/heads/master/xkcp_mon.c",
                        '/') +
                    1
              : "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                "outputs/2022-01-22/02-19-57/repos/liudf0716/xkcptun/refs/"
                "heads/master/xkcp_mon.c"),
         148, LOG_DEBUG, "xkcp_mon_read_cb [%d]", len);
  if (len > 0) {
    char *buf = malloc(len + 1);
    memset(buf, 0, len + 1);
    if (evbuffer_remove(input, buf, len) > 0)
      process_user_cmd(bev, buf, ctx);
  }
}


x86 assembly (clang, -O0):
<xkcp_mon_read_cb>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <bufferevent_get_input@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1090 <evbuffer_get_length@plt>
mov    %eax,-0x1c(%rbp)
lea    0xe50(%rip),%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
cmp    $0x0,%rax
je     11e2 <xkcp_mon_read_cb+0x62>
lea    0xe35(%rip),%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    11f2 <xkcp_mon_read_cb+0x72>
lea    0xe17(%rip),%rax
mov    %rax,-0x30(%rbp)
jmp    11f2 <xkcp_mon_read_cb+0x72>
mov    -0x30(%rbp),%rdi
mov    0x2de3(%rip),%rax
mov    (%rax),%edx
mov    -0x1c(%rbp),%r8d
mov    $0x94,%esi
lea    0xe7a(%rip),%rcx
call   1070 <_debug@plt>
cmpl   $0x0,-0x1c(%rbp)
jle    126e <xkcp_mon_read_cb+0xee>
mov    -0x1c(%rbp),%edi
add    $0x1,%edi
call   1080 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x1c(%rbp),%edx
add    $0x1,%edx
xor    %esi,%esi
call   1050 <memset@plt>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <evbuffer_remove@plt>
cmp    $0x0,%rax
jle    1269 <xkcp_mon_read_cb+0xe9>
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   10a0 <process_user_cmd@plt>
jmp    126e <xkcp_mon_read_cb+0xee>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xkcp_mon_read_cb>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
call   1050 <bufferevent_get_input@plt>
mov    %rax,%r12
mov    %rax,%rdi
call   1080 <evbuffer_get_length@plt>
mov    %eax,%ebx
mov    0x2e46(%rip),%rax
mov    (%rax),%edx
lea    0xedb(%rip),%rdi
lea    0xedf(%rip),%rcx
mov    $0x94,%esi
mov    %ebx,%r8d
call   1060 <_debug@plt>
test   %ebx,%ebx
jle    1204 <xkcp_mon_read_cb+0x94>
mov    %ebx,%ebp
add    $0x1,%ebp
mov    %ebp,%edi
call   1070 <malloc@plt>
mov    %rax,%r13
mov    %rax,%rdi
xor    %esi,%esi
mov    %ebp,%edx
call   1040 <memset@plt>
mov    %r12,%rdi
mov    %r13,%rsi
mov    %ebx,%edx
call   1030 <evbuffer_remove@plt>
test   %rax,%rax
jle    1204 <xkcp_mon_read_cb+0x94>
mov    %r15,%rdi
mov    %r13,%rsi
mov    %r14,%rdx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1090 <process_user_cmd@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.bufferevent = type { i32 }
%struct.evbuffer = type { i32 }
@.str = [137 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/liudf0716/xkcptun/refs/heads/master/xkcp_mon.c\00"
@LOG_DEBUG = global i32 0
@.str.1 = [22 x i8] c"xkcp_mon_read_cb [%d]\00"
define void @xkcp_mon_read_cb(%struct.bufferevent* %0, i8* %1) {
%3 = alloca %struct.bufferevent*
%4 = alloca i8*
%5 = alloca %struct.evbuffer*
%6 = alloca i32
%7 = alloca i8*
store %struct.bufferevent* %0, %struct.bufferevent** %3
store i8* %1, i8** %4
%8 = load %struct.bufferevent*, %struct.bufferevent** %3
%9 = call %struct.evbuffer* @bufferevent_get_input(%struct.bufferevent* %8)
store %struct.evbuffer* %9, %struct.evbuffer** %5
%10 = load %struct.evbuffer*, %struct.evbuffer** %5
%11 = call i32 @evbuffer_get_length(%struct.evbuffer* %10)
store i32 %11, i32* %6
%12 = call i8* @strrchr(i8* getelementptr inbounds ([137 x i8], [137 x i8]* @.str, i64 0, i64 0), i8 signext 47)
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %17
14: ; preds = %2
%15 = call i8* @strrchr(i8* getelementptr inbounds ([137 x i8], [137 x i8]* @.str, i64 0, i64 0), i8 signext 47)
%16 = getelementptr inbounds i8, i8* %15, i64 1
br label %18
17: ; preds = %2
br label %18
18: ; preds = %17, %14
%19 = phi i8* [ %16, %14 ], [ getelementptr inbounds ([137 x i8], [137 x i8]* @.str, i64 0, i64 0), %17 ]
%20 = load i32, i32* @LOG_DEBUG
%21 = load i32, i32* %6
%22 = call i32 @_debug(i8* %19, i32 148, i32 %20, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %21)
%23 = load i32, i32* %6
%24 = icmp sgt i32 %23, 0
br i1 %24, label %25, label %44
25: ; preds = %18
%26 = load i32, i32* %6
%27 = add nsw i32 %26, 1
%28 = call i8* @malloc(i32 %27)
store i8* %28, i8** %7
%29 = load i8*, i8** %7
%30 = load i32, i32* %6
%31 = add nsw i32 %30, 1
%32 = call i32 @memset(i8* %29, i32 0, i32 %31)
%33 = load %struct.evbuffer*, %struct.evbuffer** %5
%34 = load i8*, i8** %7
%35 = load i32, i32* %6
%36 = call i64 @evbuffer_remove(%struct.evbuffer* %33, i8* %34, i32 %35)
%37 = icmp sgt i64 %36, 0
br i1 %37, label %38, label %43
38: ; preds = %25
%39 = load %struct.bufferevent*, %struct.bufferevent** %3
%40 = load i8*, i8** %7
%41 = load i8*, i8** %4
%42 = call i32 @process_user_cmd(%struct.bufferevent* %39, i8* %40, i8* %41)
br label %43
43: ; preds = %38, %25
br label %44
44: ; preds = %43, %18
ret void
}

LLVM IR (-O2):
%struct.bufferevent = type { i32 }
%struct.evbuffer = type { i32 }
@.str = [137 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/liudf0716/xkcptun/refs/heads/master/xkcp_mon.c\00"
@LOG_DEBUG = global i32 0
@.str.1 = [22 x i8] c"xkcp_mon_read_cb [%d]\00"
define void @xkcp_mon_read_cb(%struct.bufferevent* %0, i8* %1) {
%3 = tail call %struct.evbuffer* @bufferevent_get_input(%struct.bufferevent* %0)
%4 = tail call i32 @evbuffer_get_length(%struct.evbuffer* %3)
%5 = load i32, i32* @LOG_DEBUG
%6 = tail call i32 @_debug(i8* getelementptr inbounds ([137 x i8], [137 x i8]* @.str, i64 0, i64 126), i32 148, i32 %5, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %4)
%7 = icmp sgt i32 %4, 0
br i1 %7, label %8, label %16
8: ; preds = %2
%9 = add nuw nsw i32 %4, 1
%10 = tail call i8* @malloc(i32 %9)
%11 = tail call i32 @memset(i8* %10, i32 0, i32 %9)
%12 = tail call i64 @evbuffer_remove(%struct.evbuffer* %3, i8* %10, i32 %4)
%13 = icmp sgt i64 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %8
%15 = tail call i32 @process_user_cmd(%struct.bufferevent* %0, i8* %10, i8* %1)
br label %16
16: ; preds = %8, %14, %2
ret void
}