#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 eqep_get(unsigned char);
int /*<<< orphan*/ eqep_init(unsigned char);
void ENCStep(unsigned char Channel, int *position, unsigned char *dir,
             unsigned char reset) {
  static int pos_prev;
  if (reset != 0) {
    eqep_init(Channel);
    *dir = 0;
    *position = 0;
    pos_prev = 0;
    return;
  }
  *position = eqep_get(Channel);
  if (pos_prev < *position) {
    *dir = 1;
  } else if (pos_prev > *position) {
    *dir = 2;
  } else
    *dir = 0;
  pos_prev = *position;
}


x86 assembly (clang, -O0):
<ENCStep>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %cl,%al
mov    %dil,%cl
mov    %cl,-0x1(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %al,-0x19(%rbp)
movzbl -0x19(%rbp),%eax
cmp    $0x0,%eax
je     1171 <ENCStep+0x51>
movzbl -0x1(%rbp),%edi
call   1030 <eqep_init@plt>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rax
movl   $0x0,(%rax)
movl   $0x0,0x2ec8(%rip)
jmp    11d6 <ENCStep+0xb6>
movzbl -0x1(%rbp),%edi
call   1040 <eqep_get@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    0x2eac(%rip),%eax
mov    -0x10(%rbp),%rcx
cmp    (%rcx),%eax
jge    11a0 <ENCStep+0x80>
mov    -0x18(%rbp),%rax
movb   $0x1,(%rax)
jmp    11ca <ENCStep+0xaa>
mov    0x2e8e(%rip),%eax
mov    -0x10(%rbp),%rcx
cmp    (%rcx),%eax
jle    11be <ENCStep+0x9e>
mov    -0x18(%rbp),%rax
movb   $0x2,(%rax)
jmp    11c5 <ENCStep+0xa5>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
jmp    11ca <ENCStep+0xaa>
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,0x2e5e(%rip)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ENCStep>:
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%rbx
movzbl %dil,%edi
test   %ecx,%ecx
je     1145 <ENCStep+0x25>
call   1030 <eqep_init@plt>
movb   $0x0,(%r14)
movl   $0x0,(%rbx)
xor    %eax,%eax
jmp    116b <ENCStep+0x4b>
call   1040 <eqep_get@plt>
mov    %eax,(%rbx)
mov    0x2ee2(%rip),%ecx
cmp    %eax,%ecx
setg   %dl
add    %dl,%dl
cmp    %eax,%ecx
movzbl %dl,%eax
mov    $0x1,%ecx
cmovge %eax,%ecx
mov    %cl,(%r14)
mov    (%rbx),%eax
mov    %eax,0x2ec3(%rip)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@ENCStep.pos_prev = internal global i32 0
define void @ENCStep(i8 zeroext %0, i32* %1, i8* %2, i8 zeroext %3) {
%5 = alloca i8
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i8
store i8 %0, i8* %5
store i32* %1, i32** %6
store i8* %2, i8** %7
store i8 %3, i8* %8
%9 = load i8, i8* %8
%10 = zext i8 %9 to i32
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %17
12: ; preds = %4
%13 = load i8, i8* %5
%14 = call i32 @eqep_init(i8 zeroext %13)
%15 = load i8*, i8** %7
store i8 0, i8* %15
%16 = load i32*, i32** %6
store i32 0, i32* %16
store i32 0, i32* @ENCStep.pos_prev
br label %40
17: ; preds = %4
%18 = load i8, i8* %5
%19 = call i32 @eqep_get(i8 zeroext %18)
%20 = load i32*, i32** %6
store i32 %19, i32* %20
%21 = load i32, i32* @ENCStep.pos_prev
%22 = load i32*, i32** %6
%23 = load i32, i32* %22
%24 = icmp slt i32 %21, %23
br i1 %24, label %25, label %27
25: ; preds = %17
%26 = load i8*, i8** %7
store i8 1, i8* %26
br label %37
27: ; preds = %17
%28 = load i32, i32* @ENCStep.pos_prev
%29 = load i32*, i32** %6
%30 = load i32, i32* %29
%31 = icmp sgt i32 %28, %30
br i1 %31, label %32, label %34
32: ; preds = %27
%33 = load i8*, i8** %7
store i8 2, i8* %33
br label %36
34: ; preds = %27
%35 = load i8*, i8** %7
store i8 0, i8* %35
br label %36
36: ; preds = %34, %32
br label %37
37: ; preds = %36, %25
%38 = load i32*, i32** %6
%39 = load i32, i32* %38
store i32 %39, i32* @ENCStep.pos_prev
br label %40
40: ; preds = %37, %12
ret void
}

LLVM IR (-O2):
@ENCStep.pos_prev = internal unnamed_addr global i32 0
define void @ENCStep(i8 zeroext %0, i32* nocapture %1, i8* nocapture writeonly %2, i8 zeroext %3) {
%5 = icmp eq i8 %3, 0
br i1 %5, label %8, label %6
6: ; preds = %4
%7 = tail call i32 @eqep_init(i8 zeroext %0)
store i8 0, i8* %2
store i32 0, i32* %1
br label %16
8: ; preds = %4
%9 = tail call i32 @eqep_get(i8 zeroext %0)
store i32 %9, i32* %1
%10 = load i32, i32* @ENCStep.pos_prev
%11 = icmp slt i32 %10, %9
%12 = icmp sgt i32 %10, %9
%13 = select i1 %12, i8 2, i8 0
%14 = select i1 %11, i8 1, i8 %13
store i8 %14, i8* %2
%15 = load i32, i32* %1
br label %16
16: ; preds = %8, %6
%17 = phi i32 [ %15, %8 ], [ 0, %6 ]
store i32 %17, i32* @ENCStep.pos_prev
ret void
}