#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*/ RamRead32A(int, unsigned long *);
int /*<<< orphan*/ RamWrite32A(int, int);
void DacControl(unsigned char UcMode, unsigned long UiChannel,
                unsigned long PuiData) {
  unsigned long UlAddaInt;
  if (!UcMode) {
    RamWrite32A(0xC000, 0x0004 + 0x0004 + 0x0004 + 0x0004 + 0x0004 + 0x0004 +
                            0x0004 + 0x0004 + 0x0004 + 0x0004 + 0x0004 +
                            0x0004 + 0x0004 + 0x0004 + 0x0004 + 0x0004 +
                            0x0004 + 0x0004 + 0x0004 + 0x0004 + 0x0000 +
                            0xD01000);
    RamWrite32A(0xD000, UiChannel);
    RamWrite32A(0xC000, 0x0004 + 0x0004 + 0x0004 + 0x0004 + 0x0004 + 0x0004 +
                            0x0004 + 0x0004 + 0x0004 + 0x0004 + 0x0004 +
                            0x0004 + 0x0004 + 0x0004 + 0x0004 + 0x0004 +
                            0x0004 + 0x0004 + 0x0004 + 0x0004 + 0x0004 +
                            0x0000 + 0xD01000);
    RamWrite32A(0xD000, PuiData);
    ;
    ;
    UlAddaInt = 0x00000040;
    while ((UlAddaInt & 0x00000040) != 0) {
      RamWrite32A(0xC000, 0x0004 + 0x0004 + 0x0004 + 0x0000 + 0xD01000);
      RamRead32A(0xD000, &UlAddaInt);
      ;
    }
  } else {
    RamWrite32A(0xC000, 0x0004 + 0x0004 + 0x0004 + 0x0004 + 0x0004 + 0x0004 +
                            0x0004 + 0x0004 + 0x0004 + 0x0004 + 0x0004 +
                            0x0004 + 0x0004 + 0x0004 + 0x0004 + 0x0004 +
                            0x0004 + 0x0004 + 0x0004 + 0x0004 + 0x0000 +
                            0xD01000);
    RamWrite32A(0xD000, UiChannel);
    RamWrite32A(0xC000, 0x0004 + 0x0004 + 0x0004 + 0x0004 + 0x0004 + 0x0004 +
                            0x0004 + 0x0004 + 0x0004 + 0x0004 + 0x0004 +
                            0x0004 + 0x0004 + 0x0004 + 0x0004 + 0x0004 +
                            0x0004 + 0x0004 + 0x0004 + 0x0004 + 0x0004 +
                            0x0000 + 0xD01000);
    RamRead32A(0xD000, &PuiData);
    ;
    ;
    UlAddaInt = 0x00000040;
    while ((UlAddaInt & 0x00000040) != 0) {
      RamWrite32A(0xC000, 0x0004 + 0x0004 + 0x0004 + 0x0000 + 0xD01000);
      RamRead32A(0xD000, &UlAddaInt);
      ;
    }
  }
  return;
}


