void init_background(int bg, int priority, int scrnblk) {
  volatile unsigned short *control;
  switch (bg) {
  case 0:
    control = (volatile unsigned short *)0x4000008;
    break;
  case 1:
    control = (volatile unsigned short *)0x400000a;
    break;
  case 2:
    control = (volatile unsigned short *)0x400000c;
    break;
  case 3:
    control = (volatile unsigned short *)0x400000e;
    break;
  }
  *control = priority | (0 << 2) | (0 << 6) | (1 << 7) | (scrnblk << 8) |
             (1 << 13) | (0 << 14);
}


x86 assembly (clang, -O0):
<init_background>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    -0x4(%rbp),%eax
mov    %rax,-0x20(%rbp)
sub    $0x3,%rax
ja     1165 <init_background+0x65>
mov    -0x20(%rbp),%rax
lea    0xed7(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    $0x4000008,%eax
mov    %rax,-0x18(%rbp)
jmp    1165 <init_background+0x65>
mov    $0x400000a,%eax
mov    %rax,-0x18(%rbp)
jmp    1165 <init_background+0x65>
mov    $0x400000c,%eax
mov    %rax,-0x18(%rbp)
jmp    1165 <init_background+0x65>
mov    $0x400000e,%eax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%eax
or     $0x0,%eax
or     $0x0,%eax
or     $0x80,%eax
mov    -0xc(%rbp),%ecx
shl    $0x8,%ecx
or     %ecx,%eax
or     $0x2000,%eax
or     $0x0,%eax
mov    %ax,%cx
mov    -0x18(%rbp),%rax
mov    %cx,(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<init_background>:
cmp    $0x3,%edi
je     111b <init_background+0x1b>
cmp    $0x2,%edi
je     1122 <init_background+0x22>
mov    $0x4000008,%eax
cmp    $0x1,%edi
jne    1127 <init_background+0x27>
mov    $0x400000a,%eax
jmp    1127 <init_background+0x27>
mov    $0x400000e,%eax
jmp    1127 <init_background+0x27>
mov    $0x400000c,%eax
shl    $0x8,%edx
or     %esi,%edx
or     $0x2080,%edx
mov    %dx,(%rax)
ret

LLVM IR (-O0):
define void @init_background(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i16*
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%8 = load i32, i32* %4
switch i32 %8, label %13 [
i32 0, label %9
i32 1, label %10
i32 2, label %11
i32 3, label %12
]
9: ; preds = %3
store i16* inttoptr (i64 67108872 to i16*), i16** %7
br label %13
10: ; preds = %3
store i16* inttoptr (i64 67108874 to i16*), i16** %7
br label %13
11: ; preds = %3
store i16* inttoptr (i64 67108876 to i16*), i16** %7
br label %13
12: ; preds = %3
store i16* inttoptr (i64 67108878 to i16*), i16** %7
br label %13
13: ; preds = %3, %12, %11, %10, %9
%14 = load i32, i32* %5
%15 = or i32 %14, 0
%16 = or i32 %15, 0
%17 = or i32 %16, 128
%18 = load i32, i32* %6
%19 = shl i32 %18, 8
%20 = or i32 %17, %19
%21 = or i32 %20, 8192
%22 = or i32 %21, 0
%23 = trunc i32 %22 to i16
%24 = load i16*, i16** %7
store volatile i16 %23, i16* %24
ret void
}

LLVM IR (-O2):
define void @init_background(i32 %0, i32 %1, i32 %2) {
switch i32 %0, label %7 [
i32 3, label %6
i32 1, label %4
i32 2, label %5
]
4: ; preds = %3
br label %7
5: ; preds = %3
br label %7
6: ; preds = %3
br label %7
7: ; preds = %3, %6, %5, %4
%8 = phi i16* [ inttoptr (i64 67108878 to i16*), %6 ], [ inttoptr (i64 67108876 to i16*), %5 ], [ inttoptr (i64 67108874 to i16*), %4 ], [ inttoptr (i64 67108872 to i16*), %3 ]
%9 = shl i32 %2, 8
%10 = or i32 %9, %1
%11 = trunc i32 %10 to i16
%12 = or i16 %11, 8320
store volatile i16 %12, i16* %8
ret void
}