#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 int_abs(int);
int /*<<< orphan*/ mqc_encode(int);
int /*<<< orphan*/ mqc_setcurctx(int /*<<< orphan*/);
int /*<<< orphan*/ t1_getctxno_sc(int);
int /*<<< orphan*/ t1_getctxno_zc(int, int);
scalar_t__ t1_getnmsedec_sig(int, int);
int t1_getspb(int);
int /*<<< orphan*/ t1_updateflags(int *, int);
void t1_enc_clnpass_step(int *fp, int *dp, int orient, int bpno, int one,
                         int *nmsedec, int partial) {
  int v;
  if (partial)
    goto label_partial;
  if (!(*fp & (0x1000 | 0x4000))) {
    mqc_setcurctx(t1_getctxno_zc(*fp, orient));
    v = int_abs(*dp) & one ? 1 : 0;
    mqc_encode(v);
    if (v) {
    label_partial:
      *nmsedec += t1_getnmsedec_sig(int_abs(*dp), bpno + (7 - 1));
      mqc_setcurctx(t1_getctxno_sc(*fp));
      v = *dp < 0 ? 1 : 0;
      mqc_encode(v ^ t1_getspb(*fp));
      t1_updateflags(fp, v);
      *fp |= 0x1000;
    }
  }
  *fp &= ~0x4000;
}


x86 assembly (clang, -O0):
<t1_enc_clnpass_step>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    0x10(%rbp),%eax
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %r8d,-0x1c(%rbp)
mov    %r9,-0x28(%rbp)
cmpl   $0x0,0x10(%rbp)
je     11b0 <t1_enc_clnpass_step+0x30>
jmp    1210 <t1_enc_clnpass_step+0x90>
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
and    $0x5000,%eax
cmp    $0x0,%eax
jne    1299 <t1_enc_clnpass_step+0x119>
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%esi
call   1040 <t1_getctxno_zc@plt>
mov    %eax,%edi
call   1090 <mqc_setcurctx@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
call   1070 <int_abs@plt>
mov    %eax,%edx
and    -0x1c(%rbp),%edx
xor    %eax,%eax
mov    $0x1,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%edi
call   1050 <mqc_encode@plt>
cmpl   $0x0,-0x2c(%rbp)
je     1294 <t1_enc_clnpass_step+0x114>
jmp    1210 <t1_enc_clnpass_step+0x90>
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
call   1070 <int_abs@plt>
mov    %eax,%edi
mov    -0x18(%rbp),%esi
add    $0x6,%esi
call   1060 <t1_getnmsedec_sig@plt>
mov    %rax,%rdx
mov    -0x28(%rbp),%rax
movslq (%rax),%rcx
add    %rdx,%rcx
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
call   1030 <t1_getctxno_sc@plt>
mov    %eax,%edi
call   1090 <mqc_setcurctx@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    $0x1,%ecx
cmp    $0x0,%edx
cmovl  %ecx,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
call   10a0 <t1_getspb@plt>
mov    -0x30(%rbp),%edi
xor    %eax,%edi
call   1050 <mqc_encode@plt>
mov    -0x8(%rbp),%rdi
mov    -0x2c(%rbp),%esi
call   1080 <t1_updateflags@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%ecx
or     $0x1000,%ecx
mov    %ecx,(%rax)
jmp    1299 <t1_enc_clnpass_step+0x119>
mov    -0x8(%rbp),%rax
mov    (%rax),%ecx
and    $0xffffbfff,%ecx
mov    %ecx,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<t1_enc_clnpass_step>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9,%r15
mov    %ecx,%ebp
mov    %rsi,%r14
mov    %rdi,%rbx
cmpl   $0x0,0x40(%rsp)
je     11eb <t1_enc_clnpass_step+0x6b>
mov    (%r14),%edi
call   1070 <int_abs@plt>
add    $0x6,%ebp
mov    %eax,%edi
mov    %ebp,%esi
call   1060 <t1_getnmsedec_sig@plt>
add    %eax,(%r15)
mov    (%rbx),%edi
call   1030 <t1_getctxno_sc@plt>
mov    %eax,%edi
call   1090 <mqc_setcurctx@plt>
mov    (%r14),%ebp
shr    $0x1f,%ebp
mov    (%rbx),%edi
call   10a0 <t1_getspb@plt>
xor    %ebp,%eax
mov    %eax,%edi
call   1050 <mqc_encode@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1080 <t1_updateflags@plt>
mov    $0x1000,%edi
or     (%rbx),%edi
jmp    11f5 <t1_enc_clnpass_step+0x75>
mov    (%rbx),%edi
test   $0x5000,%edi
je     120c <t1_enc_clnpass_step+0x8c>
and    $0xffffbfff,%edi
mov    %edi,(%rbx)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r8d,%r12d
mov    %edx,%esi
call   1040 <t1_getctxno_zc@plt>
mov    %eax,%edi
call   1090 <mqc_setcurctx@plt>
mov    (%r14),%edi
call   1070 <int_abs@plt>
mov    %eax,%r13d
xor    %edi,%edi
test   %r12d,%eax
setne  %dil
call   1050 <mqc_encode@plt>
test   %r12d,%r13d
jne    119d <t1_enc_clnpass_step+0x1d>
mov    (%rbx),%edi
jmp    11f5 <t1_enc_clnpass_step+0x75>

