#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 */
typedef int /*<<< orphan*/ uint64_t;
typedef int uint32_t;

/* Variables and functions */
int /*<<< orphan*/ extractBit(int /*<<< orphan*/, int, int, int, int);
uint64_t doPermute(uint64_t input, uint32_t *mapping, uint32_t s_size,
                   uint32_t d_size) {
  uint64_t output = 0;
  for (int i = 1; i <= d_size; i++) {
    output |= extractBit(input, mapping[i - 1], i, s_size, d_size);
  }
  return output;
}


x86 assembly (clang, -O0):
<doPermute>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x1,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x18(%rbp),%eax
jg     1175 <doPermute+0x65>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%esi
mov    -0x20(%rbp),%edx
mov    -0x14(%rbp),%ecx
mov    -0x18(%rbp),%r8d
call   1030 <extractBit@plt>
or     -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1133 <doPermute+0x23>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<doPermute>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,(%rsp)
test   %ecx,%ecx
jle    1163 <doPermute+0x53>
mov    %edx,%r15d
mov    %rsi,%r12
mov    %edi,%r13d
mov    (%rsp),%rax
lea    0x1(%rax),%r14d
xor    %ebp,%ebp
mov    $0x1,%ebx
nopl   0x0(%rax,%rax,1)
mov    -0x4(%r12,%rbx,4),%esi
mov    %r13d,%edi
mov    %ebx,%edx
mov    %r15d,%ecx
mov    (%rsp),%r8
call   1030 <extractBit@plt>
or     %eax,%ebp
add    $0x1,%rbx
cmp    %rbx,%r14
jne    1140 <doPermute+0x30>
jmp    1165 <doPermute+0x55>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @doPermute(i32 %0, i32* %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 %0, i32* %5
store i32* %1, i32** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
store i32 0, i32* %9
store i32 1, i32* %10
br label %11
11: ; preds = %29, %4
%12 = load i32, i32* %10
%13 = load i32, i32* %8
%14 = icmp sle i32 %12, %13
br i1 %14, label %15, label %32
15: ; preds = %11
%16 = load i32, i32* %5
%17 = load i32*, i32** %6
%18 = load i32, i32* %10
%19 = sub nsw i32 %18, 1
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i32, i32* %17, i64 %20
%22 = load i32, i32* %21
%23 = load i32, i32* %10
%24 = load i32, i32* %7
%25 = load i32, i32* %8
%26 = call i32 @extractBit(i32 %16, i32 %22, i32 %23, i32 %24, i32 %25)
%27 = load i32, i32* %9
%28 = or i32 %27, %26
store i32 %28, i32* %9
br label %29
29: ; preds = %15
%30 = load i32, i32* %10
%31 = add nsw i32 %30, 1
store i32 %31, i32* %10
br label %11
32: ; preds = %11
%33 = load i32, i32* %9
ret i32 %33
}

LLVM IR (-O2):
define i32 @doPermute(i32 %0, i32* nocapture %1, i32 %2, i32 %3) {
%5 = icmp slt i32 %3, 1
br i1 %5, label %9, label %6
6: ; preds = %4
%7 = add nuw i32 %3, 1
%8 = zext i32 %7 to i64
br label %11
9: ; preds = %11, %4
%10 = phi i32 [ 0, %4 ], [ %19, %11 ]
ret i32 %10
11: ; preds = %6, %11
%12 = phi i64 [ 1, %6 ], [ %20, %11 ]
%13 = phi i32 [ 0, %6 ], [ %19, %11 ]
%14 = add nsw i64 %12, -1
%15 = getelementptr inbounds i32, i32* %1, i64 %14
%16 = load i32, i32* %15
%17 = trunc i64 %12 to i32
%18 = tail call i32 @extractBit(i32 %0, i32 %16, i32 %17, i32 %2, i32 %3)
%19 = or i32 %18, %13
%20 = add nuw nsw i64 %12, 1
%21 = icmp eq i64 %20, %8
br i1 %21, label %9, label %11
}