#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 */
typedef int ssize_t;
typedef int /*<<< orphan*/ regex_t;
typedef int /*<<< orphan*/ hbuf;

/* Variables and functions */
scalar_t__ EINTR;
int /*<<< orphan*/ MSG_PEEK;
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ edge_parse_line(int /*<<< orphan*/ *, char *, char **,
                                   char **);
scalar_t__ errno;
int /*<<< orphan*/ free(char *);
int recv(int, char *, int, int /*<<< orphan*/);
char *strtok_r(char *, char *, char **);
int edge_peek_hosthdr(int sock, regex_t *rp) {
  char hbuf[2048], *state, *k, *v, *ptr;
  ssize_t cc;
  while (1) {
    bzero(hbuf, sizeof(hbuf));
    cc = recv(sock, hbuf, sizeof(hbuf) - 1, MSG_PEEK);
    if (cc == 0)
      return (0);
    if (cc == -1 && errno == EINTR)
      continue;
    state = &hbuf[0];
    while ((ptr = strtok_r(state, "\n", &state))) {
      edge_parse_line(rp, ptr, &k, &v);
      if (k == NULL || v == NULL)
        continue;
      free(k);
      free(v);
    }
    break;
  }
  return (0);
}


x86 assembly (clang, -O0):
<edge_peek_hosthdr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x840,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x810(%rbp),%rdi
mov    $0x800,%esi
call   1060 <bzero@plt>
mov    -0x8(%rbp),%edi
lea    -0x810(%rbp),%rsi
mov    0x2e64(%rip),%rax
mov    (%rax),%ecx
mov    $0x7ff,%edx
call   1040 <recv@plt>
mov    %eax,-0x834(%rbp)
cmpl   $0x0,-0x834(%rbp)
jne    11af <edge_peek_hosthdr+0x5f>
movl   $0x0,-0x4(%rbp)
jmp    127c <edge_peek_hosthdr+0x12c>
cmpl   $0xffffffff,-0x834(%rbp)
jne    11db <edge_peek_hosthdr+0x8b>
mov    0x2e15(%rip),%rax
mov    (%rax),%rax
mov    0x2e03(%rip),%rcx
cmp    (%rcx),%rax
jne    11db <edge_peek_hosthdr+0x8b>
jmp    1162 <edge_peek_hosthdr+0x12>
lea    -0x810(%rbp),%rax
mov    %rax,-0x818(%rbp)
mov    -0x818(%rbp),%rdi
lea    0xe09(%rip),%rsi
lea    -0x818(%rbp),%rdx
call   1050 <strtok_r@plt>
mov    %rax,-0x830(%rbp)
cmp    $0x0,%rax
je     1270 <edge_peek_hosthdr+0x120>
mov    -0x10(%rbp),%rdi
mov    -0x830(%rbp),%rsi
lea    -0x820(%rbp),%rdx
lea    -0x828(%rbp),%rcx
call   1070 <edge_parse_line@plt>
cmpq   $0x0,-0x820(%rbp)
je     124e <edge_peek_hosthdr+0xfe>
cmpq   $0x0,-0x828(%rbp)
jne    1253 <edge_peek_hosthdr+0x103>
jmp    11e9 <edge_peek_hosthdr+0x99>
mov    -0x820(%rbp),%rdi
call   1030 <free@plt>
mov    -0x828(%rbp),%rdi
call   1030 <free@plt>
jmp    11e9 <edge_peek_hosthdr+0x99>
jmp    1275 <edge_peek_hosthdr+0x125>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x840,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<edge_peek_hosthdr>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x828,%rsp
mov    %rsi,%r14
mov    %edi,%ebp
lea    0x20(%rsp),%rbx
mov    0x2e76(%rip),%r15
mov    0x2e5f(%rip),%r12
mov    0x2e50(%rip),%r13
mov    %rbx,%rdi
mov    $0x800,%esi
call   1060 <bzero@plt>
mov    (%r15),%ecx
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x7ff,%edx
call   1040 <recv@plt>
cmp    $0xffffffff,%eax
jne    11b0 <edge_peek_hosthdr+0x60>
mov    (%r12),%rax
cmp    0x0(%r13),%rax
je     1180 <edge_peek_hosthdr+0x30>
jmp    11b8 <edge_peek_hosthdr+0x68>
test   %eax,%eax
je     1239 <edge_peek_hosthdr+0xe9>
mov    %rbx,0x8(%rsp)
lea    0xe3c(%rip),%rsi
lea    0x8(%rsp),%rdx
mov    %rbx,%rdi
call   1050 <strtok_r@plt>
test   %rax,%rax
je     1239 <edge_peek_hosthdr+0xe9>
lea    0x18(%rsp),%rbx
lea    0x10(%rsp),%r15
lea    0xe19(%rip),%r12
lea    0x8(%rsp),%r13
jmp    1205 <edge_peek_hosthdr+0xb5>
xchg   %ax,%ax
mov    0x8(%rsp),%rdi
mov    %r12,%rsi
mov    %r13,%rdx
call   1050 <strtok_r@plt>
test   %rax,%rax
je     1239 <edge_peek_hosthdr+0xe9>
mov    %r14,%rdi
mov    %rax,%rsi
mov    %rbx,%rdx
mov    %r15,%rcx
call   1070 <edge_parse_line@plt>
mov    0x18(%rsp),%rdi
test   %rdi,%rdi
je     11f0 <edge_peek_hosthdr+0xa0>
cmpq   $0x0,0x10(%rsp)
je     11f0 <edge_peek_hosthdr+0xa0>
call   1030 <free@plt>
mov    0x10(%rsp),%rdi
call   1030 <free@plt>
jmp    11f0 <edge_peek_hosthdr+0xa0>
xor    %eax,%eax
add    $0x828,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@MSG_PEEK = global i32 0
@errno = global i64 0
@EINTR = global i64 0
@.str = [2 x i8] c"\0A\00"
define i32 @edge_peek_hosthdr(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32*
%6 = alloca [2048 x i8]
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
store i32 %0, i32* %4
store i32* %1, i32** %5
br label %12
12: ; preds = %2, %29
%13 = getelementptr inbounds [2048 x i8], [2048 x i8]* %6, i64 0, i64 0
%14 = call i32 @bzero(i8* %13, i32 2048)
%15 = load i32, i32* %4
%16 = getelementptr inbounds [2048 x i8], [2048 x i8]* %6, i64 0, i64 0
%17 = load i32, i32* @MSG_PEEK
%18 = call i32 @recv(i32 %15, i8* %16, i32 2047, i32 %17)
store i32 %18, i32* %11
%19 = load i32, i32* %11
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %12
store i32 0, i32* %3
br label %53
22: ; preds = %12
%23 = load i32, i32* %11
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %30
25: ; preds = %22
%26 = load i64, i64* @errno
%27 = load i64, i64* @EINTR
%28 = icmp eq i64 %26, %27
br i1 %28, label %29, label %30
29: ; preds = %25
br label %12
30: ; preds = %25, %22
%31 = getelementptr inbounds [2048 x i8], [2048 x i8]* %6, i64 0, i64 0
store i8* %31, i8** %7
br label %32
32: ; preds = %46, %45, %30
%33 = load i8*, i8** %7
%34 = call i8* @strtok_r(i8* %33, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %7)
store i8* %34, i8** %10
%35 = icmp ne i8* %34, null
br i1 %35, label %36, label %51
36: ; preds = %32
%37 = load i32*, i32** %5
%38 = load i8*, i8** %10
%39 = call i32 @edge_parse_line(i32* %37, i8* %38, i8** %8, i8** %9)
%40 = load i8*, i8** %8
%41 = icmp eq i8* %40, null
br i1 %41, label %45, label %42
42: ; preds = %36
%43 = load i8*, i8** %9
%44 = icmp eq i8* %43, null
br i1 %44, label %45, label %46
45: ; preds = %42, %36
br label %32
46: ; preds = %42
%47 = load i8*, i8** %8
%48 = call i32 @free(i8* %47)
%49 = load i8*, i8** %9
%50 = call i32 @free(i8* %49)
br label %32
51: ; preds = %32
br label %52
52: ; preds = %51
store i32 0, i32* %3
br label %53
53: ; preds = %52, %21
%54 = load i32, i32* %3
ret i32 %54
}

