#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 read_kernel_memory(unsigned long);
int /*<<< orphan*/ usleep(int);
int /*<<< orphan*/ write_kernel_memory(unsigned long, int);
int do_fade_step(int step, int steps, int scr_height, int ol) {
  int alpha = step * 255 / steps;
  int height = step * (scr_height) / steps;
  int cur_param;
  int cur_size;
  int on = (alpha) ? 1 : 0;
  unsigned long ol_param = 0x8002a220L;
  unsigned long ol_size = 0x8002a210L;
  if (ol == 1) {
    ol_param = 0x8002a260L;
    ol_size = 0x8002a250L;
  } else if (ol == 0) {
    ol_param = 0x8002a2a0L;
    ol_size = 0x8002a290L;
  }
  cur_param = read_kernel_memory(ol_param);
  cur_size = read_kernel_memory(ol_size);
  cur_param &= 0xffff00ffL;
  cur_size &= 0xffffff00L;
  write_kernel_memory(ol_param, cur_param | (alpha << 8) | on);
  write_kernel_memory(ol_size, cur_size | height);
  usleep(1000);
  return 0;
}


x86 assembly (clang, -O0):
<do_fade_step>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %ecx,-0x10(%rbp)
imul   $0xff,-0x4(%rbp),%eax
cltd
idivl  -0x8(%rbp)
mov    %eax,-0x14(%rbp)
mov    -0x4(%rbp),%eax
imul   -0xc(%rbp),%eax
cltd
idivl  -0x8(%rbp)
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%edx
xor    %eax,%eax
mov    $0x1,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %eax,-0x24(%rbp)
mov    $0x8002a220,%eax
mov    %rax,-0x30(%rbp)
mov    $0x8002a210,%eax
mov    %rax,-0x38(%rbp)
cmpl   $0x1,-0x10(%rbp)
jne    11a6 <do_fade_step+0x76>
mov    $0x8002a260,%eax
mov    %rax,-0x30(%rbp)
mov    $0x8002a250,%eax
mov    %rax,-0x38(%rbp)
jmp    11c7 <do_fade_step+0x97>
cmpl   $0x0,-0x10(%rbp)
jne    11c2 <do_fade_step+0x92>
mov    $0x8002a2a0,%eax
mov    %rax,-0x30(%rbp)
mov    $0x8002a290,%eax
mov    %rax,-0x38(%rbp)
jmp    11c7 <do_fade_step+0x97>
mov    -0x30(%rbp),%rdi
call   1030 <read_kernel_memory@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x38(%rbp),%rdi
call   1030 <read_kernel_memory@plt>
mov    %eax,-0x20(%rbp)
movslq -0x1c(%rbp),%rax
movabs $0xffff00ff,%rcx
and    %rcx,%rax
mov    %eax,-0x1c(%rbp)
movslq -0x20(%rbp),%rax
movabs $0xffffff00,%rcx
and    %rcx,%rax
mov    %eax,-0x20(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x14(%rbp),%eax
shl    $0x8,%eax
or     %eax,%esi
or     -0x24(%rbp),%esi
call   1040 <write_kernel_memory@plt>
mov    -0x38(%rbp),%rdi
mov    -0x20(%rbp),%esi
or     -0x18(%rbp),%esi
call   1040 <write_kernel_memory@plt>
mov    $0x3e8,%edi
call   1050 <usleep@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_fade_step>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r8d
mov    $0x8002a210,%r12d
mov    %edi,%eax
shl    $0x8,%eax
sub    %edi,%eax
cltd
idiv   %esi
mov    %eax,%ebp
cmp    $0x1,%ecx
je     116a <do_fade_step+0x3a>
test   %ecx,%ecx
jne    117b <do_fade_step+0x4b>
lea    0x80(%r12),%rax
add    $0x90,%r12
jmp    1173 <do_fade_step+0x43>
lea    0x40(%r12),%rax
add    $0x50,%r12
mov    %r12,%r14
mov    %rax,%r12
jmp    1180 <do_fade_step+0x50>
lea    0x10(%r12),%r14
xor    %r15d,%r15d
test   %ebp,%ebp
setne  %r15b
imul   %edi,%r8d
mov    %r8d,%eax
cltd
idiv   %esi
mov    %eax,0x4(%rsp)
mov    %r14,%rdi
call   1030 <read_kernel_memory@plt>
mov    %eax,%r13d
mov    %r12,%rdi
call   1030 <read_kernel_memory@plt>
mov    %eax,%ebx
and    $0xffff00ff,%r13d
and    $0xffffff00,%ebx
shl    $0x8,%ebp
or     %r15d,%ebp
or     %r13d,%ebp
mov    %r14,%rdi
mov    %ebp,%esi
call   1040 <write_kernel_memory@plt>
or     0x4(%rsp),%ebx
mov    %r12,%rdi
mov    %ebx,%esi
call   1040 <write_kernel_memory@plt>
mov    $0x3e8,%edi
call   1050 <usleep@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @do_fade_step(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i64
%15 = alloca i64
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%16 = load i32, i32* %5
%17 = mul nsw i32 %16, 255
%18 = load i32, i32* %6
%19 = sdiv i32 %17, %18
store i32 %19, i32* %9
%20 = load i32, i32* %5
%21 = load i32, i32* %7
%22 = mul nsw i32 %20, %21
%23 = load i32, i32* %6
%24 = sdiv i32 %22, %23
store i32 %24, i32* %10
%25 = load i32, i32* %9
%26 = icmp ne i32 %25, 0
%27 = zext i1 %26 to i64
%28 = select i1 %26, i32 1, i32 0
store i32 %28, i32* %13
store i64 2147656224, i64* %14
store i64 2147656208, i64* %15
%29 = load i32, i32* %8
%30 = icmp eq i32 %29, 1
br i1 %30, label %31, label %32
31: ; preds = %4
store i64 2147656288, i64* %14
store i64 2147656272, i64* %15
br label %37
32: ; preds = %4
%33 = load i32, i32* %8
%34 = icmp eq i32 %33, 0
br i1 %34, label %35, label %36
35: ; preds = %32
store i64 2147656352, i64* %14
store i64 2147656336, i64* %15
br label %36
36: ; preds = %35, %32
br label %37
37: ; preds = %36, %31
%38 = load i64, i64* %14
%39 = call i32 @read_kernel_memory(i64 %38)
store i32 %39, i32* %11
%40 = load i64, i64* %15
%41 = call i32 @read_kernel_memory(i64 %40)
store i32 %41, i32* %12
%42 = load i32, i32* %11
%43 = sext i32 %42 to i64
%44 = and i64 %43, 4294902015
%45 = trunc i64 %44 to i32
store i32 %45, i32* %11
%46 = load i32, i32* %12
%47 = sext i32 %46 to i64
%48 = and i64 %47, 4294967040
%49 = trunc i64 %48 to i32
store i32 %49, i32* %12
%50 = load i64, i64* %14
%51 = load i32, i32* %11
%52 = load i32, i32* %9
%53 = shl i32 %52, 8
%54 = or i32 %51, %53
%55 = load i32, i32* %13
%56 = or i32 %54, %55
%57 = call i32 @write_kernel_memory(i64 %50, i32 %56)
%58 = load i64, i64* %15
%59 = load i32, i32* %12
%60 = load i32, i32* %10
%61 = or i32 %59, %60
%62 = call i32 @write_kernel_memory(i64 %58, i32 %61)
%63 = call i32 @usleep(i32 1000)
ret i32 0
}

LLVM IR (-O2):
define i32 @do_fade_step(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = mul nsw i32 %0, 255
%6 = sdiv i32 %5, %1
switch i32 %3, label %8 [
i32 1, label %9
i32 0, label %7
]
7: ; preds = %4
br label %9
8: ; preds = %4
br label %9
9: ; preds = %4, %8, %7
%10 = phi i64 [ 2147656352, %7 ], [ 2147656288, %4 ], [ 2147656224, %8 ]
%11 = phi i64 [ 2147656336, %7 ], [ 2147656272, %4 ], [ 2147656208, %8 ]
%12 = icmp ne i32 %6, 0
%13 = zext i1 %12 to i32
%14 = mul nsw i32 %2, %0
%15 = sdiv i32 %14, %1
%16 = tail call i32 @read_kernel_memory(i64 %10)
%17 = tail call i32 @read_kernel_memory(i64 %11)
%18 = and i32 %16, -65281
%19 = and i32 %17, -256
%20 = shl i32 %6, 8
%21 = or i32 %20, %13
%22 = or i32 %21, %18
%23 = tail call i32 @write_kernel_memory(i64 %10, i32 %22)
%24 = or i32 %19, %15
%25 = tail call i32 @write_kernel_memory(i64 %11, i32 %24)
%26 = tail call i32 @usleep(i32 1000)
ret i32 0
}