#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 */
int /*<<< orphan*/ dspic_send_24_bits(int);
int /*<<< orphan*/ p16b_do_write();
void write_config_bits_PIC24(unsigned long address, unsigned char *data,
                             char blocksize, unsigned int nv) {
  static char blockcounter;
  unsigned int payload;
  dspic_send_24_bits(0x200007 | ((address & 0xFFFF) << 4));
  dspic_send_24_bits(0x24000A | (nv << 4));
  dspic_send_24_bits(0x883B0A);
  dspic_send_24_bits(0x200000 | ((address & 0xFF0000) >> 12));
  dspic_send_24_bits(0x880190);
  for (blockcounter = 0; blockcounter < blocksize; blockcounter += 2) {
    payload = (((unsigned int)data[blockcounter]) |
               (((unsigned int)data[blockcounter + 1]) << 8));
    dspic_send_24_bits(0x200006 | ((unsigned long)payload << 4));
    dspic_send_24_bits(0x000000);
    dspic_send_24_bits(0xBB1B86);
    dspic_send_24_bits(0x000000);
    dspic_send_24_bits(0x000000);
    p16b_do_write();
  }
}


x86 assembly (clang, -O0):
<write_config_bits_PIC24>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dl,%al
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %al,-0x11(%rbp)
mov    %ecx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
and    $0xffff,%rax
shl    $0x4,%rax
or     $0x200007,%rax
mov    %eax,%edi
call   1040 <dspic_send_24_bits@plt>
mov    -0x18(%rbp),%edi
shl    $0x4,%edi
or     $0x24000a,%edi
call   1040 <dspic_send_24_bits@plt>
mov    $0x883b0a,%edi
call   1040 <dspic_send_24_bits@plt>
mov    -0x8(%rbp),%rax
and    $0xff0000,%rax
shr    $0xc,%rax
or     $0x200000,%rax
mov    %eax,%edi
call   1040 <dspic_send_24_bits@plt>
mov    $0x880190,%edi
call   1040 <dspic_send_24_bits@plt>
movb   $0x0,0x2e97(%rip)
movsbl 0x2e90(%rip),%eax
movsbl -0x11(%rbp),%ecx
cmp    %ecx,%eax
jge    1229 <write_config_bits_PIC24+0x109>
mov    -0x10(%rbp),%rax
movsbq 0x2e78(%rip),%rcx
movzbl (%rax,%rcx,1),%eax
mov    -0x10(%rbp),%rcx
movsbl 0x2e69(%rip),%edx
add    $0x1,%edx
movslq %edx,%rdx
movzbl (%rcx,%rdx,1),%ecx
shl    $0x8,%ecx
or     %ecx,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
shl    $0x4,%rax
or     $0x200006,%rax
mov    %eax,%edi
call   1040 <dspic_send_24_bits@plt>
xor    %edi,%edi
call   1040 <dspic_send_24_bits@plt>
mov    $0xbb1b86,%edi
call   1040 <dspic_send_24_bits@plt>
xor    %edi,%edi
call   1040 <dspic_send_24_bits@plt>
xor    %edi,%edi
call   1040 <dspic_send_24_bits@plt>
mov    $0x0,%al
call   1030 <p16b_do_write@plt>
movsbl 0x2e16(%rip),%eax
add    $0x2,%eax
mov    %al,0x2e0d(%rip)
jmp    119a <write_config_bits_PIC24+0x7a>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_config_bits_PIC24>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %ecx,%r15d
mov    %edx,%ebp
mov    %rsi,%rbx
mov    %rdi,%r14
movzwl %r14w,%edi
shl    $0x4,%edi
or     $0x200007,%edi
call   1040 <dspic_send_24_bits@plt>
shl    $0x4,%r15d
or     $0x24000a,%r15d
mov    %r15d,%edi
call   1040 <dspic_send_24_bits@plt>
mov    $0x883b0a,%edi
call   1040 <dspic_send_24_bits@plt>
shr    $0xc,%r14d
and    $0xff0,%r14d
or     $0x200000,%r14d
mov    %r14d,%edi
call   1040 <dspic_send_24_bits@plt>
mov    $0x880190,%edi
call   1040 <dspic_send_24_bits@plt>
movb   $0x0,0x2ea5(%rip)
test   %bpl,%bpl
jle    11fb <write_config_bits_PIC24+0xdb>
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsbq %al,%rax
movzbl (%rbx,%rax,1),%ecx
movzbl 0x1(%rbx,%rax,1),%eax
shl    $0xc,%eax
shl    $0x4,%ecx
lea    (%rcx,%rax,1),%edi
add    $0x200006,%edi
call   1040 <dspic_send_24_bits@plt>
xor    %edi,%edi
call   1040 <dspic_send_24_bits@plt>
mov    $0xbb1b86,%edi
call   1040 <dspic_send_24_bits@plt>
xor    %edi,%edi
call   1040 <dspic_send_24_bits@plt>
xor    %edi,%edi
call   1040 <dspic_send_24_bits@plt>
xor    %eax,%eax
call   1030 <p16b_do_write@plt>
movzbl 0x2e43(%rip),%eax
add    $0x2,%al
mov    %al,0x2e3b(%rip)
cmp    %bpl,%al
jl     11a0 <write_config_bits_PIC24+0x80>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@write_config_bits_PIC24.blockcounter = internal global i8 0
define void @write_config_bits_PIC24(i64 %0, i8* %1, i8 signext %2, i32 %3) {
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i8
%8 = alloca i32
%9 = alloca i32
store i64 %0, i64* %5
store i8* %1, i8** %6
store i8 %2, i8* %7
store i32 %3, i32* %8
%10 = load i64, i64* %5
%11 = and i64 %10, 65535
%12 = shl i64 %11, 4
%13 = or i64 2097159, %12
%14 = trunc i64 %13 to i32
%15 = call i32 @dspic_send_24_bits(i32 %14)
%16 = load i32, i32* %8
%17 = shl i32 %16, 4
%18 = or i32 2359306, %17
%19 = call i32 @dspic_send_24_bits(i32 %18)
%20 = call i32 @dspic_send_24_bits(i32 8928010)
%21 = load i64, i64* %5
%22 = and i64 %21, 16711680
%23 = lshr i64 %22, 12
%24 = or i64 2097152, %23
%25 = trunc i64 %24 to i32
%26 = call i32 @dspic_send_24_bits(i32 %25)
%27 = call i32 @dspic_send_24_bits(i32 8913296)
store i8 0, i8* @write_config_bits_PIC24.blockcounter
br label %28
28: ; preds = %62, %4
%29 = load i8, i8* @write_config_bits_PIC24.blockcounter
%30 = sext i8 %29 to i32
%31 = load i8, i8* %7
%32 = sext i8 %31 to i32
%33 = icmp slt i32 %30, %32
br i1 %33, label %34, label %67
34: ; preds = %28
%35 = load i8*, i8** %6
%36 = load i8, i8* @write_config_bits_PIC24.blockcounter
%37 = sext i8 %36 to i64
%38 = getelementptr inbounds i8, i8* %35, i64 %37
%39 = load i8, i8* %38
%40 = zext i8 %39 to i32
%41 = load i8*, i8** %6
%42 = load i8, i8* @write_config_bits_PIC24.blockcounter
%43 = sext i8 %42 to i32
%44 = add nsw i32 %43, 1
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8, i8* %41, i64 %45
%47 = load i8, i8* %46
%48 = zext i8 %47 to i32
%49 = shl i32 %48, 8
%50 = or i32 %40, %49
store i32 %50, i32* %9
%51 = load i32, i32* %9
%52 = zext i32 %51 to i64
%53 = shl i64 %52, 4
%54 = or i64 2097158, %53
%55 = trunc i64 %54 to i32
%56 = call i32 @dspic_send_24_bits(i32 %55)
%57 = call i32 @dspic_send_24_bits(i32 0)
%58 = call i32 @dspic_send_24_bits(i32 12262278)
%59 = call i32 @dspic_send_24_bits(i32 0)
%60 = call i32 @dspic_send_24_bits(i32 0)
%61 = call i32 (...) @p16b_do_write()
br label %62
62: ; preds = %34
%63 = load i8, i8* @write_config_bits_PIC24.blockcounter
%64 = sext i8 %63 to i32
%65 = add nsw i32 %64, 2
%66 = trunc i32 %65 to i8
store i8 %66, i8* @write_config_bits_PIC24.blockcounter
br label %28
67: ; preds = %28
ret void
}

