#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*/ music_stop();
int /*<<< orphan*/ nmi_wait();
int /*<<< orphan*/ set_bright(int);
int /*<<< orphan*/ spc_volume(char);
void fade_screen(unsigned char in, unsigned char sound) {
  static unsigned char i;
  static char volume;
  volume = 127;
  for (i = 1; i < 16; ++i) {
    nmi_wait();
    if (in) {
      set_bright(i);
    } else {
      set_bright(15 - i);
      if (sound) {
        volume -= 8;
        if (volume < 0)
          volume = 0;
        spc_volume(volume);
      }
    }
  }
  if (!in && sound)
    music_stop();
}


x86 assembly (clang, -O0):
<fade_screen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %sil,%al
mov    %dil,%cl
mov    %cl,-0x1(%rbp)
mov    %al,-0x2(%rbp)
movb   $0x7f,0x2ee7(%rip)
movb   $0x1,0x2edf(%rip)
movzbl 0x2ed8(%rip),%eax
cmp    $0x10,%eax
jge    1201 <fade_screen+0xc1>
mov    $0x0,%al
call   1050 <nmi_wait@plt>
cmpb   $0x0,-0x1(%rbp)
je     1194 <fade_screen+0x54>
movzbl 0x2eb7(%rip),%edi
call   1040 <set_bright@plt>
jmp    11e9 <fade_screen+0xa9>
movzbl 0x2ea6(%rip),%eax
mov    $0xf,%edi
sub    %eax,%edi
call   1040 <set_bright@plt>
cmpb   $0x0,-0x2(%rbp)
je     11e4 <fade_screen+0xa4>
movsbl 0x2e8a(%rip),%eax
sub    $0x8,%eax
mov    %al,0x2e81(%rip)
movsbl 0x2e7a(%rip),%eax
cmp    $0x0,%eax
jge    11d8 <fade_screen+0x98>
movb   $0x0,0x2e6a(%rip)
movsbl 0x2e63(%rip),%edi
call   1030 <spc_volume@plt>
jmp    11e9 <fade_screen+0xa9>
jmp    11ee <fade_screen+0xae>
mov    0x2e4d(%rip),%al
add    $0x1,%al
mov    %al,0x2e45(%rip)
jmp    1162 <fade_screen+0x22>
cmpb   $0x0,-0x1(%rbp)
jne    121f <fade_screen+0xdf>
movzbl -0x2(%rbp),%eax
cmp    $0x0,%eax
je     121f <fade_screen+0xdf>
mov    $0x0,%al
call   1060 <music_stop@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fade_screen>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebx
mov    %edi,%ebp
movb   $0x7f,0x2ef3(%rip)
movb   $0x1,0x2eeb(%rip)
xor    %r14d,%r14d
jmp    1178 <fade_screen+0x38>
nopl   0x0(%rax,%rax,1)
call   1040 <set_bright@plt>
movzbl 0x2ed5(%rip),%eax
add    $0x1,%al
mov    %al,0x2ecd(%rip)
cmp    $0x10,%al
jae    11bd <fade_screen+0x7d>
xor    %eax,%eax
call   1050 <nmi_wait@plt>
movzbl 0x2ebb(%rip),%edi
test   %bpl,%bpl
jne    1160 <fade_screen+0x20>
mov    $0xf,%eax
sub    %edi,%eax
mov    %eax,%edi
call   1040 <set_bright@plt>
test   %bl,%bl
je     1165 <fade_screen+0x25>
movzbl 0x2e9e(%rip),%eax
add    $0xf8,%al
movzbl %al,%eax
cmovs  %r14d,%eax
mov    %al,0x2e8f(%rip)
movsbl %al,%edi
call   1030 <spc_volume@plt>
jmp    1165 <fade_screen+0x25>
test   %bpl,%bpl
jne    11d1 <fade_screen+0x91>
test   %bl,%bl
je     11d1 <fade_screen+0x91>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
jmp    1060 <music_stop@plt>
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@fade_screen.i = internal global i8 0
@fade_screen.volume = internal global i8 0
define void @fade_screen(i8 zeroext %0, i8 zeroext %1) {
%3 = alloca i8
%4 = alloca i8
store i8 %0, i8* %3
store i8 %1, i8* %4
store i8 127, i8* @fade_screen.volume
store i8 1, i8* @fade_screen.i
br label %5
5: ; preds = %38, %2
%6 = load i8, i8* @fade_screen.i
%7 = zext i8 %6 to i32
%8 = icmp slt i32 %7, 16
br i1 %8, label %9, label %41
9: ; preds = %5
%10 = call i32 (...) @nmi_wait()
%11 = load i8, i8* %3
%12 = icmp ne i8 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %9
%14 = load i8, i8* @fade_screen.i
%15 = zext i8 %14 to i32
%16 = call i32 @set_bright(i32 %15)
br label %37
17: ; preds = %9
%18 = load i8, i8* @fade_screen.i
%19 = zext i8 %18 to i32
%20 = sub nsw i32 15, %19
%21 = call i32 @set_bright(i32 %20)
%22 = load i8, i8* %4
%23 = icmp ne i8 %22, 0
br i1 %23, label %24, label %36
24: ; preds = %17
%25 = load i8, i8* @fade_screen.volume
%26 = sext i8 %25 to i32
%27 = sub nsw i32 %26, 8
%28 = trunc i32 %27 to i8
store i8 %28, i8* @fade_screen.volume
%29 = load i8, i8* @fade_screen.volume
%30 = sext i8 %29 to i32
%31 = icmp slt i32 %30, 0
br i1 %31, label %32, label %33
32: ; preds = %24
store i8 0, i8* @fade_screen.volume
br label %33
33: ; preds = %32, %24
%34 = load i8, i8* @fade_screen.volume
%35 = call i32 @spc_volume(i8 signext %34)
br label %36
36: ; preds = %33, %17
br label %37
37: ; preds = %36, %13
br label %38
38: ; preds = %37
%39 = load i8, i8* @fade_screen.i
%40 = add i8 %39, 1
store i8 %40, i8* @fade_screen.i
br label %5
41: ; preds = %5
%42 = load i8, i8* %3
%43 = icmp ne i8 %42, 0
br i1 %43, label %50, label %44
44: ; preds = %41
%45 = load i8, i8* %4
%46 = zext i8 %45 to i32
%47 = icmp ne i32 %46, 0
br i1 %47, label %48, label %50
48: ; preds = %44
%49 = call i32 (...) @music_stop()
br label %50
50: ; preds = %48, %44, %41
ret void
}

