#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 /*<<< orphan*/ uint16_t;
typedef int /*<<< orphan*/ int16_t;

/* Variables and functions */
int bits_left();
int /*<<< orphan*/ fill_buffer();
int /*<<< orphan*/ get_value(int /*<<< orphan*/);
int /*<<< orphan*/ read_value();
int decompress_sample(int16_t *digi_x, int16_t *digi_y, int16_t *digi_z,
                      uint16_t *analog_x, uint16_t *analog_y) {
  static int first = 1;
  static int16_t last_vals[3];
  if (first) {
    first = 0;
    fill_buffer();
    *digi_x = last_vals[0] = read_value();
    *digi_y = last_vals[1] = read_value();
    *digi_z = last_vals[2] = read_value();
  } else {
    int i;
    if (bits_left() < 3 * 13) {
      fill_buffer();
    }
    for (i = 0; i < 3; i++) {
      last_vals[i] = get_value(last_vals[i]);
    }
    *digi_x = last_vals[0];
    *digi_y = last_vals[1];
    *digi_z = last_vals[2];
  }
  return 0;
}


x86 assembly (clang, -O0):
<decompress_sample>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
cmpl   $0x0,0x2edd(%rip)
je     11be <decompress_sample+0x7e>
movl   $0x0,0x2ecd(%rip)
mov    $0x0,%al
call   1030 <fill_buffer@plt>
mov    $0x0,%al
call   1040 <read_value@plt>
mov    %eax,%ecx
mov    %ecx,0x2ebf(%rip)
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
mov    $0x0,%al
call   1040 <read_value@plt>
mov    %eax,%ecx
mov    %ecx,0x2eae(%rip)
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    $0x0,%al
call   1040 <read_value@plt>
mov    %eax,%ecx
mov    %ecx,0x2e9d(%rip)
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
jmp    123b <decompress_sample+0xfb>
mov    $0x0,%al
call   1050 <bits_left@plt>
cmp    $0x27,%eax
jge    11d5 <decompress_sample+0x95>
mov    $0x0,%al
call   1030 <fill_buffer@plt>
movl   $0x0,-0x2c(%rbp)
cmpl   $0x3,-0x2c(%rbp)
jge    1217 <decompress_sample+0xd7>
movslq -0x2c(%rbp),%rcx
lea    0x2e57(%rip),%rax
mov    (%rax,%rcx,4),%edi
call   1060 <get_value@plt>
mov    %eax,%edx
movslq -0x2c(%rbp),%rcx
lea    0x2e42(%rip),%rax
mov    %edx,(%rax,%rcx,4)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11dc <decompress_sample+0x9c>
mov    0x2e2b(%rip),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
mov    0x2e23(%rip),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    0x2e1b(%rip),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<decompress_sample>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
cmpb   $0x0,0x2eef(%rip)
je     11b0 <decompress_sample+0x70>
xor    %eax,%eax
call   1050 <bits_left@plt>
cmp    $0x26,%eax
jg     116a <decompress_sample+0x2a>
xor    %eax,%eax
call   1030 <fill_buffer@plt>
mov    0x2ed8(%rip),%edi
call   1060 <get_value@plt>
mov    %eax,0x2ecd(%rip)
mov    0x2ecb(%rip),%edi
call   1060 <get_value@plt>
mov    %eax,0x2ec0(%rip)
mov    0x2ebe(%rip),%edi
call   1060 <get_value@plt>
mov    %eax,0x2eb3(%rip)
mov    0x2ea5(%rip),%ecx
mov    %ecx,(%rbx)
mov    0x2ea1(%rip),%ecx
mov    %ecx,(%r15)
jmp    11ea <decompress_sample+0xaa>
movb   $0x1,0x2e8d(%rip)
xor    %eax,%eax
call   1030 <fill_buffer@plt>
xor    %eax,%eax
call   1040 <read_value@plt>
mov    %eax,0x2e7d(%rip)
mov    %eax,(%rbx)
xor    %eax,%eax
call   1040 <read_value@plt>
mov    %eax,0x2e72(%rip)
mov    %eax,(%r15)
xor    %eax,%eax
call   1040 <read_value@plt>
mov    %eax,0x2e66(%rip)
mov    %eax,(%r14)
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@decompress_sample.first = internal global i32 1
@decompress_sample.last_vals = internal global [3 x i32] zeroinitializer
define i32 @decompress_sample(i32* %0, i32* %1, i32* %2, i32* %3, i32* %4) {
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i32
store i32* %0, i32** %6
store i32* %1, i32** %7
store i32* %2, i32** %8
store i32* %3, i32** %9
store i32* %4, i32** %10
%12 = load i32, i32* @decompress_sample.first
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %22
14: ; preds = %5
store i32 0, i32* @decompress_sample.first
%15 = call i32 (...) @fill_buffer()
%16 = call i32 (...) @read_value()
store i32 %16, i32* getelementptr inbounds ([3 x i32], [3 x i32]* @decompress_sample.last_vals, i64 0, i64 0)
%17 = load i32*, i32** %6
store i32 %16, i32* %17
%18 = call i32 (...) @read_value()
store i32 %18, i32* getelementptr inbounds ([3 x i32], [3 x i32]* @decompress_sample.last_vals, i64 0, i64 1)
%19 = load i32*, i32** %7
store i32 %18, i32* %19
%20 = call i32 (...) @read_value()
store i32 %20, i32* getelementptr inbounds ([3 x i32], [3 x i32]* @decompress_sample.last_vals, i64 0, i64 2)
%21 = load i32*, i32** %8
store i32 %20, i32* %21
br label %50
22: ; preds = %5
%23 = call i32 (...) @bits_left()
%24 = icmp slt i32 %23, 39
br i1 %24, label %25, label %27
25: ; preds = %22
%26 = call i32 (...) @fill_buffer()
br label %27
27: ; preds = %25, %22
store i32 0, i32* %11
br label %28
28: ; preds = %40, %27
%29 = load i32, i32* %11
%30 = icmp slt i32 %29, 3
br i1 %30, label %31, label %43
31: ; preds = %28
%32 = load i32, i32* %11
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [3 x i32], [3 x i32]* @decompress_sample.last_vals, i64 0, i64 %33
%35 = load i32, i32* %34
%36 = call i32 @get_value(i32 %35)
%37 = load i32, i32* %11
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [3 x i32], [3 x i32]* @decompress_sample.last_vals, i64 0, i64 %38
store i32 %36, i32* %39
br label %40
40: ; preds = %31
%41 = load i32, i32* %11
%42 = add nsw i32 %41, 1
store i32 %42, i32* %11
br label %28
43: ; preds = %28
%44 = load i32, i32* getelementptr inbounds ([3 x i32], [3 x i32]* @decompress_sample.last_vals, i64 0, i64 0)
%45 = load i32*, i32** %6
store i32 %44, i32* %45
%46 = load i32, i32* getelementptr inbounds ([3 x i32], [3 x i32]* @decompress_sample.last_vals, i64 0, i64 1)
%47 = load i32*, i32** %7
store i32 %46, i32* %47
%48 = load i32, i32* getelementptr inbounds ([3 x i32], [3 x i32]* @decompress_sample.last_vals, i64 0, i64 2)
%49 = load i32*, i32** %8
store i32 %48, i32* %49
br label %50
50: ; preds = %43, %14
ret i32 0
}

