#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 */
unsigned char inp(int);
int /*<<< orphan*/ outp(int, unsigned char);
int /*<<< orphan*/ retrace();
void fade_down(void) {
  int i, j;
  unsigned char r, g, b;
  for (j = 0; j < 64; j++) {
    for (i = 0; i < 256; i++) {
      outp(0x03c7, i);
      r = inp(0x03c9);
      g = inp(0x03c9);
      b = inp(0x03c9);
      if (r > 0)
        r--;
      if (g > 0)
        g--;
      if (b > 0)
        b--;
      outp(0x03c8, i);
      outp(0x03c9, r);
      outp(0x03c9, g);
      outp(0x03c9, b);
    }
    retrace();
  }
}


x86 assembly (clang, -O0):
<fade_down>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x8(%rbp)
cmpl   $0x40,-0x8(%rbp)
jge    1230 <fade_down+0x100>
movl   $0x0,-0x4(%rbp)
cmpl   $0x100,-0x4(%rbp)
jge    121b <fade_down+0xeb>
mov    -0x4(%rbp),%eax
mov    $0x3c7,%edi
movzbl %al,%esi
call   1040 <outp@plt>
mov    $0x3c9,%edi
call   1050 <inp@plt>
mov    %al,-0x9(%rbp)
mov    $0x3c9,%edi
call   1050 <inp@plt>
mov    %al,-0xa(%rbp)
mov    $0x3c9,%edi
call   1050 <inp@plt>
mov    %al,-0xb(%rbp)
movzbl -0x9(%rbp),%eax
cmp    $0x0,%eax
jle    11a9 <fade_down+0x79>
mov    -0x9(%rbp),%al
add    $0xff,%al
mov    %al,-0x9(%rbp)
movzbl -0xa(%rbp),%eax
cmp    $0x0,%eax
jle    11be <fade_down+0x8e>
mov    -0xa(%rbp),%al
add    $0xff,%al
mov    %al,-0xa(%rbp)
movzbl -0xb(%rbp),%eax
cmp    $0x0,%eax
jle    11d3 <fade_down+0xa3>
mov    -0xb(%rbp),%al
add    $0xff,%al
mov    %al,-0xb(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x3c8,%edi
movzbl %al,%esi
call   1040 <outp@plt>
mov    $0x3c9,%edi
movzbl -0x9(%rbp),%esi
call   1040 <outp@plt>
mov    $0x3c9,%edi
movzbl -0xa(%rbp),%esi
call   1040 <outp@plt>
mov    $0x3c9,%edi
movzbl -0xb(%rbp),%esi
call   1040 <outp@plt>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1150 <fade_down+0x20>
mov    $0x0,%al
call   1030 <retrace@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    113f <fade_down+0xf>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fade_down>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %r15d,%r15d
xor    %eax,%eax
mov    %eax,0x4(%rsp)
xor    %r12d,%r12d
nopw   0x0(%rax,%rax,1)
movzbl %r12b,%r13d
mov    $0x3c7,%edi
mov    %r13d,%esi
call   1040 <outp@plt>
mov    $0x3c9,%edi
call   1050 <inp@plt>
mov    %eax,%ebx
mov    $0x3c9,%edi
call   1050 <inp@plt>
mov    %eax,%r14d
mov    $0x3c9,%edi
call   1050 <inp@plt>
sub    $0x1,%bl
movzbl %bl,%ebx
cmovb  %r15d,%ebx
sub    $0x1,%r14b
movzbl %r14b,%ebp
cmovb  %r15d,%ebp
sub    $0x1,%al
movzbl %al,%r14d
cmovb  %r15d,%r14d
mov    $0x3c8,%edi
mov    %r13d,%esi
call   1040 <outp@plt>
movzbl %bl,%esi
mov    $0x3c9,%edi
call   1040 <outp@plt>
movzbl %bpl,%esi
mov    $0x3c9,%edi
call   1040 <outp@plt>
movzbl %r14b,%esi
mov    $0x3c9,%edi
call   1040 <outp@plt>
add    $0x1,%r12d
cmp    $0x100,%r12d
jne    1150 <fade_down+0x20>
xor    %eax,%eax
call   1030 <retrace@plt>
mov    0x4(%rsp),%eax
add    $0x1,%eax
cmp    $0x40,%eax
jne    1140 <fade_down+0x10>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @fade_down() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8
%4 = alloca i8
%5 = alloca i8
store i32 0, i32* %2
br label %6
6: ; preds = %55, %0
%7 = load i32, i32* %2
%8 = icmp slt i32 %7, 64
br i1 %8, label %9, label %58
9: ; preds = %6
store i32 0, i32* %1
br label %10
10: ; preds = %50, %9
%11 = load i32, i32* %1
%12 = icmp slt i32 %11, 256
br i1 %12, label %13, label %53
13: ; preds = %10
%14 = load i32, i32* %1
%15 = trunc i32 %14 to i8
%16 = call i32 @outp(i32 967, i8 zeroext %15)
%17 = call zeroext i8 @inp(i32 969)
store i8 %17, i8* %3
%18 = call zeroext i8 @inp(i32 969)
store i8 %18, i8* %4
%19 = call zeroext i8 @inp(i32 969)
store i8 %19, i8* %5
%20 = load i8, i8* %3
%21 = zext i8 %20 to i32
%22 = icmp sgt i32 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %13
%24 = load i8, i8* %3
%25 = add i8 %24, -1
store i8 %25, i8* %3
br label %26
26: ; preds = %23, %13
%27 = load i8, i8* %4
%28 = zext i8 %27 to i32
%29 = icmp sgt i32 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %26
%31 = load i8, i8* %4
%32 = add i8 %31, -1
store i8 %32, i8* %4
br label %33
33: ; preds = %30, %26
%34 = load i8, i8* %5
%35 = zext i8 %34 to i32
%36 = icmp sgt i32 %35, 0
br i1 %36, label %37, label %40
37: ; preds = %33
%38 = load i8, i8* %5
%39 = add i8 %38, -1
store i8 %39, i8* %5
br label %40
40: ; preds = %37, %33
%41 = load i32, i32* %1
%42 = trunc i32 %41 to i8
%43 = call i32 @outp(i32 968, i8 zeroext %42)
%44 = load i8, i8* %3
%45 = call i32 @outp(i32 969, i8 zeroext %44)
%46 = load i8, i8* %4
%47 = call i32 @outp(i32 969, i8 zeroext %46)
%48 = load i8, i8* %5
%49 = call i32 @outp(i32 969, i8 zeroext %48)
br label %50
50: ; preds = %40
%51 = load i32, i32* %1
%52 = add nsw i32 %51, 1
store i32 %52, i32* %1
br label %10
53: ; preds = %10
%54 = call i32 (...) @retrace()
br label %55
55: ; preds = %53
%56 = load i32, i32* %2
%57 = add nsw i32 %56, 1
store i32 %57, i32* %2
br label %6
58: ; preds = %6
ret void
}

