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

/* Variables and functions */
int /*<<< orphan*/ SEEK_SET;
int fread(int *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
int htonl(int);
int pcap_file_is_pcap(FILE *fp) {
  u_int32_t magic;
  int len;
  int ret = 0;
  len = fread(&magic, 1, 4, fp);
  if (len == 4 && (magic == 0xA1B2C3D4 || magic == htonl(0xA1B2C3D4))) {
    ret = 1;
  }
  fseek(fp, 0, SEEK_SET);
  return ret;
}


x86 assembly (clang, -O0):
<pcap_file_is_pcap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rcx
lea    -0xc(%rbp),%rdi
mov    $0x1,%esi
mov    $0x4,%edx
call   1030 <fread@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x4,-0x10(%rbp)
jne    1198 <pcap_file_is_pcap+0x68>
cmpl   $0xa1b2c3d4,-0xc(%rbp)
je     1191 <pcap_file_is_pcap+0x61>
mov    -0xc(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    $0xa1b2c3d4,%edi
call   1040 <htonl@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
cmp    %ecx,%eax
jne    1198 <pcap_file_is_pcap+0x68>
movl   $0x1,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e3d(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1050 <fseek@plt>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pcap_file_is_pcap>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
lea    0xc(%rsp),%rdi
mov    $0x1,%esi
mov    $0x4,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
xor    %ebp,%ebp
cmp    $0x4,%eax
jne    117b <pcap_file_is_pcap+0x4b>
mov    0xc(%rsp),%r14d
cmp    $0xa1b2c3d4,%r14d
je     1176 <pcap_file_is_pcap+0x46>
mov    $0xa1b2c3d4,%edi
call   1040 <htonl@plt>
cmp    %eax,%r14d
jne    117b <pcap_file_is_pcap+0x4b>
mov    $0x1,%ebp
mov    0x2e5e(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1050 <fseek@plt>
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@SEEK_SET = global i32 0
define i32 @pcap_file_is_pcap(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32* %0, i32** %2
store i32 0, i32* %5
%6 = load i32*, i32** %2
%7 = call i32 @fread(i32* %3, i32 1, i32 4, i32* %6)
store i32 %7, i32* %4
%8 = load i32, i32* %4
%9 = icmp eq i32 %8, 4
br i1 %9, label %10, label %18
10: ; preds = %1
%11 = load i32, i32* %3
%12 = icmp eq i32 %11, -1582119980
br i1 %12, label %17, label %13
13: ; preds = %10
%14 = load i32, i32* %3
%15 = call i32 @htonl(i32 -1582119980)
%16 = icmp eq i32 %14, %15
br i1 %16, label %17, label %18
17: ; preds = %13, %10
store i32 1, i32* %5
br label %18
18: ; preds = %17, %13, %1
%19 = load i32*, i32** %2
%20 = load i32, i32* @SEEK_SET
%21 = call i32 @fseek(i32* %19, i32 0, i32 %20)
%22 = load i32, i32* %5
ret i32 %22
}

LLVM IR (-O2):
@SEEK_SET = global i32 0
define i32 @pcap_file_is_pcap(i32* nocapture %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = call i32 @fread(i32* %2, i32 1, i32 4, i32* %0)
%5 = icmp eq i32 %4, 4
br i1 %5, label %6, label %13
6: ; preds = %1
%7 = load i32, i32* %2
%8 = icmp eq i32 %7, -1582119980
br i1 %8, label %12, label %9
9: ; preds = %6
%10 = tail call i32 @htonl(i32 -1582119980)
%11 = icmp eq i32 %7, %10
br i1 %11, label %12, label %13
12: ; preds = %9, %6
br label %13
13: ; preds = %12, %9, %1
%14 = phi i32 [ 1, %12 ], [ 0, %9 ], [ 0, %1 ]
%15 = load i32, i32* @SEEK_SET
%16 = tail call i32 @fseek(i32* %0, i32 0, i32 %15)
ret i32 %14
}