#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 checkhost {
  int dummy;
};
typedef int /*<<< orphan*/ linebuf;

/* Variables and functions */
scalar_t__ check_header(struct checkhost *, char *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int strlen(char *);
void find_header(struct checkhost *h, char *respbuf) {
  char linebuf[2048];
  char *p0, *p1;
  int lb = 0;
  p0 = linebuf;
  memset(linebuf, 0, sizeof(linebuf));
  p1 = respbuf;
  for (;;) {
    if (*p1 == '\0')
      break;
    if (*p1 == '\r') {
      p1++;
      continue;
    }
    if (*p1 == '\n') {
      if (lb == 1) {
        return;
      }
      lb = 1;
      if (check_header(h, linebuf))
        return;
      p0 = linebuf;
      memset(linebuf, 0, sizeof(linebuf));
    } else {
      lb = 0;
      if ((strlen(linebuf) + 1) < sizeof(linebuf))
        *(p0++) = *p1;
    }
    p1++;
  }
}


x86 assembly (clang, -O0):
<find_header>:
push   %rbp
mov    %rsp,%rbp
sub    $0x830,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x824(%rbp)
lea    -0x810(%rbp),%rax
mov    %rax,-0x818(%rbp)
lea    -0x810(%rbp),%rdi
xor    %esi,%esi
mov    $0x800,%edx
call   1040 <memset@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x820(%rbp)
mov    -0x820(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1191 <find_header+0x61>
jmp    1292 <find_header+0x162>
mov    -0x820(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xd,%eax
jne    11bb <find_header+0x8b>
mov    -0x820(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x820(%rbp)
jmp    1179 <find_header+0x49>
mov    -0x820(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
jne    122f <find_header+0xff>
cmpl   $0x1,-0x824(%rbp)
jne    11e0 <find_header+0xb0>
jmp    1292 <find_header+0x162>
movl   $0x1,-0x824(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x810(%rbp),%rsi
call   1050 <check_header@plt>
cmp    $0x0,%rax
je     1209 <find_header+0xd9>
jmp    1292 <find_header+0x162>
lea    -0x810(%rbp),%rax
mov    %rax,-0x818(%rbp)
lea    -0x810(%rbp),%rdi
xor    %esi,%esi
mov    $0x800,%edx
call   1040 <memset@plt>
jmp    127b <find_header+0x14b>
movl   $0x0,-0x824(%rbp)
lea    -0x810(%rbp),%rdi
call   1030 <strlen@plt>
add    $0x1,%eax
cltq
cmp    $0x800,%rax
jae    1276 <find_header+0x146>
mov    -0x820(%rbp),%rax
mov    (%rax),%cl
mov    -0x818(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x818(%rbp)
mov    %cl,(%rax)
jmp    127b <find_header+0x14b>
mov    -0x820(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x820(%rbp)
jmp    1179 <find_header+0x49>
add    $0x830,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_header>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x800,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsp,%r15
xor    %ebp,%ebp
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x800,%edx
call   1040 <memset@plt>
mov    %r15,%r12
nopl   0x0(%rax)
add    $0x1,%rbx
movzbl -0x1(%rbx),%eax
cmp    $0xd,%al
je     1160 <find_header+0x30>
test   %al,%al
je     11cb <find_header+0x9b>
cmp    $0xa,%al
je     11a0 <find_header+0x70>
mov    %r15,%rdi
call   1030 <strlen@plt>
add    $0x1,%eax
mov    $0x0,%ebp
cmp    $0x7ff,%eax
ja     1160 <find_header+0x30>
movzbl -0x1(%rbx),%eax
mov    %al,(%r12)
add    $0x1,%r12
xor    %ebp,%ebp
jmp    1160 <find_header+0x30>
nopl   0x0(%rax,%rax,1)
cmp    $0x1,%ebp
je     11cb <find_header+0x9b>
mov    %r14,%rdi
mov    %r15,%rsi
call   1050 <check_header@plt>
test   %rax,%rax
jne    11cb <find_header+0x9b>
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x800,%edx
call   1040 <memset@plt>
mov    $0x1,%ebp
jmp    1159 <find_header+0x29>
add    $0x800,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.checkhost = type { i32 }
define void @find_header(%struct.checkhost* %0, i8* %1) {
%3 = alloca %struct.checkhost*
%4 = alloca i8*
%5 = alloca [2048 x i8]
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
store %struct.checkhost* %0, %struct.checkhost** %3
store i8* %1, i8** %4
store i32 0, i32* %8
%9 = getelementptr inbounds [2048 x i8], [2048 x i8]* %5, i64 0, i64 0
store i8* %9, i8** %6
%10 = getelementptr inbounds [2048 x i8], [2048 x i8]* %5, i64 0, i64 0
%11 = call i32 @memset(i8* %10, i32 0, i32 2048)
%12 = load i8*, i8** %4
store i8* %12, i8** %7
br label %13
13: ; preds = %58, %24, %2
%14 = load i8*, i8** %7
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %13
br label %61
19: ; preds = %13
%20 = load i8*, i8** %7
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp eq i32 %22, 13
br i1 %23, label %24, label %27
24: ; preds = %19
%25 = load i8*, i8** %7
%26 = getelementptr inbounds i8, i8* %25, i32 1
store i8* %26, i8** %7
br label %13
27: ; preds = %19
%28 = load i8*, i8** %7
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = icmp eq i32 %30, 10
br i1 %31, label %32, label %46
32: ; preds = %27
%33 = load i32, i32* %8
%34 = icmp eq i32 %33, 1
br i1 %34, label %35, label %36
35: ; preds = %32
br label %61
36: ; preds = %32
store i32 1, i32* %8
%37 = load %struct.checkhost*, %struct.checkhost** %3
%38 = getelementptr inbounds [2048 x i8], [2048 x i8]* %5, i64 0, i64 0
%39 = call i64 @check_header(%struct.checkhost* %37, i8* %38)
%40 = icmp ne i64 %39, 0
br i1 %40, label %41, label %42
41: ; preds = %36
br label %61
42: ; preds = %36
%43 = getelementptr inbounds [2048 x i8], [2048 x i8]* %5, i64 0, i64 0
store i8* %43, i8** %6
%44 = getelementptr inbounds [2048 x i8], [2048 x i8]* %5, i64 0, i64 0
%45 = call i32 @memset(i8* %44, i32 0, i32 2048)
br label %58
46: ; preds = %27
store i32 0, i32* %8
%47 = getelementptr inbounds [2048 x i8], [2048 x i8]* %5, i64 0, i64 0
%48 = call i32 @strlen(i8* %47)
%49 = add nsw i32 %48, 1
%50 = sext i32 %49 to i64
%51 = icmp ult i64 %50, 2048
br i1 %51, label %52, label %57
52: ; preds = %46
%53 = load i8*, i8** %7
%54 = load i8, i8* %53
%55 = load i8*, i8** %6
%56 = getelementptr inbounds i8, i8* %55, i32 1
store i8* %56, i8** %6
store i8 %54, i8* %55
br label %57
57: ; preds = %52, %46
br label %58
58: ; preds = %57, %42
%59 = load i8*, i8** %7
%60 = getelementptr inbounds i8, i8* %59, i32 1
store i8* %60, i8** %7
br label %13
61: ; preds = %35, %41, %18
ret void
}

LLVM IR (-O2):
%struct.checkhost = type { i32 }
define void @find_header(%struct.checkhost* %0, i8* nocapture %1) {
%3 = alloca [2048 x i8]
%4 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 0
%5 = call i32 @memset(i8* %4, i32 0, i32 2048)
br label %6
6: ; preds = %29, %2
%7 = phi i8* [ %30, %29 ], [ %4, %2 ]
%8 = phi i8* [ %32, %29 ], [ %1, %2 ]
%9 = phi i32 [ %31, %29 ], [ 0, %2 ]
br label %10
10: ; preds = %6, %13
%11 = phi i8* [ %14, %13 ], [ %8, %6 ]
%12 = load i8, i8* %11
switch i8 %12, label %22 [
i8 0, label %33
i8 13, label %13
i8 10, label %15
]
13: ; preds = %10
%14 = getelementptr inbounds i8, i8* %11, i64 1
br label %10
15: ; preds = %10
%16 = icmp eq i32 %9, 1
br i1 %16, label %33, label %17
17: ; preds = %15
%18 = call i64 @check_header(%struct.checkhost* %0, i8* %4)
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %33
20: ; preds = %17
%21 = call i32 @memset(i8* %4, i32 0, i32 2048)
br label %29
22: ; preds = %10
%23 = call i32 @strlen(i8* %4)
%24 = add nsw i32 %23, 1
%25 = icmp ult i32 %24, 2048
br i1 %25, label %26, label %29
26: ; preds = %22
%27 = load i8, i8* %11
%28 = getelementptr inbounds i8, i8* %7, i64 1
store i8 %27, i8* %7
br label %29
29: ; preds = %22, %26, %20
%30 = phi i8* [ %4, %20 ], [ %28, %26 ], [ %7, %22 ]
%31 = phi i32 [ 1, %20 ], [ 0, %26 ], [ 0, %22 ]
%32 = getelementptr inbounds i8, i8* %11, i64 1
br label %6
33: ; preds = %17, %15, %10
ret void
}