#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*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
int decode_blockcode(int code, int levels, int *values) {
  int i;
  int offset = (levels - 1) >> 1;
  for (i = 0; i < 4; i++) {
    values[i] = (code % levels) - offset;
    code /= levels;
  }
  if (code == 0)
    return 1;
  else {
    fprintf(stderr, "ERROR: block code look-up failed\n");
    return 0;
  }
}


x86 assembly (clang, -O0):
<decode_blockcode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
sar    $0x1,%eax
mov    %eax,-0x20(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x4,-0x1c(%rbp)
jge    116e <decode_blockcode+0x5e>
mov    -0x8(%rbp),%eax
cltd
idivl  -0xc(%rbp)
sub    -0x20(%rbp),%edx
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0xc(%rbp),%ecx
mov    -0x8(%rbp),%eax
cltd
idiv   %ecx
mov    %eax,-0x8(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1135 <decode_blockcode+0x25>
cmpl   $0x0,-0x8(%rbp)
jne    1184 <decode_blockcode+0x74>
movl   $0x1,-0x4(%rbp)
jmp    11a0 <decode_blockcode+0x90>
mov    0x2e55(%rip),%rax
mov    (%rax),%edi
lea    0xe6c(%rip),%rsi
call   1030 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<decode_blockcode>:
push   %rax
mov    %rdx,%rcx
mov    %edi,%eax
cltd
idiv   %esi
lea    -0x1(%rsi),%edi
sar    %edi
sub    %edi,%edx
mov    %edx,(%rcx)
cltd
idiv   %esi
sub    %edi,%edx
mov    %edx,0x4(%rcx)
cltd
idiv   %esi
sub    %edi,%edx
mov    %edx,0x8(%rcx)
cltd
idiv   %esi
sub    %edi,%edx
mov    %edx,0xc(%rcx)
test   %eax,%eax
je     1157 <decode_blockcode+0x47>
mov    0x2e9b(%rip),%rax
mov    (%rax),%edi
lea    0xeb2(%rip),%rsi
call   1030 <fprintf@plt>
xor    %eax,%eax
pop    %rcx
ret
mov    $0x1,%eax
pop    %rcx
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [34 x i8] c"ERROR: block code look-up failed\0A\00"
define i32 @decode_blockcode(i32 %0, i32 %1, i32* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32* %2, i32** %7
%10 = load i32, i32* %6
%11 = sub nsw i32 %10, 1
%12 = ashr i32 %11, 1
store i32 %12, i32* %9
store i32 0, i32* %8
br label %13
13: ; preds = %29, %3
%14 = load i32, i32* %8
%15 = icmp slt i32 %14, 4
br i1 %15, label %16, label %32
16: ; preds = %13
%17 = load i32, i32* %5
%18 = load i32, i32* %6
%19 = srem i32 %17, %18
%20 = load i32, i32* %9
%21 = sub nsw i32 %19, %20
%22 = load i32*, i32** %7
%23 = load i32, i32* %8
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i32, i32* %22, i64 %24
store i32 %21, i32* %25
%26 = load i32, i32* %6
%27 = load i32, i32* %5
%28 = sdiv i32 %27, %26
store i32 %28, i32* %5
br label %29
29: ; preds = %16
%30 = load i32, i32* %8
%31 = add nsw i32 %30, 1
store i32 %31, i32* %8
br label %13
32: ; preds = %13
%33 = load i32, i32* %5
%34 = icmp eq i32 %33, 0
br i1 %34, label %35, label %36
35: ; preds = %32
store i32 1, i32* %4
br label %39
36: ; preds = %32
%37 = load i32, i32* @stderr
%38 = call i32 @fprintf(i32 %37, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %4
br label %39
39: ; preds = %36, %35
%40 = load i32, i32* %4
ret i32 %40
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [34 x i8] c"ERROR: block code look-up failed\0A\00"
define i32 @decode_blockcode(i32 %0, i32 %1, i32* nocapture writeonly %2) {
%4 = add nsw i32 %1, -1
%5 = ashr i32 %4, 1
%6 = srem i32 %0, %1
%7 = sub nsw i32 %6, %5
store i32 %7, i32* %2
%8 = sdiv i32 %0, %1
%9 = srem i32 %8, %1
%10 = sub nsw i32 %9, %5
%11 = getelementptr inbounds i32, i32* %2, i64 1
store i32 %10, i32* %11
%12 = sdiv i32 %8, %1
%13 = srem i32 %12, %1
%14 = sub nsw i32 %13, %5
%15 = getelementptr inbounds i32, i32* %2, i64 2
store i32 %14, i32* %15
%16 = sdiv i32 %12, %1
%17 = srem i32 %16, %1
%18 = sub nsw i32 %17, %5
%19 = getelementptr inbounds i32, i32* %2, i64 3
store i32 %18, i32* %19
%20 = sdiv i32 %16, %1
%21 = icmp eq i32 %20, 0
br i1 %21, label %25, label %22
22: ; preds = %3
%23 = load i32, i32* @stderr
%24 = tail call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
br label %25
25: ; preds = %3, %22
%26 = phi i32 [ 0, %22 ], [ 1, %3 ]
ret i32 %26
}