#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 uint8_t;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int fa_unique_array(int *, int, int);
int permute_byte(uint8_t value, uint8_t mask, uint8_t *buf) {
  int i;
  for (i = 0; i < 256; i++)
    buf[i] = ((uint8_t)i & ~mask) | value;
  return fa_unique_array(buf, 256, sizeof(buf[0]));
}


x86 assembly (clang, -O0):
<permute_byte>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x100,-0x14(%rbp)
jge    115d <permute_byte+0x4d>
mov    -0x14(%rbp),%edx
mov    -0x8(%rbp),%eax
xor    $0xffffffff,%eax
and    %eax,%edx
or     -0x4(%rbp),%edx
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1129 <permute_byte+0x19>
mov    -0x10(%rbp),%rdi
mov    $0x100,%esi
mov    $0x4,%edx
call   1030 <fa_unique_array@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<permute_byte>:
not    %esi
movd   %esi,%xmm0
pshufd $0x0,%xmm0,%xmm0
movd   %edi,%xmm1
pshufd $0x0,%xmm1,%xmm1
movdqa 0xed4(%rip),%xmm3
mov    $0xc,%eax
movdqa 0xed6(%rip),%xmm8
movdqa 0xede(%rip),%xmm4
movdqa 0xee6(%rip),%xmm5
movdqa 0xeee(%rip),%xmm6
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movdqa %xmm3,%xmm7
paddd  %xmm8,%xmm7
movdqa %xmm3,%xmm2
pand   %xmm0,%xmm2
pand   %xmm0,%xmm7
por    %xmm1,%xmm2
por    %xmm1,%xmm7
movdqu %xmm2,-0x30(%rdx,%rax,4)
movdqu %xmm7,-0x20(%rdx,%rax,4)
movdqa %xmm3,%xmm2
paddd  %xmm4,%xmm2
movdqa %xmm3,%xmm7
paddd  %xmm5,%xmm7
pand   %xmm0,%xmm2
pand   %xmm0,%xmm7
por    %xmm1,%xmm2
por    %xmm1,%xmm7
movdqu %xmm2,-0x10(%rdx,%rax,4)
movdqu %xmm7,(%rdx,%rax,4)
paddd  %xmm6,%xmm3
add    $0x10,%rax
cmp    $0x10c,%rax
jne    1160 <permute_byte+0x50>
mov    %rdx,%rdi
mov    $0x100,%esi
mov    $0x4,%edx
jmp    1030 <fa_unique_array@plt>

LLVM IR (-O0):
define i32 @permute_byte(i32 %0, i32 %1, i32* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32* %2, i32** %6
store i32 0, i32* %7
br label %8
8: ; preds = %22, %3
%9 = load i32, i32* %7
%10 = icmp slt i32 %9, 256
br i1 %10, label %11, label %25
11: ; preds = %8
%12 = load i32, i32* %7
%13 = load i32, i32* %5
%14 = xor i32 %13, -1
%15 = and i32 %12, %14
%16 = load i32, i32* %4
%17 = or i32 %15, %16
%18 = load i32*, i32** %6
%19 = load i32, i32* %7
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i32, i32* %18, i64 %20
store i32 %17, i32* %21
br label %22
22: ; preds = %11
%23 = load i32, i32* %7
%24 = add nsw i32 %23, 1
store i32 %24, i32* %7
br label %8
25: ; preds = %8
%26 = load i32*, i32** %6
%27 = call i32 @fa_unique_array(i32* %26, i32 256, i32 4)
ret i32 %27
}

LLVM IR (-O2):
define i32 @permute_byte(i32 %0, i32 %1, i32* %2) {
%4 = xor i32 %1, -1
%5 = insertelement <4 x i32> poison, i32 %4, i64 0
%6 = shufflevector <4 x i32> %5, <4 x i32> poison, <4 x i32> zeroinitializer
%7 = insertelement <4 x i32> poison, i32 %4, i64 0
%8 = shufflevector <4 x i32> %7, <4 x i32> poison, <4 x i32> zeroinitializer
%9 = insertelement <4 x i32> poison, i32 %0, i64 0
%10 = shufflevector <4 x i32> %9, <4 x i32> poison, <4 x i32> zeroinitializer
%11 = insertelement <4 x i32> poison, i32 %0, i64 0
%12 = shufflevector <4 x i32> %11, <4 x i32> poison, <4 x i32> zeroinitializer
br label %13
13: ; preds = %13, %3
%14 = phi i64 [ 0, %3 ], [ %36, %13 ]
%15 = phi <4 x i32> [ <i32 0, i32 1, i32 2, i32 3>, %3 ], [ %37, %13 ]
%16 = add <4 x i32> %15, <i32 4, i32 4, i32 4, i32 4>
%17 = and <4 x i32> %15, %6
%18 = and <4 x i32> %16, %8
%19 = or <4 x i32> %17, %10
%20 = or <4 x i32> %18, %12
%21 = getelementptr inbounds i32, i32* %2, i64 %14
%22 = bitcast i32* %21 to <4 x i32>*
store <4 x i32> %19, <4 x i32>* %22
%23 = getelementptr inbounds i32, i32* %21, i64 4
%24 = bitcast i32* %23 to <4 x i32>*
store <4 x i32> %20, <4 x i32>* %24
%25 = or i64 %14, 8
%26 = add <4 x i32> %15, <i32 8, i32 8, i32 8, i32 8>
%27 = add <4 x i32> %15, <i32 12, i32 12, i32 12, i32 12>
%28 = and <4 x i32> %26, %6
%29 = and <4 x i32> %27, %8
%30 = or <4 x i32> %28, %10
%31 = or <4 x i32> %29, %12
%32 = getelementptr inbounds i32, i32* %2, i64 %25
%33 = bitcast i32* %32 to <4 x i32>*
store <4 x i32> %30, <4 x i32>* %33
%34 = getelementptr inbounds i32, i32* %32, i64 4
%35 = bitcast i32* %34 to <4 x i32>*
store <4 x i32> %31, <4 x i32>* %35
%36 = add nuw nsw i64 %14, 16
%37 = add <4 x i32> %15, <i32 16, i32 16, i32 16, i32 16>
%38 = icmp eq i64 %36, 256
br i1 %38, label %39, label %13
39: ; preds = %13
%40 = tail call i32 @fa_unique_array(i32* %2, i32 256, i32 4)
ret i32 %40
}