#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 termios {
  int c_lflag;
  int /*<<< orphan*/ c_iflag;
};
struct sockaddr_can {
  int /*<<< orphan*/ can_ifindex;
  int /*<<< orphan*/ can_family;
};
struct sockaddr {
  int dummy;
};
struct can_filter {
  scalar_t__ can_mask;
  scalar_t__ can_id;
};
typedef int /*<<< orphan*/ fd_set;
typedef int /*<<< orphan*/ addr;

/* Variables and functions */
int /*<<< orphan*/ AF_CAN;
int /*<<< orphan*/ CAN_RAW;
int /*<<< orphan*/ CAN_RAW_FILTER;
int ECHO;
int ECHOE;
int ECHOK;
int ECHOKE;
int ECHONL;
int ECHOPRT;
scalar_t__ FD_ISSET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_SET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
int ICANON;
int /*<<< orphan*/ ICRNL;
int /*<<< orphan*/ INLCR;
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ PF_CAN;
int /*<<< orphan*/ SOCK_RAW;
int /*<<< orphan*/ SOL_CAN_RAW;
int /*<<< orphan*/ TCSANOW;
scalar_t__ bind(int, struct sockaddr *, int);
scalar_t__ can2pty(int, int, int *);
int check_select_stdin();
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
scalar_t__ grantpt(int);
int /*<<< orphan*/ if_nametoindex(char *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *, char *);
char *ptsname(int);
scalar_t__ pty2can(int, int, struct can_filter *, int *, int *);
scalar_t__ select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                  int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/,
                              int /*<<< orphan*/ *, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
