#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*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(char *, int, int, int /*<<< orphan*/ *);
bool test_gzip(char *filename) {
  FILE *fileptr;
  char buffer[2];
  fileptr = fopen(filename, "rb");
  fread(buffer, 2, 1, fileptr);
  if ((buffer[0] == '\x1F') && (buffer[1] == '\x8B'))
    return true;
  return false;
}


x86 assembly (clang, -O0):
<test_gzip>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xec9(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,-0x18(%rbp)
lea    -0x1a(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x2,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
movsbl -0x1a(%rbp),%eax
cmp    $0x1f,%eax
jne    117d <test_gzip+0x5d>
movsbl -0x19(%rbp),%eax
cmp    $0xffffff8b,%eax
jne    117d <test_gzip+0x5d>
movl   $0x1,-0x4(%rbp)
jmp    1184 <test_gzip+0x64>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_gzip>:
push   %rax
lea    0xed8(%rip),%rsi
call   1040 <fopen@plt>
lea    0x6(%rsp),%rdi
mov    $0x2,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1030 <fread@plt>
mov    0x6(%rsp),%cl
mov    0x7(%rsp),%dl
xor    $0x1f,%cl
xor    $0x8b,%dl
xor    %eax,%eax
or     %cl,%dl
sete   %al
pop    %rcx
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
define i32 @test_gzip(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca [2 x i8]
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %7, i32** %4
%8 = getelementptr inbounds [2 x i8], [2 x i8]* %5, i64 0, i64 0
%9 = load i32*, i32** %4
%10 = call i32 @fread(i8* %8, i32 2, i32 1, i32* %9)
%11 = getelementptr inbounds [2 x i8], [2 x i8]* %5, i64 0, i64 0
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = icmp eq i32 %13, 31
br i1 %14, label %15, label %21
15: ; preds = %1
%16 = getelementptr inbounds [2 x i8], [2 x i8]* %5, i64 0, i64 1
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp eq i32 %18, -117
br i1 %19, label %20, label %21
20: ; preds = %15
store i32 1, i32* %2
br label %22
21: ; preds = %15, %1
store i32 0, i32* %2
br label %22
22: ; preds = %21, %20
%23 = load i32, i32* %2
ret i32 %23
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
define i32 @test_gzip(i8* nocapture %0) {
%2 = alloca [2 x i8]
%3 = getelementptr inbounds [2 x i8], [2 x i8]* %2, i64 0, i64 0
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @fread(i8* %3, i32 2, i32 1, i32* %4)
%6 = load i8, i8* %3
%7 = icmp eq i8 %6, 31
%8 = getelementptr inbounds [2 x i8], [2 x i8]* %2, i64 0, i64 1
%9 = load i8, i8* %8
%10 = icmp eq i8 %9, -117
%11 = select i1 %7, i1 %10, i1 false
%12 = zext i1 %11 to i32
ret i32 %12
}