#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 get_iterator_step(int, int, int, int);
int /*<<< orphan*/ perform_command(int, int);
void loop_chpids(int css1, int id1, int css2, int id2) {
  int step = get_iterator_step(css1, id1, css2, id2);
  while (1) {
    perform_command(css1, id1);
    if ((css1 == css2) && (id1 == id2))
      break;
    id1 = id1 + step;
    if (id1 < 0) {
      css1 -= 1;
      id1 = 255;
    } else if (id2 > 255) {
      css1 += 1;
      id1 = 0;
    }
  }
}


x86 assembly (clang, -O0):
<loop_chpids>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %ecx,-0x10(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
mov    -0x10(%rbp),%ecx
call   1030 <get_iterator_step@plt>
mov    %eax,-0x14(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1040 <perform_command@plt>
mov    -0x4(%rbp),%eax
cmp    -0xc(%rbp),%eax
jne    1170 <loop_chpids+0x50>
mov    -0x8(%rbp),%eax
cmp    -0x10(%rbp),%eax
jne    1170 <loop_chpids+0x50>
jmp    11bf <loop_chpids+0x9f>
mov    -0x8(%rbp),%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    1198 <loop_chpids+0x78>
mov    -0x4(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x4(%rbp)
movl   $0xff,-0x8(%rbp)
jmp    11ba <loop_chpids+0x9a>
cmpl   $0xff,-0x10(%rbp)
jle    11b5 <loop_chpids+0x95>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
jmp    11ba <loop_chpids+0x9a>
jmp    1148 <loop_chpids+0x28>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<loop_chpids>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%r15d
mov    %esi,%ebx
mov    %edi,%ebp
mov    %edx,0x4(%rsp)
call   1030 <get_iterator_step@plt>
mov    %eax,%r12d
mov    %ebp,%edi
mov    %ebx,%esi
call   1040 <perform_command@plt>
cmp    %r15d,%ebx
jne    1152 <loop_chpids+0x32>
cmp    0x4(%rsp),%ebp
je     11ad <loop_chpids+0x8d>
xor    %r13d,%r13d
cmp    $0x100,%r15d
setge  %r13b
mov    $0xffffffff,%r14d
cs nopw 0x0(%rax,%rax,1)
add    %r12d,%ebx
cmp    $0x100,%r15d
mov    %ebx,%eax
mov    $0x0,%ecx
cmovge %ecx,%eax
test   %ebx,%ebx
mov    %eax,%ebx
mov    $0xff,%eax
cmovs  %eax,%ebx
mov    %r13d,%eax
cmovs  %r14d,%eax
add    %eax,%ebp
mov    %ebp,%edi
mov    %ebx,%esi
call   1040 <perform_command@plt>
cmp    %r15d,%ebx
jne    1170 <loop_chpids+0x50>
cmp    0x4(%rsp),%ebp
jne    1170 <loop_chpids+0x50>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @loop_chpids(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%10 = load i32, i32* %5
%11 = load i32, i32* %6
%12 = load i32, i32* %7
%13 = load i32, i32* %8
%14 = call i32 @get_iterator_step(i32 %10, i32 %11, i32 %12, i32 %13)
store i32 %14, i32* %9
br label %15
15: ; preds = %4, %43
%16 = load i32, i32* %5
%17 = load i32, i32* %6
%18 = call i32 @perform_command(i32 %16, i32 %17)
%19 = load i32, i32* %5
%20 = load i32, i32* %7
%21 = icmp eq i32 %19, %20
br i1 %21, label %22, label %27
22: ; preds = %15
%23 = load i32, i32* %6
%24 = load i32, i32* %8
%25 = icmp eq i32 %23, %24
br i1 %25, label %26, label %27
26: ; preds = %22
br label %44
27: ; preds = %22, %15
%28 = load i32, i32* %6
%29 = load i32, i32* %9
%30 = add nsw i32 %28, %29
store i32 %30, i32* %6
%31 = load i32, i32* %6
%32 = icmp slt i32 %31, 0
br i1 %32, label %33, label %36
33: ; preds = %27
%34 = load i32, i32* %5
%35 = sub nsw i32 %34, 1
store i32 %35, i32* %5
store i32 255, i32* %6
br label %43
36: ; preds = %27
%37 = load i32, i32* %8
%38 = icmp sgt i32 %37, 255
br i1 %38, label %39, label %42
39: ; preds = %36
%40 = load i32, i32* %5
%41 = add nsw i32 %40, 1
store i32 %41, i32* %5
store i32 0, i32* %6
br label %42
42: ; preds = %39, %36
br label %43
43: ; preds = %42, %33
br label %15
44: ; preds = %26
ret void
}

LLVM IR (-O2):
define void @loop_chpids(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = tail call i32 @get_iterator_step(i32 %0, i32 %1, i32 %2, i32 %3)
%6 = tail call i32 @perform_command(i32 %0, i32 %1)
%7 = icmp eq i32 %0, %2
%8 = icmp eq i32 %1, %3
%9 = and i1 %8, %7
br i1 %9, label %26, label %10
10: ; preds = %4
%11 = icmp sgt i32 %3, 255
%12 = zext i1 %11 to i32
br label %13
13: ; preds = %10, %13
%14 = phi i32 [ %0, %10 ], [ %21, %13 ]
%15 = phi i32 [ %1, %10 ], [ %19, %13 ]
%16 = add nsw i32 %15, %5
%17 = icmp slt i32 %16, 0
%18 = select i1 %11, i32 0, i32 %16
%19 = select i1 %17, i32 255, i32 %18
%20 = select i1 %17, i32 -1, i32 %12
%21 = add nsw i32 %14, %20
%22 = tail call i32 @perform_command(i32 %21, i32 %19)
%23 = icmp eq i32 %21, %2
%24 = icmp eq i32 %19, %3
%25 = and i1 %24, %23
br i1 %25, label %26, label %13
26: ; preds = %13, %4
ret void
}