#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 short permute(unsigned short, int *, int, int);
unsigned short fFunction(unsigned short r, unsigned short key) {
  int sZero[4][4] = {{1, 0, 3, 2}, {3, 2, 1, 0}, {0, 2, 1, 3}, {3, 1, 3, 2}};
  int sOne[4][4] = {{0, 1, 2, 3}, {2, 0, 1, 3}, {3, 0, 1, 0}, {2, 1, 0, 3}};
  int eP[8] = {4, 1, 2, 3, 2, 3, 4, 1};
  int pFour[4] = {2, 4, 3, 1};
  unsigned short expR;
  expR = permute(r, eP, 4, 8);
  expR = expR ^ key;
  expR = (sZero[((expR & 128) >> 6) + ((expR & 16) >> 4)]
               [((expR & 64) >> 5) + ((expR & 32) >> 5)]
          << 2) +
         sOne[((expR & 8) >> 2) + (expR & 1)]
             [((expR & 4) >> 1) + ((expR & 2) >> 1)];
  expR = permute(expR, pFour, 4, 4);
  return expR;
}


x86 assembly (clang, -O0):
<fFunction>:
push   %rbp
mov    %rsp,%rbp
sub    $0xd0,%rsp
mov    %si,%ax
mov    %di,%cx
mov    %cx,-0x2(%rbp)
mov    %ax,-0x4(%rbp)
lea    -0x50(%rbp),%rdi
lea    0xebc(%rip),%rsi
mov    $0x40,%edx
call   1040 <memcpy@plt>
lea    -0x90(%rbp),%rdi
lea    0xee4(%rip),%rsi
mov    $0x40,%edx
call   1040 <memcpy@plt>
mov    0xf13(%rip),%rax
mov    %rax,-0xb0(%rbp)
mov    0xf0d(%rip),%rax
mov    %rax,-0xa8(%rbp)
mov    0xf07(%rip),%rax
mov    %rax,-0xa0(%rbp)
mov    0xf01(%rip),%rax
mov    %rax,-0x98(%rbp)
mov    0xefb(%rip),%rax
mov    %rax,-0xc0(%rbp)
mov    0xef5(%rip),%rax
mov    %rax,-0xb8(%rbp)
mov    -0x2(%rbp),%ax
lea    -0xb0(%rbp),%rsi
mov    $0x4,%edx
mov    $0x8,%ecx
movzwl %ax,%edi
call   1030 <permute@plt>
mov    %ax,-0xc2(%rbp)
movzwl -0xc2(%rbp),%eax
movzwl -0x4(%rbp),%ecx
xor    %ecx,%eax
mov    %ax,-0xc2(%rbp)
movzwl -0xc2(%rbp),%eax
and    $0x80,%eax
sar    $0x6,%eax
movzwl -0xc2(%rbp),%ecx
and    $0x10,%ecx
sar    $0x4,%ecx
add    %ecx,%eax
movslq %eax,%rcx
lea    -0x50(%rbp),%rax
shl    $0x4,%rcx
add    %rcx,%rax
movzwl -0xc2(%rbp),%ecx
and    $0x40,%ecx
sar    $0x5,%ecx
movzwl -0xc2(%rbp),%edx
and    $0x20,%edx
sar    $0x5,%edx
add    %edx,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%eax
shl    $0x2,%eax
movzwl -0xc2(%rbp),%ecx
and    $0x8,%ecx
sar    $0x2,%ecx
movzwl -0xc2(%rbp),%edx
and    $0x1,%edx
add    %edx,%ecx
movslq %ecx,%rdx
lea    -0x90(%rbp),%rcx
shl    $0x4,%rdx
add    %rdx,%rcx
movzwl -0xc2(%rbp),%edx
and    $0x4,%edx
sar    $0x1,%edx
movzwl -0xc2(%rbp),%esi
and    $0x2,%esi
sar    $0x1,%esi
add    %esi,%edx
movslq %edx,%rdx
add    (%rcx,%rdx,4),%eax
mov    %ax,-0xc2(%rbp)
mov    -0xc2(%rbp),%ax
lea    -0xc0(%rbp),%rsi
mov    $0x4,%ecx
movzwl %ax,%edi
mov    %ecx,%edx
call   1030 <permute@plt>
mov    %ax,-0xc2(%rbp)
movzwl -0xc2(%rbp),%eax
add    $0xd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fFunction>:
push   %rbx
sub    $0x30,%rsp
mov    %esi,%ebx
movaps 0xf72(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xf56(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xf6a(%rip),%xmm0
movaps %xmm0,(%rsp)
lea    0x10(%rsp),%rsi
mov    $0x4,%edx
mov    $0x8,%ecx
call   1030 <permute@plt>
xor    %ebx,%eax
movzwl %ax,%ecx
mov    %ecx,%edx
shr    $0x6,%edx
and    $0x2,%edx
mov    %ecx,%esi
shr    $0x4,%esi
and    $0x1,%esi
or     %edx,%esi
mov    %ecx,%edx
shr    $0x5,%edx
and    $0x3,%edx
shl    $0x4,%rsi
lea    0xe88(%rip),%rdi
add    %rsi,%rdi
mov    (%rdi,%rdx,4),%edx
shl    $0x2,%edx
mov    %ecx,%esi
shr    $0x2,%esi
and    $0x2,%esi
and    $0x1,%eax
or     %esi,%eax
shr    %ecx
and    $0x3,%ecx
shl    $0x4,%rax
lea    0xea2(%rip),%rsi
add    %rax,%rsi
add    (%rsi,%rcx,4),%edx
movzwl %dx,%edi
mov    %rsp,%rsi
mov    $0x4,%edx
mov    $0x4,%ecx
call   1030 <permute@plt>
add    $0x30,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@__const.fFunction.sZero = [4 x [4 x i32]] [[4 x i32] [i32 1, i32 0, i32 3, i32 2], [4 x i32] [i32 3, i32 2, i32 1, i32 0], [4 x i32] [i32 0, i32 2, i32 1, i32 3], [4 x i32] [i32 3, i32 1, i32 3, i32 2]]
@__const.fFunction.sOne = [4 x [4 x i32]] [[4 x i32] [i32 0, i32 1, i32 2, i32 3], [4 x i32] [i32 2, i32 0, i32 1, i32 3], [4 x i32] [i32 3, i32 0, i32 1, i32 0], [4 x i32] [i32 2, i32 1, i32 0, i32 3]]
@__const.fFunction.eP = [8 x i32] [i32 4, i32 1, i32 2, i32 3, i32 2, i32 3, i32 4, i32 1]
@__const.fFunction.pFour = [4 x i32] [i32 2, i32 4, i32 3, i32 1]
define zeroext i16 @fFunction(i16 zeroext %0, i16 zeroext %1) {
%3 = alloca i16
%4 = alloca i16
%5 = alloca [4 x [4 x i32]]
%6 = alloca [4 x [4 x i32]]
%7 = alloca [8 x i32]
%8 = alloca [4 x i32]
%9 = alloca i16
store i16 %0, i16* %3
store i16 %1, i16* %4
%10 = bitcast [4 x [4 x i32]]* %5 to i8*
%11 = bitcast [4 x [4 x i32]]* %6 to i8*
%12 = bitcast [8 x i32]* %7 to i8*
%13 = bitcast [4 x i32]* %8 to i8*
%14 = load i16, i16* %3
%15 = getelementptr inbounds [8 x i32], [8 x i32]* %7, i64 0, i64 0
%16 = call zeroext i16 @permute(i16 zeroext %14, i32* %15, i32 4, i32 8)
store i16 %16, i16* %9
%17 = load i16, i16* %9
%18 = zext i16 %17 to i32
%19 = load i16, i16* %4
%20 = zext i16 %19 to i32
%21 = xor i32 %18, %20
%22 = trunc i32 %21 to i16
store i16 %22, i16* %9
%23 = load i16, i16* %9
%24 = zext i16 %23 to i32
%25 = and i32 %24, 128
%26 = ashr i32 %25, 6
%27 = load i16, i16* %9
%28 = zext i16 %27 to i32
%29 = and i32 %28, 16
%30 = ashr i32 %29, 4
%31 = add nsw i32 %26, %30
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [4 x [4 x i32]], [4 x [4 x i32]]* %5, i64 0, i64 %32
%34 = load i16, i16* %9
%35 = zext i16 %34 to i32
%36 = and i32 %35, 64
%37 = ashr i32 %36, 5
%38 = load i16, i16* %9
%39 = zext i16 %38 to i32
%40 = and i32 %39, 32
%41 = ashr i32 %40, 5
%42 = add nsw i32 %37, %41
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds [4 x i32], [4 x i32]* %33, i64 0, i64 %43
%45 = load i32, i32* %44
%46 = shl i32 %45, 2
%47 = load i16, i16* %9
%48 = zext i16 %47 to i32
%49 = and i32 %48, 8
%50 = ashr i32 %49, 2
%51 = load i16, i16* %9
%52 = zext i16 %51 to i32
%53 = and i32 %52, 1
%54 = add nsw i32 %50, %53
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds [4 x [4 x i32]], [4 x [4 x i32]]* %6, i64 0, i64 %55
%57 = load i16, i16* %9
%58 = zext i16 %57 to i32
%59 = and i32 %58, 4
%60 = ashr i32 %59, 1
%61 = load i16, i16* %9
%62 = zext i16 %61 to i32
%63 = and i32 %62, 2
%64 = ashr i32 %63, 1
%65 = add nsw i32 %60, %64
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds [4 x i32], [4 x i32]* %56, i64 0, i64 %66
%68 = load i32, i32* %67
%69 = add nsw i32 %46, %68
%70 = trunc i32 %69 to i16
store i16 %70, i16* %9
%71 = load i16, i16* %9
%72 = getelementptr inbounds [4 x i32], [4 x i32]* %8, i64 0, i64 0
%73 = call zeroext i16 @permute(i16 zeroext %71, i32* %72, i32 4, i32 4)
store i16 %73, i16* %9
%74 = load i16, i16* %9
ret i16 %74
}

LLVM IR (-O2):
@__const.fFunction.sZero = [4 x [4 x i32]] [[4 x i32] [i32 1, i32 0, i32 3, i32 2], [4 x i32] [i32 3, i32 2, i32 1, i32 0], [4 x i32] [i32 0, i32 2, i32 1, i32 3], [4 x i32] [i32 3, i32 1, i32 3, i32 2]]
@__const.fFunction.sOne = [4 x [4 x i32]] [[4 x i32] [i32 0, i32 1, i32 2, i32 3], [4 x i32] [i32 2, i32 0, i32 1, i32 3], [4 x i32] [i32 3, i32 0, i32 1, i32 0], [4 x i32] [i32 2, i32 1, i32 0, i32 3]]
@__const.fFunction.eP = [8 x i32] [i32 4, i32 1, i32 2, i32 3, i32 2, i32 3, i32 4, i32 1]
@__const.fFunction.pFour = [4 x i32] [i32 2, i32 4, i32 3, i32 1]
define zeroext i16 @fFunction(i16 zeroext %0, i16 zeroext %1) {
%3 = alloca [8 x i32]
%4 = alloca [4 x i32]
%5 = bitcast [8 x i32]* %3 to i8*
%6 = bitcast [4 x i32]* %4 to i8*
%7 = getelementptr inbounds [8 x i32], [8 x i32]* %3, i64 0, i64 0
%8 = call zeroext i16 @permute(i16 zeroext %0, i32* %7, i32 4, i32 8)
%9 = xor i16 %8, %1
%10 = zext i16 %9 to i32
%11 = lshr i32 %10, 6
%12 = and i32 %11, 2
%13 = lshr i32 %10, 4
%14 = and i32 %13, 1
%15 = or i32 %12, %14
%16 = zext i32 %15 to i64
%17 = lshr i32 %10, 5
%18 = and i32 %17, 3
%19 = zext i32 %18 to i64
%20 = getelementptr inbounds [4 x [4 x i32]], [4 x [4 x i32]]* @__const.fFunction.sZero, i64 0, i64 %16, i64 %19
%21 = load i32, i32* %20
%22 = shl i32 %21, 2
%23 = lshr i32 %10, 2
%24 = and i32 %23, 2
%25 = and i32 %10, 1
%26 = or i32 %24, %25
%27 = zext i32 %26 to i64
%28 = lshr i32 %10, 1
%29 = and i32 %28, 3
%30 = zext i32 %29 to i64
%31 = getelementptr inbounds [4 x [4 x i32]], [4 x [4 x i32]]* @__const.fFunction.sOne, i64 0, i64 %27, i64 %30
%32 = load i32, i32* %31
%33 = add nsw i32 %22, %32
%34 = trunc i32 %33 to i16
%35 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 0
%36 = call zeroext i16 @permute(i16 zeroext %34, i32* %35, i32 4, i32 4)
ret i16 %36
}