#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 strlen(char *);
char *strstr(char const *, char *);
scalar_t__ strtol(char *, int /*<<< orphan*/ *, int);
unsigned short get_content_length(const char *buffer) {
  char *cl_start = strstr(buffer, "\r\nCONTENT-LENGTH:");
  if (!cl_start) {
    return 0;
  }
  return (unsigned short)strtol(cl_start + strlen("\r\nCONTENT-LENGTH:"), NULL,
                                10);
}


x86 assembly (clang, -O0):
<get_content_length>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xeb9(%rip),%rsi
call   1050 <strstr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1166 <get_content_length+0x36>
movw   $0x0,-0x2(%rbp)
jmp    1195 <get_content_length+0x65>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
lea    0xe8b(%rip),%rdi
call   1030 <strlen@plt>
mov    -0x20(%rbp),%rdi
cltq
add    %rax,%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %ax,-0x2(%rbp)
movzwl -0x2(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_content_length>:
push   %rbx
lea    0xec8(%rip),%rsi
call   1050 <strstr@plt>
test   %rax,%rax
je     1167 <get_content_length+0x37>
mov    %rax,%rbx
lea    0xeb4(%rip),%rdi
call   1030 <strlen@plt>
cltq
add    %rax,%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1040 <strtol@plt>
pop    %rbx
ret
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [18 x i8] c"\0D\0ACONTENT-LENGTH:\00"
define zeroext i16 @get_content_length(i8* %0) {
%2 = alloca i16
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = call i8* @strstr(i8* %5, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
store i8* %6, i8** %4
%7 = load i8*, i8** %4
%8 = icmp ne i8* %7, null
br i1 %8, label %10, label %9
9: ; preds = %1
store i16 0, i16* %2
br label %17
10: ; preds = %1
%11 = load i8*, i8** %4
%12 = call i32 @strlen(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %11, i64 %13
%15 = call i64 @strtol(i8* %14, i32* null, i32 10)
%16 = trunc i64 %15 to i16
store i16 %16, i16* %2
br label %17
17: ; preds = %10, %9
%18 = load i16, i16* %2
ret i16 %18
}

LLVM IR (-O2):
@.str = [18 x i8] c"\0D\0ACONTENT-LENGTH:\00"
define zeroext i16 @get_content_length(i8* %0) {
%2 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 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 ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%6 = sext i32 %5 to i64
%7 = getelementptr inbounds i8, i8* %2, i64 %6
%8 = tail call i64 @strtol(i8* nocapture %7, i32* null, i32 10)
%9 = trunc i64 %8 to i16
br label %10
10: ; preds = %1, %4
%11 = phi i16 [ %9, %4 ], [ 0, %1 ]
ret i16 %11
}