#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 pru_get_reg(int /*<<< orphan*/, int);
int /*<<< orphan*/ pru_set_reg(int /*<<< orphan*/, int, int /*<<< orphan*/);
void ENC2Step(unsigned char reset_ch1, unsigned char reset_ch2,
              unsigned char reset_ch3, unsigned char reset_ch4, int *pos_ch1,
              unsigned char *dir_ch1, int *pos_ch2, unsigned char *dir_ch2,
              int *pos_ch3, unsigned char *dir_ch3, int *pos_ch4,
              unsigned char *dir_ch4) {
  static int prev_pos_ch1, prev_pos_ch2, prev_pos_ch3, prev_pos_ch4;
  if (reset_ch1 != 0) {
    pru_set_reg(0, 1, 0);
    *dir_ch1 = 0;
    *pos_ch1 = 0;
    prev_pos_ch1 = 0;
    return;
  }
  if (reset_ch2 != 0) {
    pru_set_reg(0, 2, 0);
    *dir_ch2 = 0;
    *pos_ch2 = 0;
    prev_pos_ch2 = 0;
    return;
  }
  if (reset_ch3 != 0) {
    pru_set_reg(0, 3, 0);
    *dir_ch3 = 0;
    *pos_ch3 = 0;
    prev_pos_ch3 = 0;
    return;
  }
  if (reset_ch4 != 0) {
    pru_set_reg(0, 4, 0);
    *dir_ch4 = 0;
    *pos_ch4 = 0;
    prev_pos_ch4 = 0;
    return;
  }
  *pos_ch1 = pru_get_reg(0, 1);
  if (prev_pos_ch1 < *pos_ch1) {
    *dir_ch1 = 1;
  } else if (prev_pos_ch1 > *pos_ch1) {
    *dir_ch1 = 2;
  } else
    *dir_ch1 = 0;
  *pos_ch2 = pru_get_reg(0, 2);
  if (prev_pos_ch2 < *pos_ch2) {
    *dir_ch2 = 1;
  } else if (prev_pos_ch2 > *pos_ch2) {
    *dir_ch2 = 2;
  } else
    *dir_ch2 = 0;
  *pos_ch3 = pru_get_reg(0, 3);
  if (prev_pos_ch3 < *pos_ch3) {
    *dir_ch3 = 1;
  } else if (prev_pos_ch3 > *pos_ch3) {
    *dir_ch3 = 2;
  } else
    *dir_ch3 = 0;
  *pos_ch4 = pru_get_reg(0, 4);
  if (prev_pos_ch4 < *pos_ch4) {
    *dir_ch4 = 1;
  } else if (prev_pos_ch4 > *pos_ch4) {
    *dir_ch4 = 2;
  } else
    *dir_ch4 = 0;
}


