#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*/ clear32(int, int);
int /*<<< orphan*/ dbgprintf(char *, int, int, int);
int /*<<< orphan*/ memcpy(void *, void *, int);
int read32(int);
int /*<<< orphan*/ set32(int, int);
int /*<<< orphan*/ write32(int, int);
void DSPUpdateRegisters(void) {
  if (read32((0x00002480 + 0x28)) != 0xdeadbeef) {
    while (read32((0x00002480 + 0x20)) == 0xdeadbeef)
      ;
    write32(((0x00002480 + 0x40) + 0x20), read32((0x00002480 + 0x20)));
    write32((0x00002480 + 0x20), 0xdeadbeef);
    while (read32((0x00002480 + 0x24)) == 0xdeadbeef)
      ;
    write32(((0x00002480 + 0x40) + 0x24), read32((0x00002480 + 0x24)));
    write32((0x00002480 + 0x24), 0xdeadbeef);
    set32((0x0d800000 + 0xE0), 1 << 5);
    if (read32((0x00002480 + 0x28)) & (1 << 31)) {
      dbgprintf("DSP:DMA Transfer: 0x%08X->0x%08X Count:0x%08X\n",
                read32(((0x00002480 + 0x40) + 0x24)),
                read32(((0x00002480 + 0x40) + 0x20)),
                ((read32((0x00002480 + 0x28))) & 0x7FFFFFFF));
      memcpy((void *)((read32(((0x00002480 + 0x40) + 0x20))) & 0x7FFFFFFF),
             (void *)(read32(((0x00002480 + 0x40) + 0x24)) | 0x11000000),
             ((read32((0x00002480 + 0x28))) & 0x7FFFFFFF));
    } else {
      dbgprintf("DSP:DMA Transfer: 0x%08X->0x%08X Count:0x%08X\n",
                read32(((0x00002480 + 0x40) + 0x20)),
                read32(((0x00002480 + 0x40) + 0x24)),
                ((read32((0x00002480 + 0x28))) & 0x7FFFFFFF));
      memcpy((void *)(read32(((0x00002480 + 0x40) + 0x24)) | 0x11000000),
             (void *)((read32(((0x00002480 + 0x40) + 0x20))) & 0x7FFFFFFF),
             ((read32((0x00002480 + 0x28))) & 0x7FFFFFFF));
    }
    clear32((0x0d800000 + 0xE0), 1 << 5);
    write32(((0x00002480 + 0x40) + 0x28), read32((0x00002480 + 0x28)));
    write32((0x00002480 + 0x28), 0xdeadbeef);
  }
}


