#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 wby_con {
  int dummy;
};

/* Variables and functions */
scalar_t__ strcasecmp(char const *, char *);
char *wby_find_header(struct wby_con *, char *);
int wby_con_is_websocket_request(struct wby_con *conn) {
  const char *hdr;
  if ((hdr = wby_find_header(conn, "Connection")) == NULL)
    return 0;
  if (strcasecmp(hdr, "Upgrade"))
    return 0;
  if ((hdr = wby_find_header(conn, "Upgrade")) == NULL)
    return 0;
  if (strcasecmp(hdr, "websocket"))
    return 0;
  return 1;
}


x86 assembly (clang, -O0):
<wby_con_is_websocket_request>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xec9(%rip),%rsi
call   1040 <wby_find_header@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1156 <wby_con_is_websocket_request+0x36>
movl   $0x0,-0x4(%rbp)
jmp    11d3 <wby_con_is_websocket_request+0xb3>
mov    -0x18(%rbp),%rdi
lea    0xeaa(%rip),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%rax
je     117c <wby_con_is_websocket_request+0x5c>
movl   $0x0,-0x4(%rbp)
jmp    11d3 <wby_con_is_websocket_request+0xb3>
mov    -0x10(%rbp),%rdi
lea    0xe84(%rip),%rsi
call   1040 <wby_find_header@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11a6 <wby_con_is_websocket_request+0x86>
movl   $0x0,-0x4(%rbp)
jmp    11d3 <wby_con_is_websocket_request+0xb3>
mov    -0x18(%rbp),%rdi
lea    0xe62(%rip),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%rax
je     11cc <wby_con_is_websocket_request+0xac>
movl   $0x0,-0x4(%rbp)
jmp    11d3 <wby_con_is_websocket_request+0xb3>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wby_con_is_websocket_request>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
lea    0xed3(%rip),%rsi
call   1040 <wby_find_header@plt>
xor    %ebp,%ebp
test   %rax,%rax
je     1179 <wby_con_is_websocket_request+0x59>
lea    0xecb(%rip),%rsi
mov    %rax,%rdi
call   1030 <strcasecmp@plt>
test   %rax,%rax
jne    1179 <wby_con_is_websocket_request+0x59>
lea    0xeb7(%rip),%rsi
mov    %rbx,%rdi
call   1040 <wby_find_header@plt>
test   %rax,%rax
je     1179 <wby_con_is_websocket_request+0x59>
lea    0xeab(%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.wby_con = 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 @wby_con_is_websocket_request(%struct.wby_con* %0) {
%2 = alloca i32
%3 = alloca %struct.wby_con*
%4 = alloca i8*
store %struct.wby_con* %0, %struct.wby_con** %3
%5 = load %struct.wby_con*, %struct.wby_con** %3
%6 = call i8* @wby_find_header(%struct.wby_con* %5, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
store i8* %6, i8** %4
%7 = icmp eq i8* %6, null
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 @strcasecmp(i8* %10, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %9
store i32 0, i32* %2
br label %25
14: ; preds = %9
%15 = load %struct.wby_con*, %struct.wby_con** %3
%16 = call i8* @wby_find_header(%struct.wby_con* %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* %16, null
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 %21, 0
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.wby_con = 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 @wby_con_is_websocket_request(%struct.wby_con* %0) {
%2 = tail call i8* @wby_find_header(%struct.wby_con* %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 @strcasecmp(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 %7, label %14
7: ; preds = %4
%8 = tail call i8* @wby_find_header(%struct.wby_con* %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
}