#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_header(char *buf, int response_len) {
  char *http_response, *http_header = NULL, *header_end;
  int header_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 ((header_end = strstr(http_response, "\r\n\r\n")) != NULL) {
      header_end += 4;
      header_len = header_end - http_response;
      http_header = (char *)http_malloc(header_len + 1);
      memcpy(http_header, http_response, header_len);
      http_header[header_len] = '\0';
    }
  }
  http_free(http_response);
  return http_header;
}


x86 assembly (clang, -O0):
<http_response_header>:
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    1219 <http_response_header+0xc9>
mov    -0x18(%rbp),%rdi
lea    0xe49(%rip),%rsi
call   1070 <strstr@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     1214 <http_response_header+0xc4>
mov    -0x28(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%edi
add    $0x1,%edi
call   1040 <http_malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x2c(%rbp),%edx
call   1060 <memcpy@plt>
mov    -0x20(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    1219 <http_response_header+0xc9>
mov    -0x18(%rbp),%rdi
call   1050 <http_free@plt>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<http_response_header>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %rdi,%r14
lea    0x1(%rbx),%edi
call   1040 <http_malloc@plt>
mov    %rax,%r12
mov    %rax,%rdi
mov    %r14,%rsi
mov    %ebx,%edx
call   1060 <memcpy@plt>
movslq %ebx,%rax
movb   $0x0,(%r12,%rax,1)
lea    0xe7c(%rip),%rsi
mov    %r12,%rdi
mov    $0x4,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     119b <http_response_header+0x4b>
xor    %r14d,%r14d
jmp    11db <http_response_header+0x8b>
lea    0xe63(%rip),%rsi
mov    %r12,%rdi
call   1070 <strstr@plt>
test   %rax,%rax
je     1196 <http_response_header+0x46>
mov    %rax,%r15
sub    %r12,%r15
add    $0x4,%r15
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)
mov    %r12,%rdi
call   1050 <http_free@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
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_header(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 %50
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 %49
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** %7
%32 = load i8*, i8** %5
%33 = ptrtoint i8* %31 to i64
%34 = ptrtoint i8* %32 to i64
%35 = sub i64 %33, %34
%36 = trunc i64 %35 to i32
store i32 %36, i32* %8
%37 = load i32, i32* %8
%38 = add nsw i32 %37, 1
%39 = call i64 @http_malloc(i32 %38)
%40 = inttoptr i64 %39 to i8*
store i8* %40, i8** %6
%41 = load i8*, i8** %6
%42 = load i8*, i8** %5
%43 = load i32, i32* %8
%44 = call i32 @memcpy(i8* %41, i8* %42, i32 %43)
%45 = load i8*, i8** %6
%46 = load i32, i32* %8
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i8, i8* %45, i64 %47
store i8 0, i8* %48
br label %49
49: ; preds = %28, %24
br label %50
50: ; preds = %49, %2
%51 = load i8*, i8** %5
%52 = call i32 @http_free(i8* %51)
%53 = load i8*, i8** %6
ret i8* %53
}

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_header(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 %26
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 %26, label %14
14: ; preds = %11
%15 = getelementptr inbounds i8, i8* %12, i64 4
%16 = ptrtoint i8* %15 to i64
%17 = sub i64 %16, %4
%18 = trunc i64 %17 to i32
%19 = add nsw i32 %18, 1
%20 = tail call i64 @http_malloc(i32 %19)
%21 = inttoptr i64 %20 to i8*
%22 = tail call i32 @memcpy(i8* %21, i8* %5, i32 %18)
%23 = shl i64 %17, 32
%24 = ashr exact i64 %23, 32
%25 = getelementptr inbounds i8, i8* %21, i64 %24
store i8 0, i8* %25
br label %26
26: ; preds = %11, %14, %2
%27 = phi i8* [ %21, %14 ], [ null, %11 ], [ null, %2 ]
%28 = tail call i32 @http_free(i8* %5)
ret i8* %27
}