#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ strcmp(char *, char *);
int strlen(char *);
char *strstr(char *, char *);
int check_header(FILE *fd, int *is_compress, int *is_html) {
  int ret = 1;
  char line[5000] = {0};
  int not_found = 1;
  while (fgets(line, 5000, fd) != NULL) {
    char *stop_sign = "\r\n";
    char *type = NULL;
    if (strcmp(stop_sign, line) == 0) {
      break;
    }
    if (strstr(line, "Content-Encoding: gzip") != NULL) {
      printf("pack is use gzip!\n");
      *is_compress = 1;
      not_found = 0;
      continue;
    }
    if ((type = strstr(line, "Content-Type")) != NULL) {
      printf("file-type=%s", line + strlen("Content-Type"));
      if (strstr(type, "html") != NULL) {
        *is_html = 1;
      }
      not_found = 0;
      continue;
    }
  }
  if (not_found == 1) {
    printf("not found info in header\n");
  }
  return ret;
}


x86 assembly (clang, -O0):
<check_header>:
push   %rbp
mov    %rsp,%rbp
sub    $0x13d0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
lea    -0x13b0(%rbp),%rdi
xor    %esi,%esi
mov    $0x1388,%edx
call   1050 <memset@plt>
movl   $0x1,-0x13b4(%rbp)
lea    -0x13b0(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0x1388,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     12cc <check_header+0x16c>
lea    0xe3f(%rip),%rax
mov    %rax,-0x13c0(%rbp)
movq   $0x0,-0x13c8(%rbp)
mov    -0x13c0(%rbp),%rdi
lea    -0x13b0(%rbp),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    11f5 <check_header+0x95>
jmp    12cc <check_header+0x16c>
lea    -0x13b0(%rbp),%rdi
lea    0xe00(%rip),%rsi
call   1080 <strstr@plt>
cmp    $0x0,%rax
je     1239 <check_header+0xd9>
lea    0xe01(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
movl   $0x1,(%rax)
movl   $0x0,-0x13b4(%rbp)
jmp    119b <check_header+0x3b>
lea    -0x13b0(%rbp),%rdi
lea    0xde6(%rip),%rsi
call   1080 <strstr@plt>
mov    %rax,-0x13c8(%rbp)
cmp    $0x0,%rax
je     12c7 <check_header+0x167>
lea    -0x13b0(%rbp),%rax
mov    %rax,-0x13d0(%rbp)
lea    0xdbb(%rip),%rdi
call   1030 <strlen@plt>
mov    -0x13d0(%rbp),%rsi
cltq
add    %rax,%rsi
lea    0xdb0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x13c8(%rbp),%rdi
lea    0xda8(%rip),%rsi
call   1080 <strstr@plt>
cmp    $0x0,%rax
je     12b8 <check_header+0x158>
mov    -0x18(%rbp),%rax
movl   $0x1,(%rax)
movl   $0x0,-0x13b4(%rbp)
jmp    119b <check_header+0x3b>
jmp    119b <check_header+0x3b>
cmpl   $0x1,-0x13b4(%rbp)
jne    12e7 <check_header+0x187>
lea    0xd6c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x13d0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_header>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1398,%rsp
mov    %rdx,0x8(%rsp)
mov    %rsi,%r15
mov    %rdi,%r13
lea    0x10(%rsp),%rbx
mov    $0x1388,%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1060 <memset@plt>
mov    %rbx,%rdi
mov    $0x1388,%esi
mov    %r13,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     1288 <check_header+0x118>
mov    $0x1,%ebp
lea    0xe3b(%rip),%r12
lea    0x10(%rsp),%rbx
jmp    1200 <check_header+0x90>
nopl   0x0(%rax)
lea    0xe7b(%rip),%rdi
call   1030 <puts@plt>
mov    %r15,%rcx
movl   $0x1,(%rcx)
xor    %ebp,%ebp
mov    %rbx,%rdi
mov    $0x1388,%esi
mov    %r13,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     1283 <check_header+0x113>
mov    %r12,%rdi
mov    %rbx,%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
je     1283 <check_header+0x113>
mov    %rbx,%rdi
lea    0xde9(%rip),%rsi
call   1090 <strstr@plt>
test   %rax,%rax
jne    11d0 <check_header+0x60>
mov    %rbx,%rdi
lea    0xdec(%rip),%rsi
call   1090 <strstr@plt>
test   %rax,%rax
je     11e7 <check_header+0x77>
mov    %rax,%r14
lea    0xdd8(%rip),%rdi
call   1040 <strlen@plt>
cltq
lea    (%rsp,%rax,1),%rsi
add    $0x10,%rsi
xor    %ebp,%ebp
lea    0xdcd(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14,%rdi
lea    0xdc9(%rip),%rsi
call   1090 <strstr@plt>
mov    0x8(%rsp),%rcx
test   %rax,%rax
jne    11df <check_header+0x6f>
jmp    11e7 <check_header+0x77>
cmp    $0x1,%ebp
jne    1294 <check_header+0x124>
lea    0xdaa(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
add    $0x1398,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"\0D\0A\00"
@.str.1 = [23 x i8] c"Content-Encoding: gzip\00"
@.str.2 = [19 x i8] c"pack is use gzip!\0A\00"
@.str.3 = [13 x i8] c"Content-Type\00"
@.str.4 = [13 x i8] c"file-type=%s\00"
@.str.5 = [5 x i8] c"html\00"
@.str.6 = [26 x i8] c"not found info in header\0A\00"
define i32 @check_header(i32* %0, i32* %1, i32* %2) {
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca [5000 x i8]
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i8*
store i32* %0, i32** %4
store i32* %1, i32** %5
store i32* %2, i32** %6
store i32 1, i32* %7
%12 = bitcast [5000 x i8]* %8 to i8*
store i32 1, i32* %9
br label %13
13: ; preds = %47, %46, %28, %3
%14 = getelementptr inbounds [5000 x i8], [5000 x i8]* %8, i64 0, i64 0
%15 = load i32*, i32** %4
%16 = call i32* @fgets(i8* %14, i32 5000, i32* %15)
%17 = icmp ne i32* %16, null
br i1 %17, label %18, label %48
18: ; preds = %13
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8** %10
store i8* null, i8** %11
%19 = load i8*, i8** %10
%20 = getelementptr inbounds [5000 x i8], [5000 x i8]* %8, i64 0, i64 0
%21 = call i64 @strcmp(i8* %19, i8* %20)
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %18
br label %48
24: ; preds = %18
%25 = getelementptr inbounds [5000 x i8], [5000 x i8]* %8, i64 0, i64 0
%26 = call i8* @strstr(i8* %25, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
%27 = icmp ne i8* %26, null
br i1 %27, label %28, label %31
28: ; preds = %24
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%30 = load i32*, i32** %5
store i32 1, i32* %30
store i32 0, i32* %9
br label %13
31: ; preds = %24
%32 = getelementptr inbounds [5000 x i8], [5000 x i8]* %8, i64 0, i64 0
%33 = call i8* @strstr(i8* %32, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
store i8* %33, i8** %11
%34 = icmp ne i8* %33, null
br i1 %34, label %35, label %47
35: ; preds = %31
%36 = getelementptr inbounds [5000 x i8], [5000 x i8]* %8, i64 0, i64 0
%37 = call i32 @strlen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %36, i64 %38
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i8* %39)
%41 = load i8*, i8** %11
%42 = call i8* @strstr(i8* %41, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%43 = icmp ne i8* %42, null
br i1 %43, label %44, label %46
44: ; preds = %35
%45 = load i32*, i32** %6
store i32 1, i32* %45
br label %46
46: ; preds = %44, %35
store i32 0, i32* %9
br label %13
47: ; preds = %31
br label %13
48: ; preds = %23, %13
%49 = load i32, i32* %9
%50 = icmp eq i32 %49, 1
br i1 %50, label %51, label %53
51: ; preds = %48
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0))
br label %53
53: ; preds = %51, %48
%54 = load i32, i32* %7
ret i32 %54
}

LLVM IR (-O2):
@.str = [3 x i8] c"\0D\0A\00"
@.str.1 = [23 x i8] c"Content-Encoding: gzip\00"
@.str.3 = [13 x i8] c"Content-Type\00"
@.str.4 = [13 x i8] c"file-type=%s\00"
@.str.5 = [5 x i8] c"html\00"
@str = [25 x i8] c"not found info in header\00"
@str.7 = [18 x i8] c"pack is use gzip!\00"
define i32 @check_header(i32* nocapture %0, i32* nocapture writeonly %1, i32* nocapture writeonly %2) {
%4 = alloca [5000 x i8]
%5 = getelementptr inbounds [5000 x i8], [5000 x i8]* %4, i64 0, i64 0
%6 = call i32* @fgets(i8* %5, i32 5000, i32* %0)
%7 = icmp eq i32* %6, null
br i1 %7, label %36, label %8
8: ; preds = %3, %29
%9 = phi i32 [ %30, %29 ], [ 1, %3 ]
%10 = call i64 @strcmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %5)
%11 = icmp eq i64 %10, 0
br i1 %11, label %33, label %12
12: ; preds = %8
%13 = call i8* @strstr(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp eq i8* %13, null
br i1 %14, label %17, label %15
15: ; preds = %12
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.7, i64 0, i64 0))
br label %27
17: ; preds = %12
%18 = call i8* @strstr(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%19 = icmp eq i8* %18, null
br i1 %19, label %29, label %20
20: ; preds = %17
%21 = call i32 @strlen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [5000 x i8], [5000 x i8]* %4, i64 0, i64 %22
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i8* %23)
%25 = call i8* @strstr(i8* %18, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%26 = icmp eq i8* %25, null
br i1 %26, label %29, label %27
27: ; preds = %20, %15
%28 = phi i32* [ %1, %15 ], [ %2, %20 ]
store i32 1, i32* %28
br label %29
29: ; preds = %27, %17, %20
%30 = phi i32 [ 0, %20 ], [ %9, %17 ], [ 0, %27 ]
%31 = call i32* @fgets(i8* %5, i32 5000, i32* %0)
%32 = icmp eq i32* %31, null
br i1 %32, label %33, label %8
33: ; preds = %29, %8
%34 = phi i32 [ %30, %29 ], [ %9, %8 ]
%35 = icmp eq i32 %34, 1
br i1 %35, label %36, label %38
36: ; preds = %3, %33
%37 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str, i64 0, i64 0))
br label %38
38: ; preds = %36, %33
ret i32 1
}