void psoc_bits(int nbits, int data) {
  unsigned int mask;
  *(volatile unsigned long *)((void *)0xfffff400 + 0x10) = (1 << (13));
  for (mask = 1 << nbits; (mask >>= 1) != 0;) {
    if (data & mask)
      *(volatile unsigned long *)((void *)0xfffff400 + 0x30) = (1 << (13));
    else
      *(volatile unsigned long *)((void *)0xfffff400 + 0x34) = (1 << (13));
    *(volatile unsigned long *)((void *)0xfffff400 + 0x30) = (1 << (14));
    *(volatile unsigned long *)((void *)0xfffff400 + 0x34) = (1 << (14));
  }
  *(volatile unsigned long *)((void *)0xfffff400 + 0x34) = (1 << (13));
  *(volatile unsigned long *)((void *)0xfffff400 + 0x14) = (1 << (13));
}


x86 assembly (clang, -O0):
<psoc_bits>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    $0xfffff400,%eax
movq   $0x2000,0x10(%rax)
mov    -0x4(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
shr    $0x1,%eax
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
je     1183 <psoc_bits+0x83>
mov    -0x8(%rbp),%eax
and    -0xc(%rbp),%eax
cmp    $0x0,%eax
je     1157 <psoc_bits+0x57>
mov    $0xfffff400,%eax
movq   $0x2000,0x30(%rax)
jmp    1164 <psoc_bits+0x64>
mov    $0xfffff400,%eax
movq   $0x2000,0x34(%rax)
mov    $0xfffff400,%eax
movq   $0x4000,0x30(%rax)
mov    $0xfffff400,%eax
movq   $0x4000,0x34(%rax)
jmp    1124 <psoc_bits+0x24>
mov    $0xfffff400,%eax
movq   $0x2000,0x34(%rax)
mov    $0xfffff400,%eax
movq   $0x2000,0x14(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<psoc_bits>:
mov    $0xfffff434,%eax
movq   $0x2000,-0x24(%rax)
test   %edi,%edi
je     114d <psoc_bits+0x4d>
mov    $0x1,%edx
mov    %edi,%ecx
shl    %cl,%edx
mov    %edx,%ecx
jmp    113d <psoc_bits+0x3d>
xchg   %ax,%ax
movq   $0x2000,(%rax)
movq   $0x4000,-0x4(%rax)
movq   $0x4000,(%rax)
cmp    $0x3,%edx
mov    %ecx,%edx
jbe    114d <psoc_bits+0x4d>
shr    %ecx
test   %esi,%ecx
je     1120 <psoc_bits+0x20>
movq   $0x2000,-0x4(%rax)
jmp    1127 <psoc_bits+0x27>
movq   $0x2000,(%rax)
movq   $0x2000,-0x20(%rax)
ret

LLVM IR (-O0):
define void @psoc_bits(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
store volatile i64 8192, i64* bitcast (i8* getelementptr (i8, i8* inttoptr (i64 4294964224 to i8*), i64 16) to i64*)
%6 = load i32, i32* %3
%7 = shl i32 1, %6
store i32 %7, i32* %5
br label %8
8: ; preds = %19, %2
%9 = load i32, i32* %5
%10 = lshr i32 %9, 1
store i32 %10, i32* %5
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %20
12: ; preds = %8
%13 = load i32, i32* %4
%14 = load i32, i32* %5
%15 = and i32 %13, %14
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %12
store volatile i64 8192, i64* bitcast (i8* getelementptr (i8, i8* inttoptr (i64 4294964224 to i8*), i64 48) to i64*)
br label %19
18: ; preds = %12
store volatile i64 8192, i64* bitcast (i8* getelementptr (i8, i8* inttoptr (i64 4294964224 to i8*), i64 52) to i64*)
br label %19
19: ; preds = %18, %17
store volatile i64 16384, i64* bitcast (i8* getelementptr (i8, i8* inttoptr (i64 4294964224 to i8*), i64 48) to i64*)
store volatile i64 16384, i64* bitcast (i8* getelementptr (i8, i8* inttoptr (i64 4294964224 to i8*), i64 52) to i64*)
br label %8
20: ; preds = %8
store volatile i64 8192, i64* bitcast (i8* getelementptr (i8, i8* inttoptr (i64 4294964224 to i8*), i64 52) to i64*)
store volatile i64 8192, i64* bitcast (i8* getelementptr (i8, i8* inttoptr (i64 4294964224 to i8*), i64 20) to i64*)
ret void
}

LLVM IR (-O2):
define void @psoc_bits(i32 %0, i32 %1) {
store volatile i64 8192, i64* inttoptr (i64 4294964240 to i64*)
%3 = icmp eq i32 %0, 0
br i1 %3, label %15, label %4
4: ; preds = %2
%5 = shl nuw i32 1, %0
br label %6
6: ; preds = %4, %13
%7 = phi i32 [ %8, %13 ], [ %5, %4 ]
%8 = lshr i32 %7, 1
%9 = and i32 %8, %1
%10 = icmp eq i32 %9, 0
br i1 %10, label %12, label %11
11: ; preds = %6
store volatile i64 8192, i64* inttoptr (i64 4294964272 to i64*)
br label %13
12: ; preds = %6
store volatile i64 8192, i64* inttoptr (i64 4294964276 to i64*)
br label %13
13: ; preds = %12, %11
store volatile i64 16384, i64* inttoptr (i64 4294964272 to i64*)
store volatile i64 16384, i64* inttoptr (i64 4294964276 to i64*)
%14 = icmp ult i32 %7, 4
br i1 %14, label %15, label %6
15: ; preds = %13, %2
store volatile i64 8192, i64* inttoptr (i64 4294964276 to i64*)
store volatile i64 8192, i64* inttoptr (i64 4294964244 to i64*)
ret void
}