#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 */

/* Variables and functions */
unsigned int crc16(int, char *, int);
int /*<<< orphan*/ print_senddata(int);
int /*<<< orphan*/ write(int, char *, int);
void read_config(int fd, unsigned int addr, unsigned length, char *buffer) {
  unsigned int crc_checksum;
  buffer[0] = 0x01;
  buffer[1] = 0x03;
  buffer[2] = (addr >> 8) & 0xff;
  buffer[3] = addr & 0xff;
  buffer[4] = (length >> 8) & 0xff;
  buffer[5] = length & 0xff;
  crc_checksum = crc16(0xffff, buffer, 6);
  buffer[6] = (char)(crc_checksum & 0xff);
  buffer[7] = (char)((crc_checksum >> 8) & 0xff);
  print_senddata(8);
  write(fd, buffer, 8);
}


x86 assembly (clang, -O0):
<read_config>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %rcx,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movb   $0x1,(%rax)
mov    -0x18(%rbp),%rax
movb   $0x3,0x1(%rax)
mov    -0x8(%rbp),%eax
shr    $0x8,%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,0x2(%rax)
mov    -0x8(%rbp),%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,0x3(%rax)
mov    -0xc(%rbp),%eax
shr    $0x8,%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,0x4(%rax)
mov    -0xc(%rbp),%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,0x5(%rax)
mov    -0x18(%rbp),%rsi
mov    $0xffff,%edi
mov    $0x6,%edx
call   1040 <crc16@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,0x6(%rax)
mov    -0x1c(%rbp),%eax
shr    $0x8,%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,0x7(%rax)
mov    $0x8,%edi
call   1050 <print_senddata@plt>
mov    -0x4(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    $0x8,%edx
call   1030 <write@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_config>:
push   %rbp
push   %rbx
push   %rax
mov    %rcx,%rbx
mov    %esi,%eax
mov    %edi,%ebp
movw   $0x301,(%rcx)
mov    %ah,0x2(%rcx)
mov    %al,0x3(%rcx)
mov    %dh,0x4(%rcx)
mov    %dl,0x5(%rcx)
mov    $0xffff,%edi
mov    %rcx,%rsi
mov    $0x6,%edx
call   1040 <crc16@plt>
mov    %ax,0x6(%rbx)
mov    $0x8,%edi
call   1050 <print_senddata@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x8,%edx
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <write@plt>

LLVM IR (-O0):
define void @read_config(i32 %0, i32 %1, i32 %2, i8* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i8* %3, i8** %8
%10 = load i8*, i8** %8
%11 = getelementptr inbounds i8, i8* %10, i64 0
store i8 1, i8* %11
%12 = load i8*, i8** %8
%13 = getelementptr inbounds i8, i8* %12, i64 1
store i8 3, i8* %13
%14 = load i32, i32* %6
%15 = lshr i32 %14, 8
%16 = and i32 %15, 255
%17 = trunc i32 %16 to i8
%18 = load i8*, i8** %8
%19 = getelementptr inbounds i8, i8* %18, i64 2
store i8 %17, i8* %19
%20 = load i32, i32* %6
%21 = and i32 %20, 255
%22 = trunc i32 %21 to i8
%23 = load i8*, i8** %8
%24 = getelementptr inbounds i8, i8* %23, i64 3
store i8 %22, i8* %24
%25 = load i32, i32* %7
%26 = lshr i32 %25, 8
%27 = and i32 %26, 255
%28 = trunc i32 %27 to i8
%29 = load i8*, i8** %8
%30 = getelementptr inbounds i8, i8* %29, i64 4
store i8 %28, i8* %30
%31 = load i32, i32* %7
%32 = and i32 %31, 255
%33 = trunc i32 %32 to i8
%34 = load i8*, i8** %8
%35 = getelementptr inbounds i8, i8* %34, i64 5
store i8 %33, i8* %35
%36 = load i8*, i8** %8
%37 = call i32 @crc16(i32 65535, i8* %36, i32 6)
store i32 %37, i32* %9
%38 = load i32, i32* %9
%39 = and i32 %38, 255
%40 = trunc i32 %39 to i8
%41 = load i8*, i8** %8
%42 = getelementptr inbounds i8, i8* %41, i64 6
store i8 %40, i8* %42
%43 = load i32, i32* %9
%44 = lshr i32 %43, 8
%45 = and i32 %44, 255
%46 = trunc i32 %45 to i8
%47 = load i8*, i8** %8
%48 = getelementptr inbounds i8, i8* %47, i64 7
store i8 %46, i8* %48
%49 = call i32 @print_senddata(i32 8)
%50 = load i32, i32* %5
%51 = load i8*, i8** %8
%52 = call i32 @write(i32 %50, i8* %51, i32 8)
ret void
}

LLVM IR (-O2):
define void @read_config(i32 %0, i32 %1, i32 %2, i8* %3) {
store i8 1, i8* %3
%5 = getelementptr inbounds i8, i8* %3, i64 1
store i8 3, i8* %5
%6 = lshr i32 %1, 8
%7 = trunc i32 %6 to i8
%8 = getelementptr inbounds i8, i8* %3, i64 2
store i8 %7, i8* %8
%9 = trunc i32 %1 to i8
%10 = getelementptr inbounds i8, i8* %3, i64 3
store i8 %9, i8* %10
%11 = lshr i32 %2, 8
%12 = trunc i32 %11 to i8
%13 = getelementptr inbounds i8, i8* %3, i64 4
store i8 %12, i8* %13
%14 = trunc i32 %2 to i8
%15 = getelementptr inbounds i8, i8* %3, i64 5
store i8 %14, i8* %15
%16 = tail call i32 @crc16(i32 65535, i8* %3, i32 6)
%17 = trunc i32 %16 to i8
%18 = getelementptr inbounds i8, i8* %3, i64 6
store i8 %17, i8* %18
%19 = lshr i32 %16, 8
%20 = trunc i32 %19 to i8
%21 = getelementptr inbounds i8, i8* %3, i64 7
store i8 %20, i8* %21
%22 = tail call i32 @print_senddata(i32 8)
%23 = tail call i32 @write(i32 %0, i8* %3, i32 8)
ret void
}