x86 assembly (clang, -O0):
<DSPUpdateRegisters>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    $0x24a8,%edi
call   1070 <read32@plt>
cmp    $0xdeadbeef,%eax
je     136e <DSPUpdateRegisters+0x20e>
jmp    1182 <DSPUpdateRegisters+0x22>
mov    $0x24a0,%edi
call   1070 <read32@plt>
cmp    $0xdeadbeef,%eax
jne    119c <DSPUpdateRegisters+0x3c>
jmp    1182 <DSPUpdateRegisters+0x22>
mov    $0x24a0,%edi
call   1070 <read32@plt>
mov    %eax,%esi
mov    $0x24e0,%edi
call   1030 <write32@plt>
mov    $0x24a0,%edi
mov    $0xdeadbeef,%esi
call   1030 <write32@plt>
mov    $0x24a4,%edi
call   1070 <read32@plt>
cmp    $0xdeadbeef,%eax
jne    11db <DSPUpdateRegisters+0x7b>
jmp    11c1 <DSPUpdateRegisters+0x61>
mov    $0x24a4,%edi
call   1070 <read32@plt>
mov    %eax,%esi
mov    $0x24e4,%edi
call   1030 <write32@plt>
mov    $0x24a4,%edi
mov    $0xdeadbeef,%esi
call   1030 <write32@plt>
mov    $0xd8000e0,%edi
mov    $0x20,%esi
call   1040 <set32@plt>
mov    $0x24a8,%edi
call   1070 <read32@plt>
and    $0x80000000,%eax
cmp    $0x0,%eax
je     12b3 <DSPUpdateRegisters+0x153>
mov    $0x24e4,%edi
call   1070 <read32@plt>
mov    %eax,-0x18(%rbp)
mov    $0x24e0,%edi
call   1070 <read32@plt>
mov    %eax,-0x14(%rbp)
mov    $0x24a8,%edi
call   1070 <read32@plt>
mov    -0x18(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    %eax,%ecx
and    $0x7fffffff,%ecx
lea    0xda0(%rip),%rdi
call   1060 <dbgprintf@plt>
mov    $0x24e0,%edi
call   1070 <read32@plt>
and    $0x7fffffff,%eax
cltq
mov    %rax,-0x10(%rbp)
mov    $0x24e4,%edi
call   1070 <read32@plt>
or     $0x11000000,%eax
cltq
mov    %rax,-0x8(%rbp)
mov    $0x24a8,%edi
call   1070 <read32@plt>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    %eax,%edx
and    $0x7fffffff,%edx
call   1050 <memcpy@plt>
jmp    133a <DSPUpdateRegisters+0x1da>
mov    $0x24e0,%edi
call   1070 <read32@plt>
mov    %eax,-0x30(%rbp)
mov    $0x24e4,%edi
call   1070 <read32@plt>
mov    %eax,-0x2c(%rbp)
mov    $0x24a8,%edi
call   1070 <read32@plt>
mov    -0x30(%rbp),%esi
mov    -0x2c(%rbp),%edx
mov    %eax,%ecx
and    $0x7fffffff,%ecx
lea    0xd14(%rip),%rdi
call   1060 <dbgprintf@plt>
mov    $0x24e4,%edi
call   1070 <read32@plt>
or     $0x11000000,%eax
cltq
mov    %rax,-0x28(%rbp)
mov    $0x24e0,%edi
call   1070 <read32@plt>
and    $0x7fffffff,%eax
cltq
mov    %rax,-0x20(%rbp)
mov    $0x24a8,%edi
call   1070 <read32@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    %eax,%edx
and    $0x7fffffff,%edx
call   1050 <memcpy@plt>
mov    $0xd8000e0,%edi
mov    $0x20,%esi
call   1080 <clear32@plt>
mov    $0x24a8,%edi
call   1070 <read32@plt>
mov    %eax,%esi
mov    $0x24e8,%edi
call   1030 <write32@plt>
mov    $0x24a8,%edi
mov    $0xdeadbeef,%esi
call   1030 <write32@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<DSPUpdateRegisters>:
push   %rbp
push   %rbx
push   %rax
mov    $0x24a8,%edi
call   1070 <read32@plt>
cmp    $0xdeadbeef,%eax
jne    1180 <DSPUpdateRegisters+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
nopl   0x0(%rax,%rax,1)
mov    $0x24a0,%edi
call   1070 <read32@plt>
cmp    $0xdeadbeef,%eax
je     1180 <DSPUpdateRegisters+0x20>
mov    $0x24a0,%edi
call   1070 <read32@plt>
mov    $0x24e0,%edi
mov    %eax,%esi
call   1030 <write32@plt>
mov    $0x24a0,%edi
mov    $0xdeadbeef,%esi
call   1030 <write32@plt>
cs nopw 0x0(%rax,%rax,1)
mov    $0x24a4,%edi
call   1070 <read32@plt>
cmp    $0xdeadbeef,%eax
je     11c0 <DSPUpdateRegisters+0x60>
mov    $0x24a4,%edi
call   1070 <read32@plt>
mov    $0x24e4,%edi
mov    %eax,%esi
call   1030 <write32@plt>
mov    $0x24a4,%edi
mov    $0xdeadbeef,%esi
call   1030 <write32@plt>
mov    $0xd8000e0,%edi
mov    $0x20,%esi
call   1040 <set32@plt>
mov    $0x24a8,%edi
call   1070 <read32@plt>
test   %eax,%eax
js     1272 <DSPUpdateRegisters+0x112>
mov    $0x24e0,%edi
call   1070 <read32@plt>
mov    %eax,%ebx
mov    $0x24e4,%edi
call   1070 <read32@plt>
mov    %eax,%ebp
mov    $0x24a8,%edi
call   1070 <read32@plt>
and    $0x7fffffff,%eax
lea    0xdbf(%rip),%rdi
mov    %ebx,%esi
mov    %ebp,%edx
mov    %eax,%ecx
call   1060 <dbgprintf@plt>
mov    $0x24e4,%edi
call   1070 <read32@plt>
or     $0x11000000,%eax
movslq %eax,%rbx
mov    $0x24e0,%edi
call   1070 <read32@plt>
mov    %eax,%ebp
and    $0x7fffffff,%ebp
jmp    12cf <DSPUpdateRegisters+0x16f>
mov    $0x24e4,%edi
call   1070 <read32@plt>
mov    %eax,%ebx
mov    $0x24e0,%edi
call   1070 <read32@plt>
mov    %eax,%ebp
mov    $0x24a8,%edi
call   1070 <read32@plt>
and    $0x7fffffff,%eax
lea    0xd60(%rip),%rdi
mov    %ebx,%esi
mov    %ebp,%edx
mov    %eax,%ecx
call   1060 <dbgprintf@plt>
mov    $0x24e0,%edi
call   1070 <read32@plt>
mov    %eax,%ebx
and    $0x7fffffff,%ebx
mov    $0x24e4,%edi
call   1070 <read32@plt>
or     $0x11000000,%eax
movslq %eax,%rbp
mov    $0x24a8,%edi
call   1070 <read32@plt>
and    $0x7fffffff,%eax
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %eax,%edx
call   1050 <memcpy@plt>
mov    $0xd8000e0,%edi
mov    $0x20,%esi
call   1080 <clear32@plt>
mov    $0x24a8,%edi
call   1070 <read32@plt>
mov    $0x24e8,%edi
mov    %eax,%esi
call   1030 <write32@plt>
mov    $0x24a8,%edi
mov    $0xdeadbeef,%esi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <write32@plt>

LLVM IR (-O0):
@.str = [47 x i8] c"DSP:DMA Transfer: 0x%08X->0x%08X Count:0x%08X\0A\00"
define void @DSPUpdateRegisters() {
%1 = call i32 @read32(i32 9384)
%2 = icmp ne i32 %1, -559038737
br i1 %2, label %3, label %63
3: ; preds = %0
br label %4
4: ; preds = %7, %3
%5 = call i32 @read32(i32 9376)
%6 = icmp eq i32 %5, -559038737
br i1 %6, label %7, label %8
7: ; preds = %4
br label %4
8: ; preds = %4
%9 = call i32 @read32(i32 9376)
%10 = call i32 @write32(i32 9440, i32 %9)
%11 = call i32 @write32(i32 9376, i32 -559038737)
br label %12
12: ; preds = %15, %8
%13 = call i32 @read32(i32 9380)
%14 = icmp eq i32 %13, -559038737
br i1 %14, label %15, label %16
15: ; preds = %12
br label %12
16: ; preds = %12
%17 = call i32 @read32(i32 9380)
%18 = call i32 @write32(i32 9444, i32 %17)
%19 = call i32 @write32(i32 9380, i32 -559038737)
%20 = call i32 @set32(i32 226492640, i32 32)
%21 = call i32 @read32(i32 9384)
%22 = and i32 %21, -2147483648
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %41
24: ; preds = %16
%25 = call i32 @read32(i32 9444)
%26 = call i32 @read32(i32 9440)
%27 = call i32 @read32(i32 9384)
%28 = and i32 %27, 2147483647
%29 = call i32 @dbgprintf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0), i32 %25, i32 %26, i32 %28)
%30 = call i32 @read32(i32 9440)
%31 = and i32 %30, 2147483647
%32 = sext i32 %31 to i64
%33 = inttoptr i64 %32 to i8*
%34 = call i32 @read32(i32 9444)
%35 = or i32 %34, 285212672
%36 = sext i32 %35 to i64
%37 = inttoptr i64 %36 to i8*
%38 = call i32 @read32(i32 9384)
%39 = and i32 %38, 2147483647
%40 = call i32 @memcpy(i8* %33, i8* %37, i32 %39)
br label %58
41: ; preds = %16
%42 = call i32 @read32(i32 9440)
%43 = call i32 @read32(i32 9444)
%44 = call i32 @read32(i32 9384)
%45 = and i32 %44, 2147483647
%46 = call i32 @dbgprintf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0), i32 %42, i32 %43, i32 %45)
%47 = call i32 @read32(i32 9444)
%48 = or i32 %47, 285212672
%49 = sext i32 %48 to i64
%50 = inttoptr i64 %49 to i8*
%51 = call i32 @read32(i32 9440)
%52 = and i32 %51, 2147483647
%53 = sext i32 %52 to i64
%54 = inttoptr i64 %53 to i8*
%55 = call i32 @read32(i32 9384)
%56 = and i32 %55, 2147483647
%57 = call i32 @memcpy(i8* %50, i8* %54, i32 %56)
br label %58
58: ; preds = %41, %24
%59 = call i32 @clear32(i32 226492640, i32 32)
%60 = call i32 @read32(i32 9384)
%61 = call i32 @write32(i32 9448, i32 %60)
%62 = call i32 @write32(i32 9384, i32 -559038737)
br label %63
63: ; preds = %58, %0
ret void
}

