#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_Off(unsigned char port) {
  int ret = 0;
  if ((port == 0x00) || (port == 0x01) || (port == 0x02)) {
    ret += _set_output_state(port, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00);
  } else if (port == 0x05) {
    ret += _set_output_state(0x01, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00);
    ret += _set_output_state(0x02, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00);
  }
  if (ret < 0) {
    fprintf(stderr, "_set_output_state Failed\n");
    return -1;
  }
  return ret;
}


x86 assembly (clang, -O0):
<NXT_Off>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dil,%al
mov    %al,-0x5(%rbp)
movl   $0x0,-0xc(%rbp)
movzbl -0x5(%rbp),%eax
cmp    $0x0,%eax
je     115c <NXT_Off+0x3c>
movzbl -0x5(%rbp),%eax
cmp    $0x1,%eax
je     115c <NXT_Off+0x3c>
movzbl -0x5(%rbp),%eax
cmp    $0x2,%eax
jne    118f <NXT_Off+0x6f>
movzbl -0x5(%rbp),%edi
xor    %r9d,%r9d
mov    $0x2,%edx
mov    %r9d,%esi
mov    %r9d,%ecx
mov    %r9d,%r8d
movl   $0x0,(%rsp)
call   1030 <_set_output_state@plt>
mov    %rax,%rcx
movslq -0xc(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0xc(%rbp)
jmp    11fc <NXT_Off+0xdc>
movzbl -0x5(%rbp),%eax
cmp    $0x5,%eax
jne    11f7 <NXT_Off+0xd7>
mov    $0x1,%edi
xor    %r9d,%r9d
mov    $0x2,%edx
mov    %r9d,%esi
mov    %r9d,%ecx
mov    %r9d,%r8d
movl   $0x0,(%rsp)
call   1030 <_set_output_state@plt>
mov    %rax,%rcx
movslq -0xc(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0xc(%rbp)
mov    $0x2,%edx
xor    %r9d,%r9d
mov    %edx,%edi
mov    %r9d,%esi
mov    %r9d,%ecx
mov    %r9d,%r8d
movl   $0x0,(%rsp)
call   1030 <_set_output_state@plt>
mov    %rax,%rcx
movslq -0xc(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0xc(%rbp)
jmp    11fc <NXT_Off+0xdc>
cmpl   $0x0,-0xc(%rbp)
jge    1227 <NXT_Off+0x107>
mov    0x2dd3(%rip),%rax
mov    (%rax),%edi
lea    0xdea(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    122d <NXT_Off+0x10d>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<NXT_Off>:
push   %rbx
sub    $0x10,%rsp
cmp    $0x2,%dil
ja     1150 <NXT_Off+0x30>
movzbl %dil,%edi
movl   $0x0,(%rsp)
xor    %esi,%esi
mov    $0x2,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   1030 <_set_output_state@plt>
test   %eax,%eax
jns    11bc <NXT_Off+0x9c>
jmp    11a2 <NXT_Off+0x82>
xor    %eax,%eax
cmp    $0x5,%dil
jne    11bc <NXT_Off+0x9c>
movl   $0x0,(%rsp)
mov    $0x1,%edi
xor    %esi,%esi
mov    $0x2,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   1030 <_set_output_state@plt>
mov    %rax,%rbx
movl   $0x0,(%rsp)
mov    $0x2,%edi
xor    %esi,%esi
mov    $0x2,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   1030 <_set_output_state@plt>
add    %rbx,%rax
test   %eax,%eax
jns    11bc <NXT_Off+0x9c>
mov    0x2e37(%rip),%rax
mov    (%rax),%edi
lea    0xe4e(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
ret

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

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