#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 uint32_t;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int getmagicnumber(int);
int open(char *, int /*<<< orphan*/);
bool testgzipfile(char *pcapinname) {
  int pcapr_fd;
  uint32_t magicnumber;
  pcapr_fd = open(pcapinname, O_RDONLY);
  if (pcapr_fd == -1)
    return false;
  magicnumber = getmagicnumber(pcapr_fd);
  close(pcapr_fd);
  if ((magicnumber & 0xffff) != 0x8b1f)
    return false;
  if (((magicnumber >> 16) & 0xff) != 0x08)
    return false;
  return true;
}


x86 assembly (clang, -O0):
<testgzipfile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2ea1(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1167 <testgzipfile+0x37>
movl   $0x0,-0x4(%rbp)
jmp    11c0 <testgzipfile+0x90>
mov    -0x14(%rbp),%edi
call   1030 <getmagicnumber@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
mov    -0x18(%rbp),%eax
and    $0xffff,%eax
cmp    $0x8b1f,%eax
je     1199 <testgzipfile+0x69>
movl   $0x0,-0x4(%rbp)
jmp    11c0 <testgzipfile+0x90>
mov    -0x18(%rbp),%eax
sar    $0x10,%eax
and    $0xff,%eax
cmp    $0x8,%eax
je     11b9 <testgzipfile+0x89>
movl   $0x0,-0x4(%rbp)
jmp    11c0 <testgzipfile+0x90>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<testgzipfile>:
push   %rbp
push   %r14
push   %rbx
mov    0x2ead(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
xor    %r14d,%r14d
cmp    $0xffffffff,%eax
je     1179 <testgzipfile+0x49>
mov    %eax,%ebx
mov    %eax,%edi
call   1030 <getmagicnumber@plt>
mov    %eax,%ebp
mov    %ebx,%edi
call   1040 <close@plt>
movzwl %bp,%eax
cmp    $0x8b1f,%eax
jne    1179 <testgzipfile+0x49>
and    $0xff0000,%ebp
xor    %r14d,%r14d
cmp    $0x80000,%ebp
sete   %r14b
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@O_RDONLY = global i32 0
define i32 @testgzipfile(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = load i32, i32* @O_RDONLY
%8 = call i32 @open(i8* %6, i32 %7)
store i32 %8, i32* %4
%9 = load i32, i32* %4
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %12
11: ; preds = %1
store i32 0, i32* %2
br label %28
12: ; preds = %1
%13 = load i32, i32* %4
%14 = call i32 @getmagicnumber(i32 %13)
store i32 %14, i32* %5
%15 = load i32, i32* %4
%16 = call i32 @close(i32 %15)
%17 = load i32, i32* %5
%18 = and i32 %17, 65535
%19 = icmp ne i32 %18, 35615
br i1 %19, label %20, label %21
20: ; preds = %12
store i32 0, i32* %2
br label %28
21: ; preds = %12
%22 = load i32, i32* %5
%23 = ashr i32 %22, 16
%24 = and i32 %23, 255
%25 = icmp ne i32 %24, 8
br i1 %25, label %26, label %27
26: ; preds = %21
store i32 0, i32* %2
br label %28
27: ; preds = %21
store i32 1, i32* %2
br label %28
28: ; preds = %27, %26, %20, %11
%29 = load i32, i32* %2
ret i32 %29
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
define i32 @testgzipfile(i8* nocapture %0) {
%2 = load i32, i32* @O_RDONLY
%3 = tail call i32 @open(i8* %0, i32 %2)
%4 = icmp eq i32 %3, -1
br i1 %4, label %14, label %5
5: ; preds = %1
%6 = tail call i32 @getmagicnumber(i32 %3)
%7 = tail call i32 @close(i32 %3)
%8 = and i32 %6, 65535
%9 = icmp eq i32 %8, 35615
br i1 %9, label %10, label %14
10: ; preds = %5
%11 = and i32 %6, 16711680
%12 = icmp eq i32 %11, 524288
%13 = zext i1 %12 to i32
br label %14
14: ; preds = %10, %5, %1
%15 = phi i32 [ 0, %1 ], [ 0, %5 ], [ %13, %10 ]
ret i32 %15
}