#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 /*<<< orphan*/ buf;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ my_fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ strncasecmp(char *, char *, int);
scalar_t__ strstr(char *, char *);
int lit_en_tetes(FILE *stream) {
  char buf[4096];
  int keepalive = 1;
  while (1) {
    my_fgets(buf, sizeof(buf), stream);
    if (buf[0] == '\n' || buf[0] == '\r')
      break;
    if (!strncasecmp(buf, "Connection:", 11) || strstr(buf, "close"))
      keepalive = 0;
  }
  return keepalive;
}


x86 assembly (clang, -O0):
<lit_en_tetes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1020,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x1,-0x1014(%rbp)
lea    -0x1010(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0x1000,%esi
call   1030 <my_fgets@plt>
movsbl -0x1010(%rbp),%eax
cmp    $0xa,%eax
je     117e <lit_en_tetes+0x4e>
movsbl -0x1010(%rbp),%eax
cmp    $0xd,%eax
jne    1183 <lit_en_tetes+0x53>
jmp    11d0 <lit_en_tetes+0xa0>
lea    -0x1010(%rbp),%rdi
lea    0xe6f(%rip),%rsi
mov    $0xb,%edx
call   1040 <strncasecmp@plt>
cmp    $0x0,%eax
je     11c1 <lit_en_tetes+0x91>
lea    -0x1010(%rbp),%rdi
lea    0xe5a(%rip),%rsi
call   1050 <strstr@plt>
cmp    $0x0,%rax
je     11cb <lit_en_tetes+0x9b>
movl   $0x0,-0x1014(%rbp)
jmp    1149 <lit_en_tetes+0x19>
mov    -0x1014(%rbp),%eax
add    $0x1020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lit_en_tetes>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1008,%rsp
mov    %rdi,%r14
mov    $0x1,%ebp
mov    %rsp,%rbx
lea    0xead(%rip),%r15
lea    0xeb2(%rip),%r12
mov    %ebp,%r13d
nopl   (%rax)
mov    %rbx,%rdi
mov    $0x1000,%esi
mov    %r14,%rdx
call   1030 <my_fgets@plt>
movzbl (%rsp),%eax
cmp    $0xa,%al
je     11a4 <lit_en_tetes+0x74>
cmp    $0xd,%al
je     11a4 <lit_en_tetes+0x74>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0xb,%edx
call   1040 <strncasecmp@plt>
xor    %ebp,%ebp
test   %eax,%eax
je     115a <lit_en_tetes+0x2a>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1050 <strstr@plt>
test   %rax,%rax
je     1160 <lit_en_tetes+0x30>
jmp    115a <lit_en_tetes+0x2a>
mov    %r13d,%eax
add    $0x1008,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"Connection:\00"
@.str.1 = [6 x i8] c"close\00"
define i32 @lit_en_tetes(i32* %0) {
%2 = alloca i32*
%3 = alloca [4096 x i8]
%4 = alloca i32
store i32* %0, i32** %2
store i32 1, i32* %4
br label %5
5: ; preds = %1, %28
%6 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%7 = load i32*, i32** %2
%8 = call i32 @my_fgets(i8* %6, i32 4096, i32* %7)
%9 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
%12 = icmp eq i32 %11, 10
br i1 %12, label %18, label %13
13: ; preds = %5
%14 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp eq i32 %16, 13
br i1 %17, label %18, label %19
18: ; preds = %13, %5
br label %29
19: ; preds = %13
%20 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%21 = call i32 @strncasecmp(i8* %20, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 11)
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %27
23: ; preds = %19
%24 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%25 = call i64 @strstr(i8* %24, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %28
27: ; preds = %23, %19
store i32 0, i32* %4
br label %28
28: ; preds = %27, %23
br label %5
29: ; preds = %18
%30 = load i32, i32* %4
ret i32 %30
}

LLVM IR (-O2):
@.str = [12 x i8] c"Connection:\00"
@.str.1 = [6 x i8] c"close\00"
define i32 @lit_en_tetes(i32* %0) {
%2 = alloca [4096 x i8]
%3 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 0
br label %4
4: ; preds = %15, %1
%5 = phi i32 [ 0, %15 ], [ 1, %1 ]
br label %6
6: ; preds = %4, %12
%7 = call i32 @my_fgets(i8* %3, i32 4096, i32* %0)
%8 = load i8, i8* %3
switch i8 %8, label %9 [
i8 13, label %16
i8 10, label %16
]
9: ; preds = %6
%10 = call i32 @strncasecmp(i8* %3, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 11)
%11 = icmp eq i32 %10, 0
br i1 %11, label %15, label %12
12: ; preds = %9
%13 = call i64 @strstr(i8* %3, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp eq i64 %13, 0
br i1 %14, label %6, label %15
15: ; preds = %12, %9
br label %4
16: ; preds = %6, %6
ret i32 %5
}