#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;
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 start_programming(int s, uint8_t module_id) {
  struct can_frame frame;
  init_set_cmd(&frame);
  frame.data[2] = module_id;
  frame.data[3] = 0x05;
  frame.data[4] = 0x55;
  frame.data[5] = 0;
  frame.data[6] = 0;
  if (write(s, &frame, sizeof(struct can_frame)) != sizeof(struct can_frame)) {
    perror("write");
    exit(1);
  }
}


x86 assembly (clang, -O0):
<start_programming>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
lea    -0x10(%rbp),%rdi
call   1030 <init_set_cmd@plt>
mov    -0x8(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0x8(%rax)
mov    -0x10(%rbp),%rax
movl   $0x5,0xc(%rax)
mov    -0x10(%rbp),%rax
movl   $0x55,0x10(%rax)
mov    -0x10(%rbp),%rax
movl   $0x0,0x14(%rax)
mov    -0x10(%rbp),%rax
movl   $0x0,0x18(%rax)
mov    -0x4(%rbp),%edi
lea    -0x10(%rbp),%rsi
mov    $0x8,%edx
call   1040 <write@plt>
cltq
cmp    $0x8,%rax
je     11c0 <start_programming+0x80>
lea    0xe4f(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<start_programming>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %esi,%ebx
mov    %edi,%ebp
lea    0x8(%rsp),%r14
mov    %r14,%rdi
call   1030 <init_set_cmd@plt>
mov    0x8(%rsp),%rax
mov    %ebx,0x8(%rax)
movaps 0xe98(%rip),%xmm0
movups %xmm0,0xc(%rax)
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x8,%edx
call   1040 <write@plt>
cmp    $0x8,%eax
jne    1189 <start_programming+0x49>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe80(%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 @start_programming(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.can_frame
store i32 %0, i32* %3
store i32 %1, i32* %4
%6 = call i32 @init_set_cmd(%struct.can_frame* %5)
%7 = load i32, i32* %4
%8 = getelementptr inbounds %struct.can_frame, %struct.can_frame* %5, i32 0, i32 0
%9 = load i32*, i32** %8
%10 = getelementptr inbounds i32, i32* %9, i64 2
store i32 %7, i32* %10
%11 = getelementptr inbounds %struct.can_frame, %struct.can_frame* %5, i32 0, i32 0
%12 = load i32*, i32** %11
%13 = getelementptr inbounds i32, i32* %12, i64 3
store i32 5, i32* %13
%14 = getelementptr inbounds %struct.can_frame, %struct.can_frame* %5, i32 0, i32 0
%15 = load i32*, i32** %14
%16 = getelementptr inbounds i32, i32* %15, i64 4
store i32 85, i32* %16
%17 = getelementptr inbounds %struct.can_frame, %struct.can_frame* %5, i32 0, i32 0
%18 = load i32*, i32** %17
%19 = getelementptr inbounds i32, i32* %18, i64 5
store i32 0, i32* %19
%20 = getelementptr inbounds %struct.can_frame, %struct.can_frame* %5, i32 0, i32 0
%21 = load i32*, i32** %20
%22 = getelementptr inbounds i32, i32* %21, i64 6
store i32 0, i32* %22
%23 = load i32, i32* %3
%24 = call i32 @write(i32 %23, %struct.can_frame* %5, i32 8)
%25 = sext i32 %24 to i64
%26 = icmp ne i64 %25, 8
br i1 %26, label %27, label %30
27: ; preds = %2
%28 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%29 = call i32 @exit(i32 1)
unreachable
30: ; preds = %2
ret void
}

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