#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 */
size_t active_source_mod_index();
scalar_t__ assignment_is_active();
int /*<<< orphan*/ begin_assignment(size_t);
int /*<<< orphan*/ cancel_assignment();
int /*<<< orphan*/ set_current_knob(size_t, int);
void handle_assign(size_t module_index) {
  if (assignment_is_active()) {
    if (module_index == active_source_mod_index()) {
      set_current_knob(0xFF, 0xFF);
      cancel_assignment();
    } else {
      set_current_knob(module_index, 0xFF);
      begin_assignment(module_index);
    }
  } else {
    set_current_knob(module_index, 0xFF);
    begin_assignment(module_index);
  }
}


x86 assembly (clang, -O0):
<handle_assign>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   1060 <assignment_is_active@plt>
cmp    $0x0,%rax
je     11c3 <handle_assign+0x73>
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    $0x0,%al
call   1040 <active_source_mod_index@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
cmp    %rcx,%rax
jne    11a7 <handle_assign+0x57>
mov    $0xff,%edi
mov    $0xff,%esi
call   1050 <set_current_knob@plt>
mov    $0x0,%al
call   1030 <cancel_assignment@plt>
jmp    11be <handle_assign+0x6e>
mov    -0x8(%rbp),%rdi
mov    $0xff,%esi
call   1050 <set_current_knob@plt>
mov    -0x8(%rbp),%rdi
call   1070 <begin_assignment@plt>
jmp    11da <handle_assign+0x8a>
mov    -0x8(%rbp),%rdi
mov    $0xff,%esi
call   1050 <set_current_knob@plt>
mov    -0x8(%rbp),%rdi
call   1070 <begin_assignment@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<handle_assign>:
push   %rbx
mov    %rdi,%rbx
xor    %eax,%eax
call   1060 <assignment_is_active@plt>
test   %rax,%rax
je     1183 <handle_assign+0x33>
xor    %eax,%eax
call   1040 <active_source_mod_index@plt>
cmp    %rbx,%rax
jne    1183 <handle_assign+0x33>
mov    $0xff,%edi
mov    $0xff,%esi
call   1050 <set_current_knob@plt>
xor    %eax,%eax
pop    %rbx
jmp    1030 <cancel_assignment@plt>
mov    %rbx,%rdi
mov    $0xff,%esi
call   1050 <set_current_knob@plt>
mov    %rbx,%rdi
pop    %rbx
jmp    1070 <begin_assignment@plt>

LLVM IR (-O0):
define void @handle_assign(i64 %0) {
%2 = alloca i64
store i64 %0, i64* %2
%3 = call i64 (...) @assignment_is_active()
%4 = icmp ne i64 %3, 0
br i1 %4, label %5, label %18
5: ; preds = %1
%6 = load i64, i64* %2
%7 = call i64 (...) @active_source_mod_index()
%8 = icmp eq i64 %6, %7
br i1 %8, label %9, label %12
9: ; preds = %5
%10 = call i32 @set_current_knob(i64 255, i32 255)
%11 = call i32 (...) @cancel_assignment()
br label %17
12: ; preds = %5
%13 = load i64, i64* %2
%14 = call i32 @set_current_knob(i64 %13, i32 255)
%15 = load i64, i64* %2
%16 = call i32 @begin_assignment(i64 %15)
br label %17
17: ; preds = %12, %9
br label %23
18: ; preds = %1
%19 = load i64, i64* %2
%20 = call i32 @set_current_knob(i64 %19, i32 255)
%21 = load i64, i64* %2
%22 = call i32 @begin_assignment(i64 %21)
br label %23
23: ; preds = %18, %17
ret void
}

LLVM IR (-O2):
define void @handle_assign(i64 %0) {
%2 = tail call i64 (...) @assignment_is_active()
%3 = icmp eq i64 %2, 0
br i1 %3, label %13, label %4
4: ; preds = %1
%5 = tail call i64 (...) @active_source_mod_index()
%6 = icmp eq i64 %5, %0
br i1 %6, label %7, label %10
7: ; preds = %4
%8 = tail call i32 @set_current_knob(i64 255, i32 255)
%9 = tail call i32 (...) @cancel_assignment()
br label %16
10: ; preds = %4
%11 = tail call i32 @set_current_knob(i64 %0, i32 255)
%12 = tail call i32 @begin_assignment(i64 %0)
br label %16
13: ; preds = %1
%14 = tail call i32 @set_current_knob(i64 %0, i32 255)
%15 = tail call i32 @begin_assignment(i64 %0)
br label %16
16: ; preds = %7, %10, %13
ret void
}