#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*/ sprintf(char *, char *, int, int);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ write(int, char *, int /*<<< orphan*/);
void EyeboxOne_use_led(int fd, int led, int color) {
  char buffer[16];
  int a, b;
  if (led > 3 || led < 1)
    return;
  switch (color) {
  case 0:
    a = b = 0;
    break;
  case 1:
    a = 1;
    b = 0;
    break;
  case 2:
    a = 1;
    b = 1;
    break;
  case 3:
    a = 0;
    b = 1;
    break;
  default:
    a = b = 0;
  }
  sprintf(buffer, "\E[%d;%dL", led + (led - 1), a);
  write(fd, buffer, strlen(buffer));
  sprintf(buffer, "\E[%d;%dL", led + (led - 1) + 1, b);
  write(fd, buffer, strlen(buffer));
}


x86 assembly (clang, -O0):
<EyeboxOne_use_led>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
cmpl   $0x3,-0x8(%rbp)
jg     1155 <EyeboxOne_use_led+0x25>
cmpl   $0x1,-0x8(%rbp)
jge    115a <EyeboxOne_use_led+0x2a>
jmp    1262 <EyeboxOne_use_led+0x132>
mov    -0xc(%rbp),%eax
mov    %rax,-0x30(%rbp)
sub    $0x3,%rax
ja     11cb <EyeboxOne_use_led+0x9b>
mov    -0x30(%rbp),%rax
lea    0xe8a(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0x0,-0x28(%rbp)
movl   $0x0,-0x24(%rbp)
jmp    11d9 <EyeboxOne_use_led+0xa9>
movl   $0x1,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
jmp    11d9 <EyeboxOne_use_led+0xa9>
movl   $0x1,-0x24(%rbp)
movl   $0x1,-0x28(%rbp)
jmp    11d9 <EyeboxOne_use_led+0xa9>
movl   $0x0,-0x24(%rbp)
movl   $0x1,-0x28(%rbp)
jmp    11d9 <EyeboxOne_use_led+0xa9>
movl   $0x0,-0x28(%rbp)
movl   $0x0,-0x24(%rbp)
lea    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%edx
mov    -0x8(%rbp),%eax
sub    $0x1,%eax
add    %eax,%edx
mov    -0x24(%rbp),%ecx
lea    0xe1e(%rip),%rsi
call   1050 <sprintf@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x4c(%rbp)
lea    -0x20(%rbp),%rax
mov    %rax,-0x48(%rbp)
lea    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x4c(%rbp),%edi
mov    -0x48(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
lea    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%edx
mov    -0x8(%rbp),%eax
sub    $0x1,%eax
add    %eax,%edx
add    $0x1,%edx
mov    -0x28(%rbp),%ecx
lea    0xdd8(%rip),%rsi
call   1050 <sprintf@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x3c(%rbp)
lea    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
lea    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x3c(%rbp),%edi
mov    -0x38(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<EyeboxOne_use_led>:
lea    -0x4(%rsi),%eax
cmp    $0xfffffffd,%eax
jb     11d8 <EyeboxOne_use_led+0xa8>
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %edi,%r15d
add    $0xffffffff,%edx
xor    %ecx,%ecx
mov    $0x0,%r14d
cmp    $0x2,%edx
ja     1173 <EyeboxOne_use_led+0x43>
movslq %edx,%rax
lea    0xea7(%rip),%rcx
mov    (%rcx,%rax,4),%ecx
lea    0xea9(%rip),%rdx
mov    (%rdx,%rax,4),%r14d
mov    %esi,%ebx
add    %esi,%ebx
lea    (%rsi,%rsi,1),%edx
add    $0xffffffff,%edx
lea    0xe7c(%rip),%r12
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    %r12,%rsi
call   1050 <sprintf@plt>
mov    %rbp,%rdi
call   1040 <strlen@plt>
mov    %r15d,%edi
mov    %rbp,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %rbp,%rdi
mov    %r12,%rsi
mov    %ebx,%edx
mov    %r14d,%ecx
call   1050 <sprintf@plt>
mov    %rbp,%rdi
call   1040 <strlen@plt>
mov    %r15d,%edi
mov    %rbp,%rsi
mov    %eax,%edx
call   1030 <write@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"\1B[%d;%dL\00"
define void @EyeboxOne_use_led(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca [16 x i8]
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%10 = load i32, i32* %5
%11 = icmp sgt i32 %10, 3
br i1 %11, label %15, label %12
12: ; preds = %3
%13 = load i32, i32* %5
%14 = icmp slt i32 %13, 1
br i1 %14, label %15, label %16
15: ; preds = %12, %3
br label %49
16: ; preds = %12
%17 = load i32, i32* %6
switch i32 %17, label %22 [
i32 0, label %18
i32 1, label %19
i32 2, label %20
i32 3, label %21
]
18: ; preds = %16
store i32 0, i32* %9
store i32 0, i32* %8
br label %23
19: ; preds = %16
store i32 1, i32* %8
store i32 0, i32* %9
br label %23
20: ; preds = %16
store i32 1, i32* %8
store i32 1, i32* %9
br label %23
21: ; preds = %16
store i32 0, i32* %8
store i32 1, i32* %9
br label %23
22: ; preds = %16
store i32 0, i32* %9
store i32 0, i32* %8
br label %23
23: ; preds = %22, %21, %20, %19, %18
%24 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 0
%25 = load i32, i32* %5
%26 = load i32, i32* %5
%27 = sub nsw i32 %26, 1
%28 = add nsw i32 %25, %27
%29 = load i32, i32* %8
%30 = call i32 @sprintf(i8* %24, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %28, i32 %29)
%31 = load i32, i32* %4
%32 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 0
%33 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 0
%34 = call i32 @strlen(i8* %33)
%35 = call i32 @write(i32 %31, i8* %32, i32 %34)
%36 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 0
%37 = load i32, i32* %5
%38 = load i32, i32* %5
%39 = sub nsw i32 %38, 1
%40 = add nsw i32 %37, %39
%41 = add nsw i32 %40, 1
%42 = load i32, i32* %9
%43 = call i32 @sprintf(i8* %36, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %41, i32 %42)
%44 = load i32, i32* %4
%45 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 0
%46 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 0
%47 = call i32 @strlen(i8* %46)
%48 = call i32 @write(i32 %44, i8* %45, i32 %47)
br label %49
49: ; preds = %23, %15
ret void
}

LLVM IR (-O2):
@.str = [9 x i8] c"\1B[%d;%dL\00"
@switch.table.EyeboxOne_use_led = [3 x i32] [i32 1, i32 1, i32 0]
@switch.table.EyeboxOne_use_led.1 = [3 x i32] [i32 0, i32 1, i32 1]
define void @EyeboxOne_use_led(i32 %0, i32 %1, i32 %2) {
%4 = alloca [16 x i8]
%5 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%6 = add i32 %1, -4
%7 = icmp ult i32 %6, -3
br i1 %7, label %29, label %8
8: ; preds = %3
%9 = add i32 %2, -1
%10 = icmp ult i32 %9, 3
br i1 %10, label %11, label %18
11: ; preds = %8
%12 = sext i32 %9 to i64
%13 = getelementptr inbounds [3 x i32], [3 x i32]* @switch.table.EyeboxOne_use_led, i64 0, i64 %12
%14 = load i32, i32* %13
%15 = sext i32 %9 to i64
%16 = getelementptr inbounds [3 x i32], [3 x i32]* @switch.table.EyeboxOne_use_led.1, i64 0, i64 %15
%17 = load i32, i32* %16
br label %18
18: ; preds = %11, %8
%19 = phi i32 [ 0, %8 ], [ %14, %11 ]
%20 = phi i32 [ 0, %8 ], [ %17, %11 ]
%21 = shl nuw nsw i32 %1, 1
%22 = add nsw i32 %21, -1
%23 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %22, i32 %19)
%24 = call i32 @strlen(i8* %5)
%25 = call i32 @write(i32 %0, i8* %5, i32 %24)
%26 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %21, i32 %20)
%27 = call i32 @strlen(i8* %5)
%28 = call i32 @write(i32 %0, i8* %5, i32 %27)
br label %29
29: ; preds = %3, %18
ret void
}