#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;
};
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ EVBUFFER_EOL_LF;
struct evbuffer *bufferevent_get_input(struct bufferevent *);
struct evbuffer *bufferevent_get_output(struct bufferevent *);
int /*<<< orphan*/ evbuffer_add(struct evbuffer *, char *, int);
int evbuffer_get_length(struct evbuffer *);
char *evbuffer_readln(struct evbuffer *, size_t *, int /*<<< orphan*/);
int evbuffer_remove(struct evbuffer *, char *, int);
int /*<<< orphan*/ free(char *);
char rot13_char(char);
void readcb(struct bufferevent *bev, void *ctx) {
  struct evbuffer *input, *output;
  char *line;
  size_t n;
  int i;
  input = bufferevent_get_input(bev);
  output = bufferevent_get_output(bev);
  while ((line = evbuffer_readln(input, &n, EVBUFFER_EOL_LF))) {
    for (i = 0; i < n; ++i)
      line[i] = rot13_char(line[i]);
    evbuffer_add(output, line, n);
    evbuffer_add(output, "\n", 1);
    free(line);
  }
  if (evbuffer_get_length(input) >= 16384) {
    char buf[1024];
    while (evbuffer_get_length(input)) {
      int n = evbuffer_remove(input, buf, sizeof(buf));
      for (i = 0; i < n; ++i)
        buf[i] = rot13_char(buf[i]);
      evbuffer_add(output, buf, n);
    }
    evbuffer_add(output, "\n", 1);
  }
}


