#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 abs(int);
int /*<<< orphan*/ printf(char *, int, int);
int writeSyntaxElement_Level_VLC1(int level) {
  int levabs = abs(level);
  int sign = (level < 0 ? 1 : 0);
  int iCodeword, iLength;
  if (levabs < 8) {
    iLength = levabs * 2 + sign - 1;
    iCodeword = 1;
  } else if (levabs < 16) {
    iLength = 19;
    iCodeword = (1 << 4) | ((levabs - 8) << 1) | sign;
  } else {
    iLength = 28;
    int numPrefix = 15;
    int addbit, offset;
    int levabsm16 = levabs - 16;
    if ((levabsm16) >= 2048) {
      numPrefix++;
      while ((levabsm16) >= (1 << (numPrefix - 3)) - 4096) {
        numPrefix++;
      }
    }
    addbit = numPrefix - 15;
    iLength += (addbit << 1);
    offset = (2048 << addbit) - 2048;
    iCodeword = (1 << (12 + addbit)) | ((levabsm16) << 1) | sign;
  }
  printf("code %x  len %d\n", iCodeword, iLength);
  return 0;
}


x86 assembly (clang, -O0):
<writeSyntaxElement_Level_VLC1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
call   1030 <abs@plt>
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%edx
xor    %eax,%eax
mov    $0x1,%ecx
cmp    $0x0,%edx
cmovl  %ecx,%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x8,-0x8(%rbp)
jge    116e <writeSyntaxElement_Level_VLC1+0x4e>
mov    -0x8(%rbp),%eax
shl    $0x1,%eax
add    -0xc(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x14(%rbp)
movl   $0x1,-0x10(%rbp)
jmp    123d <writeSyntaxElement_Level_VLC1+0x11d>
cmpl   $0x10,-0x8(%rbp)
jge    1196 <writeSyntaxElement_Level_VLC1+0x76>
movl   $0x13,-0x14(%rbp)
mov    -0x8(%rbp),%eax
sub    $0x8,%eax
shl    $0x1,%eax
or     $0x10,%eax
or     -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
jmp    1238 <writeSyntaxElement_Level_VLC1+0x118>
movl   $0x1c,-0x14(%rbp)
movl   $0xf,-0x18(%rbp)
mov    -0x8(%rbp),%eax
sub    $0x10,%eax
mov    %eax,-0x24(%rbp)
cmpl   $0x800,-0x24(%rbp)
jl     11f6 <writeSyntaxElement_Level_VLC1+0xd6>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x24(%rbp),%eax
mov    -0x18(%rbp),%ecx
sub    $0x3,%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
sub    $0x1000,%ecx
cmp    %ecx,%eax
jl     11f1 <writeSyntaxElement_Level_VLC1+0xd1>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11c3 <writeSyntaxElement_Level_VLC1+0xa3>
jmp    11f6 <writeSyntaxElement_Level_VLC1+0xd6>
mov    -0x18(%rbp),%eax
sub    $0xf,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
shl    $0x1,%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x1c(%rbp),%ecx
mov    $0x800,%eax
shl    %cl,%eax
sub    $0x800,%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%ecx
add    $0xc,%ecx
mov    $0x1,%eax
shl    %cl,%eax
mov    -0x24(%rbp),%ecx
shl    $0x1,%ecx
or     %ecx,%eax
or     -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
jmp    123d <writeSyntaxElement_Level_VLC1+0x11d>
mov    -0x10(%rbp),%esi
mov    -0x14(%rbp),%edx
lea    0xdb6(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<writeSyntaxElement_Level_VLC1>:
mov    %edi,%esi
neg    %esi
cmovs  %edi,%esi
shr    $0x1f,%edi
cmp    $0x7,%esi
ja     112c <writeSyntaxElement_Level_VLC1+0x1c>
lea    (%rdi,%rsi,2),%edx
add    $0xffffffff,%edx
mov    $0x1,%esi
jmp    1188 <writeSyntaxElement_Level_VLC1+0x78>
cmp    $0xf,%esi
ja     1141 <writeSyntaxElement_Level_VLC1+0x31>
lea    (%rdi,%rsi,2),%esi
add    $0xfffffff0,%esi
or     $0x10,%esi
mov    $0x13,%edx
jmp    1188 <writeSyntaxElement_Level_VLC1+0x78>
mov    $0xf,%eax
cmp    $0x810,%esi
jb     1177 <writeSyntaxElement_Level_VLC1+0x67>
mov    $0xf,%eax
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
lea    -0x2(%rax),%ecx
mov    $0x1,%edx
shl    %cl,%edx
add    $0xfffff010,%edx
add    $0x1,%eax
cmp    %edx,%esi
jge    1160 <writeSyntaxElement_Level_VLC1+0x50>
lea    (%rax,%rax,1),%edx
add    $0xfffffffe,%edx
add    $0xfd,%al
lea    (%rdi,%rsi,2),%esi
add    $0xffffffe0,%esi
bts    %eax,%esi
push   %rax
lea    0xe70(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [17 x i8] c"code %x len %d\0A\00"
define i32 @writeSyntaxElement_Level_VLC1(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 %0, i32* %2
%11 = load i32, i32* %2
%12 = call i32 @abs(i32 %11)
store i32 %12, i32* %3
%13 = load i32, i32* %2
%14 = icmp slt i32 %13, 0
%15 = zext i1 %14 to i64
%16 = select i1 %14, i32 1, i32 0
store i32 %16, i32* %4
%17 = load i32, i32* %3
%18 = icmp slt i32 %17, 8
br i1 %18, label %19, label %25
19: ; preds = %1
%20 = load i32, i32* %3
%21 = mul nsw i32 %20, 2
%22 = load i32, i32* %4
%23 = add nsw i32 %21, %22
%24 = sub nsw i32 %23, 1
store i32 %24, i32* %6
store i32 1, i32* %5
br label %73
25: ; preds = %1
%26 = load i32, i32* %3
%27 = icmp slt i32 %26, 16
br i1 %27, label %28, label %35
28: ; preds = %25
store i32 19, i32* %6
%29 = load i32, i32* %3
%30 = sub nsw i32 %29, 8
%31 = shl i32 %30, 1
%32 = or i32 16, %31
%33 = load i32, i32* %4
%34 = or i32 %32, %33
store i32 %34, i32* %5
br label %72
35: ; preds = %25
store i32 28, i32* %6
store i32 15, i32* %7
%36 = load i32, i32* %3
%37 = sub nsw i32 %36, 16
store i32 %37, i32* %10
%38 = load i32, i32* %10
%39 = icmp sge i32 %38, 2048
br i1 %39, label %40, label %54
40: ; preds = %35
%41 = load i32, i32* %7
%42 = add nsw i32 %41, 1
store i32 %42, i32* %7
br label %43
43: ; preds = %50, %40
%44 = load i32, i32* %10
%45 = load i32, i32* %7
%46 = sub nsw i32 %45, 3
%47 = shl i32 1, %46
%48 = sub nsw i32 %47, 4096
%49 = icmp sge i32 %44, %48
br i1 %49, label %50, label %53
50: ; preds = %43
%51 = load i32, i32* %7
%52 = add nsw i32 %51, 1
store i32 %52, i32* %7
br label %43
53: ; preds = %43
br label %54
54: ; preds = %53, %35
%55 = load i32, i32* %7
%56 = sub nsw i32 %55, 15
store i32 %56, i32* %8
%57 = load i32, i32* %8
%58 = shl i32 %57, 1
%59 = load i32, i32* %6
%60 = add nsw i32 %59, %58
store i32 %60, i32* %6
%61 = load i32, i32* %8
%62 = shl i32 2048, %61
%63 = sub nsw i32 %62, 2048
store i32 %63, i32* %9
%64 = load i32, i32* %8
%65 = add nsw i32 12, %64
%66 = shl i32 1, %65
%67 = load i32, i32* %10
%68 = shl i32 %67, 1
%69 = or i32 %66, %68
%70 = load i32, i32* %4
%71 = or i32 %69, %70
store i32 %71, i32* %5
br label %72
72: ; preds = %54, %28
br label %73
73: ; preds = %72, %19
%74 = load i32, i32* %5
%75 = load i32, i32* %6
%76 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %74, i32 %75)
ret i32 0
}

LLVM IR (-O2):
@.str = [17 x i8] c"code %x len %d\0A\00"
define i32 @writeSyntaxElement_Level_VLC1(i32 %0) {
%2 = tail call i32 @llvm.abs.i32(i32 %0, i1 true)
%3 = lshr i32 %0, 31
%4 = icmp ult i32 %2, 8
br i1 %4, label %5, label %9
5: ; preds = %1
%6 = shl nuw nsw i32 %2, 1
%7 = add nsw i32 %3, -1
%8 = add nsw i32 %7, %6
br label %35
9: ; preds = %1
%10 = icmp ult i32 %2, 16
br i1 %10, label %11, label %16
11: ; preds = %9
%12 = shl nuw nsw i32 %2, 1
%13 = add nsw i32 %12, -16
%14 = or i32 %13, %3
%15 = or i32 %14, 16
br label %35
16: ; preds = %9
%17 = icmp ugt i32 %2, 2063
br i1 %17, label %18, label %25
18: ; preds = %16, %18
%19 = phi i32 [ %24, %18 ], [ 16, %16 ]
%20 = add nsw i32 %19, -3
%21 = shl nuw i32 1, %20
%22 = add nsw i32 %21, -4080
%23 = icmp slt i32 %2, %22
%24 = add nuw nsw i32 %19, 1
br i1 %23, label %25, label %18
25: ; preds = %18, %16
%26 = phi i32 [ 15, %16 ], [ %19, %18 ]
%27 = shl nuw i32 %26, 1
%28 = add i32 %27, -2
%29 = add nsw i32 %26, -3
%30 = shl nuw i32 1, %29
%31 = shl nuw i32 %2, 1
%32 = add i32 %31, -32
%33 = or i32 %32, %3
%34 = or i32 %33, %30
br label %35
35: ; preds = %11, %25, %5
%36 = phi i32 [ %8, %5 ], [ 19, %11 ], [ %28, %25 ]
%37 = phi i32 [ 1, %5 ], [ %15, %11 ], [ %34, %25 ]
%38 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %37, i32 %36)
ret i32 0
}