LLVM IR (-O0):
define void @t1_enc_clnpass_step(i32* %0, i32* %1, i32 %2, i32 %3, i32 %4, i32* %5, i32 %6) {
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32*
%14 = alloca i32
%15 = alloca i32
store i32* %0, i32** %8
store i32* %1, i32** %9
store i32 %2, i32* %10
store i32 %3, i32* %11
store i32 %4, i32* %12
store i32* %5, i32** %13
store i32 %6, i32* %14
%16 = load i32, i32* %14
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %7
br label %43
19: ; preds = %7
%20 = load i32*, i32** %8
%21 = load i32, i32* %20
%22 = and i32 %21, 20480
%23 = icmp ne i32 %22, 0
br i1 %23, label %77, label %24
24: ; preds = %19
%25 = load i32*, i32** %8
%26 = load i32, i32* %25
%27 = load i32, i32* %10
%28 = call i32 @t1_getctxno_zc(i32 %26, i32 %27)
%29 = call i32 @mqc_setcurctx(i32 %28)
%30 = load i32*, i32** %9
%31 = load i32, i32* %30
%32 = call i32 @int_abs(i32 %31)
%33 = load i32, i32* %12
%34 = and i32 %32, %33
%35 = icmp ne i32 %34, 0
%36 = zext i1 %35 to i64
%37 = select i1 %35, i32 1, i32 0
store i32 %37, i32* %15
%38 = load i32, i32* %15
%39 = call i32 @mqc_encode(i32 %38)
%40 = load i32, i32* %15
%41 = icmp ne i32 %40, 0
br i1 %41, label %42, label %76
42: ; preds = %24
br label %43
43: ; preds = %42, %18
%44 = load i32*, i32** %9
%45 = load i32, i32* %44
%46 = call i32 @int_abs(i32 %45)
%47 = load i32, i32* %11
%48 = add nsw i32 %47, 6
%49 = call i64 @t1_getnmsedec_sig(i32 %46, i32 %48)
%50 = load i32*, i32** %13
%51 = load i32, i32* %50
%52 = sext i32 %51 to i64
%53 = add nsw i64 %52, %49
%54 = trunc i64 %53 to i32
store i32 %54, i32* %50
%55 = load i32*, i32** %8
%56 = load i32, i32* %55
%57 = call i32 @t1_getctxno_sc(i32 %56)
%58 = call i32 @mqc_setcurctx(i32 %57)
%59 = load i32*, i32** %9
%60 = load i32, i32* %59
%61 = icmp slt i32 %60, 0
%62 = zext i1 %61 to i64
%63 = select i1 %61, i32 1, i32 0
store i32 %63, i32* %15
%64 = load i32, i32* %15
%65 = load i32*, i32** %8
%66 = load i32, i32* %65
%67 = call i32 @t1_getspb(i32 %66)
%68 = xor i32 %64, %67
%69 = call i32 @mqc_encode(i32 %68)
%70 = load i32*, i32** %8
%71 = load i32, i32* %15
%72 = call i32 @t1_updateflags(i32* %70, i32 %71)
%73 = load i32*, i32** %8
%74 = load i32, i32* %73
%75 = or i32 %74, 4096
store i32 %75, i32* %73
br label %76
76: ; preds = %43, %24
br label %77
77: ; preds = %76, %19
%78 = load i32*, i32** %8
%79 = load i32, i32* %78
%80 = and i32 %79, -16385
store i32 %80, i32* %78
ret void
}

LLVM IR (-O2):
define void @t1_enc_clnpass_step(i32* %0, i32* nocapture %1, i32 %2, i32 %3, i32 %4, i32* nocapture %5, i32 %6) {
%8 = icmp eq i32 %6, 0
br i1 %8, label %9, label %25
9: ; preds = %7
%10 = load i32, i32* %0
%11 = and i32 %10, 20480
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %45
13: ; preds = %9
%14 = tail call i32 @t1_getctxno_zc(i32 %10, i32 %2)
%15 = tail call i32 @mqc_setcurctx(i32 %14)
%16 = load i32, i32* %1
%17 = tail call i32 @int_abs(i32 %16)
%18 = and i32 %17, %4
%19 = icmp eq i32 %18, 0
%20 = xor i1 %19, true
%21 = zext i1 %20 to i32
%22 = tail call i32 @mqc_encode(i32 %21)
br i1 %19, label %23, label %25
23: ; preds = %13
%24 = load i32, i32* %0
br label %45
25: ; preds = %13, %7
%26 = load i32, i32* %1
%27 = tail call i32 @int_abs(i32 %26)
%28 = add nsw i32 %3, 6
%29 = tail call i64 @t1_getnmsedec_sig(i32 %27, i32 %28)
%30 = load i32, i32* %5
%31 = trunc i64 %29 to i32
%32 = add i32 %30, %31
store i32 %32, i32* %5
%33 = load i32, i32* %0
%34 = tail call i32 @t1_getctxno_sc(i32 %33)
%35 = tail call i32 @mqc_setcurctx(i32 %34)
%36 = load i32, i32* %1
%37 = lshr i32 %36, 31
%38 = load i32, i32* %0
%39 = tail call i32 @t1_getspb(i32 %38)
%40 = xor i32 %39, %37
%41 = tail call i32 @mqc_encode(i32 %40)
%42 = tail call i32 @t1_updateflags(i32* %0, i32 %37)
%43 = load i32, i32* %0
%44 = or i32 %43, 4096
br label %45
45: ; preds = %23, %25, %9
%46 = phi i32 [ %24, %23 ], [ %44, %25 ], [ %10, %9 ]
%47 = and i32 %46, -16385
store i32 %47, i32* %0
ret void
}