#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*/ uint8_t;
struct ip {
  scalar_t__ ip_p;
};
struct ether_header {
  int dummy;
};

/* Variables and functions */
scalar_t__ IPPROTO_GRE;
scalar_t__ IPPROTO_UDP;
int not_gre_pkt(uint8_t *machdr) {
  struct ip *iph;
  struct ip *ipin;
  iph = (struct ip *)(machdr + sizeof(struct ether_header));
  if (iph->ip_p != IPPROTO_GRE) {
    return (1);
  }
  ipin = (struct ip *)(((uint8_t *)iph) + sizeof(struct ip) + 4);
  if (ipin->ip_p != IPPROTO_UDP) {
    return (1);
  }
  return (0);
}


x86 assembly (clang, -O0):
<not_gre_pkt>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
add    $0x10,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    0x2ebe(%rip),%rcx
cmp    (%rcx),%rax
je     1137 <not_gre_pkt+0x37>
movl   $0x1,-0x4(%rbp)
jmp    1171 <not_gre_pkt+0x71>
mov    -0x18(%rbp),%rax
add    $0x20,%rax
add    $0x10,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    0x2e7b(%rip),%rcx
cmp    (%rcx),%rax
je     116a <not_gre_pkt+0x6a>
movl   $0x1,-0x4(%rbp)
jmp    1171 <not_gre_pkt+0x71>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<not_gre_pkt>:
mov    0x10(%rdi),%rcx
mov    0x2ed5(%rip),%rdx
mov    $0x1,%eax
cmp    (%rdx),%rcx
jne    1128 <not_gre_pkt+0x28>
mov    0x40(%rdi),%rcx
mov    0x2eb0(%rip),%rdx
xor    %eax,%eax
cmp    (%rdx),%rcx
setne  %al
ret

LLVM IR (-O0):
%struct.ip = type { i64 }
@IPPROTO_GRE = global i64 0
@IPPROTO_UDP = global i64 0
define i32 @not_gre_pkt(i32* %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca %struct.ip*
%5 = alloca %struct.ip*
store i32* %0, i32** %3
%6 = load i32*, i32** %3
%7 = getelementptr inbounds i32, i32* %6, i64 4
%8 = bitcast i32* %7 to %struct.ip*
store %struct.ip* %8, %struct.ip** %4
%9 = load %struct.ip*, %struct.ip** %4
%10 = getelementptr inbounds %struct.ip, %struct.ip* %9, i32 0, i32 0
%11 = load i64, i64* %10
%12 = load i64, i64* @IPPROTO_GRE
%13 = icmp ne i64 %11, %12
br i1 %13, label %14, label %15
14: ; preds = %1
store i32 1, i32* %2
br label %28
15: ; preds = %1
%16 = load %struct.ip*, %struct.ip** %4
%17 = bitcast %struct.ip* %16 to i32*
%18 = getelementptr inbounds i32, i32* %17, i64 8
%19 = getelementptr inbounds i32, i32* %18, i64 4
%20 = bitcast i32* %19 to %struct.ip*
store %struct.ip* %20, %struct.ip** %5
%21 = load %struct.ip*, %struct.ip** %5
%22 = getelementptr inbounds %struct.ip, %struct.ip* %21, i32 0, i32 0
%23 = load i64, i64* %22
%24 = load i64, i64* @IPPROTO_UDP
%25 = icmp ne i64 %23, %24
br i1 %25, label %26, label %27
26: ; preds = %15
store i32 1, i32* %2
br label %28
27: ; preds = %15
store i32 0, i32* %2
br label %28
28: ; preds = %27, %26, %14
%29 = load i32, i32* %2
ret i32 %29
}

LLVM IR (-O2):
@IPPROTO_GRE = global i64 0
@IPPROTO_UDP = global i64 0
define i32 @not_gre_pkt(i32* nocapture %0) {
%2 = getelementptr inbounds i32, i32* %0, i64 4
%3 = bitcast i32* %2 to i64*
%4 = load i64, i64* %3
%5 = load i64, i64* @IPPROTO_GRE
%6 = icmp eq i64 %4, %5
br i1 %6, label %7, label %14
7: ; preds = %1
%8 = getelementptr inbounds i32, i32* %0, i64 16
%9 = bitcast i32* %8 to i64*
%10 = load i64, i64* %9
%11 = load i64, i64* @IPPROTO_UDP
%12 = icmp ne i64 %10, %11
%13 = zext i1 %12 to i32
br label %14
14: ; preds = %7, %1
%15 = phi i32 [ 1, %1 ], [ %13, %7 ]
ret i32 %15
}