#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 int uint8_t;
typedef int uint32_t;
struct can_frame {
  int *data;
};

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ init_set_cmd(struct can_frame *);
int /*<<< orphan*/ perror(char *);
int write(int, struct can_frame *, int);
void set_startaddress(int s, uint8_t module_id, uint32_t addr) {
  struct can_frame frame;
  init_set_cmd(&frame);
  frame.data[2] = module_id;
  frame.data[3] = 0x01;
  frame.data[4] = (addr >> 16) & 0xFF;
  frame.data[5] = (addr >> 8) & 0xFF;
  frame.data[6] = addr & 0xFF;
  if (write(s, &frame, sizeof(struct can_frame)) != sizeof(struct can_frame)) {
    perror("write");
    exit(1);
  }
}


x86 assembly (clang, -O0):
<set_startaddress>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
lea    -0x18(%rbp),%rdi
call   1030 <init_set_cmd@plt>
mov    -0x8(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0x8(%rax)
mov    -0x18(%rbp),%rax
movl   $0x1,0xc(%rax)
mov    -0xc(%rbp),%ecx
sar    $0x10,%ecx
and    $0xff,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0x10(%rax)
mov    -0xc(%rbp),%ecx
sar    $0x8,%ecx
and    $0xff,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0x14(%rax)
mov    -0xc(%rbp),%ecx
and    $0xff,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0x18(%rax)
mov    -0x4(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0x8,%edx
call   1040 <write@plt>
cltq
cmp    $0x8,%rax
je     11d8 <set_startaddress+0x98>
lea    0xe37(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_startaddress>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%ebx
mov    %esi,%ebp
mov    %edi,%r14d
mov    %rsp,%r15
mov    %r15,%rdi
call   1030 <init_set_cmd@plt>
mov    (%rsp),%rax
mov    %ebp,0x8(%rax)
movl   $0x1,0xc(%rax)
mov    %ebx,%ecx
shr    $0x10,%ecx
movzbl %cl,%ecx
mov    %ecx,0x10(%rax)
movzbl %bh,%ecx
mov    %ecx,0x14(%rax)
movzbl %bl,%ecx
mov    %ecx,0x18(%rax)
mov    %r14d,%edi
mov    %r15,%rsi
mov    $0x8,%edx
call   1040 <write@plt>
cmp    $0x8,%eax
jne    119e <set_startaddress+0x5e>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe5b(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
%struct.can_frame = type { i32* }
@.str = [6 x i8] c"write\00"
define void @set_startaddress(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca %struct.can_frame
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%8 = call i32 @init_set_cmd(%struct.can_frame* %7)
%9 = load i32, i32* %5
%10 = getelementptr inbounds %struct.can_frame, %struct.can_frame* %7, i32 0, i32 0
%11 = load i32*, i32** %10
%12 = getelementptr inbounds i32, i32* %11, i64 2
store i32 %9, i32* %12
%13 = getelementptr inbounds %struct.can_frame, %struct.can_frame* %7, i32 0, i32 0
%14 = load i32*, i32** %13
%15 = getelementptr inbounds i32, i32* %14, i64 3
store i32 1, i32* %15
%16 = load i32, i32* %6
%17 = ashr i32 %16, 16
%18 = and i32 %17, 255
%19 = getelementptr inbounds %struct.can_frame, %struct.can_frame* %7, i32 0, i32 0
%20 = load i32*, i32** %19
%21 = getelementptr inbounds i32, i32* %20, i64 4
store i32 %18, i32* %21
%22 = load i32, i32* %6
%23 = ashr i32 %22, 8
%24 = and i32 %23, 255
%25 = getelementptr inbounds %struct.can_frame, %struct.can_frame* %7, i32 0, i32 0
%26 = load i32*, i32** %25
%27 = getelementptr inbounds i32, i32* %26, i64 5
store i32 %24, i32* %27
%28 = load i32, i32* %6
%29 = and i32 %28, 255
%30 = getelementptr inbounds %struct.can_frame, %struct.can_frame* %7, i32 0, i32 0
%31 = load i32*, i32** %30
%32 = getelementptr inbounds i32, i32* %31, i64 6
store i32 %29, i32* %32
%33 = load i32, i32* %4
%34 = call i32 @write(i32 %33, %struct.can_frame* %7, i32 8)
%35 = sext i32 %34 to i64
%36 = icmp ne i64 %35, 8
br i1 %36, label %37, label %40
37: ; preds = %3
%38 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%39 = call i32 @exit(i32 1)
unreachable
40: ; preds = %3
ret void
}

LLVM IR (-O2):
%struct.can_frame = type { i32* }
@.str = [6 x i8] c"write\00"
define void @set_startaddress(i32 %0, i32 %1, i32 %2) {
%4 = alloca %struct.can_frame
%5 = bitcast %struct.can_frame* %4 to i8*
%6 = call i32 @init_set_cmd(%struct.can_frame* %4)
%7 = getelementptr inbounds %struct.can_frame, %struct.can_frame* %4, i64 0, i32 0
%8 = load i32*, i32** %7
%9 = getelementptr inbounds i32, i32* %8, i64 2
store i32 %1, i32* %9
%10 = getelementptr inbounds i32, i32* %8, i64 3
store i32 1, i32* %10
%11 = lshr i32 %2, 16
%12 = and i32 %11, 255
%13 = getelementptr inbounds i32, i32* %8, i64 4
store i32 %12, i32* %13
%14 = lshr i32 %2, 8
%15 = and i32 %14, 255
%16 = getelementptr inbounds i32, i32* %8, i64 5
store i32 %15, i32* %16
%17 = and i32 %2, 255
%18 = getelementptr inbounds i32, i32* %8, i64 6
store i32 %17, i32* %18
%19 = call i32 @write(i32 %0, %struct.can_frame* %4, i32 8)
%20 = icmp eq i32 %19, 8
br i1 %20, label %24, label %21
21: ; preds = %3
%22 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%23 = call i32 @exit(i32 1)
unreachable
24: ; preds = %3
ret void
}