#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 */
void wram_2M_to_1M(unsigned char *m) {
  unsigned short *m1M_b0, *m1M_b1;
  unsigned int i, tmp, *m2M;
  m2M = (unsigned int *)(m + 0x40000);
  m1M_b0 = (unsigned short *)m2M;
  m1M_b1 = (unsigned short *)(m + 0x60000);
  for (i = 0x40000 / 4; i; i--) {
    tmp = *(--m2M);
    *(--m1M_b0) = tmp;
    *(--m1M_b1) = tmp >> 16;
  }
}


x86 assembly (clang, -O0):
<wram_2M_to_1M>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40000,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
add    $0x60000,%rax
mov    %rax,-0x18(%rbp)
movl   $0x10000,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     1195 <wram_2M_to_1M+0x95>
mov    -0x28(%rbp),%rax
mov    %rax,%rcx
add    $0xfffffffffffffffc,%rcx
mov    %rcx,-0x28(%rbp)
mov    -0x4(%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    %ax,%cx
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0xfffffffffffffffe,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cx,-0x2(%rax)
mov    -0x20(%rbp),%eax
shr    $0x10,%eax
mov    %ax,%cx
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0xfffffffffffffffe,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cx,-0x2(%rax)
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
jmp    1133 <wram_2M_to_1M+0x33>
pop    %rbp
ret

x86 assembly (clang, -O2):
<wram_2M_to_1M>:
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movdqu 0x3ffe0(%rdi,%rax,4),%xmm0
movdqu 0x3fff0(%rdi,%rax,4),%xmm1
pshufd $0x1b,%xmm1,%xmm1
pshufd $0x1b,%xmm0,%xmm0
pshuflw $0xe8,%xmm1,%xmm2
pshufhw $0xe8,%xmm2,%xmm2
pshufd $0xe8,%xmm2,%xmm2
pshuflw $0x1b,%xmm2,%xmm2
pshuflw $0xe8,%xmm0,%xmm3
pshufhw $0xe8,%xmm3,%xmm3
pshufd $0xe8,%xmm3,%xmm3
pshuflw $0x1b,%xmm3,%xmm3
punpcklqdq %xmm2,%xmm3
movdqu %xmm3,0x3fff0(%rdi,%rax,2)
psrad  $0x10,%xmm1
packssdw %xmm1,%xmm1
psrad  $0x10,%xmm0
packssdw %xmm0,%xmm0
pshuflw $0x1b,%xmm1,%xmm1
pshuflw $0x1b,%xmm0,%xmm0
punpcklqdq %xmm1,%xmm0
movdqu %xmm0,0x5fff0(%rdi,%rax,2)
add    $0xfffffffffffffff8,%rax
cmp    $0xffffffffffff0000,%rax
jne    1110 <wram_2M_to_1M+0x10>
ret

LLVM IR (-O0):
define void @wram_2M_to_1M(i8* %0) {
%2 = alloca i8*
%3 = alloca i16*
%4 = alloca i16*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32*
store i8* %0, i8** %2
%8 = load i8*, i8** %2
%9 = getelementptr inbounds i8, i8* %8, i64 262144
%10 = bitcast i8* %9 to i32*
store i32* %10, i32** %7
%11 = load i32*, i32** %7
%12 = bitcast i32* %11 to i16*
store i16* %12, i16** %3
%13 = load i8*, i8** %2
%14 = getelementptr inbounds i8, i8* %13, i64 393216
%15 = bitcast i8* %14 to i16*
store i16* %15, i16** %4
store i32 65536, i32* %5
br label %16
16: ; preds = %32, %1
%17 = load i32, i32* %5
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %35
19: ; preds = %16
%20 = load i32*, i32** %7
%21 = getelementptr inbounds i32, i32* %20, i32 -1
store i32* %21, i32** %7
%22 = load i32, i32* %21
store i32 %22, i32* %6
%23 = load i32, i32* %6
%24 = trunc i32 %23 to i16
%25 = load i16*, i16** %3
%26 = getelementptr inbounds i16, i16* %25, i32 -1
store i16* %26, i16** %3
store i16 %24, i16* %26
%27 = load i32, i32* %6
%28 = lshr i32 %27, 16
%29 = trunc i32 %28 to i16
%30 = load i16*, i16** %4
%31 = getelementptr inbounds i16, i16* %30, i32 -1
store i16* %31, i16** %4
store i16 %29, i16* %31
br label %32
32: ; preds = %19
%33 = load i32, i32* %5
%34 = add i32 %33, -1
store i32 %34, i32* %5
br label %16
35: ; preds = %16
ret void
}

LLVM IR (-O2):
define void @wram_2M_to_1M(i8* nocapture %0) {
%2 = getelementptr i8, i8* %0, i64 262140
%3 = bitcast i8* %2 to i32*
%4 = getelementptr i8, i8* %0, i64 262142
%5 = bitcast i8* %4 to i16*
%6 = getelementptr i8, i8* %0, i64 393214
%7 = bitcast i8* %6 to i16*
br label %8
8: ; preds = %8, %1
%9 = phi i64 [ 0, %1 ], [ %45, %8 ]
%10 = sub i64 0, %9
%11 = sub i64 0, %9
%12 = sub i64 0, %9
%13 = getelementptr inbounds i32, i32* %3, i64 %10
%14 = getelementptr inbounds i32, i32* %13, i64 -3
%15 = bitcast i32* %14 to <4 x i32>*
%16 = load <4 x i32>, <4 x i32>* %15
%17 = shufflevector <4 x i32> %16, <4 x i32> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
%18 = getelementptr inbounds i32, i32* %13, i64 -4
%19 = getelementptr inbounds i32, i32* %18, i64 -3
%20 = bitcast i32* %19 to <4 x i32>*
%21 = load <4 x i32>, <4 x i32>* %20
%22 = shufflevector <4 x i32> %21, <4 x i32> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
%23 = trunc <4 x i32> %17 to <4 x i16>
%24 = trunc <4 x i32> %22 to <4 x i16>
%25 = getelementptr inbounds i16, i16* %5, i64 %11
%26 = shufflevector <4 x i16> %23, <4 x i16> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
%27 = getelementptr inbounds i16, i16* %25, i64 -3
%28 = bitcast i16* %27 to <4 x i16>*
store <4 x i16> %26, <4 x i16>* %28
%29 = shufflevector <4 x i16> %24, <4 x i16> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
%30 = getelementptr inbounds i16, i16* %25, i64 -4
%31 = getelementptr inbounds i16, i16* %30, i64 -3
%32 = bitcast i16* %31 to <4 x i16>*
store <4 x i16> %29, <4 x i16>* %32
%33 = lshr <4 x i32> %17, <i32 16, i32 16, i32 16, i32 16>
%34 = lshr <4 x i32> %22, <i32 16, i32 16, i32 16, i32 16>
%35 = trunc <4 x i32> %33 to <4 x i16>
%36 = trunc <4 x i32> %34 to <4 x i16>
%37 = getelementptr inbounds i16, i16* %7, i64 %12
%38 = shufflevector <4 x i16> %35, <4 x i16> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
%39 = getelementptr inbounds i16, i16* %37, i64 -3
%40 = bitcast i16* %39 to <4 x i16>*
store <4 x i16> %38, <4 x i16>* %40
%41 = shufflevector <4 x i16> %36, <4 x i16> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
%42 = getelementptr inbounds i16, i16* %37, i64 -4
%43 = getelementptr inbounds i16, i16* %42, i64 -3
%44 = bitcast i16* %43 to <4 x i16>*
store <4 x i16> %41, <4 x i16>* %44
%45 = add nuw i64 %9, 8
%46 = icmp eq i64 %45, 65536
br i1 %46, label %47, label %8
47: ; preds = %8
ret void
}