LLVM IR (-O2):
@fade_screen.i = internal unnamed_addr global i8 0
@fade_screen.volume = internal unnamed_addr global i8 0
define void @fade_screen(i8 zeroext %0, i8 zeroext %1) {
store i8 127, i8* @fade_screen.volume
store i8 1, i8* @fade_screen.i
%3 = icmp eq i8 %0, 0
%4 = icmp eq i8 %1, 0
br label %5
5: ; preds = %2, %20
%6 = tail call i32 (...) @nmi_wait()
%7 = load i8, i8* @fade_screen.i
%8 = zext i8 %7 to i32
br i1 %3, label %11, label %9
9: ; preds = %5
%10 = tail call i32 @set_bright(i32 %8)
br label %20
11: ; preds = %5
%12 = sub nsw i32 15, %8
%13 = tail call i32 @set_bright(i32 %12)
br i1 %4, label %20, label %14
14: ; preds = %11
%15 = load i8, i8* @fade_screen.volume
%16 = add i8 %15, -8
%17 = icmp sgt i8 %16, 0
%18 = select i1 %17, i8 %16, i8 0
store i8 %18, i8* @fade_screen.volume
%19 = tail call i32 @spc_volume(i8 signext %18)
br label %20
20: ; preds = %9, %14, %11
%21 = load i8, i8* @fade_screen.i
%22 = add i8 %21, 1
store i8 %22, i8* @fade_screen.i
%23 = icmp ult i8 %22, 16
br i1 %23, label %5, label %24
24: ; preds = %20
%25 = icmp ne i8 %1, 0
%26 = and i1 %3, %25
br i1 %26, label %27, label %29
27: ; preds = %24
%28 = tail call i32 (...) @music_stop()
br label %29
29: ; preds = %27, %24
ret void
}