#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_pwm(int val) {
  static int PWM = -1;
  char cmd[4] = "\033"
                "Adm";
  if (val == -1)
    return PWM;
  if (val < 0)
    val = 0;
  if (val > 255)
    val = 255;
  PWM = val;
  cmd[2] = (char)val;
  cmd[3] = val == 0 ? 1 : 2;
  drv_generic_serial_write(cmd, 4);
  return val;
}


x86 assembly (clang, -O0):
<drv_BuE_CT_pwm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    0xedf(%rip),%eax
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    113c <drv_BuE_CT_pwm+0x2c>
mov    0x2ef4(%rip),%eax
mov    %eax,-0x4(%rbp)
jmp    119a <drv_BuE_CT_pwm+0x8a>
cmpl   $0x0,-0x8(%rbp)
jge    114d <drv_BuE_CT_pwm+0x3d>
movl   $0x0,-0x8(%rbp)
cmpl   $0xff,-0x8(%rbp)
jle    1161 <drv_BuE_CT_pwm+0x51>
movl   $0xff,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,0x2ebe(%rip)
mov    -0x8(%rbp),%eax
mov    %al,-0xa(%rbp)
mov    -0x8(%rbp),%edx
mov    $0x2,%eax
mov    $0x1,%ecx
cmp    $0x0,%edx
cmove  %ecx,%eax
mov    %al,-0x9(%rbp)
lea    -0xc(%rbp),%rdi
mov    $0x4,%esi
call   1030 <drv_generic_serial_write@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<drv_BuE_CT_pwm>:
push   %rbx
sub    $0x10,%rsp
movl   $0x6d64411b,0xc(%rsp)
6d
cmp    $0xffffffff,%edi
je     115c <drv_BuE_CT_pwm+0x4c>
xor    %eax,%eax
test   %edi,%edi
cmovns %edi,%eax
cmp    $0xff,%eax
mov    $0xff,%ebx
cmovb  %eax,%ebx
mov    %ebx,0x2eec(%rip)
mov    %bl,0xe(%rsp)
cmp    $0x1,%ebx
mov    $0x2,%al
sbb    $0x0,%al
mov    %al,0xf(%rsp)
lea    0xc(%rsp),%rdi
mov    $0x4,%esi
call   1030 <drv_generic_serial_write@plt>
jmp    1162 <drv_BuE_CT_pwm+0x52>
mov    0x2ec6(%rip),%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@drv_BuE_CT_pwm.PWM = internal global i32 -1
@__const.drv_BuE_CT_pwm.cmd = [4 x i8] c"\1BAdm"
define i32 @drv_BuE_CT_pwm(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [4 x i8]
store i32 %0, i32* %3
%5 = bitcast [4 x i8]* %4 to i8*
%6 = load i32, i32* %3
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = load i32, i32* @drv_BuE_CT_pwm.PWM
store i32 %9, i32* %2
br label %32
10: ; preds = %1
%11 = load i32, i32* %3
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %10
store i32 0, i32* %3
br label %14
14: ; preds = %13, %10
%15 = load i32, i32* %3
%16 = icmp sgt i32 %15, 255
br i1 %16, label %17, label %18
17: ; preds = %14
store i32 255, i32* %3
br label %18
18: ; preds = %17, %14
%19 = load i32, i32* %3
store i32 %19, i32* @drv_BuE_CT_pwm.PWM
%20 = load i32, i32* %3
%21 = trunc i32 %20 to i8
%22 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 2
store i8 %21, i8* %22
%23 = load i32, i32* %3
%24 = icmp eq i32 %23, 0
%25 = zext i1 %24 to i64
%26 = select i1 %24, i32 1, i32 2
%27 = trunc i32 %26 to i8
%28 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 3
store i8 %27, i8* %28
%29 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 0
%30 = call i32 @drv_generic_serial_write(i8* %29, i32 4)
%31 = load i32, i32* %3
store i32 %31, i32* %2
br label %32
32: ; preds = %18, %8
%33 = load i32, i32* %2
ret i32 %33
}

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