#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_from_left_to_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_[(16 - num_bytes) + i] = x_[i];
    }
  }
}


x86 assembly (clang, -O0):
<store_partial_from_left_to_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_from_left_to_right+0x23>
jmp    11af <store_partial_from_left_to_right+0x9f>
cmpq   $0x10,-0x18(%rbp)
jb     114f <store_partial_from_left_to_right+0x3f>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1030 <storeu@plt>
jmp    11aa <store_partial_from_left_to_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_from_left_to_right+0x95>
mov    -0x30(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x28(%rbp),%rax
mov    $0x10,%ecx
sub    -0x18(%rbp),%rcx
add    -0x20(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1167 <store_partial_from_left_to_right+0x57>
jmp    11aa <store_partial_from_left_to_right+0x9a>
jmp    11af <store_partial_from_left_to_right+0x9f>
add    $0x30,%rsp
pop    %rbp
ret

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

LLVM IR (-O0):
define void @store_partial_from_left_to_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* %7
%31 = getelementptr inbounds i8, i8* %29, i64 %30
%32 = load i8, i8* %31
%33 = load i8*, i8** %8
%34 = load i64, i64* %6
%35 = sub i64 16, %34
%36 = load i64, i64* %7
%37 = add i64 %35, %36
%38 = getelementptr inbounds i8, i8* %33, i64 %37
store i8 %32, 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_from_left_to_right(i32* %0, i32 %1, i64 %2) {
%4 = alloca i32
store i32 %1, i32* %4
%5 = icmp eq i64 %2, 0
br i1 %5, label %16, label %6
6: ; preds = %3
%7 = icmp ugt i64 %2, 15
br i1 %7, label %8, label %10
8: ; preds = %6
%9 = tail call i32 @storeu(i32* %0, i32 %1)
br label %16
10: ; preds = %6
%11 = getelementptr i32, i32* %0, i64 4
%12 = bitcast i32* %11 to i8*
%13 = sub nsw i64 0, %2
%14 = getelementptr i8, i8* %12, i64 %13
%15 = bitcast i32* %4 to i8*
br label %16
16: ; preds = %10, %8, %3
ret void
}