#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*/ __m128i;

/* Variables and functions */
int /*<<< orphan*/ _mm_add_epi32(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ _mm_shuffle_epi32(int /*<<< orphan*/, int);
int /*<<< orphan*/ _mm_slli_si128(int /*<<< orphan*/, int);
__m128i PrefixSum(__m128i curr, __m128i prev) {
  __m128i Add = _mm_slli_si128(curr, 4);
  prev = _mm_shuffle_epi32(prev, 0xff);
  curr = _mm_add_epi32(curr, Add);
  Add = _mm_slli_si128(curr, 8);
  curr = _mm_add_epi32(curr, prev);
  curr = _mm_add_epi32(curr, Add);
  return curr;
}


x86 assembly (clang, -O0):
<PrefixSum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%edi
mov    $0x4,%esi
call   1050 <_mm_slli_si128@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%edi
mov    $0xff,%esi
call   1040 <_mm_shuffle_epi32@plt>
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1030 <_mm_add_epi32@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%edi
mov    $0x8,%esi
call   1050 <_mm_slli_si128@plt>
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1030 <_mm_add_epi32@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1030 <_mm_add_epi32@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<PrefixSum>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%r14d
mov    %edi,%ebp
mov    $0x4,%esi
call   1050 <_mm_slli_si128@plt>
mov    %eax,%ebx
mov    %r14d,%edi
mov    $0xff,%esi
call   1040 <_mm_shuffle_epi32@plt>
mov    %eax,%r14d
mov    %ebp,%edi
mov    %ebx,%esi
call   1030 <_mm_add_epi32@plt>
mov    %eax,%ebx
mov    %eax,%edi
mov    $0x8,%esi
call   1050 <_mm_slli_si128@plt>
mov    %eax,%ebp
mov    %ebx,%edi
mov    %r14d,%esi
call   1030 <_mm_add_epi32@plt>
mov    %eax,%edi
mov    %ebp,%esi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <_mm_add_epi32@plt>

LLVM IR (-O0):
define i32 @PrefixSum(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%6 = load i32, i32* %3
%7 = call i32 @_mm_slli_si128(i32 %6, i32 4)
store i32 %7, i32* %5
%8 = load i32, i32* %4
%9 = call i32 @_mm_shuffle_epi32(i32 %8, i32 255)
store i32 %9, i32* %4
%10 = load i32, i32* %3
%11 = load i32, i32* %5
%12 = call i32 @_mm_add_epi32(i32 %10, i32 %11)
store i32 %12, i32* %3
%13 = load i32, i32* %3
%14 = call i32 @_mm_slli_si128(i32 %13, i32 8)
store i32 %14, i32* %5
%15 = load i32, i32* %3
%16 = load i32, i32* %4
%17 = call i32 @_mm_add_epi32(i32 %15, i32 %16)
store i32 %17, i32* %3
%18 = load i32, i32* %3
%19 = load i32, i32* %5
%20 = call i32 @_mm_add_epi32(i32 %18, i32 %19)
store i32 %20, i32* %3
%21 = load i32, i32* %3
ret i32 %21
}

LLVM IR (-O2):
define i32 @PrefixSum(i32 %0, i32 %1) {
%3 = tail call i32 @_mm_slli_si128(i32 %0, i32 4)
%4 = tail call i32 @_mm_shuffle_epi32(i32 %1, i32 255)
%5 = tail call i32 @_mm_add_epi32(i32 %0, i32 %3)
%6 = tail call i32 @_mm_slli_si128(i32 %5, i32 8)
%7 = tail call i32 @_mm_add_epi32(i32 %5, i32 %4)
%8 = tail call i32 @_mm_add_epi32(i32 %7, i32 %6)
ret i32 %8
}