#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 */
struct timespec {
  scalar_t__ tv_sec;
  scalar_t__ tv_nsec;
};

/* Variables and functions */
int /*<<< orphan*/ CLOCK_MONOTONIC_RAW;
int /*<<< orphan*/ clock_gettime(int /*<<< orphan*/, struct timespec *);
int /*<<< orphan*/ memcpy(void *, void const *, int);
int packet_is_ok(void *buffer, size_t len) {
  struct timespec ctime;
  struct timespec ptime;
  if (len < (sizeof(struct timespec)))
    return 0;
  memcpy((void *)&ptime, (const void *)buffer, sizeof(struct timespec));
  clock_gettime(CLOCK_MONOTONIC_RAW, &ctime);
  if ((ptime.tv_sec < ctime.tv_sec ||
       (ptime.tv_sec == ctime.tv_sec && ptime.tv_nsec < ctime.tv_nsec)))
    return 0;
  return 1;
}


x86 assembly (clang, -O0):
<packet_is_ok>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x10,-0x18(%rbp)
jae    1147 <packet_is_ok+0x27>
movl   $0x0,-0x4(%rbp)
jmp    11a8 <packet_is_ok+0x88>
lea    -0x38(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x10,%edx
call   1040 <memcpy@plt>
mov    0x2e88(%rip),%rax
mov    (%rax),%edi
lea    -0x28(%rbp),%rsi
call   1030 <clock_gettime@plt>
mov    -0x38(%rbp),%rax
cmp    -0x28(%rbp),%rax
jl     1195 <packet_is_ok+0x75>
mov    -0x38(%rbp),%rax
cmp    -0x28(%rbp),%rax
jne    11a1 <packet_is_ok+0x81>
mov    -0x30(%rbp),%rax
cmp    -0x20(%rbp),%rax
jge    11a1 <packet_is_ok+0x81>
movl   $0x0,-0x4(%rbp)
jmp    11a8 <packet_is_ok+0x88>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<packet_is_ok>:
push   %rbx
sub    $0x20,%rsp
xor    %ebx,%ebx
cmp    $0x10,%rsi
jb     1171 <packet_is_ok+0x51>
mov    %rdi,%rax
mov    %rsp,%rdi
mov    %rax,%rsi
mov    $0x10,%edx
call   1040 <memcpy@plt>
mov    0x2ea1(%rip),%rax
mov    (%rax),%edi
lea    0x10(%rsp),%rsi
call   1030 <clock_gettime@plt>
mov    0x10(%rsp),%rax
cmp    %rax,(%rsp)
jl     1171 <packet_is_ok+0x51>
jne    116c <packet_is_ok+0x4c>
mov    0x8(%rsp),%rax
cmp    0x18(%rsp),%rax
jl     1171 <packet_is_ok+0x51>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.timespec = type { i64, i64 }
@CLOCK_MONOTONIC_RAW = global i32 0
define i32 @packet_is_ok(i8* %0, i64 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
%6 = alloca %struct.timespec
%7 = alloca %struct.timespec
store i8* %0, i8** %4
store i64 %1, i64* %5
%8 = load i64, i64* %5
%9 = icmp ult i64 %8, 16
br i1 %9, label %10, label %11
10: ; preds = %2
store i32 0, i32* %3
br label %36
11: ; preds = %2
%12 = bitcast %struct.timespec* %7 to i8*
%13 = load i8*, i8** %4
%14 = call i32 @memcpy(i8* %12, i8* %13, i32 16)
%15 = load i32, i32* @CLOCK_MONOTONIC_RAW
%16 = call i32 @clock_gettime(i32 %15, %struct.timespec* %6)
%17 = getelementptr inbounds %struct.timespec, %struct.timespec* %7, i32 0, i32 0
%18 = load i64, i64* %17
%19 = getelementptr inbounds %struct.timespec, %struct.timespec* %6, i32 0, i32 0
%20 = load i64, i64* %19
%21 = icmp slt i64 %18, %20
br i1 %21, label %34, label %22
22: ; preds = %11
%23 = getelementptr inbounds %struct.timespec, %struct.timespec* %7, i32 0, i32 0
%24 = load i64, i64* %23
%25 = getelementptr inbounds %struct.timespec, %struct.timespec* %6, i32 0, i32 0
%26 = load i64, i64* %25
%27 = icmp eq i64 %24, %26
br i1 %27, label %28, label %35
28: ; preds = %22
%29 = getelementptr inbounds %struct.timespec, %struct.timespec* %7, i32 0, i32 1
%30 = load i64, i64* %29
%31 = getelementptr inbounds %struct.timespec, %struct.timespec* %6, i32 0, i32 1
%32 = load i64, i64* %31
%33 = icmp slt i64 %30, %32
br i1 %33, label %34, label %35
34: ; preds = %28, %11
store i32 0, i32* %3
br label %36
35: ; preds = %28, %22
store i32 1, i32* %3
br label %36
36: ; preds = %35, %34, %10
%37 = load i32, i32* %3
ret i32 %37
}

LLVM IR (-O2):
%struct.timespec = type { i64, i64 }
@CLOCK_MONOTONIC_RAW = global i32 0
define i32 @packet_is_ok(i8* %0, i64 %1) {
%3 = alloca %struct.timespec
%4 = alloca %struct.timespec
%5 = bitcast %struct.timespec* %3 to i8*
%6 = bitcast %struct.timespec* %4 to i8*
%7 = icmp ult i64 %1, 16
br i1 %7, label %26, label %8
8: ; preds = %2
%9 = call i32 @memcpy(i8* %6, i8* %0, i32 16)
%10 = load i32, i32* @CLOCK_MONOTONIC_RAW
%11 = call i32 @clock_gettime(i32 %10, %struct.timespec* %3)
%12 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i64 0, i32 0
%13 = load i64, i64* %12
%14 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i64 0, i32 0
%15 = load i64, i64* %14
%16 = icmp slt i64 %13, %15
br i1 %16, label %26, label %17
17: ; preds = %8
%18 = icmp eq i64 %13, %15
br i1 %18, label %19, label %25
19: ; preds = %17
%20 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i64 0, i32 1
%21 = load i64, i64* %20
%22 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i64 0, i32 1
%23 = load i64, i64* %22
%24 = icmp slt i64 %21, %23
br i1 %24, label %26, label %25
25: ; preds = %19, %17
br label %26
26: ; preds = %8, %19, %2, %25
%27 = phi i32 [ 1, %25 ], [ 0, %2 ], [ 0, %19 ], [ 0, %8 ]
ret i32 %27
}