x86 assembly (clang, -O0):
<ENC2Step>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %cl,%al
mov    %dl,%cl
mov    %sil,%dl
mov    %dil,%sil
mov    0x38(%rbp),%rdi
mov    0x30(%rbp),%rdi
mov    0x28(%rbp),%rdi
mov    0x20(%rbp),%rdi
mov    0x18(%rbp),%rdi
mov    0x10(%rbp),%rdi
mov    %sil,-0x1(%rbp)
mov    %dl,-0x2(%rbp)
mov    %cl,-0x3(%rbp)
mov    %al,-0x4(%rbp)
mov    %r8,-0x10(%rbp)
mov    %r9,-0x18(%rbp)
movzbl -0x1(%rbp),%eax
cmp    $0x0,%eax
je     119a <ENC2Step+0x7a>
xor    %edx,%edx
mov    $0x1,%esi
mov    %edx,%edi
call   1040 <pru_set_reg@plt>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rax
movl   $0x0,(%rax)
movl   $0x0,0x2e9f(%rip)
jmp    13bb <ENC2Step+0x29b>
movzbl -0x2(%rbp),%eax
cmp    $0x0,%eax
je     11d5 <ENC2Step+0xb5>
xor    %edx,%edx
mov    $0x2,%esi
mov    %edx,%edi
call   1040 <pru_set_reg@plt>
mov    0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    0x10(%rbp),%rax
movl   $0x0,(%rax)
movl   $0x0,0x2e68(%rip)
jmp    13bb <ENC2Step+0x29b>
movzbl -0x3(%rbp),%eax
cmp    $0x0,%eax
je     1210 <ENC2Step+0xf0>
xor    %edx,%edx
mov    $0x3,%esi
mov    %edx,%edi
call   1040 <pru_set_reg@plt>
mov    0x28(%rbp),%rax
movb   $0x0,(%rax)
mov    0x20(%rbp),%rax
movl   $0x0,(%rax)
movl   $0x0,0x2e31(%rip)
jmp    13bb <ENC2Step+0x29b>
movzbl -0x4(%rbp),%eax
cmp    $0x0,%eax
je     124b <ENC2Step+0x12b>
xor    %edx,%edx
mov    $0x4,%esi
mov    %edx,%edi
call   1040 <pru_set_reg@plt>
mov    0x38(%rbp),%rax
movb   $0x0,(%rax)
mov    0x30(%rbp),%rax
movl   $0x0,(%rax)
movl   $0x0,0x2dfa(%rip)
jmp    13bb <ENC2Step+0x29b>
xor    %edi,%edi
mov    $0x1,%esi
call   1030 <pru_get_reg@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    0x2dcf(%rip),%eax
mov    -0x10(%rbp),%rcx
cmp    (%rcx),%eax
jge    127d <ENC2Step+0x15d>
mov    -0x18(%rbp),%rax
movb   $0x1,(%rax)
jmp    12a7 <ENC2Step+0x187>
mov    0x2db1(%rip),%eax
mov    -0x10(%rbp),%rcx
cmp    (%rcx),%eax
jle    129b <ENC2Step+0x17b>
mov    -0x18(%rbp),%rax
movb   $0x2,(%rax)
jmp    12a2 <ENC2Step+0x182>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
jmp    12a7 <ENC2Step+0x187>
xor    %edi,%edi
mov    $0x2,%esi
call   1030 <pru_get_reg@plt>
mov    %eax,%ecx
mov    0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    0x2d77(%rip),%eax
mov    0x10(%rbp),%rcx
cmp    (%rcx),%eax
jge    12d9 <ENC2Step+0x1b9>
mov    0x18(%rbp),%rax
movb   $0x1,(%rax)
jmp    1303 <ENC2Step+0x1e3>
mov    0x2d59(%rip),%eax
mov    0x10(%rbp),%rcx
cmp    (%rcx),%eax
jle    12f7 <ENC2Step+0x1d7>
mov    0x18(%rbp),%rax
movb   $0x2,(%rax)
jmp    12fe <ENC2Step+0x1de>
mov    0x18(%rbp),%rax
movb   $0x0,(%rax)
jmp    1303 <ENC2Step+0x1e3>
xor    %edi,%edi
mov    $0x3,%esi
call   1030 <pru_get_reg@plt>
mov    %eax,%ecx
mov    0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    0x2d1f(%rip),%eax
mov    0x20(%rbp),%rcx
cmp    (%rcx),%eax
jge    1335 <ENC2Step+0x215>
mov    0x28(%rbp),%rax
movb   $0x1,(%rax)
jmp    135f <ENC2Step+0x23f>
mov    0x2d01(%rip),%eax
mov    0x20(%rbp),%rcx
cmp    (%rcx),%eax
jle    1353 <ENC2Step+0x233>
mov    0x28(%rbp),%rax
movb   $0x2,(%rax)
jmp    135a <ENC2Step+0x23a>
mov    0x28(%rbp),%rax
movb   $0x0,(%rax)
jmp    135f <ENC2Step+0x23f>
xor    %edi,%edi
mov    $0x4,%esi
call   1030 <pru_get_reg@plt>
mov    %eax,%ecx
mov    0x30(%rbp),%rax
mov    %ecx,(%rax)
mov    0x2cc7(%rip),%eax
mov    0x30(%rbp),%rcx
cmp    (%rcx),%eax
jge    1391 <ENC2Step+0x271>
mov    0x38(%rbp),%rax
movb   $0x1,(%rax)
jmp    13bb <ENC2Step+0x29b>
mov    0x2ca9(%rip),%eax
mov    0x30(%rbp),%rcx
cmp    (%rcx),%eax
jle    13af <ENC2Step+0x28f>
mov    0x38(%rbp),%rax
movb   $0x2,(%rax)
jmp    13b6 <ENC2Step+0x296>
mov    0x38(%rbp),%rax
movb   $0x0,(%rax)
jmp    13bb <ENC2Step+0x29b>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ENC2Step>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9,%r14
mov    %r8,%rbx
test   %edi,%edi
je     1152 <ENC2Step+0x32>
xor    %edi,%edi
mov    $0x1,%esi
xor    %edx,%edx
call   1040 <pru_set_reg@plt>
movb   $0x0,(%r14)
movl   $0x0,(%rbx)
jmp    127d <ENC2Step+0x15d>
mov    0x48(%rsp),%r15
mov    0x40(%rsp),%r12
test   %sil,%sil
je     1180 <ENC2Step+0x60>
xor    %edi,%edi
mov    $0x2,%esi
xor    %edx,%edx
call   1040 <pru_set_reg@plt>
movb   $0x0,(%r15)
movl   $0x0,(%r12)
jmp    127d <ENC2Step+0x15d>
mov    0x58(%rsp),%r13
mov    0x50(%rsp),%rbp
test   %dl,%dl
je     11ad <ENC2Step+0x8d>
xor    %edi,%edi
mov    $0x3,%esi
xor    %edx,%edx
call   1040 <pru_set_reg@plt>
movb   $0x0,0x0(%r13)
movl   $0x0,0x0(%rbp)
jmp    127d <ENC2Step+0x15d>
mov    0x68(%rsp),%rax
mov    0x60(%rsp),%rdx
xor    %edi,%edi
test   %cl,%cl
je     11de <ENC2Step+0xbe>
mov    $0x4,%esi
mov    %rdx,%rbp
xor    %edx,%edx
mov    %rax,%rbx
call   1040 <pru_set_reg@plt>
movb   $0x0,(%rbx)
movl   $0x0,0x0(%rbp)
jmp    127d <ENC2Step+0x15d>
mov    $0x1,%esi
call   1030 <pru_get_reg@plt>
mov    %eax,(%rbx)
mov    %eax,%ecx
shr    $0x1e,%ecx
and    $0x2,%cl
test   %eax,%eax
movzbl %cl,%eax
mov    $0x1,%ebx
cmovg  %ebx,%eax
mov    %al,(%r14)
xor    %edi,%edi
mov    $0x2,%esi
call   1030 <pru_get_reg@plt>
mov    %eax,(%r12)
mov    %eax,%ecx
shr    $0x1e,%ecx
and    $0x2,%cl
test   %eax,%eax
movzbl %cl,%eax
cmovg  %ebx,%eax
mov    $0x1,%ebx
mov    %al,(%r15)
xor    %edi,%edi
mov    $0x3,%esi
call   1030 <pru_get_reg@plt>
mov    %eax,0x0(%rbp)
mov    %eax,%ecx
shr    $0x1e,%ecx
and    $0x2,%cl
test   %eax,%eax
movzbl %cl,%eax
cmovg  %ebx,%eax
mov    %al,0x0(%r13)
xor    %edi,%edi
mov    $0x4,%esi
call   1030 <pru_get_reg@plt>
mov    0x60(%rsp),%rcx
mov    %eax,(%rcx)
test   %eax,%eax
jle    126e <ENC2Step+0x14e>
mov    0x68(%rsp),%rax
movb   $0x1,(%rax)
jmp    127d <ENC2Step+0x15d>
mov    0x68(%rsp),%rax
js     127a <ENC2Step+0x15a>
movb   $0x0,(%rax)
jmp    127d <ENC2Step+0x15d>
movb   $0x2,(%rax)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@ENC2Step.prev_pos_ch1 = internal global i32 0
@ENC2Step.prev_pos_ch2 = internal global i32 0
@ENC2Step.prev_pos_ch3 = internal global i32 0
@ENC2Step.prev_pos_ch4 = internal global i32 0
define void @ENC2Step(i8 zeroext %0, i8 zeroext %1, i8 zeroext %2, i8 zeroext %3, i32* %4, i8* %5, i32* %6, i8* %7, i32* %8, i8* %9, i32* %10, i8* %11) {
%13 = alloca i8
%14 = alloca i8
%15 = alloca i8
%16 = alloca i8
%17 = alloca i32*
%18 = alloca i8*
%19 = alloca i32*
%20 = alloca i8*
%21 = alloca i32*
%22 = alloca i8*
%23 = alloca i32*
%24 = alloca i8*
store i8 %0, i8* %13
store i8 %1, i8* %14
store i8 %2, i8* %15
store i8 %3, i8* %16
store i32* %4, i32** %17
store i8* %5, i8** %18
store i32* %6, i32** %19
store i8* %7, i8** %20
store i32* %8, i32** %21
store i8* %9, i8** %22
store i32* %10, i32** %23
store i8* %11, i8** %24
%25 = load i8, i8* %13
%26 = zext i8 %25 to i32
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %32
28: ; preds = %12
%29 = call i32 @pru_set_reg(i32 0, i32 1, i32 0)
%30 = load i8*, i8** %18
store i8 0, i8* %30
%31 = load i32*, i32** %17
store i32 0, i32* %31
store i32 0, i32* @ENC2Step.prev_pos_ch1
br label %132
32: ; preds = %12
%33 = load i8, i8* %14
%34 = zext i8 %33 to i32
%35 = icmp ne i32 %34, 0
br i1 %35, label %36, label %40
36: ; preds = %32
%37 = call i32 @pru_set_reg(i32 0, i32 2, i32 0)
%38 = load i8*, i8** %20
store i8 0, i8* %38
%39 = load i32*, i32** %19
store i32 0, i32* %39
store i32 0, i32* @ENC2Step.prev_pos_ch2
br label %132
40: ; preds = %32
%41 = load i8, i8* %15
%42 = zext i8 %41 to i32
%43 = icmp ne i32 %42, 0
br i1 %43, label %44, label %48
44: ; preds = %40
%45 = call i32 @pru_set_reg(i32 0, i32 3, i32 0)
%46 = load i8*, i8** %22
store i8 0, i8* %46
%47 = load i32*, i32** %21
store i32 0, i32* %47
store i32 0, i32* @ENC2Step.prev_pos_ch3
br label %132
48: ; preds = %40
%49 = load i8, i8* %16
%50 = zext i8 %49 to i32
%51 = icmp ne i32 %50, 0
br i1 %51, label %52, label %56
52: ; preds = %48
%53 = call i32 @pru_set_reg(i32 0, i32 4, i32 0)
%54 = load i8*, i8** %24
store i8 0, i8* %54
%55 = load i32*, i32** %23
store i32 0, i32* %55
store i32 0, i32* @ENC2Step.prev_pos_ch4
br label %132
56: ; preds = %48
%57 = call i32 @pru_get_reg(i32 0, i32 1)
%58 = load i32*, i32** %17
store i32 %57, i32* %58
%59 = load i32, i32* @ENC2Step.prev_pos_ch1
%60 = load i32*, i32** %17
%61 = load i32, i32* %60
%62 = icmp slt i32 %59, %61
br i1 %62, label %63, label %65
63: ; preds = %56
%64 = load i8*, i8** %18
store i8 1, i8* %64
br label %75
65: ; preds = %56
%66 = load i32, i32* @ENC2Step.prev_pos_ch1
%67 = load i32*, i32** %17
%68 = load i32, i32* %67
%69 = icmp sgt i32 %66, %68
br i1 %69, label %70, label %72
70: ; preds = %65
%71 = load i8*, i8** %18
store i8 2, i8* %71
br label %74
72: ; preds = %65
%73 = load i8*, i8** %18
store i8 0, i8* %73
br label %74
74: ; preds = %72, %70
br label %75
75: ; preds = %74, %63
%76 = call i32 @pru_get_reg(i32 0, i32 2)
%77 = load i32*, i32** %19
store i32 %76, i32* %77
%78 = load i32, i32* @ENC2Step.prev_pos_ch2
%79 = load i32*, i32** %19
%80 = load i32, i32* %79
%81 = icmp slt i32 %78, %80
br i1 %81, label %82, label %84
82: ; preds = %75
%83 = load i8*, i8** %20
store i8 1, i8* %83
br label %94
84: ; preds = %75
%85 = load i32, i32* @ENC2Step.prev_pos_ch2
%86 = load i32*, i32** %19
%87 = load i32, i32* %86
%88 = icmp sgt i32 %85, %87
br i1 %88, label %89, label %91
89: ; preds = %84
%90 = load i8*, i8** %20
store i8 2, i8* %90
br label %93
91: ; preds = %84
%92 = load i8*, i8** %20
store i8 0, i8* %92
br label %93
93: ; preds = %91, %89
br label %94
94: ; preds = %93, %82
%95 = call i32 @pru_get_reg(i32 0, i32 3)
%96 = load i32*, i32** %21
store i32 %95, i32* %96
%97 = load i32, i32* @ENC2Step.prev_pos_ch3
%98 = load i32*, i32** %21
%99 = load i32, i32* %98
%100 = icmp slt i32 %97, %99
br i1 %100, label %101, label %103
101: ; preds = %94
%102 = load i8*, i8** %22
store i8 1, i8* %102
br label %113
103: ; preds = %94
%104 = load i32, i32* @ENC2Step.prev_pos_ch3
%105 = load i32*, i32** %21
%106 = load i32, i32* %105
%107 = icmp sgt i32 %104, %106
br i1 %107, label %108, label %110
108: ; preds = %103
%109 = load i8*, i8** %22
store i8 2, i8* %109
br label %112
110: ; preds = %103
%111 = load i8*, i8** %22
store i8 0, i8* %111
br label %112
112: ; preds = %110, %108
br label %113
113: ; preds = %112, %101
%114 = call i32 @pru_get_reg(i32 0, i32 4)
%115 = load i32*, i32** %23
store i32 %114, i32* %115
%116 = load i32, i32* @ENC2Step.prev_pos_ch4
%117 = load i32*, i32** %23
%118 = load i32, i32* %117
%119 = icmp slt i32 %116, %118
br i1 %119, label %120, label %122
120: ; preds = %113
%121 = load i8*, i8** %24
store i8 1, i8* %121
br label %132
122: ; preds = %113
%123 = load i32, i32* @ENC2Step.prev_pos_ch4
%124 = load i32*, i32** %23
%125 = load i32, i32* %124
%126 = icmp sgt i32 %123, %125
br i1 %126, label %127, label %129
127: ; preds = %122
%128 = load i8*, i8** %24
store i8 2, i8* %128
br label %131
129: ; preds = %122
%130 = load i8*, i8** %24
store i8 0, i8* %130
br label %131
131: ; preds = %129, %127
br label %132
132: ; preds = %28, %36, %44, %52, %131, %120
ret void
}

