#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*/ d2a_wait();
void set_d2a(int power, int channel) {
  int i, data;
  data = (power & 0xFF) | channel;
  (*((volatile unsigned long *)0xE002800C)) = (1 << 21);
  d2a_wait();
  for (i = 11; i >= 0; i--) {
    (*((volatile unsigned long *)0xE002800C)) = (1 << 4);
    d2a_wait();
    if (data & (1 << i)) {
      (*((volatile unsigned long *)0xE0028004)) = (1 << 6);
    } else {
      (*((volatile unsigned long *)0xE002800C)) = (1 << 6);
    }
    d2a_wait();
    (*((volatile unsigned long *)0xE0028004)) = (1 << 4);
    d2a_wait();
  }
  (*((volatile unsigned long *)0xE002800C)) = (1 << 4);
  d2a_wait();
  (*((volatile unsigned long *)0xE0028004)) = (1 << 21);
  d2a_wait();
}


x86 assembly (clang, -O0):
<set_d2a>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%eax
and    $0xff,%eax
or     -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    $0xe002800c,%eax
movq   $0x200000,(%rax)
mov    $0x0,%al
call   1030 <d2a_wait@plt>
movl   $0xb,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jl     11c2 <set_d2a+0xb2>
mov    $0xe002800c,%eax
movq   $0x10,(%rax)
mov    $0x0,%al
call   1030 <d2a_wait@plt>
mov    -0x10(%rbp),%eax
mov    -0xc(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     118e <set_d2a+0x7e>
mov    $0xe0028004,%eax
movq   $0x40,(%rax)
jmp    119a <set_d2a+0x8a>
mov    $0xe002800c,%eax
movq   $0x40,(%rax)
mov    $0x0,%al
call   1030 <d2a_wait@plt>
mov    $0xe0028004,%eax
movq   $0x10,(%rax)
mov    $0x0,%al
call   1030 <d2a_wait@plt>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    1146 <set_d2a+0x36>
mov    $0xe002800c,%eax
movq   $0x10,(%rax)
mov    $0x0,%al
call   1030 <d2a_wait@plt>
mov    $0xe0028004,%eax
movq   $0x200000,(%rax)
mov    $0x0,%al
call   1030 <d2a_wait@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_d2a>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r15d
movzbl %dil,%r14d
or     %esi,%r14d
mov    $0xe002800c,%ebx
movq   $0x200000,(%rbx)
xor    %eax,%eax
call   1030 <d2a_wait@plt>
movq   $0x10,(%rbx)
xor    %eax,%eax
call   1030 <d2a_wait@plt>
lea    -0x8(%rbx),%rbp
test   $0x800,%r15d
mov    %rbp,%rax
cmove  %rbx,%rax
movq   $0x40,(%rax)
xor    %eax,%eax
call   1030 <d2a_wait@plt>
movq   $0x10,-0x8(%rbx)
xor    %eax,%eax
call   1030 <d2a_wait@plt>
movq   $0x10,(%rbx)
xor    %eax,%eax
call   1030 <d2a_wait@plt>
test   $0x400,%r15d
mov    %rbp,%rax
cmove  %rbx,%rax
movq   $0x40,(%rax)
xor    %eax,%eax
call   1030 <d2a_wait@plt>
movq   $0x10,-0x8(%rbx)
xor    %eax,%eax
call   1030 <d2a_wait@plt>
movq   $0x10,(%rbx)
xor    %eax,%eax
call   1030 <d2a_wait@plt>
test   $0x200,%r15d
mov    %rbp,%rax
cmove  %rbx,%rax
movq   $0x40,(%rax)
xor    %eax,%eax
call   1030 <d2a_wait@plt>
movq   $0x10,-0x8(%rbx)
xor    %eax,%eax
call   1030 <d2a_wait@plt>
movq   $0x10,(%rbx)
xor    %eax,%eax
call   1030 <d2a_wait@plt>
test   $0x100,%r15d
mov    %rbp,%rax
cmove  %rbx,%rax
movq   $0x40,(%rax)
xor    %eax,%eax
call   1030 <d2a_wait@plt>
movq   $0x10,-0x8(%rbx)
xor    %eax,%eax
call   1030 <d2a_wait@plt>
movq   $0x10,(%rbx)
xor    %eax,%eax
call   1030 <d2a_wait@plt>
test   $0x80,%r14b
mov    %rbp,%rax
cmove  %rbx,%rax
movq   $0x40,(%rax)
xor    %eax,%eax
call   1030 <d2a_wait@plt>
movq   $0x10,-0x8(%rbx)
xor    %eax,%eax
call   1030 <d2a_wait@plt>
movq   $0x10,(%rbx)
xor    %eax,%eax
call   1030 <d2a_wait@plt>
test   $0x40,%r14b
mov    %rbp,%rax
cmove  %rbx,%rax
movq   $0x40,(%rax)
xor    %eax,%eax
call   1030 <d2a_wait@plt>
movq   $0x10,-0x8(%rbx)
xor    %eax,%eax
call   1030 <d2a_wait@plt>
movq   $0x10,(%rbx)
xor    %eax,%eax
call   1030 <d2a_wait@plt>
test   $0x20,%r14b
mov    %rbp,%rax
cmove  %rbx,%rax
movq   $0x40,(%rax)
xor    %eax,%eax
call   1030 <d2a_wait@plt>
movq   $0x10,-0x8(%rbx)
xor    %eax,%eax
call   1030 <d2a_wait@plt>
movq   $0x10,(%rbx)
xor    %eax,%eax
call   1030 <d2a_wait@plt>
test   $0x10,%r14b
mov    %rbp,%rax
cmove  %rbx,%rax
movq   $0x40,(%rax)
xor    %eax,%eax
call   1030 <d2a_wait@plt>
movq   $0x10,-0x8(%rbx)
xor    %eax,%eax
call   1030 <d2a_wait@plt>
movq   $0x10,(%rbx)
xor    %eax,%eax
call   1030 <d2a_wait@plt>
test   $0x8,%r14b
mov    %rbp,%rax
cmove  %rbx,%rax
movq   $0x40,(%rax)
xor    %eax,%eax
call   1030 <d2a_wait@plt>
movq   $0x10,-0x8(%rbx)
xor    %eax,%eax
call   1030 <d2a_wait@plt>
movq   $0x10,(%rbx)
xor    %eax,%eax
call   1030 <d2a_wait@plt>
test   $0x4,%r14b
mov    %rbp,%rax
cmove  %rbx,%rax
movq   $0x40,(%rax)
xor    %eax,%eax
call   1030 <d2a_wait@plt>
movq   $0x10,-0x8(%rbx)
xor    %eax,%eax
call   1030 <d2a_wait@plt>
movq   $0x10,(%rbx)
xor    %eax,%eax
call   1030 <d2a_wait@plt>
test   $0x2,%r14b
mov    %rbp,%rax
cmove  %rbx,%rax
movq   $0x40,(%rax)
xor    %eax,%eax
call   1030 <d2a_wait@plt>
movq   $0x10,-0x8(%rbx)
xor    %eax,%eax
call   1030 <d2a_wait@plt>
movq   $0x10,(%rbx)
xor    %eax,%eax
call   1030 <d2a_wait@plt>
test   $0x1,%r14b
cmove  %rbx,%rbp
movq   $0x40,0x0(%rbp)
xor    %eax,%eax
call   1030 <d2a_wait@plt>
movq   $0x10,-0x8(%rbx)
xor    %eax,%eax
call   1030 <d2a_wait@plt>
movq   $0x10,(%rbx)
xor    %eax,%eax
call   1030 <d2a_wait@plt>
movq   $0x200000,-0x8(%rbx)
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <d2a_wait@plt>

LLVM IR (-O0):
define void @set_d2a(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%7 = load i32, i32* %3
%8 = and i32 %7, 255
%9 = load i32, i32* %4
%10 = or i32 %8, %9
store i32 %10, i32* %6
store volatile i64 2097152, i64* inttoptr (i64 3758260236 to i64*)
%11 = call i32 (...) @d2a_wait()
store i32 11, i32* %5
br label %12
12: ; preds = %27, %2
%13 = load i32, i32* %5
%14 = icmp sge i32 %13, 0
br i1 %14, label %15, label %30
15: ; preds = %12
store volatile i64 16, i64* inttoptr (i64 3758260236 to i64*)
%16 = call i32 (...) @d2a_wait()
%17 = load i32, i32* %6
%18 = load i32, i32* %5
%19 = shl i32 1, %18
%20 = and i32 %17, %19
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %15
store volatile i64 64, i64* inttoptr (i64 3758260228 to i64*)
br label %24
23: ; preds = %15
store volatile i64 64, i64* inttoptr (i64 3758260236 to i64*)
br label %24
24: ; preds = %23, %22
%25 = call i32 (...) @d2a_wait()
store volatile i64 16, i64* inttoptr (i64 3758260228 to i64*)
%26 = call i32 (...) @d2a_wait()
br label %27
27: ; preds = %24
%28 = load i32, i32* %5
%29 = add nsw i32 %28, -1
store i32 %29, i32* %5
br label %12
30: ; preds = %12
store volatile i64 16, i64* inttoptr (i64 3758260236 to i64*)
%31 = call i32 (...) @d2a_wait()
store volatile i64 2097152, i64* inttoptr (i64 3758260228 to i64*)
%32 = call i32 (...) @d2a_wait()
ret void
}

LLVM IR (-O2):
define void @set_d2a(i32 %0, i32 %1) {
%3 = and i32 %0, 255
%4 = or i32 %3, %1
store volatile i64 2097152, i64* inttoptr (i64 3758260236 to i64*)
%5 = tail call i32 (...) @d2a_wait()
store volatile i64 16, i64* inttoptr (i64 3758260236 to i64*)
%6 = tail call i32 (...) @d2a_wait()
%7 = and i32 %1, 2048
%8 = icmp eq i32 %7, 0
%9 = select i1 %8, i64* inttoptr (i64 3758260236 to i64*), i64* inttoptr (i64 3758260228 to i64*)
store volatile i64 64, i64* %9
%10 = tail call i32 (...) @d2a_wait()
store volatile i64 16, i64* inttoptr (i64 3758260228 to i64*)
%11 = tail call i32 (...) @d2a_wait()
store volatile i64 16, i64* inttoptr (i64 3758260236 to i64*)
%12 = tail call i32 (...) @d2a_wait()
%13 = and i32 %1, 1024
%14 = icmp eq i32 %13, 0
%15 = select i1 %14, i64* inttoptr (i64 3758260236 to i64*), i64* inttoptr (i64 3758260228 to i64*)
store volatile i64 64, i64* %15
%16 = tail call i32 (...) @d2a_wait()
store volatile i64 16, i64* inttoptr (i64 3758260228 to i64*)
%17 = tail call i32 (...) @d2a_wait()
store volatile i64 16, i64* inttoptr (i64 3758260236 to i64*)
%18 = tail call i32 (...) @d2a_wait()
%19 = and i32 %1, 512
%20 = icmp eq i32 %19, 0
%21 = select i1 %20, i64* inttoptr (i64 3758260236 to i64*), i64* inttoptr (i64 3758260228 to i64*)
store volatile i64 64, i64* %21
%22 = tail call i32 (...) @d2a_wait()
store volatile i64 16, i64* inttoptr (i64 3758260228 to i64*)
%23 = tail call i32 (...) @d2a_wait()
store volatile i64 16, i64* inttoptr (i64 3758260236 to i64*)
%24 = tail call i32 (...) @d2a_wait()
%25 = and i32 %1, 256
%26 = icmp eq i32 %25, 0
%27 = select i1 %26, i64* inttoptr (i64 3758260236 to i64*), i64* inttoptr (i64 3758260228 to i64*)
store volatile i64 64, i64* %27
%28 = tail call i32 (...) @d2a_wait()
store volatile i64 16, i64* inttoptr (i64 3758260228 to i64*)
%29 = tail call i32 (...) @d2a_wait()
store volatile i64 16, i64* inttoptr (i64 3758260236 to i64*)
%30 = tail call i32 (...) @d2a_wait()
%31 = and i32 %4, 128
%32 = icmp eq i32 %31, 0
%33 = select i1 %32, i64* inttoptr (i64 3758260236 to i64*), i64* inttoptr (i64 3758260228 to i64*)
store volatile i64 64, i64* %33
%34 = tail call i32 (...) @d2a_wait()
store volatile i64 16, i64* inttoptr (i64 3758260228 to i64*)
%35 = tail call i32 (...) @d2a_wait()
store volatile i64 16, i64* inttoptr (i64 3758260236 to i64*)
%36 = tail call i32 (...) @d2a_wait()
%37 = and i32 %4, 64
%38 = icmp eq i32 %37, 0
%39 = select i1 %38, i64* inttoptr (i64 3758260236 to i64*), i64* inttoptr (i64 3758260228 to i64*)
store volatile i64 64, i64* %39
%40 = tail call i32 (...) @d2a_wait()
store volatile i64 16, i64* inttoptr (i64 3758260228 to i64*)
%41 = tail call i32 (...) @d2a_wait()
store volatile i64 16, i64* inttoptr (i64 3758260236 to i64*)
%42 = tail call i32 (...) @d2a_wait()
%43 = and i32 %4, 32
%44 = icmp eq i32 %43, 0
%45 = select i1 %44, i64* inttoptr (i64 3758260236 to i64*), i64* inttoptr (i64 3758260228 to i64*)
store volatile i64 64, i64* %45
%46 = tail call i32 (...) @d2a_wait()
store volatile i64 16, i64* inttoptr (i64 3758260228 to i64*)
%47 = tail call i32 (...) @d2a_wait()
store volatile i64 16, i64* inttoptr (i64 3758260236 to i64*)
%48 = tail call i32 (...) @d2a_wait()
%49 = and i32 %4, 16
%50 = icmp eq i32 %49, 0
%51 = select i1 %50, i64* inttoptr (i64 3758260236 to i64*), i64* inttoptr (i64 3758260228 to i64*)
store volatile i64 64, i64* %51
%52 = tail call i32 (...) @d2a_wait()
store volatile i64 16, i64* inttoptr (i64 3758260228 to i64*)
%53 = tail call i32 (...) @d2a_wait()
store volatile i64 16, i64* inttoptr (i64 3758260236 to i64*)
%54 = tail call i32 (...) @d2a_wait()
%55 = and i32 %4, 8
%56 = icmp eq i32 %55, 0
%57 = select i1 %56, i64* inttoptr (i64 3758260236 to i64*), i64* inttoptr (i64 3758260228 to i64*)
store volatile i64 64, i64* %57
%58 = tail call i32 (...) @d2a_wait()
store volatile i64 16, i64* inttoptr (i64 3758260228 to i64*)
%59 = tail call i32 (...) @d2a_wait()
store volatile i64 16, i64* inttoptr (i64 3758260236 to i64*)
%60 = tail call i32 (...) @d2a_wait()
%61 = and i32 %4, 4
%62 = icmp eq i32 %61, 0
%63 = select i1 %62, i64* inttoptr (i64 3758260236 to i64*), i64* inttoptr (i64 3758260228 to i64*)
store volatile i64 64, i64* %63
%64 = tail call i32 (...) @d2a_wait()
store volatile i64 16, i64* inttoptr (i64 3758260228 to i64*)
%65 = tail call i32 (...) @d2a_wait()
store volatile i64 16, i64* inttoptr (i64 3758260236 to i64*)
%66 = tail call i32 (...) @d2a_wait()
%67 = and i32 %4, 2
%68 = icmp eq i32 %67, 0
%69 = select i1 %68, i64* inttoptr (i64 3758260236 to i64*), i64* inttoptr (i64 3758260228 to i64*)
store volatile i64 64, i64* %69
%70 = tail call i32 (...) @d2a_wait()
store volatile i64 16, i64* inttoptr (i64 3758260228 to i64*)
%71 = tail call i32 (...) @d2a_wait()
store volatile i64 16, i64* inttoptr (i64 3758260236 to i64*)
%72 = tail call i32 (...) @d2a_wait()
%73 = and i32 %4, 1
%74 = icmp eq i32 %73, 0
%75 = select i1 %74, i64* inttoptr (i64 3758260236 to i64*), i64* inttoptr (i64 3758260228 to i64*)
store volatile i64 64, i64* %75
%76 = tail call i32 (...) @d2a_wait()
store volatile i64 16, i64* inttoptr (i64 3758260228 to i64*)
%77 = tail call i32 (...) @d2a_wait()
store volatile i64 16, i64* inttoptr (i64 3758260236 to i64*)
%78 = tail call i32 (...) @d2a_wait()
store volatile i64 2097152, i64* inttoptr (i64 3758260228 to i64*)
%79 = tail call i32 (...) @d2a_wait()
ret void
}