#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, unsigned n) {
  if (n == 0) {
    return _mm_setzero_si128();
  } else if (n % 16 == 0) {
    return _mm_loadu_si128((__m128i *)p);
  } else {
    __m128i tmp;
    unsigned 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    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    1148 <load_partial+0x28>
mov    $0x0,%al
call   1030 <_mm_setzero_si128@plt>
mov    %eax,-0x4(%rbp)
jmp    11a0 <load_partial+0x80>
mov    -0x14(%rbp),%eax
and    $0xf,%eax
cmp    $0x0,%eax
jne    1168 <load_partial+0x48>
mov    -0x10(%rbp),%rdi
call   1040 <_mm_loadu_si128@plt>
mov    %eax,-0x4(%rbp)
jmp    11a0 <load_partial+0x80>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jae    119a <load_partial+0x7a>
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
mov    (%rax,%rcx,1),%cl
mov    -0x1c(%rbp),%eax
mov    %cl,-0x18(%rbp,%rax,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    116f <load_partial+0x4f>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load_partial>:
test   %esi,%esi
je     1153 <load_partial+0x23>
mov    %rdi,%rax
test   $0xf,%sil
je     115a <load_partial+0x2a>
push   %rax
mov    %esi,%edx
lea    0x4(%rsp),%rdi
mov    %rax,%rsi
call   1040 <memcpy@plt>
mov    0x4(%rsp),%eax
pop    %rcx
ret
xor    %eax,%eax
jmp    1030 <_mm_setzero_si128@plt>
mov    %rax,%rdi
jmp    1050 <_mm_loadu_si128@plt>

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

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