#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*/ matrix_setbrightness(unsigned char);
int /*<<< orphan*/ matrix_setgamma(unsigned char);
int /*<<< orphan*/ matrix_swap();
int /*<<< orphan*/ matrix_write(unsigned char *, unsigned int);
int handle_opoutput(unsigned char Sequence, unsigned char Physical,
                    unsigned short Universe, unsigned short Length,
                    unsigned char *data) {
  if (Universe < (((96 * 48 * 3) + ((170 * 3) - 1)) / (170 * 3))) {
    unsigned int offset = Universe * (170 * 3);
    unsigned int len = Length;
    unsigned int packetlen = len + 7;
    unsigned char *packet = &data[-7];
    packet[0] = 'F';
    packet[1] = 'W';
    packet[2] = 'P';
    packet[3] = len >> 8;
    packet[4] = len & 0xFF;
    packet[5] = offset >> 8;
    packet[6] = offset & 0xFF;
    matrix_write(packet, packetlen);
    if (Universe == ((((96 * 48 * 3) + ((170 * 3) - 1)) / (170 * 3)) - 1))
      matrix_swap();
  }
  if (Universe == 0xFFFF) {
    if (Length > 0)
      matrix_setbrightness(data[0]);
    if (Length > 1)
      matrix_setgamma(data[1]);
  }
  return 0;
}


