#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_cb_info {
  scalar_t__ n_added;
};
struct evbuffer {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ EVBUFFER_EOL_CRLF;
int /*<<< orphan*/ evbuffer_drain(struct evbuffer *, int);
int evbuffer_get_contiguous_space(struct evbuffer *);
int evbuffer_get_length(struct evbuffer *);
int /*<<< orphan*/ evbuffer_readln(struct evbuffer *, int /*<<< orphan*/ *,
                                   int /*<<< orphan*/);
int /*<<< orphan*/ free(int /*<<< orphan*/);
void eb_trim_cb(struct evbuffer *b, const struct evbuffer_cb_info *i,
                void *_ts) {
  if (i->n_added == 0)
    return;
  int len = evbuffer_get_length(b);
  if (len > ((size_t)_ts)) {
    int len2;
    do {
      free(evbuffer_readln(b, NULL, EVBUFFER_EOL_CRLF));
      len2 = evbuffer_get_length(b);
    } while ((len2 > ((size_t)_ts)) && (len != len2));
    if (len2 > ((size_t)_ts)) {
      int firstchunk = evbuffer_get_contiguous_space(b);
      evbuffer_drain(b, firstchunk < 32 ? 32 : firstchunk);
    }
  }
}


x86 assembly (clang, -O0):
<eb_trim_cb>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
jne    1177 <eb_trim_cb+0x27>
jmp    1242 <eb_trim_cb+0xf2>
mov    -0x8(%rbp),%rdi
call   1050 <evbuffer_get_length@plt>
mov    %eax,-0x1c(%rbp)
movslq -0x1c(%rbp),%rax
mov    -0x18(%rbp),%rcx
cmp    %rcx,%rax
jbe    1242 <eb_trim_cb+0xf2>
jmp    1199 <eb_trim_cb+0x49>
mov    -0x8(%rbp),%rdi
mov    0x2e44(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1070 <evbuffer_readln@plt>
mov    %eax,%edi
call   1030 <free@plt>
mov    -0x8(%rbp),%rdi
call   1050 <evbuffer_get_length@plt>
mov    %eax,-0x20(%rbp)
movslq -0x20(%rbp),%rcx
mov    -0x18(%rbp),%rdx
xor    %eax,%eax
cmp    %rdx,%rcx
mov    %al,-0x25(%rbp)
jbe    11e4 <eb_trim_cb+0x94>
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
setne  %al
mov    %al,-0x25(%rbp)
mov    -0x25(%rbp),%al
test   $0x1,%al
jne    1199 <eb_trim_cb+0x49>
movslq -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
cmp    %rcx,%rax
jbe    123d <eb_trim_cb+0xed>
mov    -0x8(%rbp),%rdi
call   1040 <evbuffer_get_contiguous_space@plt>
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
cmpl   $0x20,-0x24(%rbp)
jge    122b <eb_trim_cb+0xdb>
mov    $0x20,%eax
mov    %eax,-0x34(%rbp)
jmp    1231 <eb_trim_cb+0xe1>
mov    -0x24(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x34(%rbp),%esi
call   1060 <evbuffer_drain@plt>
jmp    1242 <eb_trim_cb+0xf2>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<eb_trim_cb>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
cmpq   $0x0,(%rsi)
je     11d2 <eb_trim_cb+0x82>
mov    %rdx,%r14
mov    %rdi,%rbx
call   1050 <evbuffer_get_length@plt>
mov    %eax,%ebp
cltq
cmp    %r14,%rax
jbe    11d2 <eb_trim_cb+0x82>
mov    0x2e70(%rip),%r15
nopl   0x0(%rax,%rax,1)
mov    (%r15),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1070 <evbuffer_readln@plt>
mov    %eax,%edi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1050 <evbuffer_get_length@plt>
movslq %eax,%rcx
cmp    %r14,%rcx
jbe    11a8 <eb_trim_cb+0x58>
cmp    %eax,%ebp
jne    1180 <eb_trim_cb+0x30>
cmp    %r14,%rcx
jbe    11d2 <eb_trim_cb+0x82>
mov    %rbx,%rdi
call   1040 <evbuffer_get_contiguous_space@plt>
cmp    $0x21,%eax
mov    $0x20,%esi
cmovge %eax,%esi
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <evbuffer_drain@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.evbuffer = type { i32 }
%struct.evbuffer_cb_info = type { i64 }
@EVBUFFER_EOL_CRLF = global i32 0
define void @eb_trim_cb(%struct.evbuffer* %0, %struct.evbuffer_cb_info* %1, i8* %2) {
%4 = alloca %struct.evbuffer*
%5 = alloca %struct.evbuffer_cb_info*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store %struct.evbuffer* %0, %struct.evbuffer** %4
store %struct.evbuffer_cb_info* %1, %struct.evbuffer_cb_info** %5
store i8* %2, i8** %6
%10 = load %struct.evbuffer_cb_info*, %struct.evbuffer_cb_info** %5
%11 = getelementptr inbounds %struct.evbuffer_cb_info, %struct.evbuffer_cb_info* %10, i32 0, i32 0
%12 = load i64, i64* %11
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %3
br label %62
15: ; preds = %3
%16 = load %struct.evbuffer*, %struct.evbuffer** %4
%17 = call i32 @evbuffer_get_length(%struct.evbuffer* %16)
store i32 %17, i32* %7
%18 = load i32, i32* %7
%19 = sext i32 %18 to i64
%20 = load i8*, i8** %6
%21 = ptrtoint i8* %20 to i64
%22 = icmp ugt i64 %19, %21
br i1 %22, label %23, label %62
23: ; preds = %15
br label %24
24: ; preds = %41, %23
%25 = load %struct.evbuffer*, %struct.evbuffer** %4
%26 = load i32, i32* @EVBUFFER_EOL_CRLF
%27 = call i32 @evbuffer_readln(%struct.evbuffer* %25, i32* null, i32 %26)
%28 = call i32 @free(i32 %27)
%29 = load %struct.evbuffer*, %struct.evbuffer** %4
%30 = call i32 @evbuffer_get_length(%struct.evbuffer* %29)
store i32 %30, i32* %8
br label %31
31: ; preds = %24
%32 = load i32, i32* %8
%33 = sext i32 %32 to i64
%34 = load i8*, i8** %6
%35 = ptrtoint i8* %34 to i64
%36 = icmp ugt i64 %33, %35
br i1 %36, label %37, label %41
37: ; preds = %31
%38 = load i32, i32* %7
%39 = load i32, i32* %8
%40 = icmp ne i32 %38, %39
br label %41
41: ; preds = %37, %31
%42 = phi i1 [ false, %31 ], [ %40, %37 ]
br i1 %42, label %24, label %43
43: ; preds = %41
%44 = load i32, i32* %8
%45 = sext i32 %44 to i64
%46 = load i8*, i8** %6
%47 = ptrtoint i8* %46 to i64
%48 = icmp ugt i64 %45, %47
br i1 %48, label %49, label %61
49: ; preds = %43
%50 = load %struct.evbuffer*, %struct.evbuffer** %4
%51 = call i32 @evbuffer_get_contiguous_space(%struct.evbuffer* %50)
store i32 %51, i32* %9
%52 = load %struct.evbuffer*, %struct.evbuffer** %4
%53 = load i32, i32* %9
%54 = icmp slt i32 %53, 32
br i1 %54, label %55, label %56
55: ; preds = %49
br label %58
56: ; preds = %49
%57 = load i32, i32* %9
br label %58
58: ; preds = %56, %55
%59 = phi i32 [ 32, %55 ], [ %57, %56 ]
%60 = call i32 @evbuffer_drain(%struct.evbuffer* %52, i32 %59)
br label %61
61: ; preds = %58, %43
br label %62
62: ; preds = %14, %61, %15
ret void
}

LLVM IR (-O2):
%struct.evbuffer = type { i32 }
%struct.evbuffer_cb_info = type { i64 }
@EVBUFFER_EOL_CRLF = global i32 0
define void @eb_trim_cb(%struct.evbuffer* %0, %struct.evbuffer_cb_info* nocapture %1, i8* %2) {
%4 = getelementptr inbounds %struct.evbuffer_cb_info, %struct.evbuffer_cb_info* %1, i64 0, i32 0
%5 = load i64, i64* %4
%6 = icmp eq i64 %5, 0
br i1 %6, label %27, label %7
7: ; preds = %3
%8 = tail call i32 @evbuffer_get_length(%struct.evbuffer* %0)
%9 = sext i32 %8 to i64
%10 = ptrtoint i8* %2 to i64
%11 = icmp ugt i64 %9, %10
br i1 %11, label %12, label %27
12: ; preds = %7, %12
%13 = load i32, i32* @EVBUFFER_EOL_CRLF
%14 = tail call i32 @evbuffer_readln(%struct.evbuffer* %0, i32* null, i32 %13)
%15 = tail call i32 @free(i32 %14)
%16 = tail call i32 @evbuffer_get_length(%struct.evbuffer* %0)
%17 = sext i32 %16 to i64
%18 = icmp ugt i64 %17, %10
%19 = icmp ne i32 %8, %16
%20 = select i1 %18, i1 %19, i1 false
br i1 %20, label %12, label %21
21: ; preds = %12
br i1 %18, label %22, label %27
22: ; preds = %21
%23 = tail call i32 @evbuffer_get_contiguous_space(%struct.evbuffer* %0)
%24 = icmp sgt i32 %23, 32
%25 = select i1 %24, i32 %23, i32 32
%26 = tail call i32 @evbuffer_drain(%struct.evbuffer* %0, i32 %25)
br label %27
27: ; preds = %7, %22, %21, %3
ret void
}