x86 assembly (clang, -O0):
<DacControl>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
cmpb   $0x0,-0x1(%rbp)
jne    11bf <DacControl+0x9f>
mov    $0xc000,%edi
mov    $0xd01050,%esi
call   1040 <RamWrite32A@plt>
mov    -0x10(%rbp),%rax
mov    %eax,%esi
mov    $0xd000,%edi
call   1040 <RamWrite32A@plt>
mov    $0xc000,%edi
mov    $0xd01054,%esi
call   1040 <RamWrite32A@plt>
mov    -0x18(%rbp),%rax
mov    %eax,%esi
mov    $0xd000,%edi
call   1040 <RamWrite32A@plt>
movq   $0x40,-0x20(%rbp)
mov    -0x20(%rbp),%rax
and    $0x40,%rax
cmp    $0x0,%rax
je     11ba <DacControl+0x9a>
mov    $0xc000,%edi
mov    $0xd0100c,%esi
call   1040 <RamWrite32A@plt>
mov    $0xd000,%edi
lea    -0x20(%rbp),%rsi
call   1030 <RamRead32A@plt>
jmp    1186 <DacControl+0x66>
jmp    123c <DacControl+0x11c>
mov    $0xc000,%edi
mov    $0xd01050,%esi
call   1040 <RamWrite32A@plt>
mov    -0x10(%rbp),%rax
mov    %eax,%esi
mov    $0xd000,%edi
call   1040 <RamWrite32A@plt>
mov    $0xc000,%edi
mov    $0xd01054,%esi
call   1040 <RamWrite32A@plt>
mov    $0xd000,%edi
lea    -0x18(%rbp),%rsi
call   1030 <RamRead32A@plt>
movq   $0x40,-0x20(%rbp)
mov    -0x20(%rbp),%rax
and    $0x40,%rax
cmp    $0x0,%rax
je     1237 <DacControl+0x117>
mov    $0xc000,%edi
mov    $0xd0100c,%esi
call   1040 <RamWrite32A@plt>
mov    $0xd000,%edi
lea    -0x20(%rbp),%rsi
call   1030 <RamRead32A@plt>
jmp    1203 <DacControl+0xe3>
jmp    123c <DacControl+0x11c>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<DacControl>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %edi,%ebp
mov    %rdx,0x8(%rsp)
mov    $0xc000,%edi
mov    $0xd01050,%esi
call   1040 <RamWrite32A@plt>
mov    $0xd000,%edi
mov    %ebx,%esi
call   1040 <RamWrite32A@plt>
mov    $0xc000,%edi
mov    $0xd01054,%esi
call   1040 <RamWrite32A@plt>
test   %ebp,%ebp
je     11a4 <DacControl+0x84>
lea    0x8(%rsp),%rsi
mov    $0xd000,%edi
call   1030 <RamRead32A@plt>
movq   $0x40,(%rsp)
mov    %rsp,%rbx
nopl   (%rax)
mov    $0xc000,%edi
mov    $0xd0100c,%esi
call   1040 <RamWrite32A@plt>
mov    $0xd000,%edi
mov    %rbx,%rsi
call   1030 <RamRead32A@plt>
testb  $0x40,(%rsp)
jne    1180 <DacControl+0x60>
jmp    11e2 <DacControl+0xc2>
mov    $0xd000,%edi
mov    %r14d,%esi
call   1040 <RamWrite32A@plt>
movq   $0x40,(%rsp)
mov    %rsp,%rbx
nopl   0x0(%rax)
mov    $0xc000,%edi
mov    $0xd0100c,%esi
call   1040 <RamWrite32A@plt>
mov    $0xd000,%edi
mov    %rbx,%rsi
call   1030 <RamRead32A@plt>
testb  $0x40,(%rsp)
jne    11c0 <DacControl+0xa0>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define void @DacControl(i8 zeroext %0, i64 %1, i64 %2) {
%4 = alloca i8
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
store i8 %0, i8* %4
store i64 %1, i64* %5
store i64 %2, i64* %6
%8 = load i8, i8* %4
%9 = icmp ne i8 %8, 0
br i1 %9, label %27, label %10
10: ; preds = %3
%11 = call i32 @RamWrite32A(i32 49152, i32 13635664)
%12 = load i64, i64* %5
%13 = trunc i64 %12 to i32
%14 = call i32 @RamWrite32A(i32 53248, i32 %13)
%15 = call i32 @RamWrite32A(i32 49152, i32 13635668)
%16 = load i64, i64* %6
%17 = trunc i64 %16 to i32
%18 = call i32 @RamWrite32A(i32 53248, i32 %17)
store i64 64, i64* %7
br label %19
19: ; preds = %23, %10
%20 = load i64, i64* %7
%21 = and i64 %20, 64
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %19
%24 = call i32 @RamWrite32A(i32 49152, i32 13635596)
%25 = call i32 @RamRead32A(i32 53248, i64* %7)
br label %19
26: ; preds = %19
br label %42
27: ; preds = %3
%28 = call i32 @RamWrite32A(i32 49152, i32 13635664)
%29 = load i64, i64* %5
%30 = trunc i64 %29 to i32
%31 = call i32 @RamWrite32A(i32 53248, i32 %30)
%32 = call i32 @RamWrite32A(i32 49152, i32 13635668)
%33 = call i32 @RamRead32A(i32 53248, i64* %6)
store i64 64, i64* %7
br label %34
34: ; preds = %38, %27
%35 = load i64, i64* %7
%36 = and i64 %35, 64
%37 = icmp ne i64 %36, 0
br i1 %37, label %38, label %41
38: ; preds = %34
%39 = call i32 @RamWrite32A(i32 49152, i32 13635596)
%40 = call i32 @RamRead32A(i32 53248, i64* %7)
br label %34
41: ; preds = %34
br label %42
42: ; preds = %41, %26
ret void
}

LLVM IR (-O2):
define void @DacControl(i8 zeroext %0, i64 %1, i64 %2) {
%4 = alloca i64
%5 = alloca i64
store i64 %2, i64* %4
%6 = bitcast i64* %5 to i8*
%7 = icmp eq i8 %0, 0
%8 = tail call i32 @RamWrite32A(i32 49152, i32 13635664)
%9 = trunc i64 %1 to i32
%10 = tail call i32 @RamWrite32A(i32 53248, i32 %9)
%11 = tail call i32 @RamWrite32A(i32 49152, i32 13635668)
br i1 %7, label %12, label %21
12: ; preds = %3
%13 = trunc i64 %2 to i32
%14 = tail call i32 @RamWrite32A(i32 53248, i32 %13)
store i64 64, i64* %5
br label %15
15: ; preds = %12, %15
%16 = call i32 @RamWrite32A(i32 49152, i32 13635596)
%17 = call i32 @RamRead32A(i32 53248, i64* %5)
%18 = load i64, i64* %5
%19 = and i64 %18, 64
%20 = icmp eq i64 %19, 0
br i1 %20, label %29, label %15
21: ; preds = %3
%22 = call i32 @RamRead32A(i32 53248, i64* %4)
store i64 64, i64* %5
br label %23
23: ; preds = %21, %23
%24 = call i32 @RamWrite32A(i32 49152, i32 13635596)
%25 = call i32 @RamRead32A(i32 53248, i64* %5)
%26 = load i64, i64* %5
%27 = and i64 %26, 64
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %23
29: ; preds = %23, %15
ret void
}