#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 */

/* Variables and functions */
int /*<<< orphan*/ http_free(char *);
scalar_t__ http_malloc(int);
int /*<<< orphan*/ memcpy(char *, char *, int);
scalar_t__ strncmp(char *, char *, int);
char *strstr(char *, char *);
char *http_response_body(char *buf, int response_len) {
  char *http_response, *http_body = NULL, *body_start;
  int body_len;
  http_response = (char *)http_malloc(response_len + 1);
  memcpy(http_response, buf, response_len);
  http_response[response_len] = '\0';
  if (strncmp(http_response, "HTTP", 4) == 0) {
    if ((body_start = strstr(http_response, "\r\n\r\n")) != NULL) {
      body_start += 4;
      body_len = http_response + response_len - body_start;
      if (body_len > 0) {
        http_body = (char *)http_malloc(body_len + 1);
        memcpy(http_body, body_start, body_len);
        http_body[body_len] = '\0';
      }
      http_free(http_response);
    } else {
      http_body = http_response;
    }
  } else {
    http_body = http_response;
  }
  return http_body;
}


x86 assembly (clang, -O0):
<http_response_body>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0xc(%rbp),%edi
add    $0x1,%edi
call   1040 <http_malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   1060 <memcpy@plt>
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rdi
lea    0xe63(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1240 <http_response_body+0xf0>
mov    -0x18(%rbp),%rdi
lea    0xe49(%rip),%rsi
call   1070 <strstr@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     1233 <http_response_body+0xe3>
mov    -0x28(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
add    %rcx,%rax
mov    -0x28(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jle    1225 <http_response_body+0xd5>
mov    -0x2c(%rbp),%edi
add    $0x1,%edi
call   1040 <http_malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x2c(%rbp),%edx
call   1060 <memcpy@plt>
mov    -0x20(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rdi
call   1050 <http_free@plt>
jmp    123b <http_response_body+0xeb>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    1248 <http_response_body+0xf8>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<http_response_body>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %esi,%ebx
mov    %rdi,%r14
lea    0x1(%rbx),%edi
call   1040 <http_malloc@plt>
mov    %rax,%r13
mov    %rax,%rdi
mov    %r14,%rsi
mov    %ebx,%edx
call   1060 <memcpy@plt>
movslq %ebx,%rbx
movb   $0x0,0x0(%r13,%rbx,1)
lea    0xe7a(%rip),%rsi
mov    %r13,%rdi
mov    $0x4,%edx
call   1030 <strncmp@plt>
mov    %r13,%r14
test   %rax,%rax
jne    11f8 <http_response_body+0xa8>
lea    0xe63(%rip),%rsi
mov    %r13,%rdi
call   1070 <strstr@plt>
test   %rax,%rax
je     11e8 <http_response_body+0x98>
mov    %rax,%r12
mov    %r13,%r15
add    %rbx,%r15
add    $0x4,%r12
sub    %r12,%r15
test   %r15d,%r15d
jle    11ed <http_response_body+0x9d>
lea    0x1(%r15),%edi
call   1040 <http_malloc@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    %r12,%rsi
mov    %r15d,%edx
call   1060 <memcpy@plt>
movslq %r15d,%rax
movb   $0x0,(%r14,%rax,1)
jmp    11f0 <http_response_body+0xa0>
mov    %r13,%r14
jmp    11f8 <http_response_body+0xa8>
xor    %r14d,%r14d
mov    %r13,%rdi
call   1050 <http_free@plt>
mov    %r14,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [5 x i8] c"HTTP\00"
@.str.1 = [5 x i8] c"\0D\0A\0D\0A\00"
define i8* @http_response_body(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
store i8* null, i8** %6
%9 = load i32, i32* %4
%10 = add nsw i32 %9, 1
%11 = call i64 @http_malloc(i32 %10)
%12 = inttoptr i64 %11 to i8*
store i8* %12, i8** %5
%13 = load i8*, i8** %5
%14 = load i8*, i8** %3
%15 = load i32, i32* %4
%16 = call i32 @memcpy(i8* %13, i8* %14, i32 %15)
%17 = load i8*, i8** %5
%18 = load i32, i32* %4
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %17, i64 %19
store i8 0, i8* %20
%21 = load i8*, i8** %5
%22 = call i64 @strncmp(i8* %21, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %61
24: ; preds = %2
%25 = load i8*, i8** %5
%26 = call i8* @strstr(i8* %25, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
store i8* %26, i8** %7
%27 = icmp ne i8* %26, null
br i1 %27, label %28, label %58
28: ; preds = %24
%29 = load i8*, i8** %7
%30 = getelementptr inbounds i8, i8* %29, i64 4
store i8* %30, i8** %7
%31 = load i8*, i8** %5
%32 = load i32, i32* %4
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %31, i64 %33
%35 = load i8*, i8** %7
%36 = ptrtoint i8* %34 to i64
%37 = ptrtoint i8* %35 to i64
%38 = sub i64 %36, %37
%39 = trunc i64 %38 to i32
store i32 %39, i32* %8
%40 = load i32, i32* %8
%41 = icmp sgt i32 %40, 0
br i1 %41, label %42, label %55
42: ; preds = %28
%43 = load i32, i32* %8
%44 = add nsw i32 %43, 1
%45 = call i64 @http_malloc(i32 %44)
%46 = inttoptr i64 %45 to i8*
store i8* %46, i8** %6
%47 = load i8*, i8** %6
%48 = load i8*, i8** %7
%49 = load i32, i32* %8
%50 = call i32 @memcpy(i8* %47, i8* %48, i32 %49)
%51 = load i8*, i8** %6
%52 = load i32, i32* %8
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i8, i8* %51, i64 %53
store i8 0, i8* %54
br label %55
55: ; preds = %42, %28
%56 = load i8*, i8** %5
%57 = call i32 @http_free(i8* %56)
br label %60
58: ; preds = %24
%59 = load i8*, i8** %5
store i8* %59, i8** %6
br label %60
60: ; preds = %58, %55
br label %63
61: ; preds = %2
%62 = load i8*, i8** %5
store i8* %62, i8** %6
br label %63
63: ; preds = %61, %60
%64 = load i8*, i8** %6
ret i8* %64
}

LLVM IR (-O2):
@.str = [5 x i8] c"HTTP\00"
@.str.1 = [5 x i8] c"\0D\0A\0D\0A\00"
define i8* @http_response_body(i8* %0, i32 %1) {
%3 = add nsw i32 %1, 1
%4 = tail call i64 @http_malloc(i32 %3)
%5 = inttoptr i64 %4 to i8*
%6 = tail call i32 @memcpy(i8* %5, i8* %0, i32 %1)
%7 = sext i32 %1 to i64
%8 = getelementptr inbounds i8, i8* %5, i64 %7
store i8 0, i8* %8
%9 = tail call i64 @strncmp(i8* %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %32
11: ; preds = %2
%12 = tail call i8* @strstr(i8* dereferenceable(1) %5, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%13 = icmp eq i8* %12, null
br i1 %13, label %32, label %14
14: ; preds = %11
%15 = getelementptr inbounds i8, i8* %12, i64 4
%16 = ptrtoint i8* %8 to i64
%17 = ptrtoint i8* %15 to i64
%18 = sub i64 %16, %17
%19 = trunc i64 %18 to i32
%20 = icmp sgt i32 %19, 0
br i1 %20, label %21, label %29
21: ; preds = %14
%22 = add nuw nsw i32 %19, 1
%23 = tail call i64 @http_malloc(i32 %22)
%24 = inttoptr i64 %23 to i8*
%25 = tail call i32 @memcpy(i8* %24, i8* %15, i32 %19)
%26 = shl i64 %18, 32
%27 = ashr exact i64 %26, 32
%28 = getelementptr inbounds i8, i8* %24, i64 %27
store i8 0, i8* %28
br label %29
29: ; preds = %21, %14
%30 = phi i8* [ %24, %21 ], [ null, %14 ]
%31 = tail call i32 @http_free(i8* %5)
br label %32
32: ; preds = %2, %11, %29
%33 = phi i8* [ %30, %29 ], [ %5, %11 ], [ %5, %2 ]
ret i8* %33
}