LLVM IR (-O2):
@.str = [47 x i8] c"DSP:DMA Transfer: 0x%08X->0x%08X Count:0x%08X\0A\00"
define void @DSPUpdateRegisters() {
%1 = tail call i32 @read32(i32 9384)
%2 = icmp eq i32 %1, -559038737
br i1 %2, label %59, label %3
3: ; preds = %0, %3
%4 = tail call i32 @read32(i32 9376)
%5 = icmp eq i32 %4, -559038737
br i1 %5, label %3, label %6
6: ; preds = %3
%7 = tail call i32 @read32(i32 9376)
%8 = tail call i32 @write32(i32 9440, i32 %7)
%9 = tail call i32 @write32(i32 9376, i32 -559038737)
br label %10
10: ; preds = %10, %6
%11 = tail call i32 @read32(i32 9380)
%12 = icmp eq i32 %11, -559038737
br i1 %12, label %10, label %13
13: ; preds = %10
%14 = tail call i32 @read32(i32 9380)
%15 = tail call i32 @write32(i32 9444, i32 %14)
%16 = tail call i32 @write32(i32 9380, i32 -559038737)
%17 = tail call i32 @set32(i32 226492640, i32 32)
%18 = tail call i32 @read32(i32 9384)
%19 = icmp sgt i32 %18, -1
br i1 %19, label %37, label %20
20: ; preds = %13
%21 = tail call i32 @read32(i32 9444)
%22 = tail call i32 @read32(i32 9440)
%23 = tail call i32 @read32(i32 9384)
%24 = and i32 %23, 2147483647
%25 = tail call i32 @dbgprintf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0), i32 %21, i32 %22, i32 %24)
%26 = tail call i32 @read32(i32 9440)
%27 = and i32 %26, 2147483647
%28 = zext i32 %27 to i64
%29 = inttoptr i64 %28 to i8*
%30 = tail call i32 @read32(i32 9444)
%31 = or i32 %30, 285212672
%32 = sext i32 %31 to i64
%33 = inttoptr i64 %32 to i8*
%34 = tail call i32 @read32(i32 9384)
%35 = and i32 %34, 2147483647
%36 = tail call i32 @memcpy(i8* %29, i8* %33, i32 %35)
br label %54
37: ; preds = %13
%38 = tail call i32 @read32(i32 9440)
%39 = tail call i32 @read32(i32 9444)
%40 = tail call i32 @read32(i32 9384)
%41 = and i32 %40, 2147483647
%42 = tail call i32 @dbgprintf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0), i32 %38, i32 %39, i32 %41)
%43 = tail call i32 @read32(i32 9444)
%44 = or i32 %43, 285212672
%45 = sext i32 %44 to i64
%46 = inttoptr i64 %45 to i8*
%47 = tail call i32 @read32(i32 9440)
%48 = and i32 %47, 2147483647
%49 = zext i32 %48 to i64
%50 = inttoptr i64 %49 to i8*
%51 = tail call i32 @read32(i32 9384)
%52 = and i32 %51, 2147483647
%53 = tail call i32 @memcpy(i8* %46, i8* %50, i32 %52)
br label %54
54: ; preds = %37, %20
%55 = tail call i32 @clear32(i32 226492640, i32 32)
%56 = tail call i32 @read32(i32 9384)
%57 = tail call i32 @write32(i32 9448, i32 %56)
%58 = tail call i32 @write32(i32 9384, i32 -559038737)
br label %59
59: ; preds = %54, %0
ret void
}