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

/* Variables and functions */
int /*<<< orphan*/ storeu(int /*<<< orphan*/ const *, int /*<<< orphan*/);
void store_partial_right(const uint8_t *p, __m128i x, const size_t num_bytes) {
  if (num_bytes == 0) {
    return;
  } else if (num_bytes >= 16) {
    storeu(p, x);
  } else {
    size_t i;
    char *p_ = (char *)p;
    char *x_ = (char *)&x;
    for (i = 0; i < num_bytes; ++i) {
      p_[i] = x_[(16 - num_bytes) + i];
    }
  }
}


x86 assembly (clang, -O0):
<store_partial_right>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1133 <store_partial_right+0x23>
jmp    11af <store_partial_right+0x9f>
cmpq   $0x10,-0x18(%rbp)
jb     114f <store_partial_right+0x3f>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1030 <storeu@plt>
jmp    11aa <store_partial_right+0x9a>
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
lea    -0xc(%rbp),%rax
mov    %rax,-0x30(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    11a5 <store_partial_right+0x95>
mov    -0x30(%rbp),%rax
mov    $0x10,%ecx
sub    -0x18(%rbp),%rcx
add    -0x20(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x28(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1167 <store_partial_right+0x57>
jmp    11aa <store_partial_right+0x9a>
jmp    11af <store_partial_right+0x9f>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<store_partial_right>:
push   %rax
mov    %esi,0x4(%rsp)
test   %rdx,%rdx
je     1147 <store_partial_right+0x27>
cmp    $0x10,%rdx
jb     1136 <store_partial_right+0x16>
pop    %rax
jmp    1030 <storeu@plt>
lea    0x4(%rsp),%rsi
sub    %rdx,%rsi
add    $0x10,%rsi
call   1040 <memcpy@plt>
pop    %rax
ret

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

LLVM IR (-O2):
define void @store_partial_right(i32* %0, i32 %1, i64 %2) {
%4 = bitcast i32* %0 to i8*
%5 = alloca i32
store i32 %1, i32* %5
%6 = icmp eq i64 %2, 0
br i1 %6, label %16, label %7
7: ; preds = %3
%8 = icmp ugt i64 %2, 15
br i1 %8, label %9, label %11
9: ; preds = %7
%10 = tail call i32 @storeu(i32* %0, i32 %1)
br label %16
11: ; preds = %7
%12 = getelementptr i32, i32* %5, i64 4
%13 = bitcast i32* %12 to i8*
%14 = sub nsw i64 0, %2
%15 = getelementptr i8, i8* %13, i64 %14
br label %16
16: ; preds = %11, %9, %3
ret void
}