#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*/ CDROMEJECT;
int /*<<< orphan*/ KDSETLED;
scalar_t__ ioctl(char, int /*<<< orphan*/, int);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ sleep(int);
int main() {
  int led = 0;
  if (ioctl('/dev/cdrom', CDROMEJECT, 0))
    puts("lol");
  while (1) {
    led = 2 * led + 1;
    if (led & 8)
      led ^= 9;
    if (ioctl(0, KDSETLED, led))
      return 0;
    sleep(1);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
mov    0x2e8b(%rip),%rax
mov    (%rax),%esi
mov    $0x6d,%edi
xor    %edx,%edx
call   1040 <ioctl@plt>
cmp    $0x0,%rax
je     1171 <main+0x41>
lea    0xe94(%rip),%rdi
call   1030 <puts@plt>
jmp    1176 <main+0x46>
mov    -0x8(%rbp),%eax
shl    $0x1,%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
and    $0x8,%eax
cmp    $0x0,%eax
je     119a <main+0x6a>
mov    -0x8(%rbp),%eax
xor    $0x9,%eax
mov    %eax,-0x8(%rbp)
mov    0x2e3f(%rip),%rax
mov    (%rax),%esi
mov    -0x8(%rbp),%edx
xor    %edi,%edi
call   1040 <ioctl@plt>
cmp    $0x0,%rax
je     11bf <main+0x8f>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret
mov    $0x1,%edi
call   1050 <sleep@plt>
jmp    1176 <main+0x46>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
mov    0x2e9c(%rip),%rax
mov    (%rax),%esi
mov    $0x6d,%edi
xor    %edx,%edx
call   1040 <ioctl@plt>
test   %rax,%rax
je     115b <main+0x2b>
lea    0xeaa(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e7e(%rip),%r14
mov    (%r14),%esi
mov    $0x1,%r15d
xor    %edi,%edi
mov    $0x1,%edx
call   1040 <ioctl@plt>
test   %rax,%rax
jne    11b3 <main+0x83>
nopl   0x0(%rax)
mov    $0x1,%edi
call   1050 <sleep@plt>
lea    (%r15,%r15,1),%ebx
lea    (%r15,%r15,1),%eax
add    $0x1,%eax
xor    $0x8,%ebx
test   $0x4,%r15b
cmove  %eax,%ebx
mov    (%r14),%esi
xor    %edi,%edi
mov    %ebx,%edx
call   1040 <ioctl@plt>
mov    %ebx,%r15d
test   %rax,%rax
je     1180 <main+0x50>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@CDROMEJECT = global i32 0
@.str = [4 x i8] c"lol\00"
@KDSETLED = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %2
%3 = load i32, i32* @CDROMEJECT
%4 = call i64 @ioctl(i8 signext 109, i32 %3, i32 0)
%5 = icmp ne i64 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = call i32 @puts(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
br label %8
8: ; preds = %6, %0
br label %9
9: ; preds = %8, %25
%10 = load i32, i32* %2
%11 = mul nsw i32 2, %10
%12 = add nsw i32 %11, 1
store i32 %12, i32* %2
%13 = load i32, i32* %2
%14 = and i32 %13, 8
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %9
%17 = load i32, i32* %2
%18 = xor i32 %17, 9
store i32 %18, i32* %2
br label %19
19: ; preds = %16, %9
%20 = load i32, i32* @KDSETLED
%21 = load i32, i32* %2
%22 = call i64 @ioctl(i8 signext 0, i32 %20, i32 %21)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %19
ret i32 0
25: ; preds = %19
%26 = call i32 @sleep(i32 1)
br label %9
}

LLVM IR (-O2):
@CDROMEJECT = global i32 0
@.str = [4 x i8] c"lol\00"
@KDSETLED = global i32 0
define i32 @main() {
%1 = load i32, i32* @CDROMEJECT
%2 = tail call i64 @ioctl(i8 signext 109, i32 %1, i32 0)
%3 = icmp eq i64 %2, 0
br i1 %3, label %6, label %4
4: ; preds = %0
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
br label %6
6: ; preds = %4, %0
%7 = load i32, i32* @KDSETLED
%8 = tail call i64 @ioctl(i8 signext 0, i32 %7, i32 1)
%9 = icmp eq i64 %8, 0
br i1 %9, label %11, label %10
10: ; preds = %11, %6
ret i32 0
11: ; preds = %6, %11
%12 = phi i32 [ %19, %11 ], [ 1, %6 ]
%13 = tail call i32 @sleep(i32 1)
%14 = shl nsw i32 %12, 1
%15 = or i32 %14, 1
%16 = and i32 %12, 4
%17 = icmp eq i32 %16, 0
%18 = xor i32 %14, 8
%19 = select i1 %17, i32 %15, i32 %18
%20 = load i32, i32* @KDSETLED
%21 = tail call i64 @ioctl(i8 signext 0, i32 %20, i32 %19)
%22 = icmp eq i64 %21, 0
br i1 %22, label %11, label %10
}