#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*/ dact_bit_buffer_purge();
void *dact_bit_buffer_read(int);
int dact_bit_buffer_size();
int /*<<< orphan*/ dact_bit_buffer_write(unsigned char, int);
int dact_delta_decompress(unsigned char *curr_block, char *out_block,
                          int blk_size, int bufsize) {
  int i = 0, x = 0;
  unsigned char CurrByte;
  unsigned char DeltaByte;
  char CompBit;
  char Neg;
  char Val;
  CurrByte = curr_block[0];
  dact_bit_buffer_purge();
  while (1) {
    if ((dact_bit_buffer_size() <= 8) && i == blk_size)
      break;
    if ((dact_bit_buffer_size() <= 8) && i != blk_size)
      dact_bit_buffer_write((unsigned char)curr_block[++i], 8);
    CompBit = dact_bit_buffer_read(1);
    if ((dact_bit_buffer_size() <= 8) && i != blk_size)
      dact_bit_buffer_write((unsigned char)curr_block[++i], 8);
    if (CompBit == 1) {
      Neg = dact_bit_buffer_read(1);
      DeltaByte = dact_bit_buffer_read(5);
      Val = CurrByte + (((-2 * Neg) + 1) * DeltaByte);
    } else {
      Val = dact_bit_buffer_read(8);
    }
    out_block[x++] = CurrByte;
    CurrByte = Val;
  }
  return (x);
}


