#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 scalar_t__ time_t;
struct timeval {
  int member_0;
  int /*<<< orphan*/ member_1;
};
struct can_frame {
  int can_id;
  int can_dlc;
};
typedef int /*<<< orphan*/ fd_set;

/* Variables and functions */
scalar_t__ FD_ISSET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_SET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int read(int, struct can_frame *, int);
scalar_t__ select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                  int /*<<< orphan*/ *, struct timeval *);
scalar_t__ time(int /*<<< orphan*/ *);
int canRead(int skt) {
  struct can_frame frame;
  int recvbytes = 0;
  int read_can_port = 1;
  time_t timeStart = time(NULL);
  while (read_can_port && (time(NULL) < (timeStart + 0.5))) {
    struct timeval timeout = {1, 0};
    fd_set readSet;
    FD_ZERO(&readSet);
    FD_SET(skt, &readSet);
    if (select((skt + 1), &readSet, NULL, NULL, &timeout) >= 0) {
      if (!read_can_port) {
        break;
      }
      if (FD_ISSET(skt, &readSet)) {
        recvbytes = read(skt, &frame, sizeof(struct can_frame));
        if (recvbytes) {
          int can_id = (frame.can_id & 0x1FFFFFFF);
          int can_address = (frame.can_id & 0x000000FF);
          printf("skt= %d dlc = %d, id= %02x\n", skt, frame.can_dlc, can_id);
          if (can_id == 0x18EAFFFE) {
            printf("Detected Adress-CLaim-Message");
            return 1;
          }
        }
      }
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<canRead>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x1,-0x18(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1060 <time@plt>
mov    %rax,-0x20(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x18(%rbp)
mov    %al,-0x35(%rbp)
je     11cf <canRead+0x5f>
xor    %eax,%eax
mov    %eax,%edi
call   1060 <time@plt>
cvtsi2sd %rax,%xmm1
cvtsi2sdq -0x20(%rbp),%xmm0
movsd  0xe3f(%rip),%xmm2
addsd  %xmm2,%xmm0
ucomisd %xmm1,%xmm0
seta   %al
mov    %al,-0x35(%rbp)
mov    -0x35(%rbp),%al
test   $0x1,%al
jne    11df <canRead+0x6f>
jmp    12ce <canRead+0x15e>
mov    0xe22(%rip),%rax
mov    %rax,-0x28(%rbp)
lea    -0x2c(%rbp),%rdi
call   1070 <FD_ZERO@plt>
mov    -0x8(%rbp),%edi
lea    -0x2c(%rbp),%rsi
call   1090 <FD_SET@plt>
mov    -0x8(%rbp),%edi
add    $0x1,%edi
lea    -0x2c(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x28(%rbp),%r8
mov    %rcx,%rdx
call   1080 <select@plt>
cmp    $0x0,%rax
jl     12c9 <canRead+0x159>
cmpl   $0x0,-0x18(%rbp)
jne    1232 <canRead+0xc2>
jmp    12ce <canRead+0x15e>
mov    -0x8(%rbp),%edi
lea    -0x2c(%rbp),%rsi
call   1030 <FD_ISSET@plt>
cmp    $0x0,%rax
je     12c4 <canRead+0x154>
mov    -0x8(%rbp),%edi
lea    -0x10(%rbp),%rsi
mov    $0x8,%edx
call   1050 <read@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     12bf <canRead+0x14f>
mov    -0x10(%rbp),%eax
and    $0x1fffffff,%eax
mov    %eax,-0x30(%rbp)
mov    -0x10(%rbp),%eax
and    $0xff,%eax
mov    %eax,-0x34(%rbp)
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
mov    -0x30(%rbp),%ecx
lea    0xd84(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x18eafffe,-0x30(%rbp)
jne    12ba <canRead+0x14a>
lea    0xd85(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12d5 <canRead+0x165>
jmp    12bf <canRead+0x14f>
jmp    12c4 <canRead+0x154>
jmp    12c9 <canRead+0x159>
jmp    1196 <canRead+0x26>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<canRead>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %edi,%ebx
xor    %r13d,%r13d
xor    %edi,%edi
call   1060 <time@plt>
mov    %rax,%rbp
xor    %edi,%edi
call   1060 <time@plt>
cvtsi2sd %rax,%xmm0
cvtsi2sd %rbp,%xmm1
addsd  0xe5a(%rip),%xmm1
movsd  %xmm1,0x10(%rsp)
ucomisd %xmm0,%xmm1
jbe    1289 <canRead+0x119>
lea    0x1(%rbx),%r14d
lea    0x24(%rsp),%r12
lea    0x18(%rsp),%r15
jmp    11f2 <canRead+0x82>
cs nopw 0x0(%rax,%rax,1)
xor    %r13d,%r13d
xor    %edi,%edi
call   1060 <time@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  0x10(%rsp),%xmm1
ucomisd %xmm0,%xmm1
jbe    1289 <canRead+0x119>
movq   $0x1,0x18(%rsp)
mov    %r12,%rdi
call   1070 <FD_ZERO@plt>
mov    %ebx,%edi
mov    %r12,%rsi
call   1090 <FD_SET@plt>
mov    %r14d,%edi
mov    %r12,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
mov    %r15,%r8
call   1080 <select@plt>
test   %rax,%rax
js     11d0 <canRead+0x60>
mov    %ebx,%edi
mov    %r12,%rsi
call   1030 <FD_ISSET@plt>
test   %rax,%rax
je     11d0 <canRead+0x60>
mov    %ebx,%edi
lea    0x8(%rsp),%rsi
mov    $0x8,%edx
call   1050 <read@plt>
test   %eax,%eax
je     11d0 <canRead+0x60>
mov    0x8(%rsp),%ebp
mov    $0x1fffffff,%eax
and    %eax,%ebp
mov    0xc(%rsp),%edx
lea    0xdaa(%rip),%rdi
mov    %ebx,%esi
mov    %ebp,%ecx
xor    %eax,%eax
call   1040 <printf@plt>
cmp    $0x18eafffe,%ebp
jne    11d0 <canRead+0x60>
lea    0xda8(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%r13d
mov    %r13d,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
%struct.can_frame = type { i32, i32 }
@__const.canRead.timeout = %struct.timeval { i32 1, i32 0 }
@.str = [28 x i8] c"skt= %d dlc = %d, id= %02x\0A\00"
@.str.1 = [30 x i8] c"Detected Adress-CLaim-Message\00"
define i32 @canRead(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.can_frame
%5 = alloca i32
%6 = alloca i32
%7 = alloca i64
%8 = alloca %struct.timeval
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 %0, i32* %3
store i32 0, i32* %5
store i32 1, i32* %6
%12 = call i64 @time(i32* null)
store i64 %12, i64* %7
br label %13
13: ; preds = %66, %1
%14 = load i32, i32* %6
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %23
16: ; preds = %13
%17 = call i64 @time(i32* null)
%18 = sitofp i64 %17 to double
%19 = load i64, i64* %7
%20 = sitofp i64 %19 to double
%21 = fadd double %20, 5.000000e-01
%22 = fcmp olt double %18, %21
br label %23
23: ; preds = %16, %13
%24 = phi i1 [ false, %13 ], [ %22, %16 ]
br i1 %24, label %25, label %67
25: ; preds = %23
%26 = bitcast %struct.timeval* %8 to i8*
%27 = call i32 @FD_ZERO(i32* %9)
%28 = load i32, i32* %3
%29 = call i32 @FD_SET(i32 %28, i32* %9)
%30 = load i32, i32* %3
%31 = add nsw i32 %30, 1
%32 = call i64 @select(i32 %31, i32* %9, i32* null, i32* null, %struct.timeval* %8)
%33 = icmp sge i64 %32, 0
br i1 %33, label %34, label %66
34: ; preds = %25
%35 = load i32, i32* %6
%36 = icmp ne i32 %35, 0
br i1 %36, label %38, label %37
37: ; preds = %34
br label %67
38: ; preds = %34
%39 = load i32, i32* %3
%40 = call i64 @FD_ISSET(i32 %39, i32* %9)
%41 = icmp ne i64 %40, 0
br i1 %41, label %42, label %65
42: ; preds = %38
%43 = load i32, i32* %3
%44 = call i32 @read(i32 %43, %struct.can_frame* %4, i32 8)
store i32 %44, i32* %5
%45 = load i32, i32* %5
%46 = icmp ne i32 %45, 0
br i1 %46, label %47, label %64
47: ; preds = %42
%48 = getelementptr inbounds %struct.can_frame, %struct.can_frame* %4, i32 0, i32 0
%49 = load i32, i32* %48
%50 = and i32 %49, 536870911
store i32 %50, i32* %10
%51 = getelementptr inbounds %struct.can_frame, %struct.can_frame* %4, i32 0, i32 0
%52 = load i32, i32* %51
%53 = and i32 %52, 255
store i32 %53, i32* %11
%54 = load i32, i32* %3
%55 = getelementptr inbounds %struct.can_frame, %struct.can_frame* %4, i32 0, i32 1
%56 = load i32, i32* %55
%57 = load i32, i32* %10
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i32 %54, i32 %56, i32 %57)
%59 = load i32, i32* %10
%60 = icmp eq i32 %59, 418054142
br i1 %60, label %61, label %63
61: ; preds = %47
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %2
br label %68
63: ; preds = %47
br label %64
64: ; preds = %63, %42
br label %65
65: ; preds = %64, %38
br label %66
66: ; preds = %65, %25
br label %13
67: ; preds = %37, %23
store i32 0, i32* %2
br label %68
68: ; preds = %67, %61
%69 = load i32, i32* %2
ret i32 %69
}

LLVM IR (-O2):
%struct.can_frame = type { i32, i32 }
%struct.timeval = type { i32, i32 }
@.str = [28 x i8] c"skt= %d dlc = %d, id= %02x\0A\00"
@.str.1 = [30 x i8] c"Detected Adress-CLaim-Message\00"
define i32 @canRead(i32 %0) {
%2 = alloca %struct.can_frame
%3 = alloca i64
%4 = bitcast i64* %3 to %struct.timeval*
%5 = alloca i32
%6 = bitcast %struct.can_frame* %2 to i8*
%7 = tail call i64 @time(i32* null)
%8 = call i64 @time(i32* null)
%9 = sitofp i64 %8 to double
%10 = sitofp i64 %7 to double
%11 = fadd double %10, 5.000000e-01
%12 = fcmp ogt double %11, %9
br i1 %12, label %13, label %42
13: ; preds = %1
%14 = bitcast i64* %3 to i8*
%15 = bitcast i32* %5 to i8*
%16 = add nsw i32 %0, 1
%17 = getelementptr inbounds %struct.can_frame, %struct.can_frame* %2, i64 0, i32 0
%18 = getelementptr inbounds %struct.can_frame, %struct.can_frame* %2, i64 0, i32 1
br label %19
19: ; preds = %13, %38
store i64 1, i64* %3
%20 = call i32 @FD_ZERO(i32* %5)
%21 = call i32 @FD_SET(i32 %0, i32* %5)
%22 = call i64 @select(i32 %16, i32* %5, i32* null, i32* null, %struct.timeval* %4)
%23 = icmp sgt i64 %22, -1
br i1 %23, label %24, label %38
24: ; preds = %19
%25 = call i64 @FD_ISSET(i32 %0, i32* %5)
%26 = icmp eq i64 %25, 0
br i1 %26, label %38, label %27
27: ; preds = %24
%28 = call i32 @read(i32 %0, %struct.can_frame* %2, i32 8)
%29 = icmp eq i32 %28, 0
br i1 %29, label %38, label %30
30: ; preds = %27
%31 = load i32, i32* %17
%32 = and i32 %31, 536870911
%33 = load i32, i32* %18
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i32 %0, i32 %33, i32 %32)
%35 = icmp eq i32 %32, 418054142
br i1 %35, label %36, label %38
36: ; preds = %30
%37 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
br label %42
38: ; preds = %19, %27, %24, %30
%39 = call i64 @time(i32* null)
%40 = sitofp i64 %39 to double
%41 = fcmp ogt double %11, %40
br i1 %41, label %19, label %42
42: ; preds = %38, %1, %36
%43 = phi i32 [ 1, %36 ], [ 0, %1 ], [ 0, %38 ]
ret i32 %43
}