#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 uint16_t;

/* Variables and functions */
int get_word(int /*<<< orphan*/ *);
int /*<<< orphan*/ make_word(int /*<<< orphan*/ *, int);
void add_zchar(int c, int n, uint8_t *encoded) {
  uint16_t w = get_word(&encoded[2 * (n / 3)]);
  w |= (c & 0x1f) << (5 * (2 - (n % 3)));
  make_word(&encoded[2 * (n / 3)], w);
}


x86 assembly (clang, -O0):
<add_zchar>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
shl    $0x1,%eax
cltq
shl    $0x2,%rax
add    %rax,%rdi
call   1040 <get_word@plt>
mov    %eax,-0x14(%rbp)
mov    -0x4(%rbp),%eax
and    $0x1f,%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
mov    -0x18(%rbp),%eax
mov    $0x2,%ecx
sub    %edx,%ecx
imul   $0x5,%ecx,%ecx
shl    %cl,%eax
or     -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
shl    $0x1,%eax
cltq
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x14(%rbp),%esi
call   1030 <make_word@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add_zchar>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebp
movslq %esi,%r15
imul   $0x55555556,%r15,%rbx
mov    %rbx,%rax
shr    $0x3f,%rax
shr    $0x20,%rbx
add    %eax,%ebx
lea    (%rbx,%rbx,1),%eax
cltq
lea    (%rdx,%rax,4),%r14
mov    %r14,%rdi
call   1040 <get_word@plt>
and    $0x1f,%ebp
lea    (%rbx,%rbx,2),%ecx
sub    %ecx,%r15d
mov    $0x2,%cl
sub    %r15b,%cl
movzbl %cl,%ecx
lea    (%rcx,%rcx,4),%ecx
shl    %cl,%ebp
or     %eax,%ebp
mov    %r14,%rdi
mov    %ebp,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <make_word@plt>

LLVM IR (-O0):
define void @add_zchar(i32 %0, i32 %1, i32* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32* %2, i32** %6
%8 = load i32*, i32** %6
%9 = load i32, i32* %5
%10 = sdiv i32 %9, 3
%11 = mul nsw i32 2, %10
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i32, i32* %8, i64 %12
%14 = call i32 @get_word(i32* %13)
store i32 %14, i32* %7
%15 = load i32, i32* %4
%16 = and i32 %15, 31
%17 = load i32, i32* %5
%18 = srem i32 %17, 3
%19 = sub nsw i32 2, %18
%20 = mul nsw i32 5, %19
%21 = shl i32 %16, %20
%22 = load i32, i32* %7
%23 = or i32 %22, %21
store i32 %23, i32* %7
%24 = load i32*, i32** %6
%25 = load i32, i32* %5
%26 = sdiv i32 %25, 3
%27 = mul nsw i32 2, %26
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i32, i32* %24, i64 %28
%30 = load i32, i32* %7
%31 = call i32 @make_word(i32* %29, i32 %30)
ret void
}

LLVM IR (-O2):
define void @add_zchar(i32 %0, i32 %1, i32* %2) {
%4 = sdiv i32 %1, 3
%5 = shl nsw i32 %4, 1
%6 = sext i32 %5 to i64
%7 = getelementptr inbounds i32, i32* %2, i64 %6
%8 = tail call i32 @get_word(i32* %7)
%9 = and i32 %0, 31
%10 = srem i32 %1, 3
%11 = sub nsw i32 2, %10
%12 = mul nuw nsw i32 %11, 5
%13 = shl nuw nsw i32 %9, %12
%14 = or i32 %8, %13
%15 = tail call i32 @make_word(i32* %7, i32 %14)
ret void
}