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

/* Variables and functions */
int ip_get_version(int /*<<< orphan*/ const *, int);
int ip_read16(int /*<<< orphan*/ const *);
int ip_is_valid(const uint8_t *data, int size) {
  switch (ip_get_version(data, size)) {
  case 4:
    return size == ip_read16(&data[2]);
  case 6:
    return size == ip_read16(&data[4]) + 40;
  }
  return 0;
}


x86 assembly (clang, -O0):
<ip_is_valid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1030 <ip_get_version@plt>
mov    %eax,%ecx
mov    %ecx,-0x18(%rbp)
sub    $0x4,%eax
je     115f <ip_is_valid+0x3f>
jmp    114e <ip_is_valid+0x2e>
mov    -0x18(%rbp),%eax
sub    $0x6,%eax
je     1189 <ip_is_valid+0x69>
jmp    11b6 <ip_is_valid+0x96>
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
add    $0x8,%rdi
call   1040 <ip_read16@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
cmp    %ecx,%eax
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
jmp    11bd <ip_is_valid+0x9d>
mov    -0x14(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
add    $0x10,%rdi
call   1040 <ip_read16@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
add    $0x28,%ecx
cmp    %ecx,%eax
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
jmp    11bd <ip_is_valid+0x9d>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ip_is_valid>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
call   1030 <ip_get_version@plt>
cmp    $0x6,%eax
je     1145 <ip_is_valid+0x25>
cmp    $0x4,%eax
jne    115b <ip_is_valid+0x3b>
add    $0x8,%rbx
mov    %rbx,%rdi
call   1040 <ip_read16@plt>
jmp    1154 <ip_is_valid+0x34>
add    $0x10,%rbx
mov    %rbx,%rdi
call   1040 <ip_read16@plt>
add    $0x28,%eax
cmp    %ebp,%eax
sete   %al
jmp    115d <ip_is_valid+0x3d>
xor    %eax,%eax
movzbl %al,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @ip_is_valid(i32* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
%6 = load i32*, i32** %4
%7 = load i32, i32* %5
%8 = call i32 @ip_get_version(i32* %6, i32 %7)
switch i32 %8, label %24 [
i32 4, label %9
i32 6, label %16
]
9: ; preds = %2
%10 = load i32, i32* %5
%11 = load i32*, i32** %4
%12 = getelementptr inbounds i32, i32* %11, i64 2
%13 = call i32 @ip_read16(i32* %12)
%14 = icmp eq i32 %10, %13
%15 = zext i1 %14 to i32
store i32 %15, i32* %3
br label %25
16: ; preds = %2
%17 = load i32, i32* %5
%18 = load i32*, i32** %4
%19 = getelementptr inbounds i32, i32* %18, i64 4
%20 = call i32 @ip_read16(i32* %19)
%21 = add nsw i32 %20, 40
%22 = icmp eq i32 %17, %21
%23 = zext i1 %22 to i32
store i32 %23, i32* %3
br label %25
24: ; preds = %2
store i32 0, i32* %3
br label %25
25: ; preds = %24, %16, %9
%26 = load i32, i32* %3
ret i32 %26
}

LLVM IR (-O2):
define i32 @ip_is_valid(i32* %0, i32 %1) {
%3 = tail call i32 @ip_get_version(i32* %0, i32 %1)
switch i32 %3, label %13 [
i32 4, label %4
i32 6, label %8
]
4: ; preds = %2
%5 = getelementptr inbounds i32, i32* %0, i64 2
%6 = tail call i32 @ip_read16(i32* %5)
%7 = icmp eq i32 %6, %1
br label %13
8: ; preds = %2
%9 = getelementptr inbounds i32, i32* %0, i64 4
%10 = tail call i32 @ip_read16(i32* %9)
%11 = add nsw i32 %10, 40
%12 = icmp eq i32 %11, %1
br label %13
13: ; preds = %2, %8, %4
%14 = phi i1 [ %12, %8 ], [ %7, %4 ], [ false, %2 ]
%15 = zext i1 %14 to i32
ret i32 %15
}