#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 reader_thread {
  int dummy;
};
struct evhttp_request {
  scalar_t__ response_code;
  int /*<<< orphan*/ input_buffer;
};

/* Variables and functions */
size_t EVBUFFER_LENGTH(int /*<<< orphan*/);
scalar_t__ HTTP_OK;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, scalar_t__);
int /*<<< orphan*/ process_message(struct reader_thread *, size_t);
int /*<<< orphan*/ stderr;
void on_http_message_chunk(struct evhttp_request *req, void *ptr) {
  struct reader_thread *rt = ptr;
  if (req->response_code == HTTP_OK) {
    size_t sz = EVBUFFER_LENGTH(req->input_buffer);
    process_message(rt, sz);
  } else {
    fprintf(stderr, "CHUNK FAIL (ret=%d)\n", req->response_code);
  }
}


x86 assembly (clang, -O0):
<on_http_message_chunk>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    0x2e8a(%rip),%rcx
cmp    (%rcx),%rax
jne    1181 <on_http_message_chunk+0x51>
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%edi
call   1050 <EVBUFFER_LENGTH@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <process_message@plt>
jmp    119d <on_http_message_chunk+0x6d>
mov    0x2e50(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rax
mov    (%rax),%rdx
lea    0xe68(%rip),%rsi
call   1040 <fprintf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<on_http_message_chunk>:
push   %rbx
mov    (%rdi),%rdx
mov    0x2ea5(%rip),%rax
cmp    (%rax),%rdx
jne    1157 <on_http_message_chunk+0x27>
mov    %rsi,%rbx
mov    0x8(%rdi),%edi
call   1050 <EVBUFFER_LENGTH@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
pop    %rbx
jmp    1030 <process_message@plt>
mov    0x2e7a(%rip),%rax
mov    (%rax),%edi
lea    0xe99(%rip),%rsi
pop    %rbx
jmp    1040 <fprintf@plt>

LLVM IR (-O0):
%struct.evhttp_request = type { i64, i32 }
%struct.reader_thread = type { i32 }
@HTTP_OK = global i64 0
@stderr = global i32 0
@.str = [21 x i8] c"CHUNK FAIL (ret=%d)\0A\00"
define void @on_http_message_chunk(%struct.evhttp_request* %0, i8* %1) {
%3 = alloca %struct.evhttp_request*
%4 = alloca i8*
%5 = alloca %struct.reader_thread*
%6 = alloca i64
store %struct.evhttp_request* %0, %struct.evhttp_request** %3
store i8* %1, i8** %4
%7 = load i8*, i8** %4
%8 = bitcast i8* %7 to %struct.reader_thread*
store %struct.reader_thread* %8, %struct.reader_thread** %5
%9 = load %struct.evhttp_request*, %struct.evhttp_request** %3
%10 = getelementptr inbounds %struct.evhttp_request, %struct.evhttp_request* %9, i32 0, i32 0
%11 = load i64, i64* %10
%12 = load i64, i64* @HTTP_OK
%13 = icmp eq i64 %11, %12
br i1 %13, label %14, label %22
14: ; preds = %2
%15 = load %struct.evhttp_request*, %struct.evhttp_request** %3
%16 = getelementptr inbounds %struct.evhttp_request, %struct.evhttp_request* %15, i32 0, i32 1
%17 = load i32, i32* %16
%18 = call i64 @EVBUFFER_LENGTH(i32 %17)
store i64 %18, i64* %6
%19 = load %struct.reader_thread*, %struct.reader_thread** %5
%20 = load i64, i64* %6
%21 = call i32 @process_message(%struct.reader_thread* %19, i64 %20)
br label %28
22: ; preds = %2
%23 = load i32, i32* @stderr
%24 = load %struct.evhttp_request*, %struct.evhttp_request** %3
%25 = getelementptr inbounds %struct.evhttp_request, %struct.evhttp_request* %24, i32 0, i32 0
%26 = load i64, i64* %25
%27 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i64 %26)
br label %28
28: ; preds = %22, %14
ret void
}

LLVM IR (-O2):
%struct.evhttp_request = type { i64, i32 }
%struct.reader_thread = type { i32 }
@HTTP_OK = global i64 0
@stderr = global i32 0
@.str = [21 x i8] c"CHUNK FAIL (ret=%d)\0A\00"
define void @on_http_message_chunk(%struct.evhttp_request* nocapture %0, i8* %1) {
%3 = getelementptr inbounds %struct.evhttp_request, %struct.evhttp_request* %0, i64 0, i32 0
%4 = load i64, i64* %3
%5 = load i64, i64* @HTTP_OK
%6 = icmp eq i64 %4, %5
br i1 %6, label %7, label %13
7: ; preds = %2
%8 = bitcast i8* %1 to %struct.reader_thread*
%9 = getelementptr inbounds %struct.evhttp_request, %struct.evhttp_request* %0, i64 0, i32 1
%10 = load i32, i32* %9
%11 = tail call i64 @EVBUFFER_LENGTH(i32 %10)
%12 = tail call i32 @process_message(%struct.reader_thread* %8, i64 %11)
br label %16
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = tail call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i64 %4)
br label %16
16: ; preds = %13, %7
ret void
}