LLVM IR (-O2):
@write_config_bits_PIC24.blockcounter = internal unnamed_addr global i8 0
define void @write_config_bits_PIC24(i64 %0, i8* nocapture %1, i8 signext %2, i32 %3) {
%5 = trunc i64 %0 to i32
%6 = shl i32 %5, 4
%7 = and i32 %6, 1048560
%8 = or i32 %7, 2097159
%9 = tail call i32 @dspic_send_24_bits(i32 %8)
%10 = shl i32 %3, 4
%11 = or i32 %10, 2359306
%12 = tail call i32 @dspic_send_24_bits(i32 %11)
%13 = tail call i32 @dspic_send_24_bits(i32 8928010)
%14 = lshr i32 %5, 12
%15 = and i32 %14, 4080
%16 = or i32 %15, 2097152
%17 = tail call i32 @dspic_send_24_bits(i32 %16)
%18 = tail call i32 @dspic_send_24_bits(i32 8913296)
store i8 0, i8* @write_config_bits_PIC24.blockcounter
%19 = icmp sgt i8 %2, 0
br i1 %19, label %20, label %43
20: ; preds = %4, %20
%21 = phi i8 [ %41, %20 ], [ 0, %4 ]
%22 = sext i8 %21 to i64
%23 = getelementptr inbounds i8, i8* %1, i64 %22
%24 = load i8, i8* %23
%25 = zext i8 %24 to i32
%26 = add nsw i64 %22, 1
%27 = getelementptr inbounds i8, i8* %1, i64 %26
%28 = load i8, i8* %27
%29 = zext i8 %28 to i32
%30 = shl nuw nsw i32 %29, 12
%31 = shl nuw nsw i32 %25, 4
%32 = or i32 %31, %30
%33 = or i32 %32, 2097158
%34 = tail call i32 @dspic_send_24_bits(i32 %33)
%35 = tail call i32 @dspic_send_24_bits(i32 0)
%36 = tail call i32 @dspic_send_24_bits(i32 12262278)
%37 = tail call i32 @dspic_send_24_bits(i32 0)
%38 = tail call i32 @dspic_send_24_bits(i32 0)
%39 = tail call i32 (...) @p16b_do_write()
%40 = load i8, i8* @write_config_bits_PIC24.blockcounter
%41 = add i8 %40, 2
store i8 %41, i8* @write_config_bits_PIC24.blockcounter
%42 = icmp slt i8 %41, %2
br i1 %42, label %20, label %43
43: ; preds = %20, %4
ret void
}