#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__ USBSTK5515_ULED_getall(unsigned short *);
scalar_t__ USBSTK5515_ULED_setall(unsigned short);
short USBSTK5515_ULED_toggle(unsigned short number) {
  unsigned short led_state;
  unsigned short new_led_state;
  unsigned short led_bit_toggle;
  led_bit_toggle = 1 << (3 - number);
  if (USBSTK5515_ULED_getall(&led_state))
    return -1;
  if ((led_state & led_bit_toggle) == 0)
    new_led_state = led_state | led_bit_toggle;
  else
    new_led_state = led_state & ~led_bit_toggle;
  if (USBSTK5515_ULED_setall(new_led_state))
    return -1;
  return 0;
}


x86 assembly (clang, -O0):
<USBSTK5515_ULED_toggle>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %di,%ax
mov    %ax,-0x4(%rbp)
movzwl -0x4(%rbp),%eax
mov    $0x3,%ecx
sub    %eax,%ecx
mov    $0x1,%eax
shl    %cl,%eax
mov    %ax,-0xa(%rbp)
lea    -0x6(%rbp),%rdi
call   1030 <USBSTK5515_ULED_getall@plt>
cmp    $0x0,%rax
je     1163 <USBSTK5515_ULED_toggle+0x43>
movw   $0xffff,-0x2(%rbp)
jmp    11be <USBSTK5515_ULED_toggle+0x9e>
movzwl -0x6(%rbp),%eax
movzwl -0xa(%rbp),%ecx
and    %ecx,%eax
cmp    $0x0,%eax
jne    1189 <USBSTK5515_ULED_toggle+0x69>
movzwl -0x6(%rbp),%eax
movzwl -0xa(%rbp),%ecx
or     %ecx,%eax
mov    %ax,-0x8(%rbp)
jmp    119a <USBSTK5515_ULED_toggle+0x7a>
movzwl -0x6(%rbp),%eax
movzwl -0xa(%rbp),%ecx
xor    $0xffffffff,%ecx
and    %ecx,%eax
mov    %ax,-0x8(%rbp)
movzwl -0x8(%rbp),%edi
call   1040 <USBSTK5515_ULED_setall@plt>
cmp    $0x0,%rax
je     11b8 <USBSTK5515_ULED_toggle+0x98>
movw   $0xffff,-0x2(%rbp)
jmp    11be <USBSTK5515_ULED_toggle+0x9e>
movw   $0x0,-0x2(%rbp)
movswl -0x2(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<USBSTK5515_ULED_toggle>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
lea    0xe(%rsp),%rdi
call   1030 <USBSTK5515_ULED_getall@plt>
mov    %rax,%rcx
mov    $0xffff,%ax
test   %rcx,%rcx
jne    1166 <USBSTK5515_ULED_toggle+0x46>
mov    $0x3,%al
sub    %bl,%al
movzwl 0xe(%rsp),%ecx
movzbl %al,%eax
mov    %ecx,%edx
bts    %eax,%edx
mov    %ecx,%esi
btr    %eax,%esi
bt     %eax,%ecx
cmovae %edx,%esi
movzwl %si,%edi
call   1040 <USBSTK5515_ULED_setall@plt>
neg    %rax
sbb    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define signext i16 @USBSTK5515_ULED_toggle(i16 zeroext %0) {
%2 = alloca i16
%3 = alloca i16
%4 = alloca i16
%5 = alloca i16
%6 = alloca i16
store i16 %0, i16* %3
%7 = load i16, i16* %3
%8 = zext i16 %7 to i32
%9 = sub nsw i32 3, %8
%10 = shl i32 1, %9
%11 = trunc i32 %10 to i16
store i16 %11, i16* %6
%12 = call i64 @USBSTK5515_ULED_getall(i16* %4)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %1
store i16 -1, i16* %2
br label %43
15: ; preds = %1
%16 = load i16, i16* %4
%17 = zext i16 %16 to i32
%18 = load i16, i16* %6
%19 = zext i16 %18 to i32
%20 = and i32 %17, %19
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %29
22: ; preds = %15
%23 = load i16, i16* %4
%24 = zext i16 %23 to i32
%25 = load i16, i16* %6
%26 = zext i16 %25 to i32
%27 = or i32 %24, %26
%28 = trunc i32 %27 to i16
store i16 %28, i16* %5
br label %37
29: ; preds = %15
%30 = load i16, i16* %4
%31 = zext i16 %30 to i32
%32 = load i16, i16* %6
%33 = zext i16 %32 to i32
%34 = xor i32 %33, -1
%35 = and i32 %31, %34
%36 = trunc i32 %35 to i16
store i16 %36, i16* %5
br label %37
37: ; preds = %29, %22
%38 = load i16, i16* %5
%39 = call i64 @USBSTK5515_ULED_setall(i16 zeroext %38)
%40 = icmp ne i64 %39, 0
br i1 %40, label %41, label %42
41: ; preds = %37
store i16 -1, i16* %2
br label %43
42: ; preds = %37
store i16 0, i16* %2
br label %43
43: ; preds = %42, %41, %14
%44 = load i16, i16* %2
ret i16 %44
}

LLVM IR (-O2):
define signext i16 @USBSTK5515_ULED_toggle(i16 zeroext %0) {
%2 = alloca i16
%3 = bitcast i16* %2 to i8*
%4 = call i64 @USBSTK5515_ULED_getall(i16* %2)
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %22
6: ; preds = %1
%7 = zext i16 %0 to i32
%8 = sub nsw i32 3, %7
%9 = shl nuw nsw i32 1, %8
%10 = load i16, i16* %2
%11 = zext i16 %10 to i32
%12 = and i32 %9, %11
%13 = icmp eq i32 %12, 0
%14 = trunc i32 %9 to i16
%15 = or i16 %10, %14
%16 = xor i16 %14, -1
%17 = and i16 %10, %16
%18 = select i1 %13, i16 %15, i16 %17
%19 = call i64 @USBSTK5515_ULED_setall(i16 zeroext %18)
%20 = icmp ne i64 %19, 0
%21 = sext i1 %20 to i16
br label %22
22: ; preds = %6, %1
%23 = phi i16 [ -1, %1 ], [ %21, %6 ]
ret i16 %23
}