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

/* Variables and functions */
scalar_t__ EVHTTP_REQ_POST;
size_t evbuffer_get_length(struct evbuffer *);
int /*<<< orphan*/ evbuffer_remove(struct evbuffer *, char *, size_t);
scalar_t__ evhttp_request_get_command(struct evhttp_request *);
struct evbuffer *evhttp_request_get_input_buffer(struct evhttp_request *);
char *malloc(size_t);
char *get_POST_str(struct evhttp_request *req) {
  struct evbuffer *buf;
  size_t len;
  char *cbuf;
  if (evhttp_request_get_command(req) != EVHTTP_REQ_POST) {
    return NULL;
  }
  buf = evhttp_request_get_input_buffer(req);
  len = evbuffer_get_length(buf);
  if (len == 0)
    return NULL;
  cbuf = malloc(len + 1);
  if (cbuf == NULL)
    return NULL;
  evbuffer_remove(buf, cbuf, len);
  cbuf[len] = '\0';
  return cbuf;
}


x86 assembly (clang, -O0):
<get_POST_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <evhttp_request_get_command@plt>
mov    0x2e7c(%rip),%rcx
cmp    (%rcx),%rax
je     1182 <get_POST_str+0x32>
movq   $0x0,-0x8(%rbp)
jmp    1202 <get_POST_str+0xb2>
mov    -0x10(%rbp),%rdi
call   1070 <evhttp_request_get_input_buffer@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <evbuffer_get_length@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11b4 <get_POST_str+0x64>
movq   $0x0,-0x8(%rbp)
jmp    1202 <get_POST_str+0xb2>
mov    -0x20(%rbp),%rdi
add    $0x1,%rdi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11dd <get_POST_str+0x8d>
movq   $0x0,-0x8(%rbp)
jmp    1202 <get_POST_str+0xb2>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1040 <evbuffer_remove@plt>
mov    -0x28(%rbp),%rax
mov    -0x20(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_POST_str>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%rbx
call   1030 <evhttp_request_get_command@plt>
mov    0x2e84(%rip),%rcx
cmp    (%rcx),%rax
jne    11aa <get_POST_str+0x5a>
mov    %rbx,%rdi
call   1070 <evhttp_request_get_input_buffer@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   1060 <evbuffer_get_length@plt>
test   %rax,%rax
je     11aa <get_POST_str+0x5a>
mov    %rax,%r15
lea    0x1(%rax),%rdi
call   1050 <malloc@plt>
test   %rax,%rax
je     11aa <get_POST_str+0x5a>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %rax,%rsi
mov    %r15,%rdx
call   1040 <evbuffer_remove@plt>
movb   $0x0,(%rbx,%r15,1)
jmp    11ac <get_POST_str+0x5c>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.evhttp_request = type { i32 }
%struct.evbuffer = type { i32 }
@EVHTTP_REQ_POST = global i64 0
define i8* @get_POST_str(%struct.evhttp_request* %0) {
%2 = alloca i8*
%3 = alloca %struct.evhttp_request*
%4 = alloca %struct.evbuffer*
%5 = alloca i64
%6 = alloca i8*
store %struct.evhttp_request* %0, %struct.evhttp_request** %3
%7 = load %struct.evhttp_request*, %struct.evhttp_request** %3
%8 = call i64 @evhttp_request_get_command(%struct.evhttp_request* %7)
%9 = load i64, i64* @EVHTTP_REQ_POST
%10 = icmp ne i64 %8, %9
br i1 %10, label %11, label %12
11: ; preds = %1
store i8* null, i8** %2
br label %36
12: ; preds = %1
%13 = load %struct.evhttp_request*, %struct.evhttp_request** %3
%14 = call %struct.evbuffer* @evhttp_request_get_input_buffer(%struct.evhttp_request* %13)
store %struct.evbuffer* %14, %struct.evbuffer** %4
%15 = load %struct.evbuffer*, %struct.evbuffer** %4
%16 = call i64 @evbuffer_get_length(%struct.evbuffer* %15)
store i64 %16, i64* %5
%17 = load i64, i64* %5
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %12
store i8* null, i8** %2
br label %36
20: ; preds = %12
%21 = load i64, i64* %5
%22 = add i64 %21, 1
%23 = call i8* @malloc(i64 %22)
store i8* %23, i8** %6
%24 = load i8*, i8** %6
%25 = icmp eq i8* %24, null
br i1 %25, label %26, label %27
26: ; preds = %20
store i8* null, i8** %2
br label %36
27: ; preds = %20
%28 = load %struct.evbuffer*, %struct.evbuffer** %4
%29 = load i8*, i8** %6
%30 = load i64, i64* %5
%31 = call i32 @evbuffer_remove(%struct.evbuffer* %28, i8* %29, i64 %30)
%32 = load i8*, i8** %6
%33 = load i64, i64* %5
%34 = getelementptr inbounds i8, i8* %32, i64 %33
store i8 0, i8* %34
%35 = load i8*, i8** %6
store i8* %35, i8** %2
br label %36
36: ; preds = %27, %26, %19, %11
%37 = load i8*, i8** %2
ret i8* %37
}

LLVM IR (-O2):
%struct.evhttp_request = type { i32 }
%struct.evbuffer = type { i32 }
@EVHTTP_REQ_POST = global i64 0
define i8* @get_POST_str(%struct.evhttp_request* %0) {
%2 = tail call i64 @evhttp_request_get_command(%struct.evhttp_request* %0)
%3 = load i64, i64* @EVHTTP_REQ_POST
%4 = icmp eq i64 %2, %3
br i1 %4, label %5, label %16
5: ; preds = %1
%6 = tail call %struct.evbuffer* @evhttp_request_get_input_buffer(%struct.evhttp_request* %0)
%7 = tail call i64 @evbuffer_get_length(%struct.evbuffer* %6)
%8 = icmp eq i64 %7, 0
br i1 %8, label %16, label %9
9: ; preds = %5
%10 = add i64 %7, 1
%11 = tail call i8* @malloc(i64 %10)
%12 = icmp eq i8* %11, null
br i1 %12, label %16, label %13
13: ; preds = %9
%14 = tail call i32 @evbuffer_remove(%struct.evbuffer* %6, i8* %11, i64 %7)
%15 = getelementptr inbounds i8, i8* %11, i64 %7
store i8 0, i8* %15
br label %16
16: ; preds = %9, %5, %1, %13
%17 = phi i8* [ %11, %13 ], [ null, %1 ], [ null, %5 ], [ null, %9 ]
ret i8* %17
}