#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 scalar_t__ uint32_t;
typedef int /*<<< orphan*/ __m128i;

/* Variables and functions */
int /*<<< orphan*/ _mm_loadu_si128(int /*<<< orphan*/ const *);
int lower_bound(scalar_t__ *, scalar_t__, int /*<<< orphan*/, int);
int iunpacksearch32(__m128i *initOffset, const __m128i *in, uint32_t key,
                    uint32_t *presult) {
  uint32_t *in32 = (uint32_t *)in;
  int answer = lower_bound(in32, key, 0, 128);
  if (in32[answer] < key) {
    *presult = key + 1;
    return (128);
  }
  *presult = in32[answer];
  *initOffset = _mm_loadu_si128(in + 31);
  return answer;
}


x86 assembly (clang, -O0):
<iunpacksearch32>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rsi
xor    %edx,%edx
mov    $0x80,%ecx
call   1030 <lower_bound@plt>
mov    %eax,-0x34(%rbp)
mov    -0x30(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
cmp    -0x20(%rbp),%rax
jge    1188 <iunpacksearch32+0x68>
mov    -0x20(%rbp),%rcx
add    $0x1,%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x80,-0x4(%rbp)
jmp    11b6 <iunpacksearch32+0x96>
mov    -0x30(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,8),%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rdi
add    $0x7c,%rdi
call   1040 <_mm_loadu_si128@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<iunpacksearch32>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r15
mov    %rdx,%rbp
mov    %rsi,%rbx
mov    %rdi,%r14
mov    $0x80,%r12d
mov    %rsi,%rdi
mov    %rdx,%rsi
xor    %edx,%edx
mov    $0x80,%ecx
call   1030 <lower_bound@plt>
mov    %eax,%r13d
cltq
mov    (%rbx,%rax,8),%rax
cmp    %rbp,%rax
jge    1166 <iunpacksearch32+0x46>
add    $0x1,%rbp
mov    %rbp,(%r15)
jmp    117b <iunpacksearch32+0x5b>
mov    %rax,(%r15)
add    $0x7c,%rbx
mov    %rbx,%rdi
call   1040 <_mm_loadu_si128@plt>
mov    %eax,(%r14)
mov    %r13d,%r12d
mov    %r12d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @iunpacksearch32(i32* %0, i32* %1, i64 %2, i64* %3) {
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i64
%9 = alloca i64*
%10 = alloca i64*
%11 = alloca i32
store i32* %0, i32** %6
store i32* %1, i32** %7
store i64 %2, i64* %8
store i64* %3, i64** %9
%12 = load i32*, i32** %7
%13 = bitcast i32* %12 to i64*
store i64* %13, i64** %10
%14 = load i64*, i64** %10
%15 = load i64, i64* %8
%16 = call i32 @lower_bound(i64* %14, i64 %15, i32 0, i32 128)
store i32 %16, i32* %11
%17 = load i64*, i64** %10
%18 = load i32, i32* %11
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i64, i64* %17, i64 %19
%21 = load i64, i64* %20
%22 = load i64, i64* %8
%23 = icmp slt i64 %21, %22
br i1 %23, label %24, label %28
24: ; preds = %4
%25 = load i64, i64* %8
%26 = add nsw i64 %25, 1
%27 = load i64*, i64** %9
store i64 %26, i64* %27
store i32 128, i32* %5
br label %40
28: ; preds = %4
%29 = load i64*, i64** %10
%30 = load i32, i32* %11
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i64, i64* %29, i64 %31
%33 = load i64, i64* %32
%34 = load i64*, i64** %9
store i64 %33, i64* %34
%35 = load i32*, i32** %7
%36 = getelementptr inbounds i32, i32* %35, i64 31
%37 = call i32 @_mm_loadu_si128(i32* %36)
%38 = load i32*, i32** %6
store i32 %37, i32* %38
%39 = load i32, i32* %11
store i32 %39, i32* %5
br label %40
40: ; preds = %28, %24
%41 = load i32, i32* %5
ret i32 %41
}

LLVM IR (-O2):
define i32 @iunpacksearch32(i32* nocapture writeonly %0, i32* %1, i64 %2, i64* nocapture writeonly %3) {
%5 = bitcast i32* %1 to i64*
%6 = tail call i32 @lower_bound(i64* %5, i64 %2, i32 0, i32 128)
%7 = sext i32 %6 to i64
%8 = getelementptr inbounds i64, i64* %5, i64 %7
%9 = load i64, i64* %8
%10 = icmp slt i64 %9, %2
br i1 %10, label %11, label %13
11: ; preds = %4
%12 = add nsw i64 %2, 1
store i64 %12, i64* %3
br label %16
13: ; preds = %4
store i64 %9, i64* %3
%14 = getelementptr inbounds i32, i32* %1, i64 31
%15 = tail call i32 @_mm_loadu_si128(i32* %14)
store i32 %15, i32* %0
br label %16
16: ; preds = %13, %11
%17 = phi i32 [ 128, %11 ], [ %6, %13 ]
ret i32 %17
}