#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_loadu_si128(int /*<<< orphan*/ *);
int /*<<< orphan*/ _mm_setzero_si128();
__m128i load_partial(const void *p, size_t n) {
  if (n == 0) {
    return _mm_setzero_si128();
  } else if (n % 16 == 0) {
    return _mm_loadu_si128((__m128i *)p);
  } else {
    __m128i tmp;
    size_t i;
    for (i = 0; i < n; ++i) {
      ((char *)&tmp)[i] = ((char *)p)[i];
    }
    return tmp;
  }
}


x86 assembly (clang, -O0):
<load_partial>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    114a <load_partial+0x2a>
mov    $0x0,%al
call   1030 <_mm_setzero_si128@plt>
mov    %eax,-0x4(%rbp)
jmp    11ad <load_partial+0x8d>
mov    -0x18(%rbp),%rax
and    $0xf,%rax
cmp    $0x0,%rax
jne    116d <load_partial+0x4d>
mov    -0x10(%rbp),%rdi
call   1040 <_mm_loadu_si128@plt>
mov    %eax,-0x4(%rbp)
jmp    11ad <load_partial+0x8d>
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    11a7 <load_partial+0x87>
mov    -0x10(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    (%rax,%rcx,1),%cl
mov    -0x28(%rbp),%rax
mov    %cl,-0x1c(%rbp,%rax,1)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1175 <load_partial+0x55>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load_partial>:
mov    %rsi,%rdx
test   %rsi,%rsi
je     1151 <load_partial+0x21>
mov    %rdi,%rsi
test   $0xf,%dl
je     1158 <load_partial+0x28>
push   %rax
lea    0x4(%rsp),%rdi
call   1040 <memcpy@plt>
mov    0x4(%rsp),%eax
pop    %rcx
ret
xor    %eax,%eax
jmp    1030 <_mm_setzero_si128@plt>
mov    %rsi,%rdi
jmp    1050 <_mm_loadu_si128@plt>

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

LLVM IR (-O2):
define i32 @load_partial(i8* %0, i64 %1) {
%3 = alloca i32
%4 = icmp eq i64 %1, 0
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i32 (...) @_mm_setzero_si128()
br label %16
7: ; preds = %2
%8 = and i64 %1, 15
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %7
%11 = bitcast i8* %0 to i32*
%12 = tail call i32 @_mm_loadu_si128(i32* %11)
br label %16
13: ; preds = %7
%14 = bitcast i32* %3 to i8*
%15 = load i32, i32* %3
br label %16
16: ; preds = %13, %10, %5
%17 = phi i32 [ %6, %5 ], [ %12, %10 ], [ %15, %13 ]
ret i32 %17
}