#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;

/* Variables and functions */
void set_nonce_in_tweak(uint8_t *tweak, const uint8_t *nonce) {
  tweak[0] = (tweak[0] & 0xf0) ^ (nonce[0] >> 4);
  tweak[1] = ((nonce[0] & 0xf) << 4) ^ (nonce[1] >> 4);
  tweak[2] = ((nonce[1] & 0xf) << 4) ^ (nonce[2] >> 4);
  tweak[3] = ((nonce[2] & 0xf) << 4);
}


x86 assembly (clang, -O0):
<set_nonce_in_tweak>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%ecx
and    $0xf0,%ecx
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
sar    $0x4,%eax
xor    %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
and    $0xf,%ecx
shl    $0x4,%ecx
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%eax
sar    $0x4,%eax
xor    %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%ecx
and    $0xf,%ecx
shl    $0x4,%ecx
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%eax
sar    $0x4,%eax
xor    %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x8(%rax)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%ecx
and    $0xf,%ecx
shl    $0x4,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0xc(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_nonce_in_tweak>:
mov    $0xf0,%eax
and    (%rdi),%eax
mov    (%rsi),%ecx
sar    $0x4,%ecx
xor    %eax,%ecx
mov    %ecx,(%rdi)
mov    (%rsi),%eax
mov    0x4(%rsi),%ecx
shl    $0x4,%eax
movzbl %al,%eax
sar    $0x4,%ecx
xor    %eax,%ecx
mov    %ecx,0x4(%rdi)
mov    0x4(%rsi),%eax
mov    0x8(%rsi),%ecx
shl    $0x4,%eax
movzbl %al,%eax
sar    $0x4,%ecx
xor    %eax,%ecx
mov    %ecx,0x8(%rdi)
mov    0x8(%rsi),%eax
shl    $0x4,%eax
movzbl %al,%eax
mov    %eax,0xc(%rdi)
ret

LLVM IR (-O0):
define void @set_nonce_in_tweak(i32* %0, i32* %1) {
%3 = alloca i32*
%4 = alloca i32*
store i32* %0, i32** %3
store i32* %1, i32** %4
%5 = load i32*, i32** %3
%6 = getelementptr inbounds i32, i32* %5, i64 0
%7 = load i32, i32* %6
%8 = and i32 %7, 240
%9 = load i32*, i32** %4
%10 = getelementptr inbounds i32, i32* %9, i64 0
%11 = load i32, i32* %10
%12 = ashr i32 %11, 4
%13 = xor i32 %8, %12
%14 = load i32*, i32** %3
%15 = getelementptr inbounds i32, i32* %14, i64 0
store i32 %13, i32* %15
%16 = load i32*, i32** %4
%17 = getelementptr inbounds i32, i32* %16, i64 0
%18 = load i32, i32* %17
%19 = and i32 %18, 15
%20 = shl i32 %19, 4
%21 = load i32*, i32** %4
%22 = getelementptr inbounds i32, i32* %21, i64 1
%23 = load i32, i32* %22
%24 = ashr i32 %23, 4
%25 = xor i32 %20, %24
%26 = load i32*, i32** %3
%27 = getelementptr inbounds i32, i32* %26, i64 1
store i32 %25, i32* %27
%28 = load i32*, i32** %4
%29 = getelementptr inbounds i32, i32* %28, i64 1
%30 = load i32, i32* %29
%31 = and i32 %30, 15
%32 = shl i32 %31, 4
%33 = load i32*, i32** %4
%34 = getelementptr inbounds i32, i32* %33, i64 2
%35 = load i32, i32* %34
%36 = ashr i32 %35, 4
%37 = xor i32 %32, %36
%38 = load i32*, i32** %3
%39 = getelementptr inbounds i32, i32* %38, i64 2
store i32 %37, i32* %39
%40 = load i32*, i32** %4
%41 = getelementptr inbounds i32, i32* %40, i64 2
%42 = load i32, i32* %41
%43 = and i32 %42, 15
%44 = shl i32 %43, 4
%45 = load i32*, i32** %3
%46 = getelementptr inbounds i32, i32* %45, i64 3
store i32 %44, i32* %46
ret void
}

LLVM IR (-O2):
define void @set_nonce_in_tweak(i32* nocapture %0, i32* nocapture %1) {
%3 = load i32, i32* %0
%4 = and i32 %3, 240
%5 = load i32, i32* %1
%6 = ashr i32 %5, 4
%7 = xor i32 %6, %4
store i32 %7, i32* %0
%8 = load i32, i32* %1
%9 = shl i32 %8, 4
%10 = and i32 %9, 240
%11 = getelementptr inbounds i32, i32* %1, i64 1
%12 = load i32, i32* %11
%13 = ashr i32 %12, 4
%14 = xor i32 %10, %13
%15 = getelementptr inbounds i32, i32* %0, i64 1
store i32 %14, i32* %15
%16 = load i32, i32* %11
%17 = shl i32 %16, 4
%18 = and i32 %17, 240
%19 = getelementptr inbounds i32, i32* %1, i64 2
%20 = load i32, i32* %19
%21 = ashr i32 %20, 4
%22 = xor i32 %18, %21
%23 = getelementptr inbounds i32, i32* %0, i64 2
store i32 %22, i32* %23
%24 = load i32, i32* %19
%25 = shl i32 %24, 4
%26 = and i32 %25, 240
%27 = getelementptr inbounds i32, i32* %0, i64 3
store i32 %26, i32* %27
ret void
}