#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 */
scalar_t__ _set_output_state(int, int, int, int, int, int, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
int NXT_OnFwd(unsigned char port, int power) {
  int ret = 0;
  if ((port == 0x00) || (port == 0x01) || (port == 0x02)) {
    ret += _set_output_state(port, ((power & 0xF0) + (power & 0x0F)), 0x07,
                             0x00, 0x00, 0x20, 0x00);
  } else if (port == 0x05) {
    ret += _set_output_state(0x01, ((power & 0xF0) + (power & 0x0F)), 0x07,
                             0x00, 0x00, 0x20, 0x00);
    ret += _set_output_state(0x02, ((power & 0xF0) + (power & 0x0F)), 0x07,
                             0x00, 0x00, 0x20, 0x00);
  }
  if (ret < 0) {
    fprintf(stderr, "_set_output_state Failed\n");
    return -1;
  }
  return ret;
}


x86 assembly (clang, -O0):
<NXT_OnFwd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dil,%al
mov    %al,-0x5(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movzbl -0x5(%rbp),%eax
cmp    $0x0,%eax
je     115f <NXT_OnFwd+0x3f>
movzbl -0x5(%rbp),%eax
cmp    $0x1,%eax
je     115f <NXT_OnFwd+0x3f>
movzbl -0x5(%rbp),%eax
cmp    $0x2,%eax
jne    11a3 <NXT_OnFwd+0x83>
movzbl -0x5(%rbp),%edi
mov    -0xc(%rbp),%esi
and    $0xf0,%esi
mov    -0xc(%rbp),%eax
and    $0xf,%eax
add    %eax,%esi
mov    $0x7,%edx
xor    %r8d,%r8d
mov    $0x20,%r9d
mov    %r8d,%ecx
movl   $0x0,(%rsp)
call   1030 <_set_output_state@plt>
mov    %rax,%rcx
movslq -0x10(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x10(%rbp)
jmp    1235 <NXT_OnFwd+0x115>
movzbl -0x5(%rbp),%eax
cmp    $0x5,%eax
jne    1230 <NXT_OnFwd+0x110>
mov    -0xc(%rbp),%esi
and    $0xf0,%esi
mov    -0xc(%rbp),%eax
and    $0xf,%eax
add    %eax,%esi
mov    $0x1,%edi
mov    $0x7,%edx
xor    %r8d,%r8d
mov    $0x20,%r9d
mov    %r8d,%ecx
movl   $0x0,(%rsp)
call   1030 <_set_output_state@plt>
mov    %rax,%rcx
movslq -0x10(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%esi
and    $0xf0,%esi
mov    -0xc(%rbp),%eax
and    $0xf,%eax
add    %eax,%esi
mov    $0x2,%edi
mov    $0x7,%edx
xor    %r8d,%r8d
mov    $0x20,%r9d
mov    %r8d,%ecx
movl   $0x0,(%rsp)
call   1030 <_set_output_state@plt>
mov    %rax,%rcx
movslq -0x10(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x10(%rbp)
jmp    1235 <NXT_OnFwd+0x115>
cmpl   $0x0,-0x10(%rbp)
jge    1260 <NXT_OnFwd+0x140>
mov    0x2d9a(%rip),%rax
mov    (%rax),%edi
lea    0xdb1(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1266 <NXT_OnFwd+0x146>
mov    -0x10(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<NXT_OnFwd>:
push   %r14
push   %rbx
push   %rax
cmp    $0x2,%dil
ja     1154 <NXT_OnFwd+0x34>
movzbl %dil,%edi
movzbl %sil,%esi
movl   $0x0,(%rsp)
mov    $0x7,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
mov    $0x20,%r9d
call   1030 <_set_output_state@plt>
test   %eax,%eax
jns    11ca <NXT_OnFwd+0xaa>
jmp    11b0 <NXT_OnFwd+0x90>
xor    %eax,%eax
cmp    $0x5,%dil
jne    11ca <NXT_OnFwd+0xaa>
movzbl %sil,%ebx
movl   $0x0,(%rsp)
mov    $0x1,%edi
mov    %ebx,%esi
mov    $0x7,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
mov    $0x20,%r9d
call   1030 <_set_output_state@plt>
mov    %rax,%r14
movl   $0x0,(%rsp)
mov    $0x2,%edi
mov    %ebx,%esi
mov    $0x7,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
mov    $0x20,%r9d
call   1030 <_set_output_state@plt>
add    %r14,%rax
test   %eax,%eax
jns    11ca <NXT_OnFwd+0xaa>
mov    0x2e29(%rip),%rax
mov    (%rax),%edi
lea    0xe40(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [26 x i8] c"_set_output_state Failed\0A\00"
define i32 @NXT_OnFwd(i8 zeroext %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8
%5 = alloca i32
%6 = alloca i32
store i8 %0, i8* %4
store i32 %1, i32* %5
store i32 0, i32* %6
%7 = load i8, i8* %4
%8 = zext i8 %7 to i32
%9 = icmp eq i32 %8, 0
br i1 %9, label %18, label %10
10: ; preds = %2
%11 = load i8, i8* %4
%12 = zext i8 %11 to i32
%13 = icmp eq i32 %12, 1
br i1 %13, label %18, label %14
14: ; preds = %10
%15 = load i8, i8* %4
%16 = zext i8 %15 to i32
%17 = icmp eq i32 %16, 2
br i1 %17, label %18, label %31
18: ; preds = %14, %10, %2
%19 = load i8, i8* %4
%20 = zext i8 %19 to i32
%21 = load i32, i32* %5
%22 = and i32 %21, 240
%23 = load i32, i32* %5
%24 = and i32 %23, 15
%25 = add nsw i32 %22, %24
%26 = call i64 @_set_output_state(i32 %20, i32 %25, i32 7, i32 0, i32 0, i32 32, i32 0)
%27 = load i32, i32* %6
%28 = sext i32 %27 to i64
%29 = add nsw i64 %28, %26
%30 = trunc i64 %29 to i32
store i32 %30, i32* %6
br label %57
31: ; preds = %14
%32 = load i8, i8* %4
%33 = zext i8 %32 to i32
%34 = icmp eq i32 %33, 5
br i1 %34, label %35, label %56
35: ; preds = %31
%36 = load i32, i32* %5
%37 = and i32 %36, 240
%38 = load i32, i32* %5
%39 = and i32 %38, 15
%40 = add nsw i32 %37, %39
%41 = call i64 @_set_output_state(i32 1, i32 %40, i32 7, i32 0, i32 0, i32 32, i32 0)
%42 = load i32, i32* %6
%43 = sext i32 %42 to i64
%44 = add nsw i64 %43, %41
%45 = trunc i64 %44 to i32
store i32 %45, i32* %6
%46 = load i32, i32* %5
%47 = and i32 %46, 240
%48 = load i32, i32* %5
%49 = and i32 %48, 15
%50 = add nsw i32 %47, %49
%51 = call i64 @_set_output_state(i32 2, i32 %50, i32 7, i32 0, i32 0, i32 32, i32 0)
%52 = load i32, i32* %6
%53 = sext i32 %52 to i64
%54 = add nsw i64 %53, %51
%55 = trunc i64 %54 to i32
store i32 %55, i32* %6
br label %56
56: ; preds = %35, %31
br label %57
57: ; preds = %56, %18
%58 = load i32, i32* %6
%59 = icmp slt i32 %58, 0
br i1 %59, label %60, label %63
60: ; preds = %57
%61 = load i32, i32* @stderr
%62 = call i32 @fprintf(i32 %61, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %65
63: ; preds = %57
%64 = load i32, i32* %6
store i32 %64, i32* %3
br label %65
65: ; preds = %63, %60
%66 = load i32, i32* %3
ret i32 %66
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [26 x i8] c"_set_output_state Failed\0A\00"
define i32 @NXT_OnFwd(i8 zeroext %0, i32 %1) {
%3 = icmp ult i8 %0, 3
br i1 %3, label %4, label %8
4: ; preds = %2
%5 = zext i8 %0 to i32
%6 = and i32 %1, 255
%7 = tail call i64 @_set_output_state(i32 %5, i32 %6, i32 7, i32 0, i32 0, i32 32, i32 0)
br label %15
8: ; preds = %2
%9 = icmp eq i8 %0, 5
br i1 %9, label %10, label %22
10: ; preds = %8
%11 = and i32 %1, 255
%12 = tail call i64 @_set_output_state(i32 1, i32 %11, i32 7, i32 0, i32 0, i32 32, i32 0)
%13 = tail call i64 @_set_output_state(i32 2, i32 %11, i32 7, i32 0, i32 0, i32 32, i32 0)
%14 = add i64 %13, %12
br label %15
15: ; preds = %10, %4
%16 = phi i64 [ %7, %4 ], [ %14, %10 ]
%17 = trunc i64 %16 to i32
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %15
%20 = load i32, i32* @stderr
%21 = tail call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %22
22: ; preds = %8, %15, %19
%23 = phi i32 [ -1, %19 ], [ %17, %15 ], [ 0, %8 ]
ret i32 %23
}