x86 assembly (clang, -O0):
<handle_opoutput>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %cx,%ax
mov    %dx,%cx
mov    %sil,%dl
mov    %dil,%sil
mov    %sil,-0x1(%rbp)
mov    %dl,-0x2(%rbp)
mov    %cx,-0x4(%rbp)
mov    %ax,-0x6(%rbp)
mov    %r8,-0x10(%rbp)
movzwl -0x4(%rbp),%eax
cmp    $0x1c,%eax
jge    1219 <handle_opoutput+0xd9>
movzwl -0x4(%rbp),%eax
imul   $0x1fe,%eax,%eax
mov    %eax,-0x14(%rbp)
movzwl -0x6(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
add    $0x7,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
add    $0xfffffffffffffff9,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
movb   $0x46,(%rax)
mov    -0x28(%rbp),%rax
movb   $0x57,0x1(%rax)
mov    -0x28(%rbp),%rax
movb   $0x50,0x2(%rax)
mov    -0x18(%rbp),%eax
shr    $0x8,%eax
mov    %al,%cl
mov    -0x28(%rbp),%rax
mov    %cl,0x3(%rax)
mov    -0x18(%rbp),%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x28(%rbp),%rax
mov    %cl,0x4(%rax)
mov    -0x14(%rbp),%eax
shr    $0x8,%eax
mov    %al,%cl
mov    -0x28(%rbp),%rax
mov    %cl,0x5(%rax)
mov    -0x14(%rbp),%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x28(%rbp),%rax
mov    %cl,0x6(%rax)
mov    -0x28(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1040 <matrix_write@plt>
movzwl -0x4(%rbp),%eax
cmp    $0x1b,%eax
jne    1214 <handle_opoutput+0xd4>
mov    $0x0,%al
call   1060 <matrix_swap@plt>
jmp    1219 <handle_opoutput+0xd9>
movzwl -0x4(%rbp),%eax
cmp    $0xffff,%eax
jne    1260 <handle_opoutput+0x120>
movzwl -0x6(%rbp),%eax
cmp    $0x0,%eax
jle    1241 <handle_opoutput+0x101>
mov    -0x10(%rbp),%rax
movzbl (%rax),%edi
call   1050 <matrix_setbrightness@plt>
movzwl -0x6(%rbp),%eax
cmp    $0x1,%eax
jle    125b <handle_opoutput+0x11b>
mov    -0x10(%rbp),%rax
movzbl 0x1(%rax),%edi
call   1030 <matrix_setgamma@plt>
jmp    1260 <handle_opoutput+0x120>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<handle_opoutput>:
push   %rbp
push   %r14
push   %rbx
mov    %r8,%rbx
mov    %ecx,%r14d
mov    %edx,%ebp
cmp    $0x1b,%bp
ja     1194 <handle_opoutput+0x54>
movzwl %bp,%ecx
mov    %ecx,%eax
shl    $0x9,%eax
sub    %ecx,%eax
sub    %ecx,%eax
movzwl %r14w,%ecx
lea    0x7(%rcx),%esi
lea    -0x7(%rbx),%rdi
movw   $0x5746,-0x7(%rbx)
movb   $0x50,-0x5(%rbx)
mov    %ch,-0x4(%rbx)
mov    %r14b,-0x3(%rbx)
mov    %ah,-0x2(%rbx)
mov    %al,-0x1(%rbx)
call   1040 <matrix_write@plt>
cmp    $0x1b,%bp
jne    11b8 <handle_opoutput+0x78>
xor    %eax,%eax
call   1060 <matrix_swap@plt>
jmp    11b8 <handle_opoutput+0x78>
cmp    $0xffff,%bp
jne    11b8 <handle_opoutput+0x78>
test   %r14w,%r14w
je     11b8 <handle_opoutput+0x78>
movzbl (%rbx),%edi
call   1050 <matrix_setbrightness@plt>
cmp    $0x2,%r14w
jb     11b8 <handle_opoutput+0x78>
movzbl 0x1(%rbx),%edi
call   1030 <matrix_setgamma@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @handle_opoutput(i8 zeroext %0, i8 zeroext %1, i16 zeroext %2, i16 zeroext %3, i8* %4) {
%6 = alloca i8
%7 = alloca i8
%8 = alloca i16
%9 = alloca i16
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i8*
store i8 %0, i8* %6
store i8 %1, i8* %7
store i16 %2, i16* %8
store i16 %3, i16* %9
store i8* %4, i8** %10
%15 = load i16, i16* %8
%16 = zext i16 %15 to i32
%17 = icmp slt i32 %16, 28
br i1 %17, label %18, label %63
18: ; preds = %5
%19 = load i16, i16* %8
%20 = zext i16 %19 to i32
%21 = mul nsw i32 %20, 510
store i32 %21, i32* %11
%22 = load i16, i16* %9
%23 = zext i16 %22 to i32
store i32 %23, i32* %12
%24 = load i32, i32* %12
%25 = add i32 %24, 7
store i32 %25, i32* %13
%26 = load i8*, i8** %10
%27 = getelementptr inbounds i8, i8* %26, i64 -7
store i8* %27, i8** %14
%28 = load i8*, i8** %14
%29 = getelementptr inbounds i8, i8* %28, i64 0
store i8 70, i8* %29
%30 = load i8*, i8** %14
%31 = getelementptr inbounds i8, i8* %30, i64 1
store i8 87, i8* %31
%32 = load i8*, i8** %14
%33 = getelementptr inbounds i8, i8* %32, i64 2
store i8 80, i8* %33
%34 = load i32, i32* %12
%35 = lshr i32 %34, 8
%36 = trunc i32 %35 to i8
%37 = load i8*, i8** %14
%38 = getelementptr inbounds i8, i8* %37, i64 3
store i8 %36, i8* %38
%39 = load i32, i32* %12
%40 = and i32 %39, 255
%41 = trunc i32 %40 to i8
%42 = load i8*, i8** %14
%43 = getelementptr inbounds i8, i8* %42, i64 4
store i8 %41, i8* %43
%44 = load i32, i32* %11
%45 = lshr i32 %44, 8
%46 = trunc i32 %45 to i8
%47 = load i8*, i8** %14
%48 = getelementptr inbounds i8, i8* %47, i64 5
store i8 %46, i8* %48
%49 = load i32, i32* %11
%50 = and i32 %49, 255
%51 = trunc i32 %50 to i8
%52 = load i8*, i8** %14
%53 = getelementptr inbounds i8, i8* %52, i64 6
store i8 %51, i8* %53
%54 = load i8*, i8** %14
%55 = load i32, i32* %13
%56 = call i32 @matrix_write(i8* %54, i32 %55)
%57 = load i16, i16* %8
%58 = zext i16 %57 to i32
%59 = icmp eq i32 %58, 27
br i1 %59, label %60, label %62
60: ; preds = %18
%61 = call i32 (...) @matrix_swap()
br label %62
62: ; preds = %60, %18
br label %63
63: ; preds = %62, %5
%64 = load i16, i16* %8
%65 = zext i16 %64 to i32
%66 = icmp eq i32 %65, 65535
br i1 %66, label %67, label %86
67: ; preds = %63
%68 = load i16, i16* %9
%69 = zext i16 %68 to i32
%70 = icmp sgt i32 %69, 0
br i1 %70, label %71, label %76
71: ; preds = %67
%72 = load i8*, i8** %10
%73 = getelementptr inbounds i8, i8* %72, i64 0
%74 = load i8, i8* %73
%75 = call i32 @matrix_setbrightness(i8 zeroext %74)
br label %76
76: ; preds = %71, %67
%77 = load i16, i16* %9
%78 = zext i16 %77 to i32
%79 = icmp sgt i32 %78, 1
br i1 %79, label %80, label %85
80: ; preds = %76
%81 = load i8*, i8** %10
%82 = getelementptr inbounds i8, i8* %81, i64 1
%83 = load i8, i8* %82
%84 = call i32 @matrix_setgamma(i8 zeroext %83)
br label %85
85: ; preds = %80, %76
br label %86
86: ; preds = %85, %63
ret i32 0
}

LLVM IR (-O2):
define i32 @handle_opoutput(i8 zeroext %0, i8 zeroext %1, i16 zeroext %2, i16 zeroext %3, i8* %4) {
%6 = icmp ult i16 %2, 28
br i1 %6, label %7, label %29
7: ; preds = %5
%8 = zext i16 %2 to i32
%9 = mul nuw nsw i32 %8, 510
%10 = zext i16 %3 to i32
%11 = add nuw nsw i32 %10, 7
%12 = getelementptr inbounds i8, i8* %4, i64 -7
store i8 70, i8* %12
%13 = getelementptr inbounds i8, i8* %4, i64 -6
store i8 87, i8* %13
%14 = getelementptr inbounds i8, i8* %4, i64 -5
store i8 80, i8* %14
%15 = lshr i16 %3, 8
%16 = trunc i16 %15 to i8
%17 = getelementptr inbounds i8, i8* %4, i64 -4
store i8 %16, i8* %17
%18 = trunc i16 %3 to i8
%19 = getelementptr inbounds i8, i8* %4, i64 -3
store i8 %18, i8* %19
%20 = lshr i32 %9, 8
%21 = trunc i32 %20 to i8
%22 = getelementptr inbounds i8, i8* %4, i64 -2
store i8 %21, i8* %22
%23 = trunc i32 %9 to i8
%24 = getelementptr inbounds i8, i8* %4, i64 -1
store i8 %23, i8* %24
%25 = tail call i32 @matrix_write(i8* %12, i32 %11)
%26 = icmp eq i16 %2, 27
br i1 %26, label %27, label %41
27: ; preds = %7
%28 = tail call i32 (...) @matrix_swap()
br label %41
29: ; preds = %5
%30 = icmp ne i16 %2, -1
%31 = icmp eq i16 %3, 0
%32 = or i1 %30, %31
br i1 %32, label %41, label %33
33: ; preds = %29
%34 = load i8, i8* %4
%35 = tail call i32 @matrix_setbrightness(i8 zeroext %34)
%36 = icmp ugt i16 %3, 1
br i1 %36, label %37, label %41
37: ; preds = %33
%38 = getelementptr inbounds i8, i8* %4, i64 1
%39 = load i8, i8* %38
%40 = tail call i32 @matrix_setgamma(i8 zeroext %39)
br label %41
41: ; preds = %7, %27, %33, %37, %29
ret i32 0
}