#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*/ *);
__m128i load_partial(const void *p, unsigned n) {
  if ((unsigned long)p % 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)
mov    -0x10(%rbp),%rax
and    $0xf,%rax
cmp    $0x0,%rax
jne    1142 <load_partial+0x32>
mov    -0x10(%rbp),%rdi
call   1030 <_mm_loadu_si128@plt>
mov    %eax,-0x4(%rbp)
jmp    117a <load_partial+0x6a>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jae    1174 <load_partial+0x64>
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    1149 <load_partial+0x39>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load_partial>:
mov    %rdi,%rax
test   $0xf,%al
je     1144 <load_partial+0x24>
test   %esi,%esi
je     114c <load_partial+0x2c>
push   %rax
mov    %esi,%edx
lea    0x4(%rsp),%rdi
mov    %rax,%rsi
call   1030 <memcpy@plt>
mov    0x4(%rsp),%eax
add    $0x8,%rsp
ret
mov    %rax,%rdi
jmp    1040 <_mm_loadu_si128@plt>
ret

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 i8*, i8** %4
%9 = ptrtoint i8* %8 to i64
%10 = urem i64 %9, 16
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %16
12: ; preds = %2
%13 = load i8*, i8** %4
%14 = bitcast i8* %13 to i32*
%15 = call i32 @_mm_loadu_si128(i32* %14)
store i32 %15, i32* %3
br label %36
16: ; preds = %2
store i32 0, i32* %7
br label %17
17: ; preds = %31, %16
%18 = load i32, i32* %7
%19 = load i32, i32* %5
%20 = icmp ult i32 %18, %19
br i1 %20, label %21, label %34
21: ; preds = %17
%22 = load i8*, i8** %4
%23 = load i32, i32* %7
%24 = zext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %22, i64 %24
%26 = load i8, i8* %25
%27 = bitcast i32* %6 to i8*
%28 = load i32, i32* %7
%29 = zext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %27, i64 %29
store i8 %26, i8* %30
br label %31
31: ; preds = %21
%32 = load i32, i32* %7
%33 = add i32 %32, 1
store i32 %33, i32* %7
br label %17
34: ; preds = %17
%35 = load i32, i32* %6
store i32 %35, i32* %3
br label %36
36: ; preds = %34, %12
%37 = load i32, i32* %3
ret i32 %37
}

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