scalar_t__ tcgetattr(int, struct termios *);
int /*<<< orphan*/ tcsetattr(int, int /*<<< orphan*/, struct termios *);
scalar_t__ unlockpt(int);
int main(int argc, char **argv) {
  fd_set rdfs;
  int p;
  int s;
  struct sockaddr_can addr;
  struct termios topts;
  int select_stdin = 0;
  int running = 1;
  int tstamp = 0;
  int is_open = 0;
  struct can_filter fi;
  if (argc != 3) {
    fprintf(stderr, "\n");
    fprintf(stderr,
            "%s creates a pty for applications using"
            " the slcan ASCII protocol and\n",
            argv[0]);
    fprintf(stderr, "converts the ASCII data to a CAN network"
                    " interface (and vice versa)\n\n");
    fprintf(stderr, "Usage: %s <pty> <can interface>\n", argv[0]);
    fprintf(stderr,
            "e.g. '%s /dev/ptyc0 can0' creates"
            " /dev/ttyc0 for the slcan application\n",
            argv[0]);
    fprintf(stderr,
            "e.g. for pseudo-terminal '%s %s can0' creates"
            " /dev/pts/N\n",
            argv[0], "/dev/ptmx");
    fprintf(stderr, "\n");
    return 1;
  }
  select_stdin = check_select_stdin();
  p = open(argv[1], O_RDWR);
  if (p < 0) {
    perror("open pty");
    return 1;
  }
  if (tcgetattr(p, &topts)) {
    perror("tcgetattr");
    return 1;
  }
  topts.c_lflag &= ~(ICANON | ECHO | ECHOE | ECHOK | ECHONL | ECHOPRT | ECHOKE);
  topts.c_iflag &= ~(ICRNL);
  topts.c_iflag |= INLCR;
  tcsetattr(p, TCSANOW, &topts);
  if (strcmp(argv[1], "/dev/ptmx") == 0) {
    char *name_pts = NULL;
    if (grantpt(p) < 0) {
      perror("grantpt");
      return 1;
    }
    if (unlockpt(p) < 0) {
      perror("unlockpt");
      return 1;
    }
    name_pts = ptsname(p);
    if (name_pts == NULL) {
      perror("ptsname");
      return 1;
    }
    printf("open: %s: slave pseudo-terminal is %s\n", argv[1], name_pts);
  }
  s = socket(PF_CAN, SOCK_RAW, CAN_RAW);
  if (s < 0) {
    perror("socket");
    return 1;
  }
  addr.can_family = AF_CAN;
  addr.can_ifindex = if_nametoindex(argv[2]);
  setsockopt(s, SOL_CAN_RAW, CAN_RAW_FILTER, NULL, 0);
  if (bind(s, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
    perror("bind");
    return 1;
  }
  fi.can_id = 0;
  fi.can_mask = 0;
  while (running) {
    FD_ZERO(&rdfs);
    if (select_stdin)
      FD_SET(0, &rdfs);
    FD_SET(p, &rdfs);
    FD_SET(s, &rdfs);
    if (select(s + 1, &rdfs, NULL, NULL, NULL) < 0) {
      perror("select");
      return 1;
    }
    if (FD_ISSET(0, &rdfs)) {
      running = 0;
      continue;
    }
    if (FD_ISSET(p, &rdfs))
      if (pty2can(p, s, &fi, &is_open, &tstamp)) {
        running = 0;
        continue;
      }
    if (FD_ISSET(s, &rdfs))
      if (can2pty(p, s, &tstamp)) {
        running = 0;
        continue;
      }
  }
  close(p);
  close(s);
  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,-0x34(%rbp)
movl   $0x1,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
movl   $0x0,-0x40(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     136c <main+0x10c>
mov    0x2ced(%rip),%rax
mov    (%rax),%edi
lea    0xdde(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    0x2cd6(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xd36(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    0x2cb8(%rip),%rax
mov    (%rax),%edi
lea    0xd65(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    0x2ca1(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xd8d(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    0x2c83(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xd90(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    0x2c65(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xdba(%rip),%rsi
lea    0xded(%rip),%rcx
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    0x2c40(%rip),%rax
mov    (%rax),%edi
lea    0xd31(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1724 <main+0x4c4>
mov    $0x0,%al
call   10f0 <check_select_stdin@plt>
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2c5b(%rip),%rax
mov    (%rax),%esi
call   1130 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    13b1 <main+0x151>
lea    0xd99(%rip),%rdi
call   1140 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1724 <main+0x4c4>
mov    -0x18(%rbp),%edi
lea    -0x30(%rbp),%rsi
call   1110 <tcgetattr@plt>
cmp    $0x0,%rax
je     13df <main+0x17f>
lea    0xd74(%rip),%rdi
call   1140 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1724 <main+0x4c4>
mov    0x2b72(%rip),%rax
mov    (%rax),%eax
mov    0x2bc1(%rip),%rcx
or     (%rcx),%eax
mov    0x2bb0(%rip),%rcx
or     (%rcx),%eax
mov    0x2b7f(%rip),%rcx
or     (%rcx),%eax
mov    0x2b6e(%rip),%rcx
or     (%rcx),%eax
mov    0x2b5d(%rip),%rcx
or     (%rcx),%eax
mov    0x2b7c(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    0x2baa(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x2c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    0x2b90(%rip),%rax
mov    (%rax),%eax
or     -0x2c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%edi
mov    0x2b66(%rip),%rax
mov    (%rax),%esi
lea    -0x30(%rbp),%rdx
call   1120 <tcsetattr@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xcc3(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    151e <main+0x2be>
movq   $0x0,-0x58(%rbp)
mov    -0x18(%rbp),%edi
call   1160 <grantpt@plt>
cmp    $0x0,%rax
jge    14ad <main+0x24d>
lea    0xcb0(%rip),%rdi
call   1140 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1724 <main+0x4c4>
mov    -0x18(%rbp),%edi
call   1090 <unlockpt@plt>
cmp    $0x0,%rax
jge    14d7 <main+0x277>
lea    0xc8e(%rip),%rdi
call   1140 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1724 <main+0x4c4>
mov    -0x18(%rbp),%edi
call   1030 <ptsname@plt>
mov    %rax,-0x58(%rbp)
cmpq   $0x0,-0x58(%rbp)
jne    1506 <main+0x2a6>
lea    0xc68(%rip),%rdi
call   1140 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1724 <main+0x4c4>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    -0x58(%rbp),%rdx
lea    0xc4c(%rip),%rdi
call   1060 <printf@plt>
mov    0x2a43(%rip),%rax
mov    (%rax),%edi
mov    0x2a9a(%rip),%rax
mov    (%rax),%esi
mov    0x2a29(%rip),%rax
mov    (%rax),%edx
call   1180 <socket@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1563 <main+0x303>
lea    0xc3a(%rip),%rdi
call   1140 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1724 <main+0x4c4>
mov    0x2a86(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10b0 <if_nametoindex@plt>
mov    %eax,-0x28(%rbp)
mov    -0x1c(%rbp),%edi
mov    0x2a37(%rip),%rax
mov    (%rax),%esi
mov    0x29f6(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%ecx
xor    %r8d,%r8d
call   1040 <setsockopt@plt>
mov    -0x1c(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0x8,%edx
call   1100 <bind@plt>
cmp    $0x0,%rax
jge    15d3 <main+0x373>
lea    0xbd1(%rip),%rdi
call   1140 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1724 <main+0x4c4>
movq   $0x0,-0x48(%rbp)
movq   $0x0,-0x50(%rbp)
cmpl   $0x0,-0x38(%rbp)
je     170d <main+0x4ad>
lea    -0x14(%rbp),%rdi
call   10c0 <FD_ZERO@plt>
cmpl   $0x0,-0x34(%rbp)
je     160b <main+0x3ab>
xor    %edi,%edi
lea    -0x14(%rbp),%rsi
call   1170 <FD_SET@plt>
mov    -0x18(%rbp),%edi
lea    -0x14(%rbp),%rsi
call   1170 <FD_SET@plt>
mov    -0x1c(%rbp),%edi
lea    -0x14(%rbp),%rsi
call   1170 <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   10d0 <select@plt>
cmp    $0x0,%rax
jge    165f <main+0x3ff>
lea    0xb4a(%rip),%rdi
call   1140 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1724 <main+0x4c4>
xor    %edi,%edi
lea    -0x14(%rbp),%rsi
call   1050 <FD_ISSET@plt>
cmp    $0x0,%rax
je     1680 <main+0x420>
movl   $0x0,-0x38(%rbp)
jmp    15e3 <main+0x383>
mov    -0x18(%rbp),%edi
lea    -0x14(%rbp),%rsi
call   1050 <FD_ISSET@plt>
cmp    $0x0,%rax
je     16c8 <main+0x468>
mov    -0x18(%rbp),%edi
mov    -0x1c(%rbp),%esi
lea    -0x50(%rbp),%rdx
lea    -0x40(%rbp),%rcx
lea    -0x3c(%rbp),%r8
call   1150 <pty2can@plt>
cmp    $0x0,%rax
je     16c3 <main+0x463>
movl   $0x0,-0x38(%rbp)
jmp    15e3 <main+0x383>
jmp    16c8 <main+0x468>
mov    -0x1c(%rbp),%edi
lea    -0x14(%rbp),%rsi
call   1050 <FD_ISSET@plt>
cmp    $0x0,%rax
je     1708 <main+0x4a8>
mov    -0x18(%rbp),%edi
mov    -0x1c(%rbp),%esi
lea    -0x3c(%rbp),%rdx
call   10e0 <can2pty@plt>
cmp    $0x0,%rax
je     1703 <main+0x4a3>
movl   $0x0,-0x38(%rbp)
jmp    15e3 <main+0x383>
jmp    1708 <main+0x4a8>
jmp    15e3 <main+0x383>
mov    -0x18(%rbp),%edi
call   1070 <close@plt>
mov    -0x1c(%rbp),%edi
call   1070 <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    %rsi,%r15
movl   $0x0,0xc(%rsp)
movl   $0x0,0x8(%rsp)
cmp    $0x3,%edi
jne    14f1 <main+0x291>
xor    %eax,%eax
call   10f0 <check_select_stdin@plt>
mov    %eax,%r14d
mov    0x8(%r15),%rdi
mov    0x2d41(%rip),%rax
mov    (%rax),%esi
call   1130 <open@plt>
test   %eax,%eax
js     1583 <main+0x323>
mov    %eax,%r12d
mov    %rsp,%rsi
mov    %eax,%edi
call   1110 <tcgetattr@plt>
test   %rax,%rax
jne    158c <main+0x32c>
mov    0x2c8d(%rip),%rax
mov    0x2cde(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2ccb(%rip),%rax
or     (%rax),%ecx
mov    0x2c9a(%rip),%rax
or     (%rax),%ecx
mov    0x2c89(%rip),%rax
or     (%rax),%ecx
mov    0x2c78(%rip),%rax
or     (%rax),%ecx
mov    0x2c97(%rip),%rax
or     (%rax),%ecx
not    %ecx
and    %ecx,(%rsp)
mov    0x2cc9(%rip),%rax
mov    (%rax),%eax
not    %eax
and    0x4(%rsp),%eax
mov    0x2cb2(%rip),%rcx
or     (%rcx),%eax
mov    %eax,0x4(%rsp)
mov    0x2c8d(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdx
mov    %r12d,%edi
call   1120 <tcsetattr@plt>
mov    0x8(%r15),%rdi
lea    0xdec(%rip),%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
jne    1393 <main+0x133>
mov    %r12d,%edi
call   1160 <grantpt@plt>
test   %rax,%rax
js     15a7 <main+0x347>
mov    %r12d,%edi
call   1090 <unlockpt@plt>
test   %rax,%rax
js     15b9 <main+0x359>
mov    %r12d,%edi
call   1030 <ptsname@plt>
test   %rax,%rax
je     15c2 <main+0x362>
mov    0x8(%r15),%rsi
lea    0xdda(%rip),%rdi
mov    %rax,%rdx
call   1060 <printf@plt>
mov    0x2bce(%rip),%rax
mov    (%rax),%edi
mov    0x2c25(%rip),%rax
mov    (%rax),%esi
mov    0x2bb4(%rip),%rax
mov    (%rax),%edx
call   1180 <socket@plt>
test   %eax,%eax
js     1595 <main+0x335>
mov    %eax,%ebx
mov    0x2c2c(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x14(%rsp)
mov    0x10(%r15),%rdi
call   10b0 <if_nametoindex@plt>
mov    %eax,0x10(%rsp)
mov    0x2be2(%rip),%rax
mov    (%rax),%esi
mov    0x2ba1(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1040 <setsockopt@plt>
lea    0x10(%rsp),%rsi
mov    %ebx,%edi
mov    $0x8,%edx
call   1100 <bind@plt>
test   %rax,%rax
js     159e <main+0x33e>
mov    %ebx,%r15d
add    $0x1,%r15d
xorps  %xmm0,%xmm0
movaps %xmm0,0x20(%rsp)
lea    0x1c(%rsp),%rbp
lea    0xc(%rsp),%r13
nopl   0x0(%rax,%rax,1)
mov    %rbp,%rdi
call   10c0 <FD_ZERO@plt>
test   %r14d,%r14d
je     1447 <main+0x1e7>
xor    %edi,%edi
mov    %rbp,%rsi
call   1170 <FD_SET@plt>
mov    %r12d,%edi
mov    %rbp,%rsi
call   1170 <FD_SET@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
call   1170 <FD_SET@plt>
mov    %r15d,%edi
mov    %rbp,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   10d0 <select@plt>
test   %rax,%rax
js     15b0 <main+0x350>
xor    %edi,%edi
mov    %rbp,%rsi
call   1050 <FD_ISSET@plt>
test   %rax,%rax
jne    14db <main+0x27b>
mov    %r12d,%edi
mov    %rbp,%rsi
call   1050 <FD_ISSET@plt>
test   %rax,%rax
je     14b2 <main+0x252>
mov    %r12d,%edi
mov    %ebx,%esi
lea    0x20(%rsp),%rdx
lea    0x8(%rsp),%rcx
mov    %r13,%r8
call   1150 <pty2can@plt>
test   %rax,%rax
jne    14db <main+0x27b>
mov    %ebx,%edi
mov    %rbp,%rsi
call   1050 <FD_ISSET@plt>
test   %rax,%rax
je     1430 <main+0x1d0>
mov    %r12d,%edi
mov    %ebx,%esi
mov    %r13,%rdx
call   10e0 <can2pty@plt>
test   %rax,%rax
je     1430 <main+0x1d0>
mov    %r12d,%edi
call   1070 <close@plt>
mov    %ebx,%edi
call   1070 <close@plt>
xor    %eax,%eax
jmp    15d3 <main+0x373>
mov    0x2a98(%rip),%rbp
mov    0x0(%rbp),%edi
lea    0xb88(%rip),%rbx
mov    %rbx,%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    0x0(%rbp),%edi
mov    (%r15),%rdx
lea    0xae7(%rip),%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    0x0(%rbp),%edi
lea    0xb1c(%rip),%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    0x0(%rbp),%edi
mov    (%r15),%rdx
lea    0xb4e(%rip),%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    0x0(%rbp),%edi
mov    (%r15),%rdx
lea    0xb5b(%rip),%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    0x0(%rbp),%edi
mov    (%r15),%rdx
lea    0xb8f(%rip),%rsi
lea    0xbc2(%rip),%rcx
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    0x0(%rbp),%edi
mov    %rbx,%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
jmp    15ce <main+0x36e>
lea    0xbaf(%rip),%rdi
jmp    15c9 <main+0x369>
lea    0xbaf(%rip),%rdi
jmp    15c9 <main+0x369>
lea    0xbf0(%rip),%rdi
jmp    15c9 <main+0x369>
lea    0xbee(%rip),%rdi
jmp    15c9 <main+0x369>
lea    0xb9e(%rip),%rdi
jmp    15c9 <main+0x369>
lea    0xbe1(%rip),%rdi
jmp    15c9 <main+0x369>
lea    0xb94(%rip),%rdi
jmp    15c9 <main+0x369>
lea    0xb94(%rip),%rdi
call   1140 <perror@plt>
mov    $0x1,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_can = type { i32, i32 }
%struct.termios = type { i32, i32 }
%struct.can_filter = type { i64, i64 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [2 x i8] c"\0A\00"
@.str.1 = [70 x i8] c"%s creates a pty for applications using the slcan ASCII protocol and\0A\00"
@.str.2 = [70 x i8] c"converts the ASCII data to a CAN network interface (and vice versa)\0A\0A\00"
@.str.3 = [33 x i8] c"Usage: %s <pty> <can interface>\0A\00"
@.str.4 = [72 x i8] c"e.g. '%s /dev/ptyc0 can0' creates /dev/ttyc0 for the slcan application\0A\00"
@.str.5 = [58 x i8] c"e.g. for pseudo-terminal '%s %s can0' creates /dev/pts/N\0A\00"
@.str.6 = [10 x i8] c"/dev/ptmx\00"
@O_RDWR = global i32 0
@.str.7 = [9 x i8] c"open pty\00"
@.str.8 = [10 x i8] c"tcgetattr\00"
@ICANON = global i32 0
@ECHO = global i32 0
@ECHOE = global i32 0
@ECHOK = global i32 0
@ECHONL = global i32 0
@ECHOPRT = global i32 0
@ECHOKE = global i32 0
@ICRNL = global i32 0
@INLCR = global i32 0
@TCSANOW = global i32 0
@.str.9 = [8 x i8] c"grantpt\00"
@.str.10 = [9 x i8] c"unlockpt\00"
@.str.11 = [8 x i8] c"ptsname\00"
@.str.12 = [39 x i8] c"open: %s: slave pseudo-terminal is %s\0A\00"
@PF_CAN = global i32 0
@SOCK_RAW = global i32 0
@CAN_RAW = global i32 0
@.str.13 = [7 x i8] c"socket\00"
@AF_CAN = global i32 0
@SOL_CAN_RAW = global i32 0
@CAN_RAW_FILTER = global i32 0
@.str.14 = [5 x i8] c"bind\00"
@.str.15 = [7 x i8] c"select\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.termios
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca %struct.can_filter
%16 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %11
store i32 1, i32* %12
store i32 0, i32* %13
store i32 0, i32* %14
%17 = load i32, i32* %4
%18 = icmp ne i32 %17, 3
br i1 %18, label %19, label %46
19: ; preds = %2
%20 = load i32, i32* @stderr
%21 = call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%22 = load i32, i32* @stderr
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 0
%25 = load i8*, i8** %24
%26 = call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str.1, i64 0, i64 0), i8* %25)
%27 = load i32, i32* @stderr
%28 = call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str.2, i64 0, i64 0))
%29 = load i32, i32* @stderr
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 0
%32 = load i8*, i8** %31
%33 = call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i8* %32)
%34 = load i32, i32* @stderr
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 0
%37 = load i8*, i8** %36
%38 = call i32 (i32, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str.4, i64 0, i64 0), i8* %37)
%39 = load i32, i32* @stderr
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i64 0
%42 = load i8*, i8** %41
%43 = call i32 (i32, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.5, i64 0, i64 0), i8* %42, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0))
%44 = load i32, i32* @stderr
%45 = call i32 (i32, i8*, ...) @fprintf(i32 %44, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %205
46: ; preds = %2
%47 = call i32 (...) @check_select_stdin()
store i32 %47, i32* %11
%48 = load i8**, i8*** %5
%49 = getelementptr inbounds i8*, i8** %48, i64 1
%50 = load i8*, i8** %49
%51 = load i32, i32* @O_RDWR
%52 = call i32 @open(i8* %50, i32 %51)
store i32 %52, i32* %7
%53 = load i32, i32* %7
%54 = icmp slt i32 %53, 0
br i1 %54, label %55, label %57
55: ; preds = %46
%56 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0))
store i32 1, i32* %3
br label %205
57: ; preds = %46
%58 = load i32, i32* %7
%59 = call i64 @tcgetattr(i32 %58, %struct.termios* %10)
%60 = icmp ne i64 %59, 0
br i1 %60, label %61, label %63
61: ; preds = %57
%62 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0))
store i32 1, i32* %3
br label %205
63: ; preds = %57
%64 = load i32, i32* @ICANON
%65 = load i32, i32* @ECHO
%66 = or i32 %64, %65
%67 = load i32, i32* @ECHOE
%68 = or i32 %66, %67
%69 = load i32, i32* @ECHOK
%70 = or i32 %68, %69
%71 = load i32, i32* @ECHONL
%72 = or i32 %70, %71
%73 = load i32, i32* @ECHOPRT
%74 = or i32 %72, %73
%75 = load i32, i32* @ECHOKE
%76 = or i32 %74, %75
%77 = xor i32 %76, -1
%78 = getelementptr inbounds %struct.termios, %struct.termios* %10, i32 0, i32 0
%79 = load i32, i32* %78
%80 = and i32 %79, %77
store i32 %80, i32* %78
%81 = load i32, i32* @ICRNL
%82 = xor i32 %81, -1
%83 = getelementptr inbounds %struct.termios, %struct.termios* %10, i32 0, i32 1
%84 = load i32, i32* %83
%85 = and i32 %84, %82
store i32 %85, i32* %83
%86 = load i32, i32* @INLCR
%87 = getelementptr inbounds %struct.termios, %struct.termios* %10, i32 0, i32 1
%88 = load i32, i32* %87
%89 = or i32 %88, %86
store i32 %89, i32* %87
%90 = load i32, i32* %7
%91 = load i32, i32* @TCSANOW
%92 = call i32 @tcsetattr(i32 %90, i32 %91, %struct.termios* %10)
%93 = load i8**, i8*** %5
%94 = getelementptr inbounds i8*, i8** %93, i64 1
%95 = load i8*, i8** %94
%96 = call i64 @strcmp(i8* %95, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0))
%97 = icmp eq i64 %96, 0
br i1 %97, label %98, label %123
98: ; preds = %63
store i8* null, i8** %16
%99 = load i32, i32* %7
%100 = call i64 @grantpt(i32 %99)
%101 = icmp slt i64 %100, 0
br i1 %101, label %102, label %104
102: ; preds = %98
%103 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.9, i64 0, i64 0))
store i32 1, i32* %3
br label %205
104: ; preds = %98
%105 = load i32, i32* %7
%106 = call i64 @unlockpt(i32 %105)
%107 = icmp slt i64 %106, 0
br i1 %107, label %108, label %110
108: ; preds = %104
%109 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.10, i64 0, i64 0))
store i32 1, i32* %3
br label %205
110: ; preds = %104
%111 = load i32, i32* %7
%112 = call i8* @ptsname(i32 %111)
store i8* %112, i8** %16
%113 = load i8*, i8** %16
%114 = icmp eq i8* %113, null
br i1 %114, label %115, label %117
115: ; preds = %110
%116 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.11, i64 0, i64 0))
store i32 1, i32* %3
br label %205
117: ; preds = %110
%118 = load i8**, i8*** %5
%119 = getelementptr inbounds i8*, i8** %118, i64 1
%120 = load i8*, i8** %119
%121 = load i8*, i8** %16
%122 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.12, i64 0, i64 0), i8* %120, i8* %121)
br label %123
123: ; preds = %117, %63
%124 = load i32, i32* @PF_CAN
%125 = load i32, i32* @SOCK_RAW
%126 = load i32, i32* @CAN_RAW
%127 = call i32 @socket(i32 %124, i32 %125, i32 %126)
store i32 %127, i32* %8
%128 = load i32, i32* %8
%129 = icmp slt i32 %128, 0
br i1 %129, label %130, label %132
130: ; preds = %123
%131 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.13, i64 0, i64 0))
store i32 1, i32* %3
br label %205
132: ; preds = %123
%133 = load i32, i32* @AF_CAN
%134 = getelementptr inbounds %struct.sockaddr_can, %struct.sockaddr_can* %9, i32 0, i32 1
store i32 %133, i32* %134
%135 = load i8**, i8*** %5
%136 = getelementptr inbounds i8*, i8** %135, i64 2
%137 = load i8*, i8** %136
%138 = call i32 @if_nametoindex(i8* %137)
%139 = getelementptr inbounds %struct.sockaddr_can, %struct.sockaddr_can* %9, i32 0, i32 0
store i32 %138, i32* %139
%140 = load i32, i32* %8
%141 = load i32, i32* @SOL_CAN_RAW
%142 = load i32, i32* @CAN_RAW_FILTER
%143 = call i32 @setsockopt(i32 %140, i32 %141, i32 %142, i32* null, i32 0)
%144 = load i32, i32* %8
%145 = bitcast %struct.sockaddr_can* %9 to %struct.sockaddr*
%146 = call i64 @bind(i32 %144, %struct.sockaddr* %145, i32 8)
%147 = icmp slt i64 %146, 0
br i1 %147, label %148, label %150
148: ; preds = %132
%149 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.14, i64 0, i64 0))
store i32 1, i32* %3
br label %205
150: ; preds = %132
%151 = getelementptr inbounds %struct.can_filter, %struct.can_filter* %15, i32 0, i32 1
store i64 0, i64* %151
%152 = getelementptr inbounds %struct.can_filter, %struct.can_filter* %15, i32 0, i32 0
store i64 0, i64* %152
br label %153
153: ; preds = %199, %197, %186, %176, %150
%154 = load i32, i32* %12
%155 = icmp ne i32 %154, 0
br i1 %155, label %156, label %200
156: ; preds = %153
%157 = call i32 @FD_ZERO(i32* %6)
%158 = load i32, i32* %11
%159 = icmp ne i32 %158, 0
br i1 %159, label %160, label %162
160: ; preds = %156
%161 = call i32 @FD_SET(i32 0, i32* %6)
br label %162
162: ; preds = %160, %156
%163 = load i32, i32* %7
%164 = call i32 @FD_SET(i32 %163, i32* %6)
%165 = load i32, i32* %8
%166 = call i32 @FD_SET(i32 %165, i32* %6)
%167 = load i32, i32* %8
%168 = add nsw i32 %167, 1
%169 = call i64 @select(i32 %168, i32* %6, i32* null, i32* null, i32* null)
%170 = icmp slt i64 %169, 0
br i1 %170, label %171, label %173
171: ; preds = %162
%172 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.15, i64 0, i64 0))
store i32 1, i32* %3
br label %205
173: ; preds = %162
%174 = call i64 @FD_ISSET(i32 0, i32* %6)
%175 = icmp ne i64 %174, 0
br i1 %175, label %176, label %177
176: ; preds = %173
store i32 0, i32* %12
br label %153
177: ; preds = %173
%178 = load i32, i32* %7
%179 = call i64 @FD_ISSET(i32 %178, i32* %6)
%180 = icmp ne i64 %179, 0
br i1 %180, label %181, label %188
181: ; preds = %177
%182 = load i32, i32* %7
%183 = load i32, i32* %8
%184 = call i64 @pty2can(i32 %182, i32 %183, %struct.can_filter* %15, i32* %14, i32* %13)
%185 = icmp ne i64 %184, 0
br i1 %185, label %186, label %187
186: ; preds = %181
store i32 0, i32* %12
br label %153
187: ; preds = %181
br label %188
188: ; preds = %187, %177
%189 = load i32, i32* %8
%190 = call i64 @FD_ISSET(i32 %189, i32* %6)
%191 = icmp ne i64 %190, 0
br i1 %191, label %192, label %199
192: ; preds = %188
%193 = load i32, i32* %7
%194 = load i32, i32* %8
%195 = call i64 @can2pty(i32 %193, i32 %194, i32* %13)
%196 = icmp ne i64 %195, 0
br i1 %196, label %197, label %198
197: ; preds = %192
store i32 0, i32* %12
br label %153
198: ; preds = %192
br label %199
199: ; preds = %198, %188
br label %153
200: ; preds = %153
%201 = load i32, i32* %7
%202 = call i32 @close(i32 %201)
%203 = load i32, i32* %8
%204 = call i32 @close(i32 %203)
store i32 0, i32* %3
br label %205
205: ; preds = %200, %171, %148, %130, %115, %108, %102, %61, %55, %19
%206 = load i32, i32* %3
ret i32 %206
}