x86 assembly (clang, -O0):
<readcb>:
push   %rbp
mov    %rsp,%rbp
sub    $0x450,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <bufferevent_get_input@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <bufferevent_get_output@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2e30(%rip),%rax
mov    (%rax),%edx
lea    -0x30(%rbp),%rsi
call   10a0 <evbuffer_readln@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     1248 <readcb+0xc8>
movl   $0x0,-0x34(%rbp)
movslq -0x34(%rbp),%rax
cmp    -0x30(%rbp),%rax
jae    1212 <readcb+0x92>
mov    -0x28(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1070 <rot13_char@plt>
mov    %al,%dl
mov    -0x28(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11d8 <readcb+0x58>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%rax
mov    %eax,%edx
call   1080 <evbuffer_add@plt>
mov    -0x20(%rbp),%rdi
lea    0xdd0(%rip),%rsi
mov    $0x1,%edx
call   1080 <evbuffer_add@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
jmp    11ad <readcb+0x2d>
mov    -0x18(%rbp),%rdi
call   1090 <evbuffer_get_length@plt>
cmp    $0x4000,%eax
jl     1300 <readcb+0x180>
jmp    1261 <readcb+0xe1>
mov    -0x18(%rbp),%rdi
call   1090 <evbuffer_get_length@plt>
cmp    $0x0,%eax
je     12eb <readcb+0x16b>
mov    -0x18(%rbp),%rdi
lea    -0x440(%rbp),%rsi
mov    $0x400,%edx
call   1040 <evbuffer_remove@plt>
mov    %eax,-0x444(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x444(%rbp),%eax
jge    12d0 <readcb+0x150>
movslq -0x34(%rbp),%rax
movsbl -0x440(%rbp,%rax,1),%edi
ff
call   1070 <rot13_char@plt>
mov    %al,%cl
movslq -0x34(%rbp),%rax
mov    %cl,-0x440(%rbp,%rax,1)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1295 <readcb+0x115>
mov    -0x20(%rbp),%rdi
lea    -0x440(%rbp),%rsi
mov    -0x444(%rbp),%edx
call   1080 <evbuffer_add@plt>
jmp    1261 <readcb+0xe1>
mov    -0x20(%rbp),%rdi
lea    0xd0a(%rip),%rsi
mov    $0x1,%edx
call   1080 <evbuffer_add@plt>
add    $0x450,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readcb>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x418,%rsp
mov    %rdi,%rbx
call   1060 <bufferevent_get_input@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1050 <bufferevent_get_output@plt>
mov    %rax,%r13
mov    0x2e3a(%rip),%rax
mov    (%rax),%edx
lea    0x8(%rsp),%rsi
mov    %r14,%rdi
call   10a0 <evbuffer_readln@plt>
test   %rax,%rax
je     124c <readcb+0xcc>
mov    %rax,%rbx
lea    0xe30(%rip),%r15
lea    0x8(%rsp),%r12
jmp    1221 <readcb+0xa1>
nopw   0x0(%rax,%rax,1)
xor    %edx,%edx
mov    %r13,%rdi
mov    %rbx,%rsi
call   1080 <evbuffer_add@plt>
mov    %r13,%rdi
mov    %r15,%rsi
mov    $0x1,%edx
call   1080 <evbuffer_add@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    0x2ddc(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
mov    %r12,%rsi
call   10a0 <evbuffer_readln@plt>
mov    %rax,%rbx
test   %rax,%rax
je     124c <readcb+0xcc>
cmpq   $0x0,0x8(%rsp)
je     11e0 <readcb+0x60>
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
movsbl (%rbx,%rbp,1),%edi
call   1070 <rot13_char@plt>
mov    %al,(%rbx,%rbp,1)
add    $0x1,%rbp
mov    0x8(%rsp),%rdx
cmp    %rbp,%rdx
ja     1230 <readcb+0xb0>
jmp    11e2 <readcb+0x62>
mov    %r14,%rdi
call   1090 <evbuffer_get_length@plt>
cmp    $0x4000,%eax
jl     12ed <readcb+0x16d>
mov    %r14,%rdi
call   1090 <evbuffer_get_length@plt>
test   %eax,%eax
je     12d9 <readcb+0x159>
lea    0x10(%rsp),%r15
jmp    129a <readcb+0x11a>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r13,%rdi
mov    %r15,%rsi
mov    %r12d,%edx
call   1080 <evbuffer_add@plt>
mov    %r14,%rdi
call   1090 <evbuffer_get_length@plt>
test   %eax,%eax
je     12d9 <readcb+0x159>
mov    %r14,%rdi
mov    %r15,%rsi
mov    $0x400,%edx
call   1040 <evbuffer_remove@plt>
mov    %eax,%r12d
test   %eax,%eax
jle    1280 <readcb+0x100>
mov    %r12d,%ebx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
movsbl 0x10(%rsp,%rbp,1),%edi
call   1070 <rot13_char@plt>
mov    %al,0x10(%rsp,%rbp,1)
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    12c0 <readcb+0x140>
jmp    1280 <readcb+0x100>
lea    0xd20(%rip),%rsi
mov    %r13,%rdi
mov    $0x1,%edx
call   1080 <evbuffer_add@plt>
add    $0x418,%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 }
@EVBUFFER_EOL_LF = global i32 0
@.str = [2 x i8] c"\0A\00"
define void @readcb(%struct.bufferevent* %0, i8* %1) {
%3 = alloca %struct.bufferevent*
%4 = alloca i8*
%5 = alloca %struct.evbuffer*
%6 = alloca %struct.evbuffer*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32
%10 = alloca [1024 x i8]
%11 = alloca i32
store %struct.bufferevent* %0, %struct.bufferevent** %3
store i8* %1, i8** %4
%12 = load %struct.bufferevent*, %struct.bufferevent** %3
%13 = call %struct.evbuffer* @bufferevent_get_input(%struct.bufferevent* %12)
store %struct.evbuffer* %13, %struct.evbuffer** %5
%14 = load %struct.bufferevent*, %struct.bufferevent** %3
%15 = call %struct.evbuffer* @bufferevent_get_output(%struct.bufferevent* %14)
store %struct.evbuffer* %15, %struct.evbuffer** %6
br label %16
16: ; preds = %41, %2
%17 = load %struct.evbuffer*, %struct.evbuffer** %5
%18 = load i32, i32* @EVBUFFER_EOL_LF
%19 = call i8* @evbuffer_readln(%struct.evbuffer* %17, i64* %8, i32 %18)
store i8* %19, i8** %7
%20 = icmp ne i8* %19, null
br i1 %20, label %21, label %51
21: ; preds = %16
store i32 0, i32* %9
br label %22
22: ; preds = %38, %21
%23 = load i32, i32* %9
%24 = sext i32 %23 to i64
%25 = load i64, i64* %8
%26 = icmp ult i64 %24, %25
br i1 %26, label %27, label %41
27: ; preds = %22
%28 = load i8*, i8** %7
%29 = load i32, i32* %9
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %28, i64 %30
%32 = load i8, i8* %31
%33 = call signext i8 @rot13_char(i8 signext %32)
%34 = load i8*, i8** %7
%35 = load i32, i32* %9
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %34, i64 %36
store i8 %33, i8* %37
br label %38
38: ; preds = %27
%39 = load i32, i32* %9
%40 = add nsw i32 %39, 1
store i32 %40, i32* %9
br label %22
41: ; preds = %22
%42 = load %struct.evbuffer*, %struct.evbuffer** %6
%43 = load i8*, i8** %7
%44 = load i64, i64* %8
%45 = trunc i64 %44 to i32
%46 = call i32 @evbuffer_add(%struct.evbuffer* %42, i8* %43, i32 %45)
%47 = load %struct.evbuffer*, %struct.evbuffer** %6
%48 = call i32 @evbuffer_add(%struct.evbuffer* %47, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1)
%49 = load i8*, i8** %7
%50 = call i32 @free(i8* %49)
br label %16
51: ; preds = %16
%52 = load %struct.evbuffer*, %struct.evbuffer** %5
%53 = call i32 @evbuffer_get_length(%struct.evbuffer* %52)
%54 = icmp sge i32 %53, 16384
br i1 %54, label %55, label %88
55: ; preds = %51
br label %56
56: ; preds = %80, %55
%57 = load %struct.evbuffer*, %struct.evbuffer** %5
%58 = call i32 @evbuffer_get_length(%struct.evbuffer* %57)
%59 = icmp ne i32 %58, 0
br i1 %59, label %60, label %85
60: ; preds = %56
%61 = load %struct.evbuffer*, %struct.evbuffer** %5
%62 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%63 = call i32 @evbuffer_remove(%struct.evbuffer* %61, i8* %62, i32 1024)
store i32 %63, i32* %11
store i32 0, i32* %9
br label %64
64: ; preds = %77, %60
%65 = load i32, i32* %9
%66 = load i32, i32* %11
%67 = icmp slt i32 %65, %66
br i1 %67, label %68, label %80
68: ; preds = %64
%69 = load i32, i32* %9
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 %70
%72 = load i8, i8* %71
%73 = call signext i8 @rot13_char(i8 signext %72)
%74 = load i32, i32* %9
%75 = sext i32 %74 to i64
%76 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 %75
store i8 %73, i8* %76
br label %77
77: ; preds = %68
%78 = load i32, i32* %9
%79 = add nsw i32 %78, 1
store i32 %79, i32* %9
br label %64
80: ; preds = %64
%81 = load %struct.evbuffer*, %struct.evbuffer** %6
%82 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%83 = load i32, i32* %11
%84 = call i32 @evbuffer_add(%struct.evbuffer* %81, i8* %82, i32 %83)
br label %56
85: ; preds = %56
%86 = load %struct.evbuffer*, %struct.evbuffer** %6
%87 = call i32 @evbuffer_add(%struct.evbuffer* %86, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1)
br label %88
88: ; preds = %85, %51
ret void
}

LLVM IR (-O2):
%struct.bufferevent = type { i32 }
%struct.evbuffer = type { i32 }
@EVBUFFER_EOL_LF = global i32 0
@.str = [2 x i8] c"\0A\00"
define void @readcb(%struct.bufferevent* %0, i8* nocapture readnone %1) {
%3 = alloca i64
%4 = alloca [1024 x i8]
%5 = bitcast i64* %3 to i8*
%6 = tail call %struct.evbuffer* @bufferevent_get_input(%struct.bufferevent* %0)
%7 = tail call %struct.evbuffer* @bufferevent_get_output(%struct.bufferevent* %0)
%8 = load i32, i32* @EVBUFFER_EOL_LF
%9 = call i8* @evbuffer_readln(%struct.evbuffer* %6, i64* %3, i32 %8)
%10 = icmp eq i8* %9, null
br i1 %10, label %32, label %11
11: ; preds = %2, %23
%12 = phi i8* [ %30, %23 ], [ %9, %2 ]
%13 = load i64, i64* %3
%14 = icmp eq i64 %13, 0
br i1 %14, label %23, label %15
15: ; preds = %11, %15
%16 = phi i64 [ %20, %15 ], [ 0, %11 ]
%17 = getelementptr inbounds i8, i8* %12, i64 %16
%18 = load i8, i8* %17
%19 = call signext i8 @rot13_char(i8 signext %18)
store i8 %19, i8* %17
%20 = add nuw i64 %16, 1
%21 = load i64, i64* %3
%22 = icmp ugt i64 %21, %20
br i1 %22, label %15, label %23
23: ; preds = %15, %11
%24 = phi i64 [ 0, %11 ], [ %21, %15 ]
%25 = trunc i64 %24 to i32
%26 = call i32 @evbuffer_add(%struct.evbuffer* %7, i8* %12, i32 %25)
%27 = call i32 @evbuffer_add(%struct.evbuffer* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1)
%28 = call i32 @free(i8* %12)
%29 = load i32, i32* @EVBUFFER_EOL_LF
%30 = call i8* @evbuffer_readln(%struct.evbuffer* %6, i64* %3, i32 %29)
%31 = icmp eq i8* %30, null
br i1 %31, label %32, label %11
32: ; preds = %23, %2
%33 = call i32 @evbuffer_get_length(%struct.evbuffer* %6)
%34 = icmp sgt i32 %33, 16383
br i1 %34, label %35, label %57
35: ; preds = %32
%36 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%37 = call i32 @evbuffer_get_length(%struct.evbuffer* %6)
%38 = icmp eq i32 %37, 0
br i1 %38, label %55, label %39
39: ; preds = %35, %51
%40 = call i32 @evbuffer_remove(%struct.evbuffer* %6, i8* %36, i32 1024)
%41 = icmp sgt i32 %40, 0
br i1 %41, label %42, label %51
42: ; preds = %39
%43 = zext i32 %40 to i64
br label %44
44: ; preds = %42, %44
%45 = phi i64 [ 0, %42 ], [ %49, %44 ]
%46 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 %45
%47 = load i8, i8* %46
%48 = call signext i8 @rot13_char(i8 signext %47)
store i8 %48, i8* %46
%49 = add nuw nsw i64 %45, 1
%50 = icmp eq i64 %49, %43
br i1 %50, label %51, label %44
51: ; preds = %44, %39
%52 = call i32 @evbuffer_add(%struct.evbuffer* %7, i8* %36, i32 %40)
%53 = call i32 @evbuffer_get_length(%struct.evbuffer* %6)
%54 = icmp eq i32 %53, 0
br i1 %54, label %55, label %39
55: ; preds = %51, %35
%56 = call i32 @evbuffer_add(%struct.evbuffer* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1)
br label %57
57: ; preds = %55, %32
ret void
}