#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 */

/* Variables and functions */
int /*<<< orphan*/ assert(int);
void write_nibble(unsigned long *w, int i, int v) {
  assert(i >= 0 && i < 16);
  unsigned long mask = 0xf;
  mask <<= (i * 4);
  *w &= ~mask;
  unsigned long prom = v;
  prom <<= (i * 4);
  *w |= prom;
}


x86 assembly (clang, -O0):
<write_nibble>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0xc(%rbp)
mov    %al,-0x21(%rbp)
jl     113b <write_nibble+0x2b>
cmpl   $0x10,-0xc(%rbp)
setl   %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
movq   $0xf,-0x18(%rbp)
mov    -0xc(%rbp),%ecx
shl    $0x2,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,%ecx
shl    %cl,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rcx
xor    $0xffffffffffffffff,%rcx
mov    -0x8(%rbp),%rax
and    (%rax),%rcx
mov    %rcx,(%rax)
movslq -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0xc(%rbp),%ecx
shl    $0x2,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,%ecx
shl    %cl,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rcx
mov    -0x8(%rbp),%rax
or     (%rax),%rcx
mov    %rcx,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_nibble>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%r14d
mov    %esi,%ebp
mov    %rdi,%rbx
xor    %edi,%edi
cmp    $0x10,%esi
setb   %dil
call   1030 <assert@plt>
shl    $0x2,%ebp
mov    $0xf,%eax
mov    %ebp,%ecx
shl    %cl,%rax
not    %rax
movslq %r14d,%rdx
shl    %cl,%rdx
and    (%rbx),%rax
or     %rax,%rdx
mov    %rdx,(%rbx)
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define void @write_nibble(i64* %0, i32 %1, i32 %2) {
%4 = alloca i64*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i64
%8 = alloca i64
store i64* %0, i64** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%9 = load i32, i32* %5
%10 = icmp sge i32 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %3
%12 = load i32, i32* %5
%13 = icmp slt i32 %12, 16
br label %14
14: ; preds = %11, %3
%15 = phi i1 [ false, %3 ], [ %13, %11 ]
%16 = zext i1 %15 to i32
%17 = call i32 @assert(i32 %16)
store i64 15, i64* %7
%18 = load i32, i32* %5
%19 = mul nsw i32 %18, 4
%20 = load i64, i64* %7
%21 = zext i32 %19 to i64
%22 = shl i64 %20, %21
store i64 %22, i64* %7
%23 = load i64, i64* %7
%24 = xor i64 %23, -1
%25 = load i64*, i64** %4
%26 = load i64, i64* %25
%27 = and i64 %26, %24
store i64 %27, i64* %25
%28 = load i32, i32* %6
%29 = sext i32 %28 to i64
store i64 %29, i64* %8
%30 = load i32, i32* %5
%31 = mul nsw i32 %30, 4
%32 = load i64, i64* %8
%33 = zext i32 %31 to i64
%34 = shl i64 %32, %33
store i64 %34, i64* %8
%35 = load i64, i64* %8
%36 = load i64*, i64** %4
%37 = load i64, i64* %36
%38 = or i64 %37, %35
store i64 %38, i64* %36
ret void
}

LLVM IR (-O2):
define void @write_nibble(i64* nocapture %0, i32 %1, i32 %2) {
%4 = icmp ult i32 %1, 16
%5 = zext i1 %4 to i32
%6 = tail call i32 @assert(i32 %5)
%7 = shl nsw i32 %1, 2
%8 = zext i32 %7 to i64
%9 = shl i64 15, %8
%10 = xor i64 %9, -1
%11 = load i64, i64* %0
%12 = and i64 %11, %10
%13 = sext i32 %2 to i64
%14 = shl i64 %13, %8
%15 = or i64 %12, %14
store i64 %15, i64* %0
ret void
}