LLVM IR (-O2):
%struct.sockaddr_can = type { i32, i32 }
%struct.termios = type { i32, i32 }
%struct.can_filter = type { i64, i64 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [2 x i8] c"\0A\00"
@.str.1 = [70 x i8] c"%s creates a pty for applications using the slcan ASCII protocol and\0A\00"
@.str.2 = [70 x i8] c"converts the ASCII data to a CAN network interface (and vice versa)\0A\0A\00"
@.str.3 = [33 x i8] c"Usage: %s <pty> <can interface>\0A\00"
@.str.4 = [72 x i8] c"e.g. '%s /dev/ptyc0 can0' creates /dev/ttyc0 for the slcan application\0A\00"
@.str.5 = [58 x i8] c"e.g. for pseudo-terminal '%s %s can0' creates /dev/pts/N\0A\00"
@.str.6 = [10 x i8] c"/dev/ptmx\00"
@O_RDWR = global i32 0
@.str.7 = [9 x i8] c"open pty\00"
@.str.8 = [10 x i8] c"tcgetattr\00"
@ICANON = global i32 0
@ECHO = global i32 0
@ECHOE = global i32 0
@ECHOK = global i32 0
@ECHONL = global i32 0
@ECHOPRT = global i32 0
@ECHOKE = global i32 0
@ICRNL = global i32 0
@INLCR = global i32 0
@TCSANOW = global i32 0
@.str.9 = [8 x i8] c"grantpt\00"
@.str.10 = [9 x i8] c"unlockpt\00"
@.str.11 = [8 x i8] c"ptsname\00"
@.str.12 = [39 x i8] c"open: %s: slave pseudo-terminal is %s\0A\00"
@PF_CAN = global i32 0
@SOCK_RAW = global i32 0
@CAN_RAW = global i32 0
@.str.13 = [7 x i8] c"socket\00"
@AF_CAN = global i32 0
@SOL_CAN_RAW = global i32 0
@CAN_RAW_FILTER = global i32 0
@.str.14 = [5 x i8] c"bind\00"
@.str.15 = [7 x i8] c"select\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca %struct.sockaddr_can
%5 = alloca %struct.termios
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.can_filter
%9 = bitcast i32* %3 to i8*
%10 = bitcast %struct.sockaddr_can* %4 to i8*
%11 = bitcast %struct.termios* %5 to i8*
%12 = bitcast i32* %6 to i8*
store i32 0, i32* %6
%13 = bitcast i32* %7 to i8*
store i32 0, i32* %7
%14 = bitcast %struct.can_filter* %8 to i8*
%15 = icmp eq i32 %0, 3
br i1 %15, label %35, label %16
16: ; preds = %2
%17 = load i32, i32* @stderr
%18 = tail call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%19 = load i32, i32* @stderr
%20 = load i8*, i8** %1
%21 = tail call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str.1, i64 0, i64 0), i8* %20)
%22 = load i32, i32* @stderr
%23 = tail call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str.2, i64 0, i64 0))
%24 = load i32, i32* @stderr
%25 = load i8*, i8** %1
%26 = tail call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i8* %25)
%27 = load i32, i32* @stderr
%28 = load i8*, i8** %1
%29 = tail call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str.4, i64 0, i64 0), i8* %28)
%30 = load i32, i32* @stderr
%31 = load i8*, i8** %1
%32 = tail call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.5, i64 0, i64 0), i8* %31, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0))
%33 = load i32, i32* @stderr
%34 = tail call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %154
35: ; preds = %2
%36 = tail call i32 (...) @check_select_stdin()
%37 = getelementptr inbounds i8*, i8** %1, i64 1
%38 = load i8*, i8** %37
%39 = load i32, i32* @O_RDWR
%40 = tail call i32 @open(i8* %38, i32 %39)
%41 = icmp slt i32 %40, 0
br i1 %41, label %42, label %44
42: ; preds = %35
%43 = tail call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0))
br label %154
44: ; preds = %35
%45 = call i64 @tcgetattr(i32 %40, %struct.termios* %5)
%46 = icmp eq i64 %45, 0
br i1 %46, label %49, label %47
47: ; preds = %44
%48 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0))
br label %154
49: ; preds = %44
%50 = load i32, i32* @ICANON
%51 = load i32, i32* @ECHO
%52 = or i32 %51, %50
%53 = load i32, i32* @ECHOE
%54 = or i32 %52, %53
%55 = load i32, i32* @ECHOK
%56 = or i32 %54, %55
%57 = load i32, i32* @ECHONL
%58 = or i32 %56, %57
%59 = load i32, i32* @ECHOPRT
%60 = or i32 %58, %59
%61 = load i32, i32* @ECHOKE
%62 = or i32 %60, %61
%63 = xor i32 %62, -1
%64 = getelementptr inbounds %struct.termios, %struct.termios* %5, i64 0, i32 0
%65 = load i32, i32* %64
%66 = and i32 %65, %63
store i32 %66, i32* %64
%67 = load i32, i32* @ICRNL
%68 = xor i32 %67, -1
%69 = getelementptr inbounds %struct.termios, %struct.termios* %5, i64 0, i32 1
%70 = load i32, i32* %69
%71 = and i32 %70, %68
%72 = load i32, i32* @INLCR
%73 = or i32 %72, %71
store i32 %73, i32* %69
%74 = load i32, i32* @TCSANOW
%75 = call i32 @tcsetattr(i32 %40, i32 %74, %struct.termios* %5)
%76 = load i8*, i8** %37
%77 = call i64 @strcmp(i8* %76, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0))
%78 = icmp eq i64 %77, 0
br i1 %78, label %79, label %97
79: ; preds = %49
%80 = call i64 @grantpt(i32 %40)
%81 = icmp slt i64 %80, 0
br i1 %81, label %82, label %84
82: ; preds = %79
%83 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.9, i64 0, i64 0))
br label %154
84: ; preds = %79
%85 = call i64 @unlockpt(i32 %40)
%86 = icmp slt i64 %85, 0
br i1 %86, label %87, label %89
87: ; preds = %84
%88 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.10, i64 0, i64 0))
br label %154
89: ; preds = %84
%90 = call i8* @ptsname(i32 %40)
%91 = icmp eq i8* %90, null
br i1 %91, label %92, label %94
92: ; preds = %89
%93 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.11, i64 0, i64 0))
br label %154
94: ; preds = %89
%95 = load i8*, i8** %37
%96 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.12, i64 0, i64 0), i8* %95, i8* %90)
br label %97
97: ; preds = %94, %49
%98 = load i32, i32* @PF_CAN
%99 = load i32, i32* @SOCK_RAW
%100 = load i32, i32* @CAN_RAW
%101 = call i32 @socket(i32 %98, i32 %99, i32 %100)
%102 = icmp slt i32 %101, 0
br i1 %102, label %103, label %105
103: ; preds = %97
%104 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.13, i64 0, i64 0))
br label %154
105: ; preds = %97
%106 = load i32, i32* @AF_CAN
%107 = getelementptr inbounds %struct.sockaddr_can, %struct.sockaddr_can* %4, i64 0, i32 1
store i32 %106, i32* %107
%108 = getelementptr inbounds i8*, i8** %1, i64 2
%109 = load i8*, i8** %108
%110 = call i32 @if_nametoindex(i8* %109)
%111 = getelementptr inbounds %struct.sockaddr_can, %struct.sockaddr_can* %4, i64 0, i32 0
store i32 %110, i32* %111
%112 = load i32, i32* @SOL_CAN_RAW
%113 = load i32, i32* @CAN_RAW_FILTER
%114 = call i32 @setsockopt(i32 %101, i32 %112, i32 %113, i32* null, i32 0)
%115 = bitcast %struct.sockaddr_can* %4 to %struct.sockaddr*
%116 = call i64 @bind(i32 %101, %struct.sockaddr* %115, i32 8)
%117 = icmp slt i64 %116, 0
br i1 %117, label %118, label %120
118: ; preds = %105
%119 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.14, i64 0, i64 0))
br label %154
120: ; preds = %105
%121 = icmp eq i32 %36, 0
%122 = add nuw nsw i32 %101, 1
%123 = bitcast %struct.can_filter* %8 to i8*
br label %124
124: ; preds = %147, %120
%125 = call i32 @FD_ZERO(i32* %3)
br i1 %121, label %128, label %126
126: ; preds = %124
%127 = call i32 @FD_SET(i32 0, i32* %3)
br label %128
128: ; preds = %126, %124
%129 = call i32 @FD_SET(i32 %40, i32* %3)
%130 = call i32 @FD_SET(i32 %101, i32* %3)
%131 = call i64 @select(i32 %122, i32* %3, i32* null, i32* null, i32* null)
%132 = icmp slt i64 %131, 0
br i1 %132, label %133, label %135
133: ; preds = %128
%134 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.15, i64 0, i64 0))
br label %154
135: ; preds = %128
%136 = call i64 @FD_ISSET(i32 0, i32* %3)
%137 = icmp eq i64 %136, 0
br i1 %137, label %138, label %151
138: ; preds = %135
%139 = call i64 @FD_ISSET(i32 %40, i32* %3)
%140 = icmp eq i64 %139, 0
br i1 %140, label %144, label %141
141: ; preds = %138
%142 = call i64 @pty2can(i32 %40, i32 %101, %struct.can_filter* %8, i32* %7, i32* %6)
%143 = icmp eq i64 %142, 0
br i1 %143, label %144, label %151
144: ; preds = %141, %138
%145 = call i64 @FD_ISSET(i32 %101, i32* %3)
%146 = icmp eq i64 %145, 0
br i1 %146, label %147, label %148
147: ; preds = %144, %148
br label %124
148: ; preds = %144
%149 = call i64 @can2pty(i32 %40, i32 %101, i32* %6)
%150 = icmp eq i64 %149, 0
br i1 %150, label %147, label %151
151: ; preds = %135, %141, %148
%152 = call i32 @close(i32 %40)
%153 = call i32 @close(i32 %101)
br label %154
154: ; preds = %82, %87, %92, %151, %133, %118, %103, %47, %42, %16
%155 = phi i32 [ 1, %16 ], [ 1, %42 ], [ 1, %47 ], [ 1, %103 ], [ 1, %118 ], [ 1, %133 ], [ 0, %151 ], [ 1, %92 ], [ 1, %87 ], [ 1, %82 ]
ret i32 %155
}