#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 can_frame {
  int can_id;
  long *data;
  int can_dlc;
};
typedef int /*<<< orphan*/ frame;

/* Variables and functions */
int CAN_EFF_FLAG;
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sscanf(char *, char *, long *);
int write(int, struct can_frame *, int);
int canSend(int skt, int canID, char *canDATA) {
  printf("Send Message\n");
  printf("Socket: %d\n", skt);
  printf("CAN Identifier: %04x\n", canID);
  printf("Message: %s\n", canDATA);
  struct can_frame frame;
  frame.can_id = canID | CAN_EFF_FLAG;
  long canData;
  sscanf(canDATA, "%lx", &canData);
  int i;
  for (i = 0; i < 8; i++) {
    frame.data[7 - i] = (canData >> (i * 8) & 0xff);
    printf("Byte: %d - %02x\n", (8 - i), frame.data[7 - i]);
  }
  frame.can_dlc = 8;
  int bytes_sent = write(skt, &frame, sizeof(frame));
  return 0;
}


x86 assembly (clang, -O0):
<canSend>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
lea    0xeb7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%esi
lea    0xeb4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%esi
lea    0xeaf(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rsi
lea    0xeb3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%eax
mov    0x2e52(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe9f(%rip),%rsi
lea    -0x30(%rbp),%rdx
call   1050 <sscanf@plt>
movl   $0x0,-0x34(%rbp)
cmpl   $0x8,-0x34(%rbp)
jge    121a <canSend+0xea>
mov    -0x30(%rbp),%rdx
mov    -0x34(%rbp),%eax
shl    $0x3,%eax
mov    %eax,%eax
mov    %eax,%ecx
sar    %cl,%rdx
and    $0xff,%rdx
mov    -0x20(%rbp),%rax
mov    $0x7,%ecx
sub    -0x34(%rbp),%ecx
movslq %ecx,%rcx
mov    %rdx,(%rax,%rcx,8)
mov    $0x8,%esi
sub    -0x34(%rbp),%esi
mov    -0x20(%rbp),%rax
mov    $0x7,%ecx
sub    -0x34(%rbp),%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xe3c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11ae <canSend+0x7e>
movl   $0x8,-0x18(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0x18,%edx
call   1030 <write@plt>
mov    %eax,-0x38(%rbp)
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<canSend>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%rbx
mov    %esi,%r14d
mov    %edi,%ebp
lea    0xeec(%rip),%rdi
call   1030 <puts@plt>
lea    0xead(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xea9(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xeae(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xeaa(%rip),%rsi
lea    0x8(%rsp),%rdx
mov    %rbx,%rdi
call   1050 <sscanf@plt>

LLVM IR (-O0):
%struct.can_frame = type { i32, i64*, i32 }
@.str = [14 x i8] c"Send Message\0A\00"
@.str.1 = [12 x i8] c"Socket: %d\0A\00"
@.str.2 = [22 x i8] c"CAN Identifier: %04x\0A\00"
@.str.3 = [13 x i8] c"Message: %s\0A\00"
@CAN_EFF_FLAG = global i32 0
@.str.4 = [4 x i8] c"%lx\00"
@.str.5 = [17 x i8] c"Byte: %d - %02x\0A\00"
define i32 @canSend(i32 %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca %struct.can_frame
%8 = alloca i64
%9 = alloca i32
%10 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%12 = load i32, i32* %4
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %12)
%14 = load i32, i32* %5
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i32 %14)
%16 = load i8*, i8** %6
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8* %16)
%18 = load i32, i32* %5
%19 = load i32, i32* @CAN_EFF_FLAG
%20 = or i32 %18, %19
%21 = getelementptr inbounds %struct.can_frame, %struct.can_frame* %7, i32 0, i32 0
store i32 %20, i32* %21
%22 = load i8*, i8** %6
%23 = call i32 @sscanf(i8* %22, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i64* %8)
store i32 0, i32* %9
br label %24
24: ; preds = %50, %3
%25 = load i32, i32* %9
%26 = icmp slt i32 %25, 8
br i1 %26, label %27, label %53
27: ; preds = %24
%28 = load i64, i64* %8
%29 = load i32, i32* %9
%30 = mul nsw i32 %29, 8
%31 = zext i32 %30 to i64
%32 = ashr i64 %28, %31
%33 = and i64 %32, 255
%34 = getelementptr inbounds %struct.can_frame, %struct.can_frame* %7, i32 0, i32 1
%35 = load i64*, i64** %34
%36 = load i32, i32* %9
%37 = sub nsw i32 7, %36
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i64, i64* %35, i64 %38
store i64 %33, i64* %39
%40 = load i32, i32* %9
%41 = sub nsw i32 8, %40
%42 = getelementptr inbounds %struct.can_frame, %struct.can_frame* %7, i32 0, i32 1
%43 = load i64*, i64** %42
%44 = load i32, i32* %9
%45 = sub nsw i32 7, %44
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i64, i64* %43, i64 %46
%48 = load i64, i64* %47
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i32 %41, i64 %48)
br label %50
50: ; preds = %27
%51 = load i32, i32* %9
%52 = add nsw i32 %51, 1
store i32 %52, i32* %9
br label %24
53: ; preds = %24
%54 = getelementptr inbounds %struct.can_frame, %struct.can_frame* %7, i32 0, i32 2
store i32 8, i32* %54
%55 = load i32, i32* %4
%56 = call i32 @write(i32 %55, %struct.can_frame* %7, i32 24)
store i32 %56, i32* %10
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [12 x i8] c"Socket: %d\0A\00"
@.str.2 = [22 x i8] c"CAN Identifier: %04x\0A\00"
@.str.3 = [13 x i8] c"Message: %s\0A\00"
@CAN_EFF_FLAG = global i32 0
@.str.4 = [4 x i8] c"%lx\00"
@str = [13 x i8] c"Send Message\00"
define i32 @canSend(i32 %0, i32 %1, i8* %2) {
%4 = alloca i64
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str, i64 0, i64 0))
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %0)
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i32 %1)
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8* %2)
%9 = bitcast i64* %4 to i8*
%10 = call i32 @sscanf(i8* %2, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i64* %4)
unreachable
}