#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 sockaddr_can {
  int can_ifindex;
  int /*<<< orphan*/ can_family;
};
struct sockaddr {
  int dummy;
};
struct ifreq {
  int ifr_ifindex;
  int /*<<< orphan*/ ifr_name;
};
struct can_frame {
  int can_id;
  int can_dlc;
  int *data;
};
struct can_filter {
  int can_id;
  int can_mask;
};
typedef int /*<<< orphan*/ rfilter;
typedef int /*<<< orphan*/ frame;
typedef int /*<<< orphan*/ fd_set;
typedef int /*<<< orphan*/ addr;

/* Variables and functions */
int /*<<< orphan*/ AF_CAN;
int CAN_EFF_FLAG;
int /*<<< orphan*/ CAN_RAW;
int /*<<< orphan*/ CAN_RAW_FILTER;
int CAN_RTR_FLAG;
int CAN_SFF_MASK;
scalar_t__ FD_ISSET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_SET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
int /*<<< orphan*/ PF_CAN;
int /*<<< orphan*/ SIOCGIFINDEX;
int /*<<< orphan*/ SOCK_RAW;
int /*<<< orphan*/ SOL_CAN_RAW;
scalar_t__ bind(int, struct sockaddr *, int);
int calc_id(int);
int calc_mask(int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ ioctl(int, int /*<<< orphan*/, struct ifreq *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int, ...);
int read(int, struct can_frame *, int);
int select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
           int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/,
                              struct can_filter *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcpy(int /*<<< orphan*/, char *);
scalar_t__ write(int, struct can_frame *, int);
int main(int argc, char **argv) {
  fd_set rdfs;
  int s, t;
  struct sockaddr_can addr;
  struct can_filter rfilter;
  struct can_frame frame;
  int testcase = 0;
  int nbytes, ret;
  struct ifreq ifr;
  int ifindex;
  if ((s = socket(PF_CAN, SOCK_RAW, CAN_RAW)) < 0) {
    perror("socket");
    return 1;
  }
  if ((t = socket(PF_CAN, SOCK_RAW, CAN_RAW)) < 0) {
    perror("socket");
    return 1;
  }
  strcpy(ifr.ifr_name, "vcan0");
  ioctl(s, SIOCGIFINDEX, &ifr);
  ifindex = ifr.ifr_ifindex;
  addr.can_family = AF_CAN;
  addr.can_ifindex = ifindex;
  if (bind(s, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
    perror("bind");
    return 1;
  }
  if (bind(t, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
    perror("bind");
    return 1;
  }
  rfilter.can_id = 0xF;
  rfilter.can_mask = CAN_SFF_MASK | CAN_EFF_FLAG | CAN_RTR_FLAG;
  setsockopt(s, SOL_CAN_RAW, CAN_RAW_FILTER, &rfilter, sizeof(rfilter));
  setsockopt(t, SOL_CAN_RAW, CAN_RAW_FILTER, NULL, 0);
  while (1) {
    FD_ZERO(&rdfs);
    FD_SET(s, &rdfs);
    FD_SET(t, &rdfs);
    if ((ret = select(t + 1, &rdfs, NULL, NULL, NULL)) < 0) {
      perror("select");
      break;
    }
    if (FD_ISSET(s, &rdfs)) {
      if ((nbytes = read(s, &frame, sizeof(struct can_frame))) < 0) {
        perror("read");
        exit(1);
      }
      if (nbytes < sizeof(struct can_frame)) {
        fprintf(stderr, "read: incomplete CAN frame\n");
        exit(1);
      }
      if ((frame.can_id != 0xF) || (frame.can_dlc != 1)) {
        fprintf(stderr, "\nWrong request from master!\n");
        exit(1);
      }
      testcase = frame.data[0];
      if (testcase < 18) {
        rfilter.can_id = calc_id(testcase);
        rfilter.can_mask = calc_mask(testcase);
        setsockopt(t, SOL_CAN_RAW, CAN_RAW_FILTER, &rfilter, sizeof(rfilter));
        printf("testcase %2d : can_id = 0x%08X can_mask = 0x%08X\n", testcase,
               rfilter.can_id, rfilter.can_mask);
      }
      frame.can_id = 0xFA;
      if (write(s, &frame, sizeof(frame)) < 0) {
        perror("write");
        exit(1);
      }
      if (testcase > 17)
        break;
    }
    if (FD_ISSET(t, &rdfs)) {
      if ((nbytes = read(t, &frame, sizeof(struct can_frame))) < 0) {
        perror("read");
        exit(1);
      }
      if (nbytes < sizeof(struct can_frame)) {
        fprintf(stderr, "read: incomplete CAN frame\n");
        exit(1);
      }
      printf("%08X\n", frame.can_id);
    }
  }
  printf("testcase %2d : Filtertest done.\n", testcase);
  close(s);
  close(t);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x44(%rbp)
mov    0x2d64(%rip),%rax
mov    (%rax),%edi
mov    0x2d93(%rip),%rax
mov    (%rax),%esi
mov    0x2d4a(%rip),%rax
mov    (%rax),%edx
call   1140 <socket@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jge    1281 <main+0x61>
lea    0xd90(%rip),%rdi
call   1110 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1636 <main+0x416>
mov    0x2d20(%rip),%rax
mov    (%rax),%edi
mov    0x2d4f(%rip),%rax
mov    (%rax),%esi
mov    0x2d06(%rip),%rax
mov    (%rax),%edx
call   1140 <socket@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jge    12c5 <main+0xa5>
lea    0xd4c(%rip),%rdi
call   1110 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1636 <main+0x416>
mov    -0x54(%rbp),%edi
lea    0xd38(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x18(%rbp),%edi
mov    0x2caa(%rip),%rax
mov    (%rax),%esi
lea    -0x58(%rbp),%rdx
call   1090 <ioctl@plt>
mov    -0x58(%rbp),%eax
mov    %eax,-0x5c(%rbp)
mov    0x2cfa(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x5c(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x18(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0x8,%edx
call   1100 <bind@plt>
cmp    $0x0,%rax
jge    1334 <main+0x114>
lea    0xcea(%rip),%rdi
call   1110 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1636 <main+0x416>
mov    -0x1c(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0x8,%edx
call   1100 <bind@plt>
cmp    $0x0,%rax
jge    1367 <main+0x147>
lea    0xcb7(%rip),%rdi
call   1110 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1636 <main+0x416>
movl   $0xf,-0x30(%rbp)
mov    0x2c1b(%rip),%rax
mov    (%rax),%eax
mov    0x2c3a(%rip),%rcx
or     (%rcx),%eax
mov    0x2c29(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%edi
mov    0x2c42(%rip),%rax
mov    (%rax),%esi
mov    0x2c21(%rip),%rax
mov    (%rax),%edx
lea    -0x30(%rbp),%rcx
mov    $0x8,%r8d
call   1040 <setsockopt@plt>
mov    -0x1c(%rbp),%edi
mov    0x2c1e(%rip),%rax
mov    (%rax),%esi
mov    0x2bfd(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%ecx
xor    %r8d,%r8d
call   1040 <setsockopt@plt>
lea    -0x14(%rbp),%rdi
call   10e0 <FD_ZERO@plt>
mov    -0x18(%rbp),%edi
lea    -0x14(%rbp),%rsi
call   1130 <FD_SET@plt>
mov    -0x1c(%rbp),%edi
lea    -0x14(%rbp),%rsi
call   1130 <FD_SET@plt>
mov    -0x1c(%rbp),%edi
add    $0x1,%edi
lea    -0x14(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%r8d
mov    %r8,%rdx
mov    %r8,%rcx
call   10f0 <select@plt>
mov    %eax,-0x4c(%rbp)
cmp    $0x0,%eax
jge    1429 <main+0x209>
lea    0xbf3(%rip),%rdi
call   1110 <perror@plt>
jmp    160e <main+0x3ee>
mov    -0x18(%rbp),%edi
lea    -0x14(%rbp),%rsi
call   1060 <FD_ISSET@plt>
cmp    $0x0,%rax
je     1582 <main+0x362>
mov    -0x18(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    $0x10,%edx
call   10b0 <read@plt>
mov    %eax,-0x48(%rbp)
cmp    $0x0,%eax
jge    1472 <main+0x252>
lea    0xbb6(%rip),%rdi
call   1110 <perror@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
movslq -0x48(%rbp),%rax
cmp    $0x10,%rax
jae    149f <main+0x27f>
mov    0x2b41(%rip),%rax
mov    (%rax),%edi
lea    0xb8e(%rip),%rsi
call   10d0 <fprintf@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
cmpl   $0xf,-0x40(%rbp)
jne    14b3 <main+0x293>
cmpl   $0x1,-0x3c(%rbp)
je     14d2 <main+0x2b2>
mov    0x2b0e(%rip),%rax
mov    (%rax),%edi
lea    0xb77(%rip),%rsi
call   10d0 <fprintf@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
mov    -0x38(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
cmpl   $0x12,-0x44(%rbp)
jge    1536 <main+0x316>
mov    -0x44(%rbp),%edi
call   10c0 <calc_id@plt>
mov    %eax,-0x30(%rbp)
mov    -0x44(%rbp),%edi
call   1070 <calc_mask@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x1c(%rbp),%edi
mov    0x2ad3(%rip),%rax
mov    (%rax),%esi
mov    0x2ab2(%rip),%rax
mov    (%rax),%edx
lea    -0x30(%rbp),%rcx
mov    $0x8,%r8d
call   1040 <setsockopt@plt>
mov    -0x44(%rbp),%esi
mov    -0x30(%rbp),%edx
mov    -0x2c(%rbp),%ecx
lea    0xb28(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
movl   $0xfa,-0x40(%rbp)
mov    -0x18(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    $0x10,%edx
call   1050 <write@plt>
cmp    $0x0,%rax
jge    156e <main+0x34e>
lea    0xb2a(%rip),%rdi
call   1110 <perror@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
cmpl   $0x11,-0x44(%rbp)
jle    157d <main+0x35d>
jmp    160e <main+0x3ee>
jmp    1582 <main+0x362>
mov    -0x1c(%rbp),%edi
lea    -0x14(%rbp),%rsi
call   1060 <FD_ISSET@plt>
cmp    $0x0,%rax
je     1609 <main+0x3e9>
mov    -0x1c(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    $0x10,%edx
call   10b0 <read@plt>
mov    %eax,-0x48(%rbp)
cmp    $0x0,%eax
jge    15cb <main+0x3ab>
lea    0xa5d(%rip),%rdi
call   1110 <perror@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
movslq -0x48(%rbp),%rax
cmp    $0x10,%rax
jae    15f8 <main+0x3d8>
mov    0x29e8(%rip),%rax
mov    (%rax),%edi
lea    0xa35(%rip),%rsi
call   10d0 <fprintf@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
mov    -0x40(%rbp),%esi
lea    0xa81(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
jmp    13d1 <main+0x1b1>
mov    -0x44(%rbp),%esi
lea    0xa77(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x18(%rbp),%edi
call   10a0 <close@plt>
mov    -0x1c(%rbp),%edi
call   10a0 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    0x2d73(%rip),%r14
mov    (%r14),%edi
mov    0x2da1(%rip),%rbp
mov    0x0(%rbp),%esi
mov    0x2d57(%rip),%rbx
mov    (%rbx),%edx
call   1140 <socket@plt>
test   %eax,%eax
js     14ec <main+0x2cc>
mov    %eax,%r12d
mov    (%r14),%edi
mov    0x0(%rbp),%esi
mov    (%rbx),%edx
call   1140 <socket@plt>
test   %eax,%eax
js     14ec <main+0x2cc>
mov    %eax,%r15d
lea    0xd8d(%rip),%rsi
call   1030 <strcpy@plt>
mov    0x2d02(%rip),%rax
mov    (%rax),%esi
lea    0x30(%rsp),%rdx
mov    %r12d,%edi
call   1090 <ioctl@plt>
mov    0x30(%rsp),%eax
mov    0x2d50(%rip),%rcx
mov    (%rcx),%ecx
mov    %ecx,0x14(%rsp)
mov    %eax,0x10(%rsp)
lea    0x10(%rsp),%rsi
mov    %r12d,%edi
mov    $0x8,%edx
call   1100 <bind@plt>
test   %rax,%rax
js     1525 <main+0x305>
lea    0x10(%rsp),%rsi
mov    %r15d,%edi
mov    $0x8,%edx
call   1100 <bind@plt>
test   %rax,%rax
js     1525 <main+0x305>
movl   $0xf,0x8(%rsp)
mov    0x2ca1(%rip),%rax
mov    0x2cc2(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2caf(%rip),%rax
or     (%rax),%ecx
mov    %ecx,0xc(%rsp)
mov    0x2cca(%rip),%rbx
mov    (%rbx),%esi
mov    0x2ca9(%rip),%rbp
mov    0x0(%rbp),%edx
lea    0x8(%rsp),%rcx
mov    %r12d,%edi
mov    $0x8,%r8d
call   1040 <setsockopt@plt>
mov    (%rbx),%esi
mov    0x0(%rbp),%edx
xor    %ebp,%ebp
mov    %r15d,%edi
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1040 <setsockopt@plt>
mov    %r15d,%r14d
add    $0x1,%r14d
lea    0x1c(%rsp),%rbx
mov    %rbx,%rdi
call   10e0 <FD_ZERO@plt>
mov    %r12d,%edi
mov    %rbx,%rsi
call   1130 <FD_SET@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
call   1130 <FD_SET@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   10f0 <select@plt>
test   %eax,%eax
js     14f5 <main+0x2d5>
lea    0x1c(%rsp),%rbx
lea    0x20(%rsp),%r13
xor    %ebp,%ebp
jmp    13d8 <main+0x1b8>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
call   10e0 <FD_ZERO@plt>
mov    %r12d,%edi
mov    %rbx,%rsi
call   1130 <FD_SET@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
call   1130 <FD_SET@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   10f0 <select@plt>
test   %eax,%eax
js     14f5 <main+0x2d5>
mov    %r12d,%edi
mov    %rbx,%rsi
call   1060 <FD_ISSET@plt>
test   %rax,%rax
je     14a8 <main+0x288>
mov    %r12d,%edi
mov    %r13,%rsi
mov    $0x10,%edx
call   10b0 <read@plt>
test   %eax,%eax
js     1547 <main+0x327>
cmp    $0xf,%eax
jbe    1550 <main+0x330>
cmpl   $0xf,0x20(%rsp)
jne    1562 <main+0x342>
cmpl   $0x1,0x24(%rsp)
jne    1562 <main+0x342>
mov    0x28(%rsp),%rax
mov    (%rax),%ebp
cmp    $0x11,%ebp
jg     1482 <main+0x262>
mov    %ebp,%edi
call   10c0 <calc_id@plt>
mov    %eax,0x8(%rsp)
mov    %ebp,%edi
call   1070 <calc_mask@plt>
mov    %eax,0xc(%rsp)
mov    0x2b8c(%rip),%rax
mov    (%rax),%esi
mov    0x2b6b(%rip),%rax
mov    (%rax),%edx
mov    %r15d,%edi
lea    0x8(%rsp),%rcx
mov    $0x8,%r8d
call   1040 <setsockopt@plt>
mov    0x8(%rsp),%edx
mov    0xc(%rsp),%ecx
lea    0xbde(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1080 <printf@plt>
movl   $0xfa,0x20(%rsp)
mov    %r12d,%edi
mov    %r13,%rsi
mov    $0x10,%edx
call   1050 <write@plt>
test   %rax,%rax
js     1581 <main+0x361>
cmp    $0x11,%ebp
jg     1501 <main+0x2e1>
mov    %r15d,%edi
mov    %rbx,%rsi
call   1060 <FD_ISSET@plt>
test   %rax,%rax
je     13a0 <main+0x180>
mov    %r15d,%edi
mov    %r13,%rsi
mov    $0x10,%edx
call   10b0 <read@plt>
test   %eax,%eax
js     1547 <main+0x327>
cmp    $0xf,%eax
jbe    1550 <main+0x330>
mov    0x20(%rsp),%esi
lea    0xba3(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
jmp    13a0 <main+0x180>
lea    0xb0d(%rip),%rdi
jmp    152c <main+0x30c>
lea    0xb16(%rip),%rdi
call   1110 <perror@plt>
lea    0xb87(%rip),%rdi
xor    %ebx,%ebx
mov    %ebp,%esi
xor    %eax,%eax
call   1080 <printf@plt>
mov    %r12d,%edi
call   10a0 <close@plt>
mov    %r15d,%edi
call   10a0 <close@plt>
jmp    1536 <main+0x316>
lea    0xae1(%rip),%rdi
call   1110 <perror@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xacb(%rip),%rdi
jmp    1588 <main+0x368>
mov    0x2a71(%rip),%rax
mov    (%rax),%edi
lea    0xabe(%rip),%rsi
jmp    1572 <main+0x352>
mov    0x2a5f(%rip),%rax
mov    (%rax),%edi
lea    0xac8(%rip),%rsi
call   10d0 <fprintf@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
lea    0xb01(%rip),%rdi
call   1110 <perror@plt>
mov    $0x1,%edi
call   1120 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_can = type { i32, i32 }
%struct.can_filter = type { i32, i32 }
%struct.can_frame = type { i32, i32, i32* }
%struct.ifreq = type { i32, i32 }
%struct.sockaddr = type { i32 }
@PF_CAN = global i32 0
@SOCK_RAW = global i32 0
@CAN_RAW = global i32 0
@.str = [7 x i8] c"socket\00"
@.str.1 = [6 x i8] c"vcan0\00"
@SIOCGIFINDEX = global i32 0
@AF_CAN = global i32 0
@.str.2 = [5 x i8] c"bind\00"
@CAN_SFF_MASK = global i32 0
@CAN_EFF_FLAG = global i32 0
@CAN_RTR_FLAG = global i32 0
@SOL_CAN_RAW = global i32 0
@CAN_RAW_FILTER = global i32 0
@.str.3 = [7 x i8] c"select\00"
@.str.4 = [5 x i8] c"read\00"
@stderr = global i32 0
@.str.5 = [28 x i8] c"read: incomplete CAN frame\0A\00"
@.str.6 = [29 x i8] c"\0AWrong request from master!\0A\00"
@.str.7 = [50 x i8] c"testcase %2d : can_id = 0x%08X can_mask = 0x%08X\0A\00"
@.str.8 = [6 x i8] c"write\00"
@.str.9 = [6 x i8] c"%08X\0A\00"
@.str.10 = [33 x i8] c"testcase %2d : Filtertest done.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca %struct.sockaddr_can
%10 = alloca %struct.can_filter
%11 = alloca %struct.can_frame
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca %struct.ifreq
%16 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %12
%17 = load i32, i32* @PF_CAN
%18 = load i32, i32* @SOCK_RAW
%19 = load i32, i32* @CAN_RAW
%20 = call i32 @socket(i32 %17, i32 %18, i32 %19)
store i32 %20, i32* %7
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %2
%23 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %185
24: ; preds = %2
%25 = load i32, i32* @PF_CAN
%26 = load i32, i32* @SOCK_RAW
%27 = load i32, i32* @CAN_RAW
%28 = call i32 @socket(i32 %25, i32 %26, i32 %27)
store i32 %28, i32* %8
%29 = icmp slt i32 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %24
%31 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %185
32: ; preds = %24
%33 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %15, i32 0, i32 1
%34 = load i32, i32* %33
%35 = call i32 @strcpy(i32 %34, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%36 = load i32, i32* %7
%37 = load i32, i32* @SIOCGIFINDEX
%38 = call i32 @ioctl(i32 %36, i32 %37, %struct.ifreq* %15)
%39 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %15, i32 0, i32 0
%40 = load i32, i32* %39
store i32 %40, i32* %16
%41 = load i32, i32* @AF_CAN
%42 = getelementptr inbounds %struct.sockaddr_can, %struct.sockaddr_can* %9, i32 0, i32 1
store i32 %41, i32* %42
%43 = load i32, i32* %16
%44 = getelementptr inbounds %struct.sockaddr_can, %struct.sockaddr_can* %9, i32 0, i32 0
store i32 %43, i32* %44
%45 = load i32, i32* %7
%46 = bitcast %struct.sockaddr_can* %9 to %struct.sockaddr*
%47 = call i64 @bind(i32 %45, %struct.sockaddr* %46, i32 8)
%48 = icmp slt i64 %47, 0
br i1 %48, label %49, label %51
49: ; preds = %32
%50 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %185
51: ; preds = %32
%52 = load i32, i32* %8
%53 = bitcast %struct.sockaddr_can* %9 to %struct.sockaddr*
%54 = call i64 @bind(i32 %52, %struct.sockaddr* %53, i32 8)
%55 = icmp slt i64 %54, 0
br i1 %55, label %56, label %58
56: ; preds = %51
%57 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %185
58: ; preds = %51
%59 = getelementptr inbounds %struct.can_filter, %struct.can_filter* %10, i32 0, i32 0
store i32 15, i32* %59
%60 = load i32, i32* @CAN_SFF_MASK
%61 = load i32, i32* @CAN_EFF_FLAG
%62 = or i32 %60, %61
%63 = load i32, i32* @CAN_RTR_FLAG
%64 = or i32 %62, %63
%65 = getelementptr inbounds %struct.can_filter, %struct.can_filter* %10, i32 0, i32 1
store i32 %64, i32* %65
%66 = load i32, i32* %7
%67 = load i32, i32* @SOL_CAN_RAW
%68 = load i32, i32* @CAN_RAW_FILTER
%69 = call i32 @setsockopt(i32 %66, i32 %67, i32 %68, %struct.can_filter* %10, i32 8)
%70 = load i32, i32* %8
%71 = load i32, i32* @SOL_CAN_RAW
%72 = load i32, i32* @CAN_RAW_FILTER
%73 = call i32 @setsockopt(i32 %70, i32 %71, i32 %72, %struct.can_filter* null, i32 0)
br label %74
74: ; preds = %58, %177
%75 = call i32 @FD_ZERO(i32* %6)
%76 = load i32, i32* %7
%77 = call i32 @FD_SET(i32 %76, i32* %6)
%78 = load i32, i32* %8
%79 = call i32 @FD_SET(i32 %78, i32* %6)
%80 = load i32, i32* %8
%81 = add nsw i32 %80, 1
%82 = call i32 @select(i32 %81, i32* %6, i32* null, i32* null, i32* null)
store i32 %82, i32* %14
%83 = icmp slt i32 %82, 0
br i1 %83, label %84, label %86
84: ; preds = %74
%85 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
br label %178
86: ; preds = %74
%87 = load i32, i32* %7
%88 = call i64 @FD_ISSET(i32 %87, i32* %6)
%89 = icmp ne i64 %88, 0
br i1 %89, label %90, label %154
90: ; preds = %86
%91 = load i32, i32* %7
%92 = call i32 @read(i32 %91, %struct.can_frame* %11, i32 16)
store i32 %92, i32* %13
%93 = icmp slt i32 %92, 0
br i1 %93, label %94, label %97
94: ; preds = %90
%95 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%96 = call i32 @exit(i32 1)
unreachable
97: ; preds = %90
%98 = load i32, i32* %13
%99 = sext i32 %98 to i64
%100 = icmp ult i64 %99, 16
br i1 %100, label %101, label %105
101: ; preds = %97
%102 = load i32, i32* @stderr
%103 = call i32 @fprintf(i32 %102, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0))
%104 = call i32 @exit(i32 1)
unreachable
105: ; preds = %97
%106 = getelementptr inbounds %struct.can_frame, %struct.can_frame* %11, i32 0, i32 0
%107 = load i32, i32* %106
%108 = icmp ne i32 %107, 15
br i1 %108, label %113, label %109
109: ; preds = %105
%110 = getelementptr inbounds %struct.can_frame, %struct.can_frame* %11, i32 0, i32 1
%111 = load i32, i32* %110
%112 = icmp ne i32 %111, 1
br i1 %112, label %113, label %117
113: ; preds = %109, %105
%114 = load i32, i32* @stderr
%115 = call i32 @fprintf(i32 %114, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.6, i64 0, i64 0))
%116 = call i32 @exit(i32 1)
unreachable
117: ; preds = %109
%118 = getelementptr inbounds %struct.can_frame, %struct.can_frame* %11, i32 0, i32 2
%119 = load i32*, i32** %118
%120 = getelementptr inbounds i32, i32* %119, i64 0
%121 = load i32, i32* %120
store i32 %121, i32* %12
%122 = load i32, i32* %12
%123 = icmp slt i32 %122, 18
br i1 %123, label %124, label %141
124: ; preds = %117
%125 = load i32, i32* %12
%126 = call i32 @calc_id(i32 %125)
%127 = getelementptr inbounds %struct.can_filter, %struct.can_filter* %10, i32 0, i32 0
store i32 %126, i32* %127
%128 = load i32, i32* %12
%129 = call i32 @calc_mask(i32 %128)
%130 = getelementptr inbounds %struct.can_filter, %struct.can_filter* %10, i32 0, i32 1
store i32 %129, i32* %130
%131 = load i32, i32* %8
%132 = load i32, i32* @SOL_CAN_RAW
%133 = load i32, i32* @CAN_RAW_FILTER
%134 = call i32 @setsockopt(i32 %131, i32 %132, i32 %133, %struct.can_filter* %10, i32 8)
%135 = load i32, i32* %12
%136 = getelementptr inbounds %struct.can_filter, %struct.can_filter* %10, i32 0, i32 0
%137 = load i32, i32* %136
%138 = getelementptr inbounds %struct.can_filter, %struct.can_filter* %10, i32 0, i32 1
%139 = load i32, i32* %138
%140 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.7, i64 0, i64 0), i32 %135, i32 %137, i32 %139)
br label %141
141: ; preds = %124, %117
%142 = getelementptr inbounds %struct.can_frame, %struct.can_frame* %11, i32 0, i32 0
store i32 250, i32* %142
%143 = load i32, i32* %7
%144 = call i64 @write(i32 %143, %struct.can_frame* %11, i32 16)
%145 = icmp slt i64 %144, 0
br i1 %145, label %146, label %149
146: ; preds = %141
%147 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0))
%148 = call i32 @exit(i32 1)
unreachable
149: ; preds = %141
%150 = load i32, i32* %12
%151 = icmp sgt i32 %150, 17
br i1 %151, label %152, label %153
152: ; preds = %149
br label %178
153: ; preds = %149
br label %154
154: ; preds = %153, %86
%155 = load i32, i32* %8
%156 = call i64 @FD_ISSET(i32 %155, i32* %6)
%157 = icmp ne i64 %156, 0
br i1 %157, label %158, label %177
158: ; preds = %154
%159 = load i32, i32* %8
%160 = call i32 @read(i32 %159, %struct.can_frame* %11, i32 16)
store i32 %160, i32* %13
%161 = icmp slt i32 %160, 0
br i1 %161, label %162, label %165
162: ; preds = %158
%163 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%164 = call i32 @exit(i32 1)
unreachable
165: ; preds = %158
%166 = load i32, i32* %13
%167 = sext i32 %166 to i64
%168 = icmp ult i64 %167, 16
br i1 %168, label %169, label %173
169: ; preds = %165
%170 = load i32, i32* @stderr
%171 = call i32 @fprintf(i32 %170, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0))
%172 = call i32 @exit(i32 1)
unreachable
173: ; preds = %165
%174 = getelementptr inbounds %struct.can_frame, %struct.can_frame* %11, i32 0, i32 0
%175 = load i32, i32* %174
%176 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.9, i64 0, i64 0), i32 %175)
br label %177
177: ; preds = %173, %154
br label %74
178: ; preds = %152, %84
%179 = load i32, i32* %12
%180 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.10, i64 0, i64 0), i32 %179)
%181 = load i32, i32* %7
%182 = call i32 @close(i32 %181)
%183 = load i32, i32* %8
%184 = call i32 @close(i32 %183)
store i32 0, i32* %3
br label %185
185: ; preds = %178, %56, %49, %30, %22
%186 = load i32, i32* %3
ret i32 %186
}

LLVM IR (-O2):
%struct.sockaddr_can = type { i32, i32 }
%struct.can_filter = type { i32, i32 }
%struct.can_frame = type { i32, i32, i32* }
%struct.ifreq = type { i32, i32 }
%struct.sockaddr = type { i32 }
@PF_CAN = global i32 0
@SOCK_RAW = global i32 0
@CAN_RAW = global i32 0
@.str = [7 x i8] c"socket\00"
@.str.1 = [6 x i8] c"vcan0\00"
@SIOCGIFINDEX = global i32 0
@AF_CAN = global i32 0
@.str.2 = [5 x i8] c"bind\00"
@CAN_SFF_MASK = global i32 0
@CAN_EFF_FLAG = global i32 0
@CAN_RTR_FLAG = global i32 0
@SOL_CAN_RAW = global i32 0
@CAN_RAW_FILTER = global i32 0
@.str.3 = [7 x i8] c"select\00"
@.str.4 = [5 x i8] c"read\00"
@stderr = global i32 0
@.str.5 = [28 x i8] c"read: incomplete CAN frame\0A\00"
@.str.6 = [29 x i8] c"\0AWrong request from master!\0A\00"
@.str.7 = [50 x i8] c"testcase %2d : can_id = 0x%08X can_mask = 0x%08X\0A\00"
@.str.8 = [6 x i8] c"write\00"
@.str.9 = [6 x i8] c"%08X\0A\00"
@.str.10 = [33 x i8] c"testcase %2d : Filtertest done.\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca %struct.sockaddr_can
%5 = alloca %struct.can_filter
%6 = alloca %struct.can_frame
%7 = alloca %struct.ifreq
%8 = bitcast i32* %3 to i8*
%9 = bitcast %struct.sockaddr_can* %4 to i8*
%10 = bitcast %struct.can_filter* %5 to i8*
%11 = bitcast %struct.can_frame* %6 to i8*
%12 = bitcast %struct.ifreq* %7 to i8*
%13 = load i32, i32* @PF_CAN
%14 = load i32, i32* @SOCK_RAW
%15 = load i32, i32* @CAN_RAW
%16 = tail call i32 @socket(i32 %13, i32 %14, i32 %15)
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %2
%19 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %150
20: ; preds = %2
%21 = load i32, i32* @PF_CAN
%22 = load i32, i32* @SOCK_RAW
%23 = load i32, i32* @CAN_RAW
%24 = tail call i32 @socket(i32 %21, i32 %22, i32 %23)
%25 = icmp slt i32 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %20
%27 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %150
28: ; preds = %20
%29 = tail call i32 @strcpy(i32 undef, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%30 = load i32, i32* @SIOCGIFINDEX
%31 = call i32 @ioctl(i32 %16, i32 %30, %struct.ifreq* %7)
%32 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %7, i64 0, i32 0
%33 = load i32, i32* %32
%34 = load i32, i32* @AF_CAN
%35 = getelementptr inbounds %struct.sockaddr_can, %struct.sockaddr_can* %4, i64 0, i32 1
store i32 %34, i32* %35
%36 = getelementptr inbounds %struct.sockaddr_can, %struct.sockaddr_can* %4, i64 0, i32 0
store i32 %33, i32* %36
%37 = bitcast %struct.sockaddr_can* %4 to %struct.sockaddr*
%38 = call i64 @bind(i32 %16, %struct.sockaddr* %37, i32 8)
%39 = icmp slt i64 %38, 0
br i1 %39, label %40, label %42
40: ; preds = %28
%41 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %150
42: ; preds = %28
%43 = call i64 @bind(i32 %24, %struct.sockaddr* %37, i32 8)
%44 = icmp slt i64 %43, 0
br i1 %44, label %45, label %47
45: ; preds = %42
%46 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %150
47: ; preds = %42
%48 = getelementptr inbounds %struct.can_filter, %struct.can_filter* %5, i64 0, i32 0
store i32 15, i32* %48
%49 = load i32, i32* @CAN_SFF_MASK
%50 = load i32, i32* @CAN_EFF_FLAG
%51 = or i32 %50, %49
%52 = load i32, i32* @CAN_RTR_FLAG
%53 = or i32 %51, %52
%54 = getelementptr inbounds %struct.can_filter, %struct.can_filter* %5, i64 0, i32 1
store i32 %53, i32* %54
%55 = load i32, i32* @SOL_CAN_RAW
%56 = load i32, i32* @CAN_RAW_FILTER
%57 = call i32 @setsockopt(i32 %16, i32 %55, i32 %56, %struct.can_filter* %5, i32 8)
%58 = load i32, i32* @SOL_CAN_RAW
%59 = load i32, i32* @CAN_RAW_FILTER
%60 = call i32 @setsockopt(i32 %24, i32 %58, i32 %59, %struct.can_filter* null, i32 0)
%61 = add nuw nsw i32 %24, 1
%62 = getelementptr inbounds %struct.can_frame, %struct.can_frame* %6, i64 0, i32 0
%63 = getelementptr inbounds %struct.can_frame, %struct.can_frame* %6, i64 0, i32 1
%64 = getelementptr inbounds %struct.can_frame, %struct.can_frame* %6, i64 0, i32 2
%65 = call i32 @FD_ZERO(i32* %3)
%66 = call i32 @FD_SET(i32 %16, i32* %3)
%67 = call i32 @FD_SET(i32 %24, i32* %3)
%68 = call i32 @select(i32 %61, i32* %3, i32* null, i32* null, i32* null)
%69 = icmp slt i32 %68, 0
br i1 %69, label %70, label %73
70: ; preds = %139, %47
%71 = phi i32 [ 0, %47 ], [ %121, %139 ]
%72 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
br label %145
73: ; preds = %47, %139
%74 = phi i32 [ %121, %139 ], [ 0, %47 ]
%75 = call i64 @FD_ISSET(i32 %16, i32* %3)
%76 = icmp eq i64 %75, 0
br i1 %76, label %120, label %77
77: ; preds = %73
%78 = call i32 @read(i32 %16, %struct.can_frame* %6, i32 16)
%79 = icmp slt i32 %78, 0
br i1 %79, label %80, label %83
80: ; preds = %77
%81 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%82 = call i32 @exit(i32 1)
unreachable
83: ; preds = %77
%84 = icmp ult i32 %78, 16
br i1 %84, label %85, label %89
85: ; preds = %83
%86 = load i32, i32* @stderr
%87 = call i32 @fprintf(i32 %86, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0))
%88 = call i32 @exit(i32 1)
unreachable
89: ; preds = %83
%90 = load i32, i32* %62
%91 = icmp ne i32 %90, 15
%92 = load i32, i32* %63
%93 = icmp ne i32 %92, 1
%94 = select i1 %91, i1 true, i1 %93
br i1 %94, label %95, label %99
95: ; preds = %89
%96 = load i32, i32* @stderr
%97 = call i32 @fprintf(i32 %96, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.6, i64 0, i64 0))
%98 = call i32 @exit(i32 1)
unreachable
99: ; preds = %89
%100 = load i32*, i32** %64
%101 = load i32, i32* %100
%102 = icmp slt i32 %101, 18
br i1 %102, label %103, label %112
103: ; preds = %99
%104 = call i32 @calc_id(i32 %101)
store i32 %104, i32* %48
%105 = call i32 @calc_mask(i32 %101)
store i32 %105, i32* %54
%106 = load i32, i32* @SOL_CAN_RAW
%107 = load i32, i32* @CAN_RAW_FILTER
%108 = call i32 @setsockopt(i32 %24, i32 %106, i32 %107, %struct.can_filter* %5, i32 8)
%109 = load i32, i32* %48
%110 = load i32, i32* %54
%111 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.7, i64 0, i64 0), i32 %101, i32 %109, i32 %110)
br label %112
112: ; preds = %103, %99
store i32 250, i32* %62
%113 = call i64 @write(i32 %16, %struct.can_frame* %6, i32 16)
%114 = icmp slt i64 %113, 0
br i1 %114, label %115, label %118
115: ; preds = %112
%116 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0))
%117 = call i32 @exit(i32 1)
unreachable
118: ; preds = %112
%119 = icmp sgt i32 %101, 17
br i1 %119, label %145, label %120
120: ; preds = %118, %73
%121 = phi i32 [ %101, %118 ], [ %74, %73 ]
%122 = call i64 @FD_ISSET(i32 %24, i32* %3)
%123 = icmp eq i64 %122, 0
br i1 %123, label %139, label %124
124: ; preds = %120
%125 = call i32 @read(i32 %24, %struct.can_frame* %6, i32 16)
%126 = icmp slt i32 %125, 0
br i1 %126, label %127, label %130
127: ; preds = %124
%128 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%129 = call i32 @exit(i32 1)
unreachable
130: ; preds = %124
%131 = icmp ult i32 %125, 16
br i1 %131, label %132, label %136
132: ; preds = %130
%133 = load i32, i32* @stderr
%134 = call i32 @fprintf(i32 %133, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0))
%135 = call i32 @exit(i32 1)
unreachable
136: ; preds = %130
%137 = load i32, i32* %62
%138 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.9, i64 0, i64 0), i32 %137)
br label %139
139: ; preds = %136, %120
%140 = call i32 @FD_ZERO(i32* %3)
%141 = call i32 @FD_SET(i32 %16, i32* %3)
%142 = call i32 @FD_SET(i32 %24, i32* %3)
%143 = call i32 @select(i32 %61, i32* %3, i32* null, i32* null, i32* null)
%144 = icmp slt i32 %143, 0
br i1 %144, label %70, label %73
145: ; preds = %118, %70
%146 = phi i32 [ %71, %70 ], [ %101, %118 ]
%147 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.10, i64 0, i64 0), i32 %146)
%148 = call i32 @close(i32 %16)
%149 = call i32 @close(i32 %24)
br label %150
150: ; preds = %145, %45, %40, %26, %18
%151 = phi i32 [ 1, %18 ], [ 1, %26 ], [ 1, %40 ], [ 1, %45 ], [ 0, %145 ]
ret i32 %151
}