#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*/ write(int, ...);
void optical_eye_write(int fd, unsigned char *request, int request_length) {
  unsigned char *pc = request;
  int chars_written = 1;
  write(fd, request, 1);
  while (chars_written < request_length - 1) {
    switch (request[chars_written]) {
    case 0x06:
      write(fd, "\x1b\xf9", 2);
      break;
    case 0x0d:
      write(fd, "\x1b\xf2", 2);
      break;
    case 0x1b:
      write(fd, "\x1b\xe4", 2);
      break;
    case 0x40:
      write(fd, "\x1b\xbf", 2);
      break;
    case 0x80:
      write(fd, "\x1b\x7f", 2);
      break;
    default:
      write(fd, request + chars_written, 1);
    }
    pc++;
    chars_written++;
  }
  write(fd, request + (request_length - 1), 1);
}


x86 assembly (clang, -O0):
<optical_eye_write>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
movl   $0x1,-0x24(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    $0x1,%edx
mov    $0x0,%al
call   1030 <write@plt>
mov    -0x24(%rbp),%eax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    1273 <optical_eye_write+0x163>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
mov    %eax,-0x28(%rbp)
sub    $0x6,%eax
je     11b8 <optical_eye_write+0xa8>
jmp    1172 <optical_eye_write+0x62>
mov    -0x28(%rbp),%eax
sub    $0xd,%eax
je     11d3 <optical_eye_write+0xc3>
jmp    1183 <optical_eye_write+0x73>
mov    -0x28(%rbp),%eax
sub    $0x1b,%eax
je     11ee <optical_eye_write+0xde>
jmp    1194 <optical_eye_write+0x84>
mov    -0x28(%rbp),%eax
sub    $0x40,%eax
je     1209 <optical_eye_write+0xf9>
jmp    11a5 <optical_eye_write+0x95>
mov    -0x28(%rbp),%eax
sub    $0x80,%eax
je     1224 <optical_eye_write+0x114>
jmp    123f <optical_eye_write+0x12f>
mov    -0x4(%rbp),%edi
lea    0xe3e(%rip),%rsi
mov    $0x2,%edx
mov    $0x0,%al
call   1030 <write@plt>
jmp    1259 <optical_eye_write+0x149>
mov    -0x4(%rbp),%edi
lea    0xe26(%rip),%rsi
mov    $0x2,%edx
mov    $0x0,%al
call   1030 <write@plt>
jmp    1259 <optical_eye_write+0x149>
mov    -0x4(%rbp),%edi
lea    0xe0e(%rip),%rsi
mov    $0x2,%edx
mov    $0x0,%al
call   1030 <write@plt>
jmp    1259 <optical_eye_write+0x149>
mov    -0x4(%rbp),%edi
lea    0xdf6(%rip),%rsi
mov    $0x2,%edx
mov    $0x0,%al
call   1030 <write@plt>
jmp    1259 <optical_eye_write+0x149>
mov    -0x4(%rbp),%edi
lea    0xdde(%rip),%rsi
mov    $0x2,%edx
mov    $0x0,%al
call   1030 <write@plt>
jmp    1259 <optical_eye_write+0x149>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
movslq -0x24(%rbp),%rax
add    %rax,%rsi
mov    $0x1,%edx
mov    $0x0,%al
call   1030 <write@plt>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1144 <optical_eye_write+0x34>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
cltq
add    %rax,%rsi
mov    $0x1,%edx
mov    $0x0,%al
call   1030 <write@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<optical_eye_write>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%ebx
mov    %rsi,%r14
mov    %edi,%ebp
mov    $0x1,%edx
xor    %eax,%eax
call   1030 <write@plt>
lea    -0x1(%rbx),%r13d
cmp    $0x3,%ebx
jl     11d8 <optical_eye_write+0xc8>
mov    %r13d,%r15d
lea    0x1(%r14),%rbx
add    $0xffffffffffffffff,%r15
lea    0xebc(%rip),%r12
jmp    1171 <optical_eye_write+0x61>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
nopl   0x0(%rax)
xor    %eax,%eax
call   1030 <write@plt>
add    $0x1,%rbx
add    $0xffffffffffffffff,%r15
je     11d8 <optical_eye_write+0xc8>
movzbl (%rbx),%eax
cmp    $0xc,%al
jle    1190 <optical_eye_write+0x80>
cmp    $0xd,%al
je     11a8 <optical_eye_write+0x98>
cmp    $0x1b,%al
je     11b8 <optical_eye_write+0xa8>
cmp    $0x40,%al
jne    114f <optical_eye_write+0x3f>
mov    %ebp,%edi
mov    %r12,%rsi
mov    $0x2,%edx
jmp    1160 <optical_eye_write+0x50>
cmp    $0x80,%al
je     11c8 <optical_eye_write+0xb8>
cmp    $0x6,%al
jne    114f <optical_eye_write+0x3f>
mov    %ebp,%edi
lea    0xe5f(%rip),%rsi
mov    $0x2,%edx
jmp    1160 <optical_eye_write+0x50>
mov    %ebp,%edi
lea    0xe52(%rip),%rsi
mov    $0x2,%edx
jmp    1160 <optical_eye_write+0x50>
mov    %ebp,%edi
lea    0xe45(%rip),%rsi
mov    $0x2,%edx
jmp    1160 <optical_eye_write+0x50>
mov    %ebp,%edi
lea    0xe3b(%rip),%rsi
mov    $0x2,%edx
jmp    1160 <optical_eye_write+0x50>
movslq %r13d,%rax
add    %rax,%r14
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x1,%edx
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <write@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"\1B\F9\00"
@.str.1 = [3 x i8] c"\1B\F2\00"
@.str.2 = [3 x i8] c"\1B\E4\00"
@.str.3 = [3 x i8] c"\1B\BF\00"
@.str.4 = [3 x i8] c"\1B\7F\00"
define void @optical_eye_write(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%9 = load i8*, i8** %5
store i8* %9, i8** %7
store i32 1, i32* %8
%10 = load i32, i32* %4
%11 = load i8*, i8** %5
%12 = call i32 (i32, ...) @write(i32 %10, i8* %11, i32 1)
br label %13
13: ; preds = %47, %3
%14 = load i32, i32* %8
%15 = load i32, i32* %6
%16 = sub nsw i32 %15, 1
%17 = icmp slt i32 %14, %16
br i1 %17, label %18, label %52
18: ; preds = %13
%19 = load i8*, i8** %5
%20 = load i32, i32* %8
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %19, i64 %21
%23 = load i8, i8* %22
%24 = zext i8 %23 to i32
switch i32 %24, label %40 [
i32 6, label %25
i32 13, label %28
i32 27, label %31
i32 64, label %34
i32 128, label %37
]
25: ; preds = %18
%26 = load i32, i32* %4
%27 = call i32 (i32, ...) @write(i32 %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 2)
br label %47
28: ; preds = %18
%29 = load i32, i32* %4
%30 = call i32 (i32, ...) @write(i32 %29, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 2)
br label %47
31: ; preds = %18
%32 = load i32, i32* %4
%33 = call i32 (i32, ...) @write(i32 %32, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 2)
br label %47
34: ; preds = %18
%35 = load i32, i32* %4
%36 = call i32 (i32, ...) @write(i32 %35, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 2)
br label %47
37: ; preds = %18
%38 = load i32, i32* %4
%39 = call i32 (i32, ...) @write(i32 %38, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 2)
br label %47
40: ; preds = %18
%41 = load i32, i32* %4
%42 = load i8*, i8** %5
%43 = load i32, i32* %8
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8, i8* %42, i64 %44
%46 = call i32 (i32, ...) @write(i32 %41, i8* %45, i32 1)
br label %47
47: ; preds = %40, %37, %34, %31, %28, %25
%48 = load i8*, i8** %7
%49 = getelementptr inbounds i8, i8* %48, i32 1
store i8* %49, i8** %7
%50 = load i32, i32* %8
%51 = add nsw i32 %50, 1
store i32 %51, i32* %8
br label %13
52: ; preds = %13
%53 = load i32, i32* %4
%54 = load i8*, i8** %5
%55 = load i32, i32* %6
%56 = sub nsw i32 %55, 1
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds i8, i8* %54, i64 %57
%59 = call i32 (i32, ...) @write(i32 %53, i8* %58, i32 1)
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"\1B\F9\00"
@.str.1 = [3 x i8] c"\1B\F2\00"
@.str.2 = [3 x i8] c"\1B\E4\00"
@.str.3 = [3 x i8] c"\1B\BF\00"
@.str.4 = [3 x i8] c"\1B\7F\00"
define void @optical_eye_write(i32 %0, i8* %1, i32 %2) {
%4 = tail call i32 (i32, ...) @write(i32 %0, i8* %1, i32 1)
%5 = add i32 %2, -1
%6 = icmp sgt i32 %2, 2
br i1 %6, label %7, label %28
7: ; preds = %3
%8 = zext i32 %5 to i64
br label %9
9: ; preds = %7, %25
%10 = phi i64 [ 1, %7 ], [ %26, %25 ]
%11 = getelementptr inbounds i8, i8* %1, i64 %10
%12 = load i8, i8* %11
switch i8 %12, label %23 [
i8 6, label %13
i8 13, label %15
i8 27, label %17
i8 64, label %19
i8 -128, label %21
]
13: ; preds = %9
%14 = tail call i32 (i32, ...) @write(i32 %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 2)
br label %25
15: ; preds = %9
%16 = tail call i32 (i32, ...) @write(i32 %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 2)
br label %25
17: ; preds = %9
%18 = tail call i32 (i32, ...) @write(i32 %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 2)
br label %25
19: ; preds = %9
%20 = tail call i32 (i32, ...) @write(i32 %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 2)
br label %25
21: ; preds = %9
%22 = tail call i32 (i32, ...) @write(i32 %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 2)
br label %25
23: ; preds = %9
%24 = tail call i32 (i32, ...) @write(i32 %0, i8* %11, i32 1)
br label %25
25: ; preds = %23, %21, %19, %17, %15, %13
%26 = add nuw nsw i64 %10, 1
%27 = icmp eq i64 %26, %8
br i1 %27, label %28, label %9
28: ; preds = %25, %3
%29 = sext i32 %5 to i64
%30 = getelementptr inbounds i8, i8* %1, i64 %29
%31 = tail call i32 (i32, ...) @write(i32 %0, i8* %30, i32 1)
ret void
}