#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*/ KDGETLED;
int /*<<< orphan*/ KDSETLED;
int /*<<< orphan*/ ioctl(int, int /*<<< orphan*/, ...);
void toggleled(int ttyfd, unsigned char led, unsigned char status) {
  unsigned char savedleds;
  unsigned char tempbyte;
  ioctl(ttyfd, KDGETLED, &savedleds);
  if (status == 1) {
    ioctl(ttyfd, KDSETLED, savedleds | led);
  } else {
    tempbyte = 0xFF;
    tempbyte ^= led;
    ioctl(ttyfd, KDSETLED, savedleds & tempbyte);
  }
}


x86 assembly (clang, -O0):
<toggleled>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %dl,%al
mov    %sil,%cl
mov    %edi,-0x4(%rbp)
mov    %cl,-0x5(%rbp)
mov    %al,-0x6(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2eb8(%rip),%rax
mov    (%rax),%esi
lea    -0x7(%rbp),%rdx
mov    $0x0,%al
call   1030 <ioctl@plt>
movzbl -0x6(%rbp),%eax
cmp    $0x1,%eax
jne    116c <toggleled+0x5c>
mov    -0x4(%rbp),%edi
mov    0x2e84(%rip),%rax
mov    (%rax),%esi
movzbl -0x7(%rbp),%edx
movzbl -0x5(%rbp),%eax
or     %eax,%edx
mov    $0x0,%al
call   1030 <ioctl@plt>
jmp    119a <toggleled+0x8a>
movb   $0xff,-0x8(%rbp)
movzbl -0x5(%rbp),%ecx
movzbl -0x8(%rbp),%eax
xor    %ecx,%eax
mov    %al,-0x8(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e51(%rip),%rax
mov    (%rax),%esi
movzbl -0x7(%rbp),%edx
movzbl -0x8(%rbp),%eax
and    %eax,%edx
mov    $0x0,%al
call   1030 <ioctl@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<toggleled>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edx,%r14d
mov    %esi,%ebp
mov    %edi,%ebx
mov    0x2ec2(%rip),%rax
mov    (%rax),%esi
lea    0xf(%rsp),%rdx
xor    %eax,%eax
call   1030 <ioctl@plt>
cmp    $0x1,%r14b
jne    1141 <toggleled+0x31>
or     0xf(%rsp),%bpl
jmp    1149 <toggleled+0x39>
not    %bpl
and    0xf(%rsp),%bpl
mov    0x2e88(%rip),%rax
mov    (%rax),%esi
movzbl %bpl,%edx
mov    %ebx,%edi
xor    %eax,%eax
call   1030 <ioctl@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@KDGETLED = global i32 0
@KDSETLED = global i32 0
define void @toggleled(i32 %0, i8 zeroext %1, i8 zeroext %2) {
%4 = alloca i32
%5 = alloca i8
%6 = alloca i8
%7 = alloca i8
%8 = alloca i8
store i32 %0, i32* %4
store i8 %1, i8* %5
store i8 %2, i8* %6
%9 = load i32, i32* %4
%10 = load i32, i32* @KDGETLED
%11 = call i32 (i32, i32, ...) @ioctl(i32 %9, i32 %10, i8* %7)
%12 = load i8, i8* %6
%13 = zext i8 %12 to i32
%14 = icmp eq i32 %13, 1
br i1 %14, label %15, label %24
15: ; preds = %3
%16 = load i32, i32* %4
%17 = load i32, i32* @KDSETLED
%18 = load i8, i8* %7
%19 = zext i8 %18 to i32
%20 = load i8, i8* %5
%21 = zext i8 %20 to i32
%22 = or i32 %19, %21
%23 = call i32 (i32, i32, ...) @ioctl(i32 %16, i32 %17, i32 %22)
br label %39
24: ; preds = %3
store i8 -1, i8* %8
%25 = load i8, i8* %5
%26 = zext i8 %25 to i32
%27 = load i8, i8* %8
%28 = zext i8 %27 to i32
%29 = xor i32 %28, %26
%30 = trunc i32 %29 to i8
store i8 %30, i8* %8
%31 = load i32, i32* %4
%32 = load i32, i32* @KDSETLED
%33 = load i8, i8* %7
%34 = zext i8 %33 to i32
%35 = load i8, i8* %8
%36 = zext i8 %35 to i32
%37 = and i32 %34, %36
%38 = call i32 (i32, i32, ...) @ioctl(i32 %31, i32 %32, i32 %37)
br label %39
39: ; preds = %24, %15
ret void
}

LLVM IR (-O2):
@KDGETLED = global i32 0
@KDSETLED = global i32 0
define void @toggleled(i32 %0, i8 zeroext %1, i8 zeroext %2) {
%4 = alloca i8
%5 = load i32, i32* @KDGETLED
%6 = call i32 (i32, i32, ...) @ioctl(i32 %0, i32 %5, i8* %4)
%7 = icmp eq i8 %2, 1
br i1 %7, label %8, label %11
8: ; preds = %3
%9 = load i8, i8* %4
%10 = or i8 %9, %1
br label %15
11: ; preds = %3
%12 = xor i8 %1, -1
%13 = load i8, i8* %4
%14 = and i8 %13, %12
br label %15
15: ; preds = %11, %8
%16 = phi i8 [ %14, %11 ], [ %10, %8 ]
%17 = load i32, i32* @KDSETLED
%18 = zext i8 %16 to i32
%19 = call i32 (i32, i32, ...) @ioctl(i32 %0, i32 %17, i32 %18)
ret void
}