LLVM IR (-O2):
define void @ENC2Step(i8 zeroext %0, i8 zeroext %1, i8 zeroext %2, i8 zeroext %3, i32* nocapture writeonly %4, i8* nocapture writeonly %5, i32* nocapture writeonly %6, i8* nocapture writeonly %7, i32* nocapture writeonly %8, i8* nocapture writeonly %9, i32* nocapture writeonly %10, i8* nocapture writeonly %11) {
%13 = icmp eq i8 %0, 0
br i1 %13, label %16, label %14
14: ; preds = %12
%15 = tail call i32 @pru_set_reg(i32 0, i32 1, i32 0)
store i8 0, i8* %5
store i32 0, i32* %4
br label %54
16: ; preds = %12
%17 = icmp eq i8 %1, 0
br i1 %17, label %20, label %18
18: ; preds = %16
%19 = tail call i32 @pru_set_reg(i32 0, i32 2, i32 0)
store i8 0, i8* %7
store i32 0, i32* %6
br label %54
20: ; preds = %16
%21 = icmp eq i8 %2, 0
br i1 %21, label %24, label %22
22: ; preds = %20
%23 = tail call i32 @pru_set_reg(i32 0, i32 3, i32 0)
store i8 0, i8* %9
store i32 0, i32* %8
br label %54
24: ; preds = %20
%25 = icmp eq i8 %3, 0
br i1 %25, label %28, label %26
26: ; preds = %24
%27 = tail call i32 @pru_set_reg(i32 0, i32 4, i32 0)
store i8 0, i8* %11
store i32 0, i32* %10
br label %54
28: ; preds = %24
%29 = tail call i32 @pru_get_reg(i32 0, i32 1)
store i32 %29, i32* %4
%30 = icmp sgt i32 %29, 0
%31 = lshr i32 %29, 30
%32 = trunc i32 %31 to i8
%33 = and i8 %32, 2
%34 = select i1 %30, i8 1, i8 %33
store i8 %34, i8* %5
%35 = tail call i32 @pru_get_reg(i32 0, i32 2)
store i32 %35, i32* %6
%36 = icmp sgt i32 %35, 0
%37 = lshr i32 %35, 30
%38 = trunc i32 %37 to i8
%39 = and i8 %38, 2
%40 = select i1 %36, i8 1, i8 %39
store i8 %40, i8* %7
%41 = tail call i32 @pru_get_reg(i32 0, i32 3)
store i32 %41, i32* %8
%42 = icmp sgt i32 %41, 0
%43 = lshr i32 %41, 30
%44 = trunc i32 %43 to i8
%45 = and i8 %44, 2
%46 = select i1 %42, i8 1, i8 %45
store i8 %46, i8* %9
%47 = tail call i32 @pru_get_reg(i32 0, i32 4)
store i32 %47, i32* %10
%48 = icmp sgt i32 %47, 0
br i1 %48, label %49, label %50
49: ; preds = %28
store i8 1, i8* %11
br label %54
50: ; preds = %28
%51 = icmp slt i32 %47, 0
br i1 %51, label %52, label %53
52: ; preds = %50
store i8 2, i8* %11
br label %54
53: ; preds = %50
store i8 0, i8* %11
br label %54
54: ; preds = %52, %53, %14, %18, %22, %26, %49
ret void
}