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

/* Variables and functions */
int /*<<< orphan*/ _mm_add_pi32(int /*<<< orphan*/, int /*<<< orphan*/);
int _mm_cvtsi64_si32(int /*<<< orphan*/);
int /*<<< orphan*/ _mm_empty();
int /*<<< orphan*/ _mm_setzero_si64();
int /*<<< orphan*/ _mm_unpackhi_pi32(int /*<<< orphan*/, int /*<<< orphan*/);
int test4(int argc, char *argv[]) {
  int array[16] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
  __m64 *p = (__m64 *)array;
  __m64 accum = _mm_setzero_si64();
  for (int i = 0; i < 8; ++i)
    accum = _mm_add_pi32(p[i], accum);
  __m64 accum2 = _mm_unpackhi_pi32(accum, accum);
  accum = _mm_add_pi32(accum, accum2);
  int result = _mm_cvtsi64_si32(accum);
  _mm_empty();
  return result;
}


x86 assembly (clang, -O0):
<test4>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x50(%rbp),%rdi
lea    0xe86(%rip),%rsi
mov    $0x40,%edx
call   1040 <memcpy@plt>
lea    -0x50(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    $0x0,%al
call   1070 <_mm_setzero_si64@plt>
mov    %eax,-0x5c(%rbp)
movl   $0x0,-0x60(%rbp)
cmpl   $0x8,-0x60(%rbp)
jge    11cb <test4+0x6b>
mov    -0x58(%rbp),%rax
movslq -0x60(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
mov    -0x5c(%rbp),%esi
call   1060 <_mm_add_pi32@plt>
mov    %eax,-0x5c(%rbp)
mov    -0x60(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x60(%rbp)
jmp    119d <test4+0x3d>
mov    -0x5c(%rbp),%edi
mov    -0x5c(%rbp),%esi
call   1050 <_mm_unpackhi_pi32@plt>
mov    %eax,-0x64(%rbp)
mov    -0x5c(%rbp),%edi
mov    -0x64(%rbp),%esi
call   1060 <_mm_add_pi32@plt>
mov    %eax,-0x5c(%rbp)
mov    -0x5c(%rbp),%edi
call   1030 <_mm_cvtsi64_si32@plt>
mov    %eax,-0x68(%rbp)
mov    $0x0,%al
call   1080 <_mm_empty@plt>
mov    -0x68(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test4>:
push   %rbx
xor    %eax,%eax
call   1060 <_mm_setzero_si64@plt>
xor    %edi,%edi
mov    %eax,%esi
call   1050 <_mm_add_pi32@plt>
mov    $0x1,%edi
mov    %eax,%esi
call   1050 <_mm_add_pi32@plt>
mov    $0x2,%edi
mov    %eax,%esi
call   1050 <_mm_add_pi32@plt>
mov    $0x3,%edi
mov    %eax,%esi
call   1050 <_mm_add_pi32@plt>
mov    $0x4,%edi
mov    %eax,%esi
call   1050 <_mm_add_pi32@plt>
mov    $0x5,%edi
mov    %eax,%esi
call   1050 <_mm_add_pi32@plt>
mov    $0x6,%edi
mov    %eax,%esi
call   1050 <_mm_add_pi32@plt>
mov    $0x7,%edi
mov    %eax,%esi
call   1050 <_mm_add_pi32@plt>
mov    %eax,%ebx
mov    %eax,%edi
mov    %eax,%esi
call   1040 <_mm_unpackhi_pi32@plt>
mov    %ebx,%edi
mov    %eax,%esi
call   1050 <_mm_add_pi32@plt>
mov    %eax,%edi
call   1030 <_mm_cvtsi64_si32@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1070 <_mm_empty@plt>
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@__const.test4.array = [16 x i32] [i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15]
define i32 @test4(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca [16 x i32]
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 %0, i32* %3
store i8** %1, i8*** %4
%11 = bitcast [16 x i32]* %5 to i8*
%12 = getelementptr inbounds [16 x i32], [16 x i32]* %5, i64 0, i64 0
store i32* %12, i32** %6
%13 = call i32 (...) @_mm_setzero_si64()
store i32 %13, i32* %7
store i32 0, i32* %8
br label %14
14: ; preds = %25, %2
%15 = load i32, i32* %8
%16 = icmp slt i32 %15, 8
br i1 %16, label %17, label %28
17: ; preds = %14
%18 = load i32*, i32** %6
%19 = load i32, i32* %8
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i32, i32* %18, i64 %20
%22 = load i32, i32* %21
%23 = load i32, i32* %7
%24 = call i32 @_mm_add_pi32(i32 %22, i32 %23)
store i32 %24, i32* %7
br label %25
25: ; preds = %17
%26 = load i32, i32* %8
%27 = add nsw i32 %26, 1
store i32 %27, i32* %8
br label %14
28: ; preds = %14
%29 = load i32, i32* %7
%30 = load i32, i32* %7
%31 = call i32 @_mm_unpackhi_pi32(i32 %29, i32 %30)
store i32 %31, i32* %9
%32 = load i32, i32* %7
%33 = load i32, i32* %9
%34 = call i32 @_mm_add_pi32(i32 %32, i32 %33)
store i32 %34, i32* %7
%35 = load i32, i32* %7
%36 = call i32 @_mm_cvtsi64_si32(i32 %35)
store i32 %36, i32* %10
%37 = call i32 (...) @_mm_empty()
%38 = load i32, i32* %10
ret i32 %38
}

LLVM IR (-O2):
define i32 @test4(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 (...) @_mm_setzero_si64()
%4 = tail call i32 @_mm_add_pi32(i32 0, i32 %3)
%5 = tail call i32 @_mm_add_pi32(i32 1, i32 %4)
%6 = tail call i32 @_mm_add_pi32(i32 2, i32 %5)
%7 = tail call i32 @_mm_add_pi32(i32 3, i32 %6)
%8 = tail call i32 @_mm_add_pi32(i32 4, i32 %7)
%9 = tail call i32 @_mm_add_pi32(i32 5, i32 %8)
%10 = tail call i32 @_mm_add_pi32(i32 6, i32 %9)
%11 = tail call i32 @_mm_add_pi32(i32 7, i32 %10)
%12 = tail call i32 @_mm_unpackhi_pi32(i32 %11, i32 %11)
%13 = tail call i32 @_mm_add_pi32(i32 %11, i32 %12)
%14 = tail call i32 @_mm_cvtsi64_si32(i32 %13)
%15 = tail call i32 (...) @_mm_empty()
ret i32 %14
}