#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 ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int find_gzip_sign(FILE *fd, char *line, int *line_len) {
  int ret = 0;
  int cnt = 5;
  int last_len = ftell(fd);
  while (fgets(line, 5000, fd) != NULL && cnt != 0) {
    *line_len = ftell(fd) - last_len;
    last_len = ftell(fd);
    if ((line[0] & 0xff) == 0x1f && (line[1] & 0xff) == 0x8b &&
        (line[2] & 0xff) == 0x08 && (line[3] & 0xff) == 0x00) {
      ret = 1;
      break;
    }
    cnt--;
    memset(line, 0, 5000);
  }
  return ret;
}


x86 assembly (clang, -O0):
<find_gzip_sign>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x5,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <ftell@plt>
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0x1388,%esi
call   1040 <fgets@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x25(%rbp)
je     118c <find_gzip_sign+0x5c>
cmpl   $0x0,-0x20(%rbp)
setne  %al
mov    %al,-0x25(%rbp)
mov    -0x25(%rbp),%al
test   $0x1,%al
jne    119c <find_gzip_sign+0x6c>
jmp    123f <find_gzip_sign+0x10f>
mov    -0x8(%rbp),%rdi
call   1050 <ftell@plt>
mov    %eax,%ecx
sub    -0x24(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rdi
call   1050 <ftell@plt>
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
and    $0xff,%eax
cmp    $0x1f,%eax
jne    1221 <find_gzip_sign+0xf1>
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%eax
and    $0xff,%eax
cmp    $0x8b,%eax
jne    1221 <find_gzip_sign+0xf1>
mov    -0x10(%rbp),%rax
movsbl 0x2(%rax),%eax
and    $0xff,%eax
cmp    $0x8,%eax
jne    1221 <find_gzip_sign+0xf1>
mov    -0x10(%rbp),%rax
movsbl 0x3(%rax),%eax
and    $0xff,%eax
cmp    $0x0,%eax
jne    1221 <find_gzip_sign+0xf1>
movl   $0x1,-0x1c(%rbp)
jmp    123f <find_gzip_sign+0x10f>
mov    -0x20(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0x1388,%edx
call   1030 <memset@plt>
jmp    115e <find_gzip_sign+0x2e>
mov    -0x1c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_gzip_sign>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r13
mov    %rdi,%r15
call   1050 <ftell@plt>
mov    %eax,%r12d
mov    %r13,%rdi
mov    $0x1388,%esi
mov    %r15,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     11df <find_gzip_sign+0xaf>
mov    $0xfffffffc,%ebx
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
call   1050 <ftell@plt>
sub    %r12d,%eax
mov    %eax,(%r14)
mov    %r15,%rdi
call   1050 <ftell@plt>
mov    %eax,%r12d
cmpb   $0x1f,0x0(%r13)
jne    11b0 <find_gzip_sign+0x80>
cmpb   $0x8b,0x1(%r13)
jne    11b0 <find_gzip_sign+0x80>
cmpb   $0x8,0x2(%r13)
jne    11b0 <find_gzip_sign+0x80>
cmpb   $0x0,0x3(%r13)
je     11f2 <find_gzip_sign+0xc2>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r13,%rdi
xor    %esi,%esi
mov    $0x1388,%edx
call   1030 <memset@plt>
mov    %r13,%rdi
mov    $0x1388,%esi
mov    %r15,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     11e1 <find_gzip_sign+0xb1>
lea    0x1(%rbx),%eax
test   %ebx,%ebx
mov    %eax,%ebx
jne    1170 <find_gzip_sign+0x40>
jmp    11e1 <find_gzip_sign+0xb1>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x1,%ebp
jmp    11e1 <find_gzip_sign+0xb1>

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

LLVM IR (-O2):
define i32 @find_gzip_sign(i32* nocapture %0, i8* %1, i32* nocapture writeonly %2) {
%4 = tail call i32 @ftell(i32* %0)
%5 = getelementptr inbounds i8, i8* %1, i64 3
%6 = tail call i32* @fgets(i8* %1, i32 5000, i32* %0)
%7 = icmp eq i32* %6, null
br i1 %7, label %35, label %8
8: ; preds = %3
%9 = getelementptr inbounds i8, i8* %1, i64 1
%10 = getelementptr inbounds i8, i8* %1, i64 2
br label %11
11: ; preds = %8, %28
%12 = phi i32 [ %4, %8 ], [ %16, %28 ]
%13 = phi i32 [ 5, %8 ], [ %29, %28 ]
%14 = tail call i32 @ftell(i32* %0)
%15 = sub nsw i32 %14, %12
store i32 %15, i32* %2
%16 = tail call i32 @ftell(i32* %0)
%17 = load i8, i8* %1
%18 = icmp eq i8 %17, 31
br i1 %18, label %19, label %28
19: ; preds = %11
%20 = load i8, i8* %9
%21 = icmp eq i8 %20, -117
br i1 %21, label %22, label %28
22: ; preds = %19
%23 = load i8, i8* %10
%24 = icmp eq i8 %23, 8
br i1 %24, label %25, label %28
25: ; preds = %22
%26 = load i8, i8* %5
%27 = icmp eq i8 %26, 0
br i1 %27, label %35, label %28
28: ; preds = %25, %22, %19, %11
%29 = add nsw i32 %13, -1
%30 = tail call i32 @memset(i8* %1, i32 0, i32 5000)
%31 = tail call i32* @fgets(i8* %1, i32 5000, i32* %0)
%32 = icmp ne i32* %31, null
%33 = icmp ne i32 %29, 0
%34 = select i1 %32, i1 %33, i1 false
br i1 %34, label %11, label %35
35: ; preds = %28, %25, %3
%36 = phi i32 [ 0, %3 ], [ 1, %25 ], [ 0, %28 ]
ret i32 %36
}