x86 assembly (clang, -O0):
<dact_delta_decompress>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x21(%rbp)
mov    $0x0,%al
call   1050 <dact_bit_buffer_purge@plt>
mov    $0x0,%al
call   1030 <dact_bit_buffer_size@plt>
cmp    $0x8,%eax
jg     1195 <dact_delta_decompress+0x55>
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jne    1195 <dact_delta_decompress+0x55>
jmp    128f <dact_delta_decompress+0x14f>
mov    $0x0,%al
call   1030 <dact_bit_buffer_size@plt>
cmp    $0x8,%eax
jg     11cf <dact_delta_decompress+0x8f>
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
je     11cf <dact_delta_decompress+0x8f>
mov    -0x8(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    $0x1,%ecx
mov    %ecx,-0x1c(%rbp)
movslq %ecx,%rcx
mov    $0x8,%esi
movzbl (%rax,%rcx,1),%edi
call   1040 <dact_bit_buffer_write@plt>
mov    $0x1,%edi
call   1060 <dact_bit_buffer_read@plt>
mov    %al,-0x23(%rbp)
mov    $0x0,%al
call   1030 <dact_bit_buffer_size@plt>
cmp    $0x8,%eax
jg     1216 <dact_delta_decompress+0xd6>
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
je     1216 <dact_delta_decompress+0xd6>
mov    -0x8(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    $0x1,%ecx
mov    %ecx,-0x1c(%rbp)
movslq %ecx,%rcx
mov    $0x8,%esi
movzbl (%rax,%rcx,1),%edi
call   1040 <dact_bit_buffer_write@plt>
movsbl -0x23(%rbp),%eax
cmp    $0x1,%eax
jne    125f <dact_delta_decompress+0x11f>
mov    $0x1,%edi
call   1060 <dact_bit_buffer_read@plt>
mov    %al,-0x24(%rbp)
mov    $0x5,%edi
call   1060 <dact_bit_buffer_read@plt>
mov    %al,-0x22(%rbp)
movzbl -0x21(%rbp),%eax
movsbl -0x24(%rbp),%ecx
imul   $0xfffffffe,%ecx,%ecx
add    $0x1,%ecx
movzbl -0x22(%rbp),%edx
imul   %edx,%ecx
add    %ecx,%eax
mov    %al,-0x25(%rbp)
jmp    126c <dact_delta_decompress+0x12c>
mov    $0x8,%edi
call   1060 <dact_bit_buffer_read@plt>
mov    %al,-0x25(%rbp)
mov    -0x21(%rbp),%dl
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x20(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x25(%rbp),%al
mov    %al,-0x21(%rbp)
jmp    1174 <dact_delta_decompress+0x34>
mov    -0x20(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dact_delta_decompress>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edx,%r12d
mov    %rsi,0x10(%rsp)
mov    %rdi,0x8(%rsp)
mov    (%rdi),%r14b
xor    %r13d,%r13d
xor    %eax,%eax
call   1050 <dact_bit_buffer_purge@plt>
xor    %eax,%eax
call   1030 <dact_bit_buffer_size@plt>
test   %r12d,%r12d
sete   %bl
cmp    $0x8,%eax
jg     1183 <dact_delta_decompress+0x43>
test   %r12d,%r12d
je     126f <dact_delta_decompress+0x12f>
xor    %r13d,%r13d
xor    %r15d,%r15d
nopl   0x0(%rax)
xor    %eax,%eax
call   1030 <dact_bit_buffer_size@plt>
cmp    $0x8,%eax
jg     11bd <dact_delta_decompress+0x7d>
test   $0x1,%bl
jne    11bd <dact_delta_decompress+0x7d>
movslq %r15d,%r15
mov    0x8(%rsp),%rax
movzbl 0x1(%rax,%r15,1),%edi
add    $0x1,%r15
mov    $0x8,%esi
call   1040 <dact_bit_buffer_write@plt>
mov    $0x1,%edi
call   1060 <dact_bit_buffer_read@plt>
mov    %rax,%rbp
xor    %eax,%eax
call   1030 <dact_bit_buffer_size@plt>
cmp    $0x8,%eax
jg     11f7 <dact_delta_decompress+0xb7>
cmp    %r12d,%r15d
je     11f7 <dact_delta_decompress+0xb7>
movslq %r15d,%r15
mov    0x8(%rsp),%rax
movzbl 0x1(%rax,%r15,1),%edi
add    $0x1,%r15
mov    $0x8,%esi
call   1040 <dact_bit_buffer_write@plt>
cmp    $0x1,%bpl
jne    1230 <dact_delta_decompress+0xf0>
mov    $0x1,%edi
call   1060 <dact_bit_buffer_read@plt>
mov    %rax,%rbx
mov    $0x5,%edi
call   1060 <dact_bit_buffer_read@plt>
add    %ebx,%ebx
mov    $0x1,%ebp
sub    %ebx,%ebp
imul   %eax,%ebp
add    %r14b,%bpl
jmp    123d <dact_delta_decompress+0xfd>
cs nopw 0x0(%rax,%rax,1)
nop
mov    $0x8,%edi
call   1060 <dact_bit_buffer_read@plt>
mov    %rax,%rbp
mov    0x10(%rsp),%rax
mov    %r14b,(%rax,%r13,1)
add    $0x1,%r13
xor    %eax,%eax
call   1030 <dact_bit_buffer_size@plt>
cmp    %r12d,%r15d
sete   %bl
mov    %ebp,%r14d
cmp    $0x8,%eax
jg     1190 <dact_delta_decompress+0x50>
mov    %ebp,%r14d
cmp    %r12d,%r15d
jne    1190 <dact_delta_decompress+0x50>
mov    %r13d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @dact_delta_decompress(i8* %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8
%12 = alloca i8
%13 = alloca i8
%14 = alloca i8
%15 = alloca i8
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
store i32 0, i32* %9
store i32 0, i32* %10
%16 = load i8*, i8** %5
%17 = getelementptr inbounds i8, i8* %16, i64 0
%18 = load i8, i8* %17
store i8 %18, i8* %11
%19 = call i32 (...) @dact_bit_buffer_purge()
br label %20
20: ; preds = %4, %83
%21 = call i32 (...) @dact_bit_buffer_size()
%22 = icmp sle i32 %21, 8
br i1 %22, label %23, label %28
23: ; preds = %20
%24 = load i32, i32* %9
%25 = load i32, i32* %7
%26 = icmp eq i32 %24, %25
br i1 %26, label %27, label %28
27: ; preds = %23
br label %91
28: ; preds = %23, %20
%29 = call i32 (...) @dact_bit_buffer_size()
%30 = icmp sle i32 %29, 8
br i1 %30, label %31, label %43
31: ; preds = %28
%32 = load i32, i32* %9
%33 = load i32, i32* %7
%34 = icmp ne i32 %32, %33
br i1 %34, label %35, label %43
35: ; preds = %31
%36 = load i8*, i8** %5
%37 = load i32, i32* %9
%38 = add nsw i32 %37, 1
store i32 %38, i32* %9
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %36, i64 %39
%41 = load i8, i8* %40
%42 = call i32 @dact_bit_buffer_write(i8 zeroext %41, i32 8)
br label %43
43: ; preds = %35, %31, %28
%44 = call i8* @dact_bit_buffer_read(i32 1)
%45 = ptrtoint i8* %44 to i8
store i8 %45, i8* %13
%46 = call i32 (...) @dact_bit_buffer_size()
%47 = icmp sle i32 %46, 8
br i1 %47, label %48, label %60
48: ; preds = %43
%49 = load i32, i32* %9
%50 = load i32, i32* %7
%51 = icmp ne i32 %49, %50
br i1 %51, label %52, label %60
52: ; preds = %48
%53 = load i8*, i8** %5
%54 = load i32, i32* %9
%55 = add nsw i32 %54, 1
store i32 %55, i32* %9
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i8, i8* %53, i64 %56
%58 = load i8, i8* %57
%59 = call i32 @dact_bit_buffer_write(i8 zeroext %58, i32 8)
br label %60
60: ; preds = %52, %48, %43
%61 = load i8, i8* %13
%62 = sext i8 %61 to i32
%63 = icmp eq i32 %62, 1
br i1 %63, label %64, label %80
64: ; preds = %60
%65 = call i8* @dact_bit_buffer_read(i32 1)
%66 = ptrtoint i8* %65 to i8
store i8 %66, i8* %14
%67 = call i8* @dact_bit_buffer_read(i32 5)
%68 = ptrtoint i8* %67 to i8
store i8 %68, i8* %12
%69 = load i8, i8* %11
%70 = zext i8 %69 to i32
%71 = load i8, i8* %14
%72 = sext i8 %71 to i32
%73 = mul nsw i32 -2, %72
%74 = add nsw i32 %73, 1
%75 = load i8, i8* %12
%76 = zext i8 %75 to i32
%77 = mul nsw i32 %74, %76
%78 = add nsw i32 %70, %77
%79 = trunc i32 %78 to i8
store i8 %79, i8* %15
br label %83
80: ; preds = %60
%81 = call i8* @dact_bit_buffer_read(i32 8)
%82 = ptrtoint i8* %81 to i8
store i8 %82, i8* %15
br label %83
83: ; preds = %80, %64
%84 = load i8, i8* %11
%85 = load i8*, i8** %6
%86 = load i32, i32* %10
%87 = add nsw i32 %86, 1
store i32 %87, i32* %10
%88 = sext i32 %86 to i64
%89 = getelementptr inbounds i8, i8* %85, i64 %88
store i8 %84, i8* %89
%90 = load i8, i8* %15
store i8 %90, i8* %11
br label %20
91: ; preds = %27
%92 = load i32, i32* %10
ret i32 %92
}

LLVM IR (-O2):
define i32 @dact_delta_decompress(i8* nocapture %0, i8* nocapture writeonly %1, i32 %2, i32 %3) {
%5 = load i8, i8* %0
%6 = tail call i32 (...) @dact_bit_buffer_purge()
%7 = tail call i32 (...) @dact_bit_buffer_size()
%8 = icmp slt i32 %7, 9
%9 = icmp eq i32 %2, 0
%10 = and i1 %8, %9
br i1 %10, label %72, label %11
11: ; preds = %4, %62
%12 = phi i64 [ %64, %62 ], [ 0, %4 ]
%13 = phi i1 [ %68, %62 ], [ %9, %4 ]
%14 = phi i32 [ %40, %62 ], [ 0, %4 ]
%15 = phi i8 [ %63, %62 ], [ %5, %4 ]
%16 = tail call i32 (...) @dact_bit_buffer_size()
%17 = icmp sgt i32 %16, 8
%18 = select i1 %17, i1 true, i1 %13
br i1 %18, label %25, label %19
19: ; preds = %11
%20 = add nsw i32 %14, 1
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %0, i64 %21
%23 = load i8, i8* %22
%24 = tail call i32 @dact_bit_buffer_write(i8 zeroext %23, i32 8)
br label %25
25: ; preds = %19, %11
%26 = phi i32 [ %20, %19 ], [ %14, %11 ]
%27 = tail call i8* @dact_bit_buffer_read(i32 1)
%28 = ptrtoint i8* %27 to i64
%29 = tail call i32 (...) @dact_bit_buffer_size()
%30 = icmp sgt i32 %29, 8
%31 = icmp eq i32 %26, %2
%32 = select i1 %30, i1 true, i1 %31
br i1 %32, label %39, label %33
33: ; preds = %25
%34 = add nsw i32 %26, 1
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %0, i64 %35
%37 = load i8, i8* %36
%38 = tail call i32 @dact_bit_buffer_write(i8 zeroext %37, i32 8)
br label %39
39: ; preds = %33, %25
%40 = phi i32 [ %34, %33 ], [ %26, %25 ]
%41 = and i64 %28, 255
%42 = icmp eq i64 %41, 1
br i1 %42, label %43, label %58
43: ; preds = %39
%44 = tail call i8* @dact_bit_buffer_read(i32 1)
%45 = ptrtoint i8* %44 to i64
%46 = trunc i64 %45 to i32
%47 = tail call i8* @dact_bit_buffer_read(i32 5)
%48 = ptrtoint i8* %47 to i64
%49 = trunc i64 %48 to i32
%50 = shl i32 %46, 24
%51 = ashr exact i32 %50, 24
%52 = mul nsw i32 %51, -2
%53 = or i32 %52, 1
%54 = and i32 %49, 255
%55 = mul nsw i32 %53, %54
%56 = trunc i32 %55 to i8
%57 = add i8 %15, %56
br label %62
58: ; preds = %39
%59 = tail call i8* @dact_bit_buffer_read(i32 8)
%60 = ptrtoint i8* %59 to i64
%61 = trunc i64 %60 to i8
br label %62
62: ; preds = %58, %43
%63 = phi i8 [ %57, %43 ], [ %61, %58 ]
%64 = add nuw i64 %12, 1
%65 = getelementptr inbounds i8, i8* %1, i64 %12
store i8 %15, i8* %65
%66 = tail call i32 (...) @dact_bit_buffer_size()
%67 = icmp slt i32 %66, 9
%68 = icmp eq i32 %40, %2
%69 = select i1 %67, i1 %68, i1 false
br i1 %69, label %70, label %11
70: ; preds = %62
%71 = trunc i64 %64 to i32
br label %72
72: ; preds = %70, %4
%73 = phi i32 [ 0, %4 ], [ %71, %70 ]
ret i32 %73
}