LLVM IR (-O2):
@MSG_PEEK = global i32 0
@errno = global i64 0
@EINTR = global i64 0
@.str = [2 x i8] c"\0A\00"
define i32 @edge_peek_hosthdr(i32 %0, i32* %1) {
%3 = alloca [2048 x i8]
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 0
%8 = bitcast i8** %4 to i8*
%9 = bitcast i8** %5 to i8*
%10 = bitcast i8** %6 to i8*
br label %11
11: ; preds = %15, %2
%12 = call i32 @bzero(i8* %7, i32 2048)
%13 = load i32, i32* @MSG_PEEK
%14 = call i32 @recv(i32 %0, i8* %7, i32 2047, i32 %13)
switch i32 %14, label %19 [
i32 0, label %38
i32 -1, label %15
]
15: ; preds = %11
%16 = load i64, i64* @errno
%17 = load i64, i64* @EINTR
%18 = icmp eq i64 %16, %17
br i1 %18, label %11, label %19
19: ; preds = %11, %15
store i8* %7, i8** %4
%20 = call i8* @strtok_r(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %4)
%21 = icmp eq i8* %20, null
br i1 %21, label %38, label %22
22: ; preds = %19, %34
%23 = phi i8* [ %36, %34 ], [ %20, %19 ]
%24 = call i32 @edge_parse_line(i32* %1, i8* %23, i8** %5, i8** %6)
%25 = load i8*, i8** %5
%26 = icmp eq i8* %25, null
%27 = load i8*, i8** %6
%28 = icmp eq i8* %27, null
%29 = select i1 %26, i1 true, i1 %28
br i1 %29, label %34, label %30
30: ; preds = %22
%31 = call i32 @free(i8* %25)
%32 = load i8*, i8** %6
%33 = call i32 @free(i8* %32)
br label %34
34: ; preds = %30, %22
%35 = load i8*, i8** %4
%36 = call i8* @strtok_r(i8* %35, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %4)
%37 = icmp eq i8* %36, null
br i1 %37, label %38, label %22
38: ; preds = %11, %34, %19
ret i32 0
}