#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 */
struct WebbyConnection {
  int dummy;
};

/* Variables and functions */
char *WebbyFindHeader(struct WebbyConnection *, char *);
scalar_t__ strcasecmp(char const *, char *);
scalar_t__ strstr(char const *, char *);
int is_websocket_request(struct WebbyConnection *conn) {
  const char *hdr;
  if (NULL == (hdr = WebbyFindHeader(conn, "Connection")))
    return 0;
  if (0 == strstr(hdr, "Upgrade"))
    return 0;
  if (NULL == (hdr = WebbyFindHeader(conn, "Upgrade")))
    return 0;
  if (0 != strcasecmp(hdr, "websocket"))
    return 0;
  return 1;
}


x86 assembly (clang, -O0):
<is_websocket_request>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xeb9(%rip),%rsi
call   1040 <WebbyFindHeader@plt>
mov    %rax,%rcx
mov    %rcx,-0x18(%rbp)
xor    %eax,%eax
cmp    %rcx,%rax
jne    116a <is_websocket_request+0x3a>
movl   $0x0,-0x4(%rbp)
jmp    11f3 <is_websocket_request+0xc3>
mov    -0x18(%rbp),%rdi
lea    0xe96(%rip),%rsi
call   1050 <strstr@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    1194 <is_websocket_request+0x64>
movl   $0x0,-0x4(%rbp)
jmp    11f3 <is_websocket_request+0xc3>
mov    -0x10(%rbp),%rdi
lea    0xe6c(%rip),%rsi
call   1040 <WebbyFindHeader@plt>
mov    %rax,%rcx
mov    %rcx,-0x18(%rbp)
xor    %eax,%eax
cmp    %rcx,%rax
jne    11c2 <is_websocket_request+0x92>
movl   $0x0,-0x4(%rbp)
jmp    11f3 <is_websocket_request+0xc3>
mov    -0x18(%rbp),%rdi
lea    0xe46(%rip),%rsi
call   1030 <strcasecmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     11ec <is_websocket_request+0xbc>
movl   $0x0,-0x4(%rbp)
jmp    11f3 <is_websocket_request+0xc3>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_websocket_request>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
lea    0xec3(%rip),%rsi
call   1040 <WebbyFindHeader@plt>
xor    %ebp,%ebp
test   %rax,%rax
je     1189 <is_websocket_request+0x59>
lea    0xebb(%rip),%rsi
mov    %rax,%rdi
call   1050 <strstr@plt>
test   %rax,%rax
je     1189 <is_websocket_request+0x59>
lea    0xea7(%rip),%rsi
mov    %rbx,%rdi
call   1040 <WebbyFindHeader@plt>
test   %rax,%rax
je     1189 <is_websocket_request+0x59>
lea    0xe9b(%rip),%rsi
mov    %rax,%rdi
call   1030 <strcasecmp@plt>
xor    %ebp,%ebp
test   %rax,%rax
sete   %bpl
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.WebbyConnection = type { i32 }
@.str = [11 x i8] c"Connection\00"
@.str.1 = [8 x i8] c"Upgrade\00"
@.str.2 = [10 x i8] c"websocket\00"
define i32 @is_websocket_request(%struct.WebbyConnection* %0) {
%2 = alloca i32
%3 = alloca %struct.WebbyConnection*
%4 = alloca i8*
store %struct.WebbyConnection* %0, %struct.WebbyConnection** %3
%5 = load %struct.WebbyConnection*, %struct.WebbyConnection** %3
%6 = call i8* @WebbyFindHeader(%struct.WebbyConnection* %5, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
store i8* %6, i8** %4
%7 = icmp eq i8* null, %6
br i1 %7, label %8, label %9
8: ; preds = %1
store i32 0, i32* %2
br label %25
9: ; preds = %1
%10 = load i8*, i8** %4
%11 = call i64 @strstr(i8* %10, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp eq i64 0, %11
br i1 %12, label %13, label %14
13: ; preds = %9
store i32 0, i32* %2
br label %25
14: ; preds = %9
%15 = load %struct.WebbyConnection*, %struct.WebbyConnection** %3
%16 = call i8* @WebbyFindHeader(%struct.WebbyConnection* %15, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
store i8* %16, i8** %4
%17 = icmp eq i8* null, %16
br i1 %17, label %18, label %19
18: ; preds = %14
store i32 0, i32* %2
br label %25
19: ; preds = %14
%20 = load i8*, i8** %4
%21 = call i64 @strcasecmp(i8* %20, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%22 = icmp ne i64 0, %21
br i1 %22, label %23, label %24
23: ; preds = %19
store i32 0, i32* %2
br label %25
24: ; preds = %19
store i32 1, i32* %2
br label %25
25: ; preds = %24, %23, %18, %13, %8
%26 = load i32, i32* %2
ret i32 %26
}

LLVM IR (-O2):
%struct.WebbyConnection = type { i32 }
@.str = [11 x i8] c"Connection\00"
@.str.1 = [8 x i8] c"Upgrade\00"
@.str.2 = [10 x i8] c"websocket\00"
define i32 @is_websocket_request(%struct.WebbyConnection* %0) {
%2 = tail call i8* @WebbyFindHeader(%struct.WebbyConnection* %0, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i8* %2, null
br i1 %3, label %14, label %4
4: ; preds = %1
%5 = tail call i64 @strstr(i8* %2, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i64 %5, 0
br i1 %6, label %14, label %7
7: ; preds = %4
%8 = tail call i8* @WebbyFindHeader(%struct.WebbyConnection* %0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%9 = icmp eq i8* %8, null
br i1 %9, label %14, label %10
10: ; preds = %7
%11 = tail call i64 @strcasecmp(i8* %8, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%12 = icmp eq i64 %11, 0
%13 = zext i1 %12 to i32
br label %14
14: ; preds = %10, %7, %4, %1
%15 = phi i32 [ 0, %1 ], [ 0, %4 ], [ 0, %7 ], [ %13, %10 ]
ret i32 %15
}