#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 uint16_t;

/* Variables and functions */
int /*<<< orphan*/ add_CRC(int *, int, int);
int /*<<< orphan*/ memcpy(int *, int *, int);
int /*<<< orphan*/ send_do(int, int);
int /*<<< orphan*/ swap16(int *);
int rt_modbus_force_multiple_outputs(uint8_t *buf, int sz) {
  uint16_t start_point;
  uint16_t num_points;
  int data_bytes;
  int size;
  int i;
  int byte, bito;
  uint8_t mask;
  int sz_check;
  uint8_t val;
  data_bytes = buf[6];
  size = 9 + data_bytes;
  memcpy(&start_point, buf + 2, 2);
  swap16(&start_point);
  memcpy(&num_points, buf + 4, 2);
  swap16(&num_points);
  sz_check = num_points / 8;
  if ((num_points % 8) != 0)
    sz_check++;
  for (i = 0; i < num_points; i++) {
    byte = i / 8;
    bito = i % 8;
    mask = 1 << bito;
    val = (buf[byte + 7] & mask) != 0;
    send_do(start_point + i, val);
  }
  add_CRC(buf, 8, 0xffff);
  return 8;
}


x86 assembly (clang, -O0):
<rt_modbus_force_multiple_outputs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    0x18(%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
add    $0x9,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rsi
add    $0x8,%rsi
lea    -0x10(%rbp),%rdi
mov    $0x2,%edx
call   1030 <memcpy@plt>
lea    -0x10(%rbp),%rdi
call   1050 <swap16@plt>
mov    -0x8(%rbp),%rsi
add    $0x10,%rsi
lea    -0x14(%rbp),%rdi
mov    $0x2,%edx
call   1030 <memcpy@plt>
lea    -0x14(%rbp),%rdi
call   1050 <swap16@plt>
mov    -0x14(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    %eax,-0x30(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     11cb <rt_modbus_force_multiple_outputs+0x8b>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1244 <rt_modbus_force_multiple_outputs+0x104>
mov    -0x20(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    %edx,-0x28(%rbp)
mov    -0x28(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x24(%rbp),%ecx
add    $0x7,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%eax
and    -0x2c(%rbp),%eax
cmp    $0x0,%eax
setne  %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%edi
add    -0x20(%rbp),%edi
mov    -0x34(%rbp),%esi
call   1060 <send_do@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11d2 <rt_modbus_force_multiple_outputs+0x92>
mov    -0x8(%rbp),%rdi
mov    $0x8,%esi
mov    $0xffff,%edx
call   1040 <add_CRC@plt>
mov    $0x8,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rt_modbus_force_multiple_outputs>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
lea    0x8(%rdi),%rsi
lea    0xc(%rsp),%r14
mov    %r14,%rdi
mov    $0x2,%edx
call   1030 <memcpy@plt>
mov    %r14,%rdi
call   1050 <swap16@plt>
lea    0x10(%rbx),%rsi
lea    0x8(%rsp),%r14
mov    %r14,%rdi
mov    $0x2,%edx
call   1030 <memcpy@plt>
mov    %r14,%rdi
call   1050 <swap16@plt>
cmpl   $0x0,0x8(%rsp)
jle    11b7 <rt_modbus_force_multiple_outputs+0x77>
xor    %ebp,%ebp
mov    %ebp,%eax
shr    $0x3,%eax
mov    0x1c(%rbx,%rax,4),%esi
mov    %ebp,%ecx
and    $0x7,%cl
shr    %cl,%esi
and    $0x1,%esi
mov    0xc(%rsp),%edi
add    %ebp,%edi
call   1060 <send_do@plt>
add    $0x1,%ebp
cmp    0x8(%rsp),%ebp
jl     1190 <rt_modbus_force_multiple_outputs+0x50>
mov    %rbx,%rdi
mov    $0x8,%esi
mov    $0xffff,%edx
call   1040 <add_CRC@plt>
mov    $0x8,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @rt_modbus_force_multiple_outputs(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
%15 = load i32*, i32** %3
%16 = getelementptr inbounds i32, i32* %15, i64 6
%17 = load i32, i32* %16
store i32 %17, i32* %7
%18 = load i32, i32* %7
%19 = add nsw i32 9, %18
store i32 %19, i32* %8
%20 = load i32*, i32** %3
%21 = getelementptr inbounds i32, i32* %20, i64 2
%22 = call i32 @memcpy(i32* %5, i32* %21, i32 2)
%23 = call i32 @swap16(i32* %5)
%24 = load i32*, i32** %3
%25 = getelementptr inbounds i32, i32* %24, i64 4
%26 = call i32 @memcpy(i32* %6, i32* %25, i32 2)
%27 = call i32 @swap16(i32* %6)
%28 = load i32, i32* %6
%29 = sdiv i32 %28, 8
store i32 %29, i32* %13
%30 = load i32, i32* %6
%31 = srem i32 %30, 8
%32 = icmp ne i32 %31, 0
br i1 %32, label %33, label %36
33: ; preds = %2
%34 = load i32, i32* %13
%35 = add nsw i32 %34, 1
store i32 %35, i32* %13
br label %36
36: ; preds = %33, %2
store i32 0, i32* %9
br label %37
37: ; preds = %63, %36
%38 = load i32, i32* %9
%39 = load i32, i32* %6
%40 = icmp slt i32 %38, %39
br i1 %40, label %41, label %66
41: ; preds = %37
%42 = load i32, i32* %9
%43 = sdiv i32 %42, 8
store i32 %43, i32* %10
%44 = load i32, i32* %9
%45 = srem i32 %44, 8
store i32 %45, i32* %11
%46 = load i32, i32* %11
%47 = shl i32 1, %46
store i32 %47, i32* %12
%48 = load i32*, i32** %3
%49 = load i32, i32* %10
%50 = add nsw i32 %49, 7
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i32, i32* %48, i64 %51
%53 = load i32, i32* %52
%54 = load i32, i32* %12
%55 = and i32 %53, %54
%56 = icmp ne i32 %55, 0
%57 = zext i1 %56 to i32
store i32 %57, i32* %14
%58 = load i32, i32* %5
%59 = load i32, i32* %9
%60 = add nsw i32 %58, %59
%61 = load i32, i32* %14
%62 = call i32 @send_do(i32 %60, i32 %61)
br label %63
63: ; preds = %41
%64 = load i32, i32* %9
%65 = add nsw i32 %64, 1
store i32 %65, i32* %9
br label %37
66: ; preds = %37
%67 = load i32*, i32** %3
%68 = call i32 @add_CRC(i32* %67, i32 8, i32 65535)
ret i32 8
}

LLVM IR (-O2):
define i32 @rt_modbus_force_multiple_outputs(i32* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %3 to i8*
%6 = bitcast i32* %4 to i8*
%7 = getelementptr inbounds i32, i32* %0, i64 2
%8 = call i32 @memcpy(i32* %3, i32* %7, i32 2)
%9 = call i32 @swap16(i32* %3)
%10 = getelementptr inbounds i32, i32* %0, i64 4
%11 = call i32 @memcpy(i32* %4, i32* %10, i32 2)
%12 = call i32 @swap16(i32* %4)
%13 = load i32, i32* %4
%14 = icmp sgt i32 %13, 0
br i1 %14, label %15, label %31
15: ; preds = %2, %15
%16 = phi i32 [ %28, %15 ], [ 0, %2 ]
%17 = lshr i32 %16, 3
%18 = and i32 %16, 7
%19 = add nuw nsw i32 %17, 7
%20 = zext i32 %19 to i64
%21 = getelementptr inbounds i32, i32* %0, i64 %20
%22 = load i32, i32* %21
%23 = lshr i32 %22, %18
%24 = and i32 %23, 1
%25 = load i32, i32* %3
%26 = add nsw i32 %25, %16
%27 = call i32 @send_do(i32 %26, i32 %24)
%28 = add nuw nsw i32 %16, 1
%29 = load i32, i32* %4
%30 = icmp slt i32 %28, %29
br i1 %30, label %15, label %31
31: ; preds = %15, %2
%32 = call i32 @add_CRC(i32* %0, i32 8, i32 65535)
ret i32 8
}