#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*/ memcpy(char *, char *, size_t);
int /*<<< orphan*/ memset(char *, char, size_t);
int strlen(char *);
char *strstr(char *, char *);
int httpreq_copy_body(char *dest, char *src, size_t size) {
  char copy[size];
  memset(copy, '\0', size);
  memcpy(copy, src, size - 1);
  char *body_substr = strstr(copy, "\r\n\r\n");
  if (body_substr == NULL)
    return 0;
  memset(dest, '\0', size);
  memcpy(dest, &(body_substr[4]), size - 1);
  return strlen(dest);
}


x86 assembly (clang, -O0):
<httpreq_copy_body>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x48(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rdx
xor    %esi,%esi
call   1040 <memset@plt>
mov    -0x48(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
sub    $0x1,%rdx
call   1050 <memcpy@plt>
mov    -0x48(%rbp),%rdi
lea    0xe5a(%rip),%rsi
call   1060 <strstr@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    11cd <httpreq_copy_body+0x8d>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x3c(%rbp)
jmp    1208 <httpreq_copy_body+0xc8>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rdx
xor    %esi,%esi
call   1040 <memset@plt>
mov    -0x10(%rbp),%rdi
mov    -0x38(%rbp),%rsi
add    $0x4,%rsi
mov    -0x20(%rbp),%rdx
sub    $0x1,%rdx
call   1050 <memcpy@plt>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x3c(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<httpreq_copy_body>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r13
mov    %rsi,%rbx
mov    %rdi,-0x30(%rbp)
mov    %rsp,%r14
lea    0xf(%rdx),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
xor    %r12d,%r12d
mov    %r14,%rdi
xor    %esi,%esi
call   1040 <memset@plt>
lea    -0x1(%r13),%r15
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1050 <memcpy@plt>
lea    0xe71(%rip),%rsi
mov    %r14,%rdi
call   1060 <strstr@plt>
test   %rax,%rax
je     11cd <httpreq_copy_body+0x8d>
mov    %rax,%rbx
mov    -0x30(%rbp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    %r13,%rdx
call   1040 <memset@plt>
add    $0x4,%rbx
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1050 <memcpy@plt>
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %eax,%r12d
mov    %r12d,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"\0D\0A\0D\0A\00"
define i32 @httpreq_copy_body(i8* %0, i8* %1, i64 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i8*
%11 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i64 %2, i64* %7
%12 = load i64, i64* %7
%13 = call i8* @llvm.stacksave()
store i8* %13, i8** %8
%14 = alloca i8, i64 %12
store i64 %12, i64* %9
%15 = load i64, i64* %7
%16 = call i32 @memset(i8* %14, i8 signext 0, i64 %15)
%17 = load i8*, i8** %6
%18 = load i64, i64* %7
%19 = sub i64 %18, 1
%20 = call i32 @memcpy(i8* %14, i8* %17, i64 %19)
%21 = call i8* @strstr(i8* %14, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i8* %21, i8** %10
%22 = load i8*, i8** %10
%23 = icmp eq i8* %22, null
br i1 %23, label %24, label %25
24: ; preds = %3
store i32 0, i32* %4
store i32 1, i32* %11
br label %37
25: ; preds = %3
%26 = load i8*, i8** %5
%27 = load i64, i64* %7
%28 = call i32 @memset(i8* %26, i8 signext 0, i64 %27)
%29 = load i8*, i8** %5
%30 = load i8*, i8** %10
%31 = getelementptr inbounds i8, i8* %30, i64 4
%32 = load i64, i64* %7
%33 = sub i64 %32, 1
%34 = call i32 @memcpy(i8* %29, i8* %31, i64 %33)
%35 = load i8*, i8** %5
%36 = call i32 @strlen(i8* %35)
store i32 %36, i32* %4
store i32 1, i32* %11
br label %37
37: ; preds = %25, %24
%38 = load i8*, i8** %8
%39 = load i32, i32* %4
ret i32 %39
}

LLVM IR (-O2):
@.str = [5 x i8] c"\0D\0A\0D\0A\00"
define i32 @httpreq_copy_body(i8* %0, i8* %1, i64 %2) {
%4 = alloca i8, i64 %2
%5 = call i32 @memset(i8* %4, i8 signext 0, i64 %2)
%6 = add i64 %2, -1
%7 = call i32 @memcpy(i8* %4, i8* %1, i64 %6)
%8 = call i8* @strstr(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i8* %8, null
br i1 %9, label %15, label %10
10: ; preds = %3
%11 = call i32 @memset(i8* %0, i8 signext 0, i64 %2)
%12 = getelementptr inbounds i8, i8* %8, i64 4
%13 = call i32 @memcpy(i8* %0, i8* %12, i64 %6)
%14 = call i32 @strlen(i8* %0)
br label %15
15: ; preds = %3, %10
%16 = phi i32 [ %14, %10 ], [ 0, %3 ]
ret i32 %16
}