LLVM IR (-O2):
define void @fade_down() {
br label %1
1: ; preds = %0, %25
%2 = phi i32 [ 0, %0 ], [ %27, %25 ]
br label %3
3: ; preds = %1, %3
%4 = phi i32 [ 0, %1 ], [ %23, %3 ]
%5 = trunc i32 %4 to i8
%6 = tail call i32 @outp(i32 967, i8 zeroext %5)
%7 = tail call zeroext i8 @inp(i32 969)
%8 = tail call zeroext i8 @inp(i32 969)
%9 = tail call zeroext i8 @inp(i32 969)
%10 = icmp eq i8 %7, 0
%11 = add i8 %7, -1
%12 = select i1 %10, i8 0, i8 %11
%13 = icmp eq i8 %8, 0
%14 = add i8 %8, -1
%15 = select i1 %13, i8 0, i8 %14
%16 = icmp eq i8 %9, 0
%17 = add i8 %9, -1
%18 = select i1 %16, i8 0, i8 %17
%19 = tail call i32 @outp(i32 968, i8 zeroext %5)
%20 = tail call i32 @outp(i32 969, i8 zeroext %12)
%21 = tail call i32 @outp(i32 969, i8 zeroext %15)
%22 = tail call i32 @outp(i32 969, i8 zeroext %18)
%23 = add nuw nsw i32 %4, 1
%24 = icmp eq i32 %23, 256
br i1 %24, label %25, label %3
25: ; preds = %3
%26 = tail call i32 (...) @retrace()
%27 = add nuw nsw i32 %2, 1
%28 = icmp eq i32 %27, 64
br i1 %28, label %29, label %1
29: ; preds = %25
ret void
}