#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef void *uint8_t;
typedef int uint16_t;
struct can_frame {
  int can_dlc;
  int *data;
  void *can_id;
};
typedef int /*<<< orphan*/ frame;

/* Variables and functions */
int CS(int);
int /*<<< orphan*/ bzero(struct can_frame *, int);
int /*<<< orphan*/ init_timeout();
int /*<<< orphan*/ socketcan_write(struct can_frame);
void sdo_upload_initiate_request(uint8_t node_id, uint16_t index,
                                 uint8_t subindex) {
  struct can_frame frame;
  bzero(&frame, sizeof(frame));
  frame.can_id = 0x600 + node_id;
  frame.can_dlc = 8;
  frame.data[0] = CS(2);
  frame.data[1] = index >> 0 & 0xFF;
  frame.data[2] = index >> 8 & 0xFF;
  frame.data[3] = subindex;
  socketcan_write(frame);
  init_timeout();
}


x86 assembly (clang, -O0):
<sdo_upload_initiate_request>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
lea    -0x30(%rbp),%rdi
mov    $0x18,%esi
call   1060 <bzero@plt>
mov    -0x8(%rbp),%rax
add    $0x600,%rax
mov    %rax,-0x20(%rbp)
movl   $0x8,-0x30(%rbp)
mov    $0x2,%edi
call   1040 <CS@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
mov    -0xc(%rbp),%ecx
sar    $0x0,%ecx
and    $0xff,%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0xc(%rbp),%ecx
sar    $0x8,%ecx
and    $0xff,%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,0x8(%rax)
mov    -0x18(%rbp),%rax
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,0xc(%rax)
lea    -0x30(%rbp),%rax
mov    (%rax),%rcx
mov    %rcx,(%rsp)
mov    0x8(%rax),%rcx
mov    %rcx,0x8(%rsp)
mov    0x10(%rax),%rax
mov    %rax,0x10(%rsp)
call   1030 <socketcan_write@plt>
mov    $0x0,%al
call   1050 <init_timeout@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sdo_upload_initiate_request>:
push   %rbp
push   %r14
push   %rbx
sub    $0x30,%rsp
mov    %rdx,%r14
mov    %esi,%ebp
mov    %rdi,%rbx
lea    0x18(%rsp),%rdi
mov    $0x18,%esi
call   1060 <bzero@plt>
add    $0x600,%rbx
mov    %rbx,0x28(%rsp)
movl   $0x8,0x18(%rsp)
mov    $0x2,%edi
call   1040 <CS@plt>
mov    0x20(%rsp),%rcx
mov    %eax,(%rcx)
mov    %ebp,%edx
movzbl %dl,%eax
mov    %eax,0x4(%rcx)
movzbl %dh,%eax
mov    %eax,0x8(%rcx)
mov    %r14d,0xc(%rcx)
mov    0x28(%rsp),%rax
mov    %rax,0x10(%rsp)
movups 0x18(%rsp),%xmm0
movups %xmm0,(%rsp)
call   1030 <socketcan_write@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %rbp
jmp    1050 <init_timeout@plt>

LLVM IR (-O0):
%struct.can_frame = type { i32, i32*, i8* }
define void @sdo_upload_initiate_request(i8* %0, i32 %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca %struct.can_frame
store i8* %0, i8** %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%8 = call i32 @bzero(%struct.can_frame* %7, i32 24)
%9 = load i8*, i8** %4
%10 = getelementptr i8, i8* %9, i64 1536
%11 = getelementptr inbounds %struct.can_frame, %struct.can_frame* %7, i32 0, i32 2
store i8* %10, i8** %11
%12 = getelementptr inbounds %struct.can_frame, %struct.can_frame* %7, i32 0, i32 0
store i32 8, i32* %12
%13 = call i32 @CS(i32 2)
%14 = getelementptr inbounds %struct.can_frame, %struct.can_frame* %7, i32 0, i32 1
%15 = load i32*, i32** %14
%16 = getelementptr inbounds i32, i32* %15, i64 0
store i32 %13, i32* %16
%17 = load i32, i32* %5
%18 = ashr i32 %17, 0
%19 = and i32 %18, 255
%20 = getelementptr inbounds %struct.can_frame, %struct.can_frame* %7, i32 0, i32 1
%21 = load i32*, i32** %20
%22 = getelementptr inbounds i32, i32* %21, i64 1
store i32 %19, i32* %22
%23 = load i32, i32* %5
%24 = ashr i32 %23, 8
%25 = and i32 %24, 255
%26 = getelementptr inbounds %struct.can_frame, %struct.can_frame* %7, i32 0, i32 1
%27 = load i32*, i32** %26
%28 = getelementptr inbounds i32, i32* %27, i64 2
store i32 %25, i32* %28
%29 = load i8*, i8** %6
%30 = ptrtoint i8* %29 to i32
%31 = getelementptr inbounds %struct.can_frame, %struct.can_frame* %7, i32 0, i32 1
%32 = load i32*, i32** %31
%33 = getelementptr inbounds i32, i32* %32, i64 3
store i32 %30, i32* %33
%34 = call i32 @socketcan_write(%struct.can_frame* byval(%struct.can_frame) align 8 %7)
%35 = call i32 (...) @init_timeout()
ret void
}

LLVM IR (-O2):
%struct.can_frame = type { i32, i32*, i8* }
define void @sdo_upload_initiate_request(i8* %0, i32 %1, i8* %2) {
%4 = alloca %struct.can_frame
%5 = bitcast %struct.can_frame* %4 to i8*
%6 = call i32 @bzero(%struct.can_frame* %4, i32 24)
%7 = getelementptr i8, i8* %0, i64 1536
%8 = getelementptr inbounds %struct.can_frame, %struct.can_frame* %4, i64 0, i32 2
store i8* %7, i8** %8
%9 = getelementptr inbounds %struct.can_frame, %struct.can_frame* %4, i64 0, i32 0
store i32 8, i32* %9
%10 = tail call i32 @CS(i32 2)
%11 = getelementptr inbounds %struct.can_frame, %struct.can_frame* %4, i64 0, i32 1
%12 = load i32*, i32** %11
store i32 %10, i32* %12
%13 = and i32 %1, 255
%14 = getelementptr inbounds i32, i32* %12, i64 1
store i32 %13, i32* %14
%15 = lshr i32 %1, 8
%16 = and i32 %15, 255
%17 = getelementptr inbounds i32, i32* %12, i64 2
store i32 %16, i32* %17
%18 = ptrtoint i8* %2 to i64
%19 = trunc i64 %18 to i32
%20 = getelementptr inbounds i32, i32* %12, i64 3
store i32 %19, i32* %20
%21 = tail call i32 @socketcan_write(%struct.can_frame* byval(%struct.can_frame) align 8 %4)
%22 = tail call i32 (...) @init_timeout()
ret void
}