#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 /*<<< orphan*/ drv_generic_serial_write(char *, int);
int drv_BuE_CT_gpo(int num, int val) {
  static int GPO[8] = {-1, -1, -1, -1, -1, -1, -1, -1};
  char cmd[4] = "\033"
                "Pnx";
  if (num < 0)
    num = 0;
  if (num > 7)
    num = 7;
  if (val == -1)
    return GPO[num];
  if (val < 0)
    val = 0;
  if (val > 255)
    val = 255;
  GPO[num] = val;
  cmd[2] = (char)num;
  cmd[3] = (char)val;
  drv_generic_serial_write(cmd, 4);
  return GPO[num];
}


x86 assembly (clang, -O0):
<drv_BuE_CT_gpo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    0xedc(%rip),%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    1138 <drv_BuE_CT_gpo+0x28>
movl   $0x0,-0x8(%rbp)
cmpl   $0x7,-0x8(%rbp)
jle    1149 <drv_BuE_CT_gpo+0x39>
movl   $0x7,-0x8(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    1169 <drv_BuE_CT_gpo+0x59>
movslq -0x8(%rbp),%rcx
lea    0x2ed2(%rip),%rax
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x4(%rbp)
jmp    11ca <drv_BuE_CT_gpo+0xba>
cmpl   $0x0,-0xc(%rbp)
jge    117a <drv_BuE_CT_gpo+0x6a>
movl   $0x0,-0xc(%rbp)
cmpl   $0xff,-0xc(%rbp)
jle    118e <drv_BuE_CT_gpo+0x7e>
movl   $0xff,-0xc(%rbp)
mov    -0xc(%rbp),%edx
movslq -0x8(%rbp),%rcx
lea    0x2e94(%rip),%rax
mov    %edx,(%rax,%rcx,4)
mov    -0x8(%rbp),%eax
mov    %al,-0xe(%rbp)
mov    -0xc(%rbp),%eax
mov    %al,-0xd(%rbp)
lea    -0x10(%rbp),%rdi
mov    $0x4,%esi
call   1030 <drv_generic_serial_write@plt>
movslq -0x8(%rbp),%rcx
lea    0x2e6c(%rip),%rax
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<drv_BuE_CT_gpo>:
push   %rbx
sub    $0x10,%rsp
movl   $0x786e501b,0xc(%rsp)
78
xor    %ecx,%ecx
test   %edi,%edi
cmovs  %ecx,%edi
cmp    $0x7,%edi
mov    $0x7,%eax
cmovb  %edi,%eax
cmp    $0xffffffff,%esi
je     1170 <drv_BuE_CT_gpo+0x60>
test   %esi,%esi
cmovns %esi,%ecx
cmp    $0xff,%ecx
mov    $0xff,%edx
cmovb  %ecx,%edx
mov    %eax,%ecx
lea    0x2ee0(%rip),%rsi
lea    (%rsi,%rcx,4),%rbx
mov    %edx,(%rsi,%rcx,4)
mov    %al,0xe(%rsp)
mov    %dl,0xf(%rsp)
lea    0xc(%rsp),%rdi
mov    $0x4,%esi
call   1030 <drv_generic_serial_write@plt>
jmp    117d <drv_BuE_CT_gpo+0x6d>
mov    %eax,%eax
lea    0x2eb7(%rip),%rcx
lea    (%rcx,%rax,4),%rbx
mov    (%rbx),%eax
add    $0x10,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
@drv_BuE_CT_gpo.GPO = internal unnamed_addr global [8 x i32] [i32 -1, i32 -1, i32 -1, i32 -1, i32 -1, i32 -1, i32 -1, i32 -1]
define i32 @drv_BuE_CT_gpo(i32 %0, i32 %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to [4 x i8]*
%5 = bitcast i32* %3 to i8*
store i32 2020495387, i32* %3
%6 = icmp sgt i32 %0, 0
%7 = select i1 %6, i32 %0, i32 0
%8 = icmp ult i32 %7, 7
%9 = select i1 %8, i32 %7, i32 7
%10 = icmp eq i32 %1, -1
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = zext i32 %9 to i64
%13 = getelementptr inbounds [8 x i32], [8 x i32]* @drv_BuE_CT_gpo.GPO, i64 0, i64 %12
br label %26
14: ; preds = %2
%15 = icmp sgt i32 %1, 0
%16 = select i1 %15, i32 %1, i32 0
%17 = icmp ult i32 %16, 255
%18 = select i1 %17, i32 %16, i32 255
%19 = zext i32 %9 to i64
%20 = getelementptr inbounds [8 x i32], [8 x i32]* @drv_BuE_CT_gpo.GPO, i64 0, i64 %19
store i32 %18, i32* %20
%21 = trunc i32 %9 to i8
%22 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 2
store i8 %21, i8* %22
%23 = trunc i32 %18 to i8
%24 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 3
store i8 %23, i8* %24
%25 = call i32 @drv_generic_serial_write(i8* %5, i32 4)
br label %26
26: ; preds = %14, %11
%27 = phi i32* [ %13, %11 ], [ %20, %14 ]
%28 = load i32, i32* %27
ret i32 %28
}