LLVM IR (-O2):
@decompress_sample.first = internal unnamed_addr global i1 false
@decompress_sample.last_vals.0 = internal unnamed_addr global i32 0
@decompress_sample.last_vals.1 = internal unnamed_addr global i32 0
@decompress_sample.last_vals.2 = internal unnamed_addr global i32 0
define i32 @decompress_sample(i32* nocapture writeonly %0, i32* nocapture writeonly %1, i32* nocapture writeonly %2, i32* nocapture readnone %3, i32* nocapture readnone %4) {
%6 = load i1, i1* @decompress_sample.first
br i1 %6, label %12, label %7
7: ; preds = %5
store i1 true, i1* @decompress_sample.first
%8 = tail call i32 (...) @fill_buffer()
%9 = tail call i32 (...) @read_value()
store i32 %9, i32* @decompress_sample.last_vals.0
store i32 %9, i32* %0
%10 = tail call i32 (...) @read_value()
store i32 %10, i32* @decompress_sample.last_vals.1
store i32 %10, i32* %1
%11 = tail call i32 (...) @read_value()
store i32 %11, i32* @decompress_sample.last_vals.2
br label %26
12: ; preds = %5
%13 = tail call i32 (...) @bits_left()
%14 = icmp slt i32 %13, 39
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = tail call i32 (...) @fill_buffer()
br label %17
17: ; preds = %15, %12
%18 = load i32, i32* @decompress_sample.last_vals.0
%19 = tail call i32 @get_value(i32 %18)
store i32 %19, i32* @decompress_sample.last_vals.0
%20 = load i32, i32* @decompress_sample.last_vals.1
%21 = tail call i32 @get_value(i32 %20)
store i32 %21, i32* @decompress_sample.last_vals.1
%22 = load i32, i32* @decompress_sample.last_vals.2
%23 = tail call i32 @get_value(i32 %22)
store i32 %23, i32* @decompress_sample.last_vals.2
%24 = load i32, i32* @decompress_sample.last_vals.0
store i32 %24, i32* %0
%25 = load i32, i32* @decompress_sample.last_vals.1
store i32 %25, i32* %1
br label %26
26: ; preds = %17, %7
%27 = phi i32 [ %23, %17 ], [ %11, %7 ]
store i32 %27, i32* %2
ret i32 0
}