#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 {
  scalar_t__ can_ifindex;
  int /*<<< orphan*/ can_family;
};
struct sockaddr {
  int dummy;
};
struct ifreq {
  char *ifr_name;
  int ifr_mtu;
  scalar_t__ ifr_ifindex;
};
struct canfd_frame {
  int /*<<< orphan*/ len;
};
typedef int /*<<< orphan*/ enable_canfd;
typedef int /*<<< orphan*/ addr;

/* Variables and functions */
int /*<<< orphan*/ AF_CAN;
int CANFD_MTU;
int CAN_MTU;
int /*<<< orphan*/ CAN_RAW;
int /*<<< orphan*/ CAN_RAW_FD_FRAMES;
int /*<<< orphan*/ CAN_RAW_FILTER;
int IFNAMSIZ;
int /*<<< orphan*/ PF_CAN;
int /*<<< orphan*/ SIOCGIFMTU;
int /*<<< orphan*/ SOCK_RAW;
int /*<<< orphan*/ SOL_CAN_RAW;
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ can_dlc2len(int /*<<< orphan*/);
int /*<<< orphan*/ can_len2dlc(int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
scalar_t__ if_nametoindex(char *);
scalar_t__ ioctl(int, int /*<<< orphan*/, struct ifreq *);
int parse_canframe(char *, struct canfd_frame *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
scalar_t__ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, int *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strncpy(char *, char *, int);
int write(int, struct canfd_frame *, int);
int main(int argc, char **argv) {
  int s;
  int required_mtu;
  int mtu;
  int enable_canfd = 1;
  struct sockaddr_can addr;
  struct canfd_frame frame;
  struct ifreq ifr;
  if (argc != 3) {
    fprintf(stderr, "Usage: %s <device> <can_frame>.\n", argv[0]);
    return 1;
  }
  required_mtu = parse_canframe(argv[2], &frame);
  if (!required_mtu) {
    fprintf(stderr, "\nWrong CAN-frame format! Try:\n\n");
    fprintf(stderr, "    <can_id>#{R|data}          for CAN 2.0 frames\n");
    fprintf(stderr, "    <can_id>##<flags>{data}    for CAN FD frames\n\n");
    fprintf(stderr, "<can_id> can have 3 (SFF) or 8 (EFF) hex chars\n");
    fprintf(stderr,
            "{data} has 0..8 (0..64 CAN FD) ASCII hex-values (optionally");
    fprintf(stderr, " separated by '.')\n");
    fprintf(stderr, "<flags> a single ASCII Hex value (0 .. F) which defines");
    fprintf(stderr, " canfd_frame.flags\n\n");
    fprintf(stderr, "e.g. 5A1#11.2233.44556677.88 / 123#DEADBEEF / 5AA# / ");
    fprintf(stderr,
            "123##1 / 213##311\n     1F334455#1122334455667788 / 123#R ");
    fprintf(stderr, "for remote transmission request.\n\n");
    return 1;
  }
  if ((s = socket(PF_CAN, SOCK_RAW, CAN_RAW)) < 0) {
    perror("socket");
    return 1;
  }
  strncpy(ifr.ifr_name, argv[1], IFNAMSIZ - 1);
  ifr.ifr_name[IFNAMSIZ - 1] = '\0';
  ifr.ifr_ifindex = if_nametoindex(ifr.ifr_name);
  if (!ifr.ifr_ifindex) {
    perror("if_nametoindex");
    return 1;
  }
  addr.can_family = AF_CAN;
  addr.can_ifindex = ifr.ifr_ifindex;
  if (required_mtu > CAN_MTU) {
    if (ioctl(s, SIOCGIFMTU, &ifr) < 0) {
      perror("SIOCGIFMTU");
      return 1;
    }
    mtu = ifr.ifr_mtu;
    if (mtu != CANFD_MTU) {
      printf("CAN interface ist not CAN FD capable - sorry.\n");
      return 1;
    }
    if (setsockopt(s, SOL_CAN_RAW, CAN_RAW_FD_FRAMES, &enable_canfd,
                   sizeof(enable_canfd))) {
      printf("error when enabling CAN FD support\n");
      return 1;
    }
    frame.len = can_dlc2len(can_len2dlc(frame.len));
  }
  setsockopt(s, SOL_CAN_RAW, CAN_RAW_FILTER, NULL, 0);
  if (bind(s, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
    perror("bind");
    return 1;
  }
  if (write(s, &frame, required_mtu) != required_mtu) {
    perror("write");
    return 1;
  }
  close(s);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x20(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     1231 <main+0x51>
mov    0x2da2(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xde2(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1578 <main+0x398>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    -0x38(%rbp),%rsi
call   10d0 <parse_canframe@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jne    1358 <main+0x178>
mov    0x2d5a(%rip),%rax
mov    (%rax),%edi
lea    0xdc2(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    0x2d43(%rip),%rax
mov    (%rax),%edi
lea    0xdcb(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    0x2d2c(%rip),%rax
mov    (%rax),%edi
lea    0xde7(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    0x2d15(%rip),%rax
mov    (%rax),%edi
lea    0xe03(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    0x2cfe(%rip),%rax
mov    (%rax),%edi
lea    0xe1c(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    0x2ce7(%rip),%rax
mov    (%rax),%edi
lea    0xe41(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    0x2cd0(%rip),%rax
mov    (%rax),%edi
lea    0xe3e(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    0x2cb9(%rip),%rax
mov    (%rax),%edi
lea    0xe5f(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    0x2ca2(%rip),%rax
mov    (%rax),%edi
lea    0xe5d(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    0x2c8b(%rip),%rax
mov    (%rax),%edi
lea    0xe7c(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    0x2c74(%rip),%rax
mov    (%rax),%edi
lea    0xe9f(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1578 <main+0x398>
mov    0x2c31(%rip),%rax
mov    (%rax),%edi
mov    0x2c78(%rip),%rax
mov    (%rax),%esi
mov    0x2c17(%rip),%rax
mov    (%rax),%edx
call   1100 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    139c <main+0x1bc>
lea    0xe7c(%rip),%rdi
call   10f0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1578 <main+0x398>
mov    -0x50(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    0x2bf9(%rip),%rax
mov    (%rax),%edx
sub    $0x1,%edx
call   1030 <strncpy@plt>
mov    -0x50(%rbp),%rax
mov    0x2be4(%rip),%rcx
mov    (%rcx),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x50(%rbp),%rdi
call   10b0 <if_nametoindex@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    1400 <main+0x220>
lea    0xe1f(%rip),%rdi
call   10f0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1578 <main+0x398>
mov    0x2be9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    -0x40(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%eax
mov    0x2b82(%rip),%rcx
cmp    (%rcx),%eax
jle    14e5 <main+0x305>
mov    -0x14(%rbp),%edi
mov    0x2ba0(%rip),%rax
mov    (%rax),%esi
lea    -0x50(%rbp),%rdx
call   1070 <ioctl@plt>
cmp    $0x0,%rax
jge    145d <main+0x27d>
lea    0xdd1(%rip),%rdi
call   10f0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1578 <main+0x398>
mov    -0x48(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    0x2b6b(%rip),%rcx
cmp    (%rcx),%eax
je     148d <main+0x2ad>
lea    0xdac(%rip),%rdi
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1578 <main+0x398>
mov    -0x14(%rbp),%edi
mov    0x2b31(%rip),%rax
mov    (%rax),%esi
mov    0x2b20(%rip),%rax
mov    (%rax),%edx
lea    -0x20(%rbp),%rcx
mov    $0x4,%r8d
call   1040 <setsockopt@plt>
cmp    $0x0,%rax
je     14d3 <main+0x2f3>
lea    0xd95(%rip),%rdi
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1578 <main+0x398>
mov    -0x38(%rbp),%edi
call   10c0 <can_len2dlc@plt>
mov    %eax,%edi
call   1090 <can_dlc2len@plt>
mov    %eax,-0x38(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2ad9(%rip),%rax
mov    (%rax),%esi
mov    0x2aa0(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%ecx
xor    %r8d,%r8d
call   1040 <setsockopt@plt>
mov    -0x14(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0x10,%edx
call   10e0 <bind@plt>
cmp    $0x0,%rax
jge    1539 <main+0x359>
lea    0xd53(%rip),%rdi
call   10f0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1578 <main+0x398>
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%edx
lea    -0x38(%rbp),%rsi
call   1050 <write@plt>
cmp    -0x18(%rbp),%eax
je     1569 <main+0x389>
lea    0xd28(%rip),%rdi
call   10f0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1578 <main+0x398>
mov    -0x14(%rbp),%edi
call   1080 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
cmp    $0x3,%edi
jne    1230 <main+0xe0>
mov    0x10(%rbx),%rdi
lea    0x8(%rsp),%rsi
call   1050 <parse_canframe@plt>
test   %eax,%eax
jne    1255 <main+0x105>
mov    0x2e5a(%rip),%rbx
mov    (%rbx),%edi
lea    0xe9a(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    (%rbx),%edi
lea    0xeaa(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    (%rbx),%edi
lea    0xecd(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    (%rbx),%edi
lea    0xef0(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    (%rbx),%edi
lea    0xf10(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    (%rbx),%edi
lea    0xf3c(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    (%rbx),%edi
lea    0xf40(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    (%rbx),%edi
lea    0xf68(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    (%rbx),%edi
lea    0xf6d(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    (%rbx),%edi
lea    0xf93(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    (%rbx),%edi
lea    0xfbd(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    124a <main+0xfa>
mov    0x2da1(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xdbd(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbx
ret
mov    0x2d6c(%rip),%rax
mov    (%rax),%edi
mov    0x2d83(%rip),%rax
mov    (%rax),%esi
mov    0x2d52(%rip),%rax
mov    (%rax),%edx
call   1070 <socket@plt>
test   %eax,%eax
jns    1287 <main+0x137>
lea    0xf87(%rip),%rdi
call   1060 <perror@plt>
jmp    124a <main+0xfa>
mov    0x8(%rbx),%rsi
mov    0x2d3e(%rip),%rax
mov    (%rax),%edx
add    $0xffffffff,%edx
call   1030 <strncpy@plt>

LLVM IR (-O0):
%struct.sockaddr_can = type { i64, i32 }
%struct.canfd_frame = type { i32 }
%struct.ifreq = type { i8*, i32, i64 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [33 x i8] c"Usage: %s <device> <can_frame>.\0A\00"
@.str.1 = [32 x i8] c"\0AWrong CAN-frame format! Try:\0A\0A\00"
@.str.2 = [51 x i8] c" <can_id>#{R|data} for CAN 2.0 frames\0A\00"
@.str.3 = [51 x i8] c" <can_id>##<flags>{data} for CAN FD frames\0A\0A\00"
@.str.4 = [48 x i8] c"<can_id> can have 3 (SFF) or 8 (EFF) hex chars\0A\00"
@.str.5 = [60 x i8] c"{data} has 0..8 (0..64 CAN FD) ASCII hex-values (optionally\00"
@.str.6 = [20 x i8] c" separated by '.')\0A\00"
@.str.7 = [56 x i8] c"<flags> a single ASCII Hex value (0 .. F) which defines\00"
@.str.8 = [21 x i8] c" canfd_frame.flags\0A\0A\00"
@.str.9 = [54 x i8] c"e.g. 5A1.2233.44556677.88 / 123#DEADBEEF / 5AA# / \00"
@.str.10 = [58 x i8] c"123# / 213#\0A 1F334455 / 123#R \00"
@.str.11 = [35 x i8] c"for remote transmission request.\0A\0A\00"
@PF_CAN = global i32 0
@SOCK_RAW = global i32 0
@CAN_RAW = global i32 0
@.str.12 = [7 x i8] c"socket\00"
@IFNAMSIZ = global i32 0
@.str.13 = [15 x i8] c"if_nametoindex\00"
@AF_CAN = global i32 0
@CAN_MTU = global i32 0
@SIOCGIFMTU = global i32 0
@.str.14 = [11 x i8] c"SIOCGIFMTU\00"
@CANFD_MTU = global i32 0
@.str.15 = [47 x i8] c"CAN interface ist not CAN FD capable - sorry.\0A\00"
@SOL_CAN_RAW = global i32 0
@CAN_RAW_FD_FRAMES = global i32 0
@.str.16 = [36 x i8] c"error when enabling CAN FD support\0A\00"
@CAN_RAW_FILTER = global i32 0
@.str.17 = [5 x i8] c"bind\00"
@.str.18 = [6 x i8] c"write\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 i32
%10 = alloca %struct.sockaddr_can
%11 = alloca %struct.canfd_frame
%12 = alloca %struct.ifreq
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 1, i32* %9
%13 = load i32, i32* %4
%14 = icmp ne i32 %13, 3
br i1 %14, label %15, label %21
15: ; preds = %2
%16 = load i32, i32* @stderr
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 0
%19 = load i8*, i8** %18
%20 = call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8* %19)
store i32 1, i32* %3
br label %143
21: ; preds = %2
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 2
%24 = load i8*, i8** %23
%25 = call i32 @parse_canframe(i8* %24, %struct.canfd_frame* %11)
store i32 %25, i32* %7
%26 = load i32, i32* %7
%27 = icmp ne i32 %26, 0
br i1 %27, label %51, label %28
28: ; preds = %21
%29 = load i32, i32* @stderr
%30 = call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
%31 = load i32, i32* @stderr
%32 = call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.2, i64 0, i64 0))
%33 = load i32, i32* @stderr
%34 = call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.3, i64 0, i64 0))
%35 = load i32, i32* @stderr
%36 = call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.4, i64 0, i64 0))
%37 = load i32, i32* @stderr
%38 = call i32 (i32, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.5, i64 0, i64 0))
%39 = load i32, i32* @stderr
%40 = call i32 (i32, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0))
%41 = load i32, i32* @stderr
%42 = call i32 (i32, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.7, i64 0, i64 0))
%43 = load i32, i32* @stderr
%44 = call i32 (i32, i8*, ...) @fprintf(i32 %43, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.8, i64 0, i64 0))
%45 = load i32, i32* @stderr
%46 = call i32 (i32, i8*, ...) @fprintf(i32 %45, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.9, i64 0, i64 0))
%47 = load i32, i32* @stderr
%48 = call i32 (i32, i8*, ...) @fprintf(i32 %47, i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.10, i64 0, i64 0))
%49 = load i32, i32* @stderr
%50 = call i32 (i32, i8*, ...) @fprintf(i32 %49, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.11, i64 0, i64 0))
store i32 1, i32* %3
br label %143
51: ; preds = %21
%52 = load i32, i32* @PF_CAN
%53 = load i32, i32* @SOCK_RAW
%54 = load i32, i32* @CAN_RAW
%55 = call i32 @socket(i32 %52, i32 %53, i32 %54)
store i32 %55, i32* %6
%56 = icmp slt i32 %55, 0
br i1 %56, label %57, label %59
57: ; preds = %51
%58 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.12, i64 0, i64 0))
store i32 1, i32* %3
br label %143
59: ; preds = %51
%60 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %12, i32 0, i32 0
%61 = load i8*, i8** %60
%62 = load i8**, i8*** %5
%63 = getelementptr inbounds i8*, i8** %62, i64 1
%64 = load i8*, i8** %63
%65 = load i32, i32* @IFNAMSIZ
%66 = sub nsw i32 %65, 1
%67 = call i32 @strncpy(i8* %61, i8* %64, i32 %66)
%68 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %12, i32 0, i32 0
%69 = load i8*, i8** %68
%70 = load i32, i32* @IFNAMSIZ
%71 = sub nsw i32 %70, 1
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds i8, i8* %69, i64 %72
store i8 0, i8* %73
%74 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %12, i32 0, i32 0
%75 = load i8*, i8** %74
%76 = call i64 @if_nametoindex(i8* %75)
%77 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %12, i32 0, i32 2
store i64 %76, i64* %77
%78 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %12, i32 0, i32 2
%79 = load i64, i64* %78
%80 = icmp ne i64 %79, 0
br i1 %80, label %83, label %81
81: ; preds = %59
%82 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.13, i64 0, i64 0))
store i32 1, i32* %3
br label %143
83: ; preds = %59
%84 = load i32, i32* @AF_CAN
%85 = getelementptr inbounds %struct.sockaddr_can, %struct.sockaddr_can* %10, i32 0, i32 1
store i32 %84, i32* %85
%86 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %12, i32 0, i32 2
%87 = load i64, i64* %86
%88 = getelementptr inbounds %struct.sockaddr_can, %struct.sockaddr_can* %10, i32 0, i32 0
store i64 %87, i64* %88
%89 = load i32, i32* %7
%90 = load i32, i32* @CAN_MTU
%91 = icmp sgt i32 %89, %90
br i1 %91, label %92, label %121
92: ; preds = %83
%93 = load i32, i32* %6
%94 = load i32, i32* @SIOCGIFMTU
%95 = call i64 @ioctl(i32 %93, i32 %94, %struct.ifreq* %12)
%96 = icmp slt i64 %95, 0
br i1 %96, label %97, label %99
97: ; preds = %92
%98 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.14, i64 0, i64 0))
store i32 1, i32* %3
br label %143
99: ; preds = %92
%100 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %12, i32 0, i32 1
%101 = load i32, i32* %100
store i32 %101, i32* %8
%102 = load i32, i32* %8
%103 = load i32, i32* @CANFD_MTU
%104 = icmp ne i32 %102, %103
br i1 %104, label %105, label %107
105: ; preds = %99
%106 = call i32 @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.15, i64 0, i64 0))
store i32 1, i32* %3
br label %143
107: ; preds = %99
%108 = load i32, i32* %6
%109 = load i32, i32* @SOL_CAN_RAW
%110 = load i32, i32* @CAN_RAW_FD_FRAMES
%111 = call i64 @setsockopt(i32 %108, i32 %109, i32 %110, i32* %9, i32 4)
%112 = icmp ne i64 %111, 0
br i1 %112, label %113, label %115
113: ; preds = %107
%114 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.16, i64 0, i64 0))
store i32 1, i32* %3
br label %143
115: ; preds = %107
%116 = getelementptr inbounds %struct.canfd_frame, %struct.canfd_frame* %11, i32 0, i32 0
%117 = load i32, i32* %116
%118 = call i32 @can_len2dlc(i32 %117)
%119 = call i32 @can_dlc2len(i32 %118)
%120 = getelementptr inbounds %struct.canfd_frame, %struct.canfd_frame* %11, i32 0, i32 0
store i32 %119, i32* %120
br label %121
121: ; preds = %115, %83
%122 = load i32, i32* %6
%123 = load i32, i32* @SOL_CAN_RAW
%124 = load i32, i32* @CAN_RAW_FILTER
%125 = call i64 @setsockopt(i32 %122, i32 %123, i32 %124, i32* null, i32 0)
%126 = load i32, i32* %6
%127 = bitcast %struct.sockaddr_can* %10 to %struct.sockaddr*
%128 = call i64 @bind(i32 %126, %struct.sockaddr* %127, i32 16)
%129 = icmp slt i64 %128, 0
br i1 %129, label %130, label %132
130: ; preds = %121
%131 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.17, i64 0, i64 0))
store i32 1, i32* %3
br label %143
132: ; preds = %121
%133 = load i32, i32* %6
%134 = load i32, i32* %7
%135 = call i32 @write(i32 %133, %struct.canfd_frame* %11, i32 %134)
%136 = load i32, i32* %7
%137 = icmp ne i32 %135, %136
br i1 %137, label %138, label %140
138: ; preds = %132
%139 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.18, i64 0, i64 0))
store i32 1, i32* %3
br label %143
140: ; preds = %132
%141 = load i32, i32* %6
%142 = call i32 @close(i32 %141)
store i32 0, i32* %3
br label %143
143: ; preds = %140, %138, %130, %113, %105, %97, %81, %57, %28, %15
%144 = load i32, i32* %3
ret i32 %144
}

LLVM IR (-O2):
%struct.canfd_frame = type { i32 }
@stderr = global i32 0
@.str = [33 x i8] c"Usage: %s <device> <can_frame>.\0A\00"
@.str.1 = [32 x i8] c"\0AWrong CAN-frame format! Try:\0A\0A\00"
@.str.2 = [51 x i8] c" <can_id>#{R|data} for CAN 2.0 frames\0A\00"
@.str.3 = [51 x i8] c" <can_id>##<flags>{data} for CAN FD frames\0A\0A\00"
@.str.4 = [48 x i8] c"<can_id> can have 3 (SFF) or 8 (EFF) hex chars\0A\00"
@.str.5 = [60 x i8] c"{data} has 0..8 (0..64 CAN FD) ASCII hex-values (optionally\00"
@.str.6 = [20 x i8] c" separated by '.')\0A\00"
@.str.7 = [56 x i8] c"<flags> a single ASCII Hex value (0 .. F) which defines\00"
@.str.8 = [21 x i8] c" canfd_frame.flags\0A\0A\00"
@.str.9 = [54 x i8] c"e.g. 5A1.2233.44556677.88 / 123#DEADBEEF / 5AA# / \00"
@.str.10 = [58 x i8] c"123# / 213#\0A 1F334455 / 123#R \00"
@.str.11 = [35 x i8] c"for remote transmission request.\0A\0A\00"
@PF_CAN = global i32 0
@SOCK_RAW = global i32 0
@CAN_RAW = global i32 0
@.str.12 = [7 x i8] c"socket\00"
@IFNAMSIZ = global i32 0
@AF_CAN = global i32 0
@CAN_MTU = global i32 0
@SIOCGIFMTU = global i32 0
@CANFD_MTU = global i32 0
@SOL_CAN_RAW = global i32 0
@CAN_RAW_FD_FRAMES = global i32 0
@CAN_RAW_FILTER = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.canfd_frame
%4 = bitcast %struct.canfd_frame* %3 to i8*
%5 = icmp eq i32 %0, 3
br i1 %5, label %10, label %6
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = load i8*, i8** %1
%9 = tail call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8* %8)
br label %52
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 2
%12 = load i8*, i8** %11
%13 = call i32 @parse_canframe(i8* %12, %struct.canfd_frame* %3)
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %38
15: ; preds = %10
%16 = load i32, i32* @stderr
%17 = call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
%18 = load i32, i32* @stderr
%19 = call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.2, i64 0, i64 0))
%20 = load i32, i32* @stderr
%21 = call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.3, i64 0, i64 0))
%22 = load i32, i32* @stderr
%23 = call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.4, i64 0, i64 0))
%24 = load i32, i32* @stderr
%25 = call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.5, i64 0, i64 0))
%26 = load i32, i32* @stderr
%27 = call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0))
%28 = load i32, i32* @stderr
%29 = call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.7, i64 0, i64 0))
%30 = load i32, i32* @stderr
%31 = call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.8, i64 0, i64 0))
%32 = load i32, i32* @stderr
%33 = call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.9, i64 0, i64 0))
%34 = load i32, i32* @stderr
%35 = call i32 (i32, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.10, i64 0, i64 0))
%36 = load i32, i32* @stderr
%37 = call i32 (i32, i8*, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.11, i64 0, i64 0))
br label %52
38: ; preds = %10
%39 = load i32, i32* @PF_CAN
%40 = load i32, i32* @SOCK_RAW
%41 = load i32, i32* @CAN_RAW
%42 = call i32 @socket(i32 %39, i32 %40, i32 %41)
%43 = icmp slt i32 %42, 0
br i1 %43, label %44, label %46
44: ; preds = %38
%45 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.12, i64 0, i64 0))
br label %52
46: ; preds = %38
%47 = getelementptr inbounds i8*, i8** %1, i64 1
%48 = load i8*, i8** %47
%49 = load i32, i32* @IFNAMSIZ
%50 = add nsw i32 %49, -1
%51 = call i32 @strncpy(i8* undef, i8* %48, i32 %50)
unreachable
52: ; preds = %44, %15, %6
ret i32 1
}