#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 */
unsigned long pow(int, size_t);
unsigned long int UntwiddleValue(unsigned long int value) {
  unsigned long int untwiddled = 0;
  for (size_t i = 0; i < 10; i++) {
    unsigned long int shift = pow(2, i);
    if (value & shift)
      untwiddled |= (shift << i);
  }
  return untwiddled;
}


x86 assembly (clang, -O0):
<UntwiddleValue>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
cmpq   $0xa,-0x18(%rbp)
jae    1184 <UntwiddleValue+0x74>
mov    -0x18(%rbp),%rsi
mov    $0x2,%edi
call   1030 <pow@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
and    -0x20(%rbp),%rax
cmp    $0x0,%rax
je     116e <UntwiddleValue+0x5e>
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
shl    %cl,%rax
or     -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
jmp    1173 <UntwiddleValue+0x63>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    112c <UntwiddleValue+0x1c>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<UntwiddleValue>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdi,%r14
mov    $0x2,%edi
xor    %esi,%esi
call   1030 <pow@plt>
mov    %rax,%r15
and    %r14,%rax
cmove  %rax,%r15
mov    $0x1,%esi
mov    $0x2,%edi
call   1030 <pow@plt>
mov    %rax,%r13
and    %r14,%rax
add    %r13,%r13
test   %rax,%rax
cmove  %rax,%r13
or     %r15,%r13
mov    $0x2,%esi
mov    $0x2,%edi
call   1030 <pow@plt>
mov    %rax,%rbx
and    %r14,%rax
shl    $0x2,%rbx
test   %rax,%rax
cmove  %rax,%rbx
mov    $0x3,%esi
mov    $0x2,%edi
call   1030 <pow@plt>
mov    %rax,%r12
and    %r14,%rax
shl    $0x3,%r12
test   %rax,%rax
cmove  %rax,%r12
or     %rbx,%r12
or     %r13,%r12
mov    $0x4,%esi
mov    $0x2,%edi
call   1030 <pow@plt>
mov    %rax,%r15
and    %r14,%rax
shl    $0x4,%r15
test   %rax,%rax
cmove  %rax,%r15
mov    $0x5,%esi
mov    $0x2,%edi
call   1030 <pow@plt>
mov    %rax,%rbx
and    %r14,%rax
shl    $0x5,%rbx
test   %rax,%rax
cmove  %rax,%rbx
or     %r15,%rbx
mov    $0x6,%esi
mov    $0x2,%edi
call   1030 <pow@plt>
mov    %rax,%r15
and    %r14,%rax
shl    $0x6,%r15
test   %rax,%rax
cmove  %rax,%r15
or     %rbx,%r15
or     %r12,%r15
mov    $0x7,%esi
mov    $0x2,%edi
call   1030 <pow@plt>
mov    %rax,%r12
and    %r14,%rax
shl    $0x7,%r12
test   %rax,%rax
cmove  %rax,%r12
mov    $0x8,%esi
mov    $0x2,%edi
call   1030 <pow@plt>
mov    %rax,%rbx
and    %r14,%rax
shl    $0x8,%rbx
test   %rax,%rax
cmove  %rax,%rbx
or     %r12,%rbx
mov    $0x9,%esi
mov    $0x2,%edi
call   1030 <pow@plt>
and    %rax,%r14
shl    $0x9,%rax
test   %r14,%r14
cmove  %r14,%rax
or     %rbx,%rax
or     %r15,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i64 @UntwiddleValue(i64 %0) {
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
store i64 %0, i64* %2
store i64 0, i64* %3
store i64 0, i64* %4
br label %6
6: ; preds = %23, %1
%7 = load i64, i64* %4
%8 = icmp ult i64 %7, 10
br i1 %8, label %9, label %26
9: ; preds = %6
%10 = load i64, i64* %4
%11 = call i64 @pow(i32 2, i64 %10)
store i64 %11, i64* %5
%12 = load i64, i64* %2
%13 = load i64, i64* %5
%14 = and i64 %12, %13
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %22
16: ; preds = %9
%17 = load i64, i64* %5
%18 = load i64, i64* %4
%19 = shl i64 %17, %18
%20 = load i64, i64* %3
%21 = or i64 %20, %19
store i64 %21, i64* %3
br label %22
22: ; preds = %16, %9
br label %23
23: ; preds = %22
%24 = load i64, i64* %4
%25 = add i64 %24, 1
store i64 %25, i64* %4
br label %6
26: ; preds = %6
%27 = load i64, i64* %3
ret i64 %27
}

LLVM IR (-O2):
define i64 @UntwiddleValue(i64 %0) {
%2 = tail call i64 @pow(i32 2, i64 0)
%3 = and i64 %2, %0
%4 = icmp eq i64 %3, 0
%5 = select i1 %4, i64 0, i64 %2
%6 = tail call i64 @pow(i32 2, i64 1)
%7 = and i64 %6, %0
%8 = icmp eq i64 %7, 0
%9 = shl i64 %6, 1
%10 = select i1 %8, i64 0, i64 %9
%11 = or i64 %10, %5
%12 = tail call i64 @pow(i32 2, i64 2)
%13 = and i64 %12, %0
%14 = icmp eq i64 %13, 0
%15 = shl i64 %12, 2
%16 = select i1 %14, i64 0, i64 %15
%17 = or i64 %16, %11
%18 = tail call i64 @pow(i32 2, i64 3)
%19 = and i64 %18, %0
%20 = icmp eq i64 %19, 0
%21 = shl i64 %18, 3
%22 = select i1 %20, i64 0, i64 %21
%23 = or i64 %22, %17
%24 = tail call i64 @pow(i32 2, i64 4)
%25 = and i64 %24, %0
%26 = icmp eq i64 %25, 0
%27 = shl i64 %24, 4
%28 = select i1 %26, i64 0, i64 %27
%29 = or i64 %28, %23
%30 = tail call i64 @pow(i32 2, i64 5)
%31 = and i64 %30, %0
%32 = icmp eq i64 %31, 0
%33 = shl i64 %30, 5
%34 = select i1 %32, i64 0, i64 %33
%35 = or i64 %34, %29
%36 = tail call i64 @pow(i32 2, i64 6)
%37 = and i64 %36, %0
%38 = icmp eq i64 %37, 0
%39 = shl i64 %36, 6
%40 = select i1 %38, i64 0, i64 %39
%41 = or i64 %40, %35
%42 = tail call i64 @pow(i32 2, i64 7)
%43 = and i64 %42, %0
%44 = icmp eq i64 %43, 0
%45 = shl i64 %42, 7
%46 = select i1 %44, i64 0, i64 %45
%47 = or i64 %46, %41
%48 = tail call i64 @pow(i32 2, i64 8)
%49 = and i64 %48, %0
%50 = icmp eq i64 %49, 0
%51 = shl i64 %48, 8
%52 = select i1 %50, i64 0, i64 %51
%53 = or i64 %52, %47
%54 = tail call i64 @pow(i32 2, i64 9)
%55 = and i64 %54, %0
%56 = icmp eq i64 %55, 0
%57 = shl i64 %54, 9
%58 = select i1 %56, i64 0, i64 %57
%59 = or i64 %58, %53
ret i64 %59
}