#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_mag(int);
scalar_t__ t1_getnmsedec_ref(int, int);
void t1_enc_refpass_step(int *fp, int *dp, int bpno, int one, int *nmsedec) {
  int v;
  if ((*fp & (0x1000 | 0x4000)) == 0x1000) {
    *nmsedec += t1_getnmsedec_ref(int_abs(*dp), bpno + (7 - 1));
    mqc_setcurctx(t1_getctxno_mag(*fp));
    v = int_abs(*dp) & one ? 1 : 0;
    mqc_encode(v);
    *fp |= 0x2000;
  }
}


x86 assembly (clang, -O0):
<t1_enc_refpass_step>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
and    $0x5000,%eax
cmp    $0x1000,%eax
jne    11ef <t1_enc_refpass_step+0x9f>
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
call   1050 <int_abs@plt>
mov    %eax,%edi
mov    -0x14(%rbp),%esi
add    $0x6,%esi
call   1060 <t1_getnmsedec_ref@plt>
mov    %rax,%rdx
mov    -0x20(%rbp),%rax
movslq (%rax),%rcx
add    %rdx,%rcx
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
call   1030 <t1_getctxno_mag@plt>
mov    %eax,%edi
call   1070 <mqc_setcurctx@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
call   1050 <int_abs@plt>
mov    %eax,%edx
and    -0x18(%rbp),%edx
xor    %eax,%eax
mov    $0x1,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%edi
call   1040 <mqc_encode@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%ecx
or     $0x2000,%ecx
mov    %ecx,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<t1_enc_refpass_step>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    $0x5000,%eax
and    (%rdi),%eax
cmp    $0x1000,%eax
jne    11b3 <t1_enc_refpass_step+0x63>
mov    %r8,%r15
mov    %ecx,%r14d
mov    %edx,%ebp
mov    %rsi,%r12
mov    %rdi,%rbx
mov    (%rsi),%edi
call   1050 <int_abs@plt>
add    $0x6,%ebp
mov    %eax,%edi
mov    %ebp,%esi
call   1060 <t1_getnmsedec_ref@plt>
add    %eax,(%r15)
mov    (%rbx),%edi
call   1030 <t1_getctxno_mag@plt>
mov    %eax,%edi
call   1070 <mqc_setcurctx@plt>
mov    (%r12),%edi
call   1050 <int_abs@plt>
xor    %edi,%edi
test   %r14d,%eax
setne  %dil
call   1040 <mqc_encode@plt>
orb    $0x20,0x1(%rbx)
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @t1_enc_refpass_step(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** %6
%13 = load i32, i32* %12
%14 = and i32 %13, 20480
%15 = icmp eq i32 %14, 4096
br i1 %15, label %16, label %45
16: ; preds = %5
%17 = load i32*, i32** %7
%18 = load i32, i32* %17
%19 = call i32 @int_abs(i32 %18)
%20 = load i32, i32* %8
%21 = add nsw i32 %20, 6
%22 = call i64 @t1_getnmsedec_ref(i32 %19, i32 %21)
%23 = load i32*, i32** %10
%24 = load i32, i32* %23
%25 = sext i32 %24 to i64
%26 = add nsw i64 %25, %22
%27 = trunc i64 %26 to i32
store i32 %27, i32* %23
%28 = load i32*, i32** %6
%29 = load i32, i32* %28
%30 = call i32 @t1_getctxno_mag(i32 %29)
%31 = call i32 @mqc_setcurctx(i32 %30)
%32 = load i32*, i32** %7
%33 = load i32, i32* %32
%34 = call i32 @int_abs(i32 %33)
%35 = load i32, i32* %9
%36 = and i32 %34, %35
%37 = icmp ne i32 %36, 0
%38 = zext i1 %37 to i64
%39 = select i1 %37, i32 1, i32 0
store i32 %39, i32* %11
%40 = load i32, i32* %11
%41 = call i32 @mqc_encode(i32 %40)
%42 = load i32*, i32** %6
%43 = load i32, i32* %42
%44 = or i32 %43, 8192
store i32 %44, i32* %42
br label %45
45: ; preds = %16, %5
ret void
}

LLVM IR (-O2):
define void @t1_enc_refpass_step(i32* nocapture %0, i32* nocapture %1, i32 %2, i32 %3, i32* nocapture %4) {
%6 = load i32, i32* %0
%7 = and i32 %6, 20480
%8 = icmp eq i32 %7, 4096
br i1 %8, label %9, label %28
9: ; preds = %5
%10 = load i32, i32* %1
%11 = tail call i32 @int_abs(i32 %10)
%12 = add nsw i32 %2, 6
%13 = tail call i64 @t1_getnmsedec_ref(i32 %11, i32 %12)
%14 = load i32, i32* %4
%15 = trunc i64 %13 to i32
%16 = add i32 %14, %15
store i32 %16, i32* %4
%17 = load i32, i32* %0
%18 = tail call i32 @t1_getctxno_mag(i32 %17)
%19 = tail call i32 @mqc_setcurctx(i32 %18)
%20 = load i32, i32* %1
%21 = tail call i32 @int_abs(i32 %20)
%22 = and i32 %21, %3
%23 = icmp ne i32 %22, 0
%24 = zext i1 %23 to i32
%25 = tail call i32 @mqc_encode(i32 %24)
%26 = load i32, i32* %0
%27 = or i32 %26, 8192
store i32 %27, i32* %0
br label %28
28: ; preds = %9, %5
ret void
}