#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 */
scalar_t__ atoi(char *);
scalar_t__ strlen(char *);
scalar_t__ strncmp(char *, char *, short);
int sip_msg_is_response(char *buffer) {
  short size = strlen((char *)"SIP/2.0");
  if (buffer && strlen((char *)buffer) > 0 &&
      strncmp(buffer, "SIP/2.0", size) == 0) {
    return (int)atoi(buffer + size + 1);
  }
  return (int)-1;
}


x86 assembly (clang, -O0):
<sip_msg_is_response>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
lea    0xebd(%rip),%rdi
call   1040 <strlen@plt>
mov    %ax,-0x12(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11a6 <sip_msg_is_response+0x76>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x0,%rax
jle    11a6 <sip_msg_is_response+0x76>
mov    -0x10(%rbp),%rdi
lea    0xe8b(%rip),%rsi
movswl -0x12(%rbp),%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    11a6 <sip_msg_is_response+0x76>
mov    -0x10(%rbp),%rdi
movswl -0x12(%rbp),%eax
cltq
add    %rax,%rdi
add    $0x1,%rdi
call   1050 <atoi@plt>
mov    %eax,-0x4(%rbp)
jmp    11ad <sip_msg_is_response+0x7d>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sip_msg_is_response>:
push   %r14
push   %rbx
push   %rax
mov    $0xffffffff,%r14d
test   %rdi,%rdi
je     1174 <sip_msg_is_response+0x44>
mov    %rdi,%rbx
call   1040 <strlen@plt>
test   %rax,%rax
jle    1174 <sip_msg_is_response+0x44>
lea    0xead(%rip),%rsi
mov    %rbx,%rdi
mov    $0x7,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    1174 <sip_msg_is_response+0x44>
add    $0x8,%rbx
mov    %rbx,%rdi
call   1050 <atoi@plt>
mov    %rax,%r14
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [8 x i8] c"SIP/2.0\00"
define i32 @sip_msg_is_response(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i16
store i8* %0, i8** %3
%5 = call i64 @strlen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%6 = trunc i64 %5 to i16
store i16 %6, i16* %4
%7 = load i8*, i8** %3
%8 = icmp ne i8* %7, null
br i1 %8, label %9, label %27
9: ; preds = %1
%10 = load i8*, i8** %3
%11 = call i64 @strlen(i8* %10)
%12 = icmp sgt i64 %11, 0
br i1 %12, label %13, label %27
13: ; preds = %9
%14 = load i8*, i8** %3
%15 = load i16, i16* %4
%16 = call i64 @strncmp(i8* %14, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i16 signext %15)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %27
18: ; preds = %13
%19 = load i8*, i8** %3
%20 = load i16, i16* %4
%21 = sext i16 %20 to i32
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %19, i64 %22
%24 = getelementptr inbounds i8, i8* %23, i64 1
%25 = call i64 @atoi(i8* %24)
%26 = trunc i64 %25 to i32
store i32 %26, i32* %2
br label %28
27: ; preds = %13, %9, %1
store i32 -1, i32* %2
br label %28
28: ; preds = %27, %18
%29 = load i32, i32* %2
ret i32 %29
}

LLVM IR (-O2):
@.str = [8 x i8] c"SIP/2.0\00"
define i32 @sip_msg_is_response(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %13, label %3
3: ; preds = %1
%4 = tail call i64 @strlen(i8* %0)
%5 = icmp sgt i64 %4, 0
br i1 %5, label %6, label %13
6: ; preds = %3
%7 = tail call i64 @strncmp(i8* %0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i16 signext 7)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %13
9: ; preds = %6
%10 = getelementptr inbounds i8, i8* %0, i64 8
%11 = tail call i64 @atoi(i8* %10)
%12 = trunc i64 %11 to i32
br label %13
13: ; preds = %1, %3, %6, %9
%14 = phi i32 [ %12, %9 ], [ -1, %6 ], [ -1, %3 ], [ -1, %1 ]
ret i32 %14
}