#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*/ GPIOPinWrite(int, int, int);
void DAC_write_data(unsigned short dat, int channel) {
  unsigned int i;
  GPIOPinWrite(0x40005000, 0x00000020, 0x00);
  dat &= 0xfff;
  switch (channel) {
  case 0:
    dat |= ((0x8) << 12);
    break;
  case 1:
    dat |= ((0x0) << 12);
    break;
  default:
    break;
  }
  for (i = 0; i < 16; i++) {
    GPIOPinWrite(0x40007000, 0x00000020, 0x00);
    if (dat & 0x8000)
      GPIOPinWrite(0x40007000, 0x00000010, 0xff);
    else
      GPIOPinWrite(0x40007000, 0x00000010, 0x00);
    dat <<= 1;
    GPIOPinWrite(0x40007000, 0x00000020, 0xff);
  }
  GPIOPinWrite(0x40005000, 0x00000020, 0xff);
}


x86 assembly (clang, -O0):
<DAC_write_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %di,%ax
mov    %ax,-0x2(%rbp)
mov    %esi,-0x8(%rbp)
mov    $0x40005000,%edi
mov    $0x20,%esi
xor    %edx,%edx
call   1030 <GPIOPinWrite@plt>
mov    -0x1(%rbp),%al
and    $0xf,%al
mov    %al,-0x1(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
test   %eax,%eax
je     115f <DAC_write_data+0x4f>
jmp    114e <DAC_write_data+0x3e>
mov    -0x10(%rbp),%eax
sub    $0x1,%eax
je     1171 <DAC_write_data+0x61>
jmp    1181 <DAC_write_data+0x71>
movzwl -0x2(%rbp),%eax
or     $0x8000,%eax
mov    %ax,-0x2(%rbp)
jmp    1186 <DAC_write_data+0x76>
movzwl -0x2(%rbp),%eax
or     $0x0,%eax
mov    %ax,-0x2(%rbp)
jmp    1186 <DAC_write_data+0x76>
jmp    1186 <DAC_write_data+0x76>
movl   $0x0,-0xc(%rbp)
cmpl   $0x10,-0xc(%rbp)
jae    1211 <DAC_write_data+0x101>
mov    $0x40007000,%edi
mov    $0x20,%esi
xor    %edx,%edx
call   1030 <GPIOPinWrite@plt>
movzwl -0x2(%rbp),%eax
and    $0x8000,%eax
cmp    $0x0,%eax
je     11d3 <DAC_write_data+0xc3>
mov    $0x40007000,%edi
mov    $0x10,%esi
mov    $0xff,%edx
call   1030 <GPIOPinWrite@plt>
jmp    11e4 <DAC_write_data+0xd4>
mov    $0x40007000,%edi
mov    $0x10,%esi
xor    %edx,%edx
call   1030 <GPIOPinWrite@plt>
movzwl -0x2(%rbp),%eax
shl    $0x1,%eax
mov    %ax,-0x2(%rbp)
mov    $0x40007000,%edi
mov    $0x20,%esi
mov    $0xff,%edx
call   1030 <GPIOPinWrite@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    118d <DAC_write_data+0x7d>
mov    $0x40005000,%edi
mov    $0x20,%esi
mov    $0xff,%edx
call   1030 <GPIOPinWrite@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<DAC_write_data>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%r14d
mov    %edi,%r15d
xor    %r12d,%r12d
mov    $0x40005000,%edi
mov    $0x20,%esi
xor    %edx,%edx
call   1030 <GPIOPinWrite@plt>
and    $0xfff,%r15d
lea    -0x8000(%r15),%ebx
test   %r14d,%r14d
cmovne %r15d,%ebx
mov    $0x10,%ebp
nopl   0x0(%rax)
mov    $0x40007000,%edi
mov    $0x20,%esi
xor    %edx,%edx
call   1030 <GPIOPinWrite@plt>
test   %bx,%bx
mov    $0xff,%edx
cmovns %r12d,%edx
mov    $0x40007000,%edi
mov    $0x10,%esi
call   1030 <GPIOPinWrite@plt>
add    %ebx,%ebx
mov    $0x40007000,%edi
mov    $0x20,%esi
mov    $0xff,%edx
call   1030 <GPIOPinWrite@plt>
add    $0xffffffff,%ebp
jne    1150 <DAC_write_data+0x40>
mov    $0x40005000,%edi
mov    $0x20,%esi
mov    $0xff,%edx
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <GPIOPinWrite@plt>

LLVM IR (-O0):
define void @DAC_write_data(i16 zeroext %0, i32 %1) {
%3 = alloca i16
%4 = alloca i32
%5 = alloca i32
store i16 %0, i16* %3
store i32 %1, i32* %4
%6 = call i32 @GPIOPinWrite(i32 1073762304, i32 32, i32 0)
%7 = load i16, i16* %3
%8 = zext i16 %7 to i32
%9 = and i32 %8, 4095
%10 = trunc i32 %9 to i16
store i16 %10, i16* %3
%11 = load i32, i32* %4
switch i32 %11, label %22 [
i32 0, label %12
i32 1, label %17
]
12: ; preds = %2
%13 = load i16, i16* %3
%14 = zext i16 %13 to i32
%15 = or i32 %14, 32768
%16 = trunc i32 %15 to i16
store i16 %16, i16* %3
br label %23
17: ; preds = %2
%18 = load i16, i16* %3
%19 = zext i16 %18 to i32
%20 = or i32 %19, 0
%21 = trunc i32 %20 to i16
store i16 %21, i16* %3
br label %23
22: ; preds = %2
br label %23
23: ; preds = %22, %17, %12
store i32 0, i32* %5
br label %24
24: ; preds = %43, %23
%25 = load i32, i32* %5
%26 = icmp ult i32 %25, 16
br i1 %26, label %27, label %46
27: ; preds = %24
%28 = call i32 @GPIOPinWrite(i32 1073770496, i32 32, i32 0)
%29 = load i16, i16* %3
%30 = zext i16 %29 to i32
%31 = and i32 %30, 32768
%32 = icmp ne i32 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %27
%34 = call i32 @GPIOPinWrite(i32 1073770496, i32 16, i32 255)
br label %37
35: ; preds = %27
%36 = call i32 @GPIOPinWrite(i32 1073770496, i32 16, i32 0)
br label %37
37: ; preds = %35, %33
%38 = load i16, i16* %3
%39 = zext i16 %38 to i32
%40 = shl i32 %39, 1
%41 = trunc i32 %40 to i16
store i16 %41, i16* %3
%42 = call i32 @GPIOPinWrite(i32 1073770496, i32 32, i32 255)
br label %43
43: ; preds = %37
%44 = load i32, i32* %5
%45 = add i32 %44, 1
store i32 %45, i32* %5
br label %24
46: ; preds = %24
%47 = call i32 @GPIOPinWrite(i32 1073762304, i32 32, i32 255)
ret void
}

LLVM IR (-O2):
define void @DAC_write_data(i16 zeroext %0, i32 %1) {
%3 = tail call i32 @GPIOPinWrite(i32 1073762304, i32 32, i32 0)
%4 = and i16 %0, 4095
%5 = icmp eq i32 %1, 0
%6 = or i16 %4, -32768
%7 = select i1 %5, i16 %6, i16 %4
br label %8
8: ; preds = %2, %8
%9 = phi i32 [ %17, %8 ], [ 0, %2 ]
%10 = phi i16 [ %15, %8 ], [ %7, %2 ]
%11 = tail call i32 @GPIOPinWrite(i32 1073770496, i32 32, i32 0)
%12 = icmp sgt i16 %10, -1
%13 = select i1 %12, i32 0, i32 255
%14 = tail call i32 @GPIOPinWrite(i32 1073770496, i32 16, i32 %13)
%15 = shl i16 %10, 1
%16 = tail call i32 @GPIOPinWrite(i32 1073770496, i32 32, i32 255)
%17 = add nuw nsw i32 %9, 1
%18 = icmp eq i32 %17, 16
br i1 %18, label %19, label %8
19: ; preds = %8
%20 = tail call i32 @GPIOPinWrite(i32 1073762304, i32 32, i32 255)
ret void
}