#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*/ sscanf(char *, char *, unsigned char *);
unsigned short readData(char **data, unsigned int *partial_code,
                        unsigned int *partial_bits, unsigned int code_len) {
  unsigned short code = 0;
  unsigned char unpack = 0;
  while (*partial_bits < code_len) {
    if (*partial_code != -1) {
      sscanf(&(*data[0]), "%c", &unpack);
      *partial_code = (*partial_code << 8) + unpack;
    } else {
      sscanf(&(*data[0]), "%c", &unpack);
      *partial_code = unpack;
    }
    *data += 1;
    *partial_bits += 8;
  }
  code = *partial_code >> (*partial_bits - code_len);
  *partial_code &= (1 << (*partial_bits - code_len)) - 1;
  *partial_bits -= code_len;
  return code;
}


x86 assembly (clang, -O0):
<readData>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
movw   $0x0,-0x1e(%rbp)
movb   $0x0,-0x1f(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
cmp    -0x1c(%rbp),%eax
jae    11bd <readData+0xad>
mov    -0x10(%rbp),%rax
cmpl   $0xffffffff,(%rax)
je     117e <readData+0x6e>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
lea    0xea5(%rip),%rsi
lea    -0x1f(%rbp),%rdx
call   1030 <sscanf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
shl    $0x8,%ecx
movzbl -0x1f(%rbp),%eax
add    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
jmp    119f <readData+0x8f>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
lea    0xe74(%rip),%rsi
lea    -0x1f(%rbp),%rdx
call   1030 <sscanf@plt>
movzbl -0x1f(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%rcx
add    $0x1,%rcx
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
add    $0x8,%ecx
mov    %ecx,(%rax)
jmp    1131 <readData+0x21>
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    -0x18(%rbp),%rcx
mov    (%rcx),%ecx
sub    -0x1c(%rbp),%ecx
shr    %cl,%eax
mov    %ax,-0x1e(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
sub    -0x1c(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
mov    %eax,%ecx
sub    $0x1,%ecx
mov    -0x10(%rbp),%rax
and    (%rax),%ecx
mov    %ecx,(%rax)
mov    -0x1c(%rbp),%edx
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
sub    %edx,%ecx
mov    %ecx,(%rax)
movzwl -0x1e(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readData>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%r14d
mov    %rdx,%r15
mov    %rsi,%rbp
movb   $0x0,0x7(%rsp)
mov    (%rdx),%ecx
cmp    %r14d,%ecx
jae    1185 <readData+0x75>
mov    %rdi,%rbx
lea    0x7(%rsp),%r13
jmp    115a <readData+0x4a>
nopw   0x0(%rax,%rax,1)
movzbl 0x7(%rsp),%eax
mov    %eax,0x0(%rbp)
addq   $0x1,(%rbx)
mov    (%r15),%ecx
add    $0x8,%ecx
mov    %ecx,(%r15)
cmp    %r14d,%ecx
jae    1185 <readData+0x75>
mov    0x0(%rbp),%r12d
mov    (%rbx),%rdi
lea    0xe98(%rip),%rsi
mov    %r13,%rdx
call   1030 <sscanf@plt>
cmp    $0xffffffff,%r12d
je     1140 <readData+0x30>
mov    0x0(%rbp),%ecx
shl    $0x8,%ecx
movzbl 0x7(%rsp),%eax
or     %ecx,%eax
jmp    1145 <readData+0x35>
mov    0x0(%rbp),%edx
sub    %r14d,%ecx
mov    %edx,%eax
shr    %cl,%eax
mov    $0xffffffff,%esi
shl    %cl,%esi
not    %esi
and    %edx,%esi
mov    %esi,0x0(%rbp)
sub    %r14d,(%r15)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%c\00"
define zeroext i16 @readData(i8** %0, i32* %1, i32* %2, i32 %3) {
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i16
%10 = alloca i8
store i8** %0, i8*** %5
store i32* %1, i32** %6
store i32* %2, i32** %7
store i32 %3, i32* %8
store i16 0, i16* %9
store i8 0, i8* %10
br label %11
11: ; preds = %40, %4
%12 = load i32*, i32** %7
%13 = load i32, i32* %12
%14 = load i32, i32* %8
%15 = icmp ult i32 %13, %14
br i1 %15, label %16, label %47
16: ; preds = %11
%17 = load i32*, i32** %6
%18 = load i32, i32* %17
%19 = icmp ne i32 %18, -1
br i1 %19, label %20, label %32
20: ; preds = %16
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 0
%23 = load i8*, i8** %22
%24 = call i32 @sscanf(i8* %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %10)
%25 = load i32*, i32** %6
%26 = load i32, i32* %25
%27 = shl i32 %26, 8
%28 = load i8, i8* %10
%29 = zext i8 %28 to i32
%30 = add i32 %27, %29
%31 = load i32*, i32** %6
store i32 %30, i32* %31
br label %40
32: ; preds = %16
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 0
%35 = load i8*, i8** %34
%36 = call i32 @sscanf(i8* %35, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %10)
%37 = load i8, i8* %10
%38 = zext i8 %37 to i32
%39 = load i32*, i32** %6
store i32 %38, i32* %39
br label %40
40: ; preds = %32, %20
%41 = load i8**, i8*** %5
%42 = load i8*, i8** %41
%43 = getelementptr inbounds i8, i8* %42, i64 1
store i8* %43, i8** %41
%44 = load i32*, i32** %7
%45 = load i32, i32* %44
%46 = add i32 %45, 8
store i32 %46, i32* %44
br label %11
47: ; preds = %11
%48 = load i32*, i32** %6
%49 = load i32, i32* %48
%50 = load i32*, i32** %7
%51 = load i32, i32* %50
%52 = load i32, i32* %8
%53 = sub i32 %51, %52
%54 = lshr i32 %49, %53
%55 = trunc i32 %54 to i16
store i16 %55, i16* %9
%56 = load i32*, i32** %7
%57 = load i32, i32* %56
%58 = load i32, i32* %8
%59 = sub i32 %57, %58
%60 = shl i32 1, %59
%61 = sub nsw i32 %60, 1
%62 = load i32*, i32** %6
%63 = load i32, i32* %62
%64 = and i32 %63, %61
store i32 %64, i32* %62
%65 = load i32, i32* %8
%66 = load i32*, i32** %7
%67 = load i32, i32* %66
%68 = sub i32 %67, %65
store i32 %68, i32* %66
%69 = load i16, i16* %9
ret i16 %69
}

LLVM IR (-O2):
@.str = [3 x i8] c"%c\00"
define zeroext i16 @readData(i8** nocapture %0, i32* nocapture %1, i32* nocapture %2, i32 %3) {
%5 = alloca i8
store i8 0, i8* %5
%6 = load i32, i32* %2
%7 = icmp ult i32 %6, %3
br i1 %7, label %8, label %29
8: ; preds = %4, %22
%9 = load i32, i32* %1
%10 = icmp eq i32 %9, -1
%11 = load i8*, i8** %0
%12 = call i32 @sscanf(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %5)
br i1 %10, label %19, label %13
13: ; preds = %8
%14 = load i32, i32* %1
%15 = shl i32 %14, 8
%16 = load i8, i8* %5
%17 = zext i8 %16 to i32
%18 = or i32 %15, %17
br label %22
19: ; preds = %8
%20 = load i8, i8* %5
%21 = zext i8 %20 to i32
br label %22
22: ; preds = %19, %13
%23 = phi i32 [ %21, %19 ], [ %18, %13 ]
store i32 %23, i32* %1
%24 = load i8*, i8** %0
%25 = getelementptr inbounds i8, i8* %24, i64 1
store i8* %25, i8** %0
%26 = load i32, i32* %2
%27 = add i32 %26, 8
store i32 %27, i32* %2
%28 = icmp ult i32 %27, %3
br i1 %28, label %8, label %29
29: ; preds = %22, %4
%30 = phi i32 [ %6, %4 ], [ %27, %22 ]
%31 = load i32, i32* %1
%32 = sub i32 %30, %3
%33 = lshr i32 %31, %32
%34 = trunc i32 %33 to i16
%35 = shl nsw i32 -1, %32
%36 = xor i32 %35, -1
%37 = and i32 %31, %36
store i32 %37, i32* %1
%38 = load i32, i32* %2
%39 = sub i32 %38, %3
store i32 %39, i32* %2
ret i16 %34
}