#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 atoi(char *);
int strlen(char *);
char *strstr(char *, char *);
int http_get_content_length(char *revbuf) {
  char *p1 = NULL, *p2 = NULL;
  int http_body = 0;
  p1 = strstr(revbuf, "Content-Length");
  if (p1 == NULL) {
    return -2;
  } else {
    p2 = p1 + strlen("Content-Length") + 2;
    http_body = atoi(p2);
    return http_body;
  }
}


x86 assembly (clang, -O0):
<http_get_content_length>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xea2(%rip),%rsi
call   1050 <strstr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    117e <http_get_content_length+0x4e>
movl   $0xfffffffe,-0x4(%rbp)
jmp    11b8 <http_get_content_length+0x88>
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
lea    0xe73(%rip),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
add    $0x2,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <atoi@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<http_get_content_length>:
push   %rbx
lea    0xec8(%rip),%rsi
call   1050 <strstr@plt>
test   %rax,%rax
je     1161 <http_get_content_length+0x31>
mov    %rax,%rbx
lea    0xeb4(%rip),%rdi
call   1030 <strlen@plt>
cltq
lea    (%rbx,%rax,1),%rdi
add    $0x2,%rdi
pop    %rbx
jmp    1040 <atoi@plt>
mov    $0xfffffffe,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [15 x i8] c"Content-Length\00"
define i32 @http_get_content_length(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
store i8* %0, i8** %3
store i8* null, i8** %4
store i8* null, i8** %5
store i32 0, i32* %6
%7 = load i8*, i8** %3
%8 = call i8* @strstr(i8* %7, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
store i8* %8, i8** %4
%9 = load i8*, i8** %4
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %12
11: ; preds = %1
store i32 -2, i32* %2
br label %21
12: ; preds = %1
%13 = load i8*, i8** %4
%14 = call i32 @strlen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %13, i64 %15
%17 = getelementptr inbounds i8, i8* %16, i64 2
store i8* %17, i8** %5
%18 = load i8*, i8** %5
%19 = call i32 @atoi(i8* %18)
store i32 %19, i32* %6
%20 = load i32, i32* %6
store i32 %20, i32* %2
br label %21
21: ; preds = %12, %11
%22 = load i32, i32* %2
ret i32 %22
}

LLVM IR (-O2):
@.str = [15 x i8] c"Content-Length\00"
define i32 @http_get_content_length(i8* %0) {
%2 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i8* %2, null
br i1 %3, label %10, label %4
4: ; preds = %1
%5 = tail call i32 @strlen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%6 = sext i32 %5 to i64
%7 = getelementptr inbounds i8, i8* %2, i64 %6
%8 = getelementptr inbounds i8, i8* %7, i64 2
%9 = tail call i32 @atoi(i8* %8)
br label %10
10: ; preds = %1, %4
%11 = phi i32 [ %9, %4 ], [ -2, %1 ]
ret i32 %11
}