#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 jvc_unit;
typedef enum rc_proto { ____Placeholder_rc_proto } rc_proto;

/* Variables and functions */
int jvc_encode(enum rc_proto proto, unsigned scancode, unsigned *buf) {
  const int jvc_unit = 525000;
  int i;
  scancode = ((scancode << 8) & 0xff00) | ((scancode >> 8) & 0x00ff);
  *buf++ = (((jvc_unit * 16) + 500) / 1000);
  *buf++ = (((jvc_unit * 8) + 500) / 1000);
  for (i = 0; i < 16; i++) {
    *buf++ = (((jvc_unit) + 500) / 1000);
    if (scancode & 1)
      *buf++ = (((jvc_unit * 3) + 500) / 1000);
    else
      *buf++ = (((jvc_unit) + 500) / 1000);
    scancode >>= 1;
  }
  *buf = (((jvc_unit) + 500) / 1000);
  return 35;
}


x86 assembly (clang, -O0):
<jvc_encode>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
movl   $0x802c8,-0x14(%rbp)
mov    -0x8(%rbp),%eax
shl    $0x8,%eax
and    $0xff00,%eax
mov    -0x8(%rbp),%ecx
shr    $0x8,%ecx
and    $0xff,%ecx
or     %ecx,%eax
mov    %eax,-0x8(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x10(%rbp)
movl   $0x20d0,(%rax)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x10(%rbp)
movl   $0x1068,(%rax)
movl   $0x0,-0x18(%rbp)
cmpl   $0x10,-0x18(%rbp)
jge    11d6 <jvc_encode+0xd6>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x10(%rbp)
movl   $0x20d,(%rax)
mov    -0x8(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     11aa <jvc_encode+0xaa>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x10(%rbp)
movl   $0x627,(%rax)
jmp    11bf <jvc_encode+0xbf>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x10(%rbp)
movl   $0x20d,(%rax)
mov    -0x8(%rbp),%eax
shr    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1162 <jvc_encode+0x62>
mov    -0x10(%rbp),%rax
movl   $0x20d,(%rax)
mov    $0x23,%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<jvc_encode>:
rol    $0x8,%si
movzwl %si,%eax
movabs $0x1068000020d0,%rcx
mov    %rcx,(%rdx)
movl   $0x20d,0x8(%rdx)
test   $0x1,%al
mov    $0x20d,%ecx
mov    $0x627,%r8d
mov    $0x627,%edi
cmove  %ecx,%edi
mov    %edi,0xc(%rdx)
movl   $0x20d,0x10(%rdx)
test   $0x2,%al
mov    $0x627,%edi
cmove  %ecx,%edi
mov    %edi,0x14(%rdx)
movl   $0x20d,0x18(%rdx)
test   $0x4,%al
mov    $0x627,%edi
cmove  %ecx,%edi
mov    %edi,0x1c(%rdx)
movl   $0x20d,0x20(%rdx)
test   $0x8,%al
mov    $0x627,%edi
cmove  %ecx,%edi
mov    %edi,0x24(%rdx)
movl   $0x20d,0x28(%rdx)
test   $0x10,%al
mov    $0x627,%edi
cmove  %ecx,%edi
mov    %edi,0x2c(%rdx)
movl   $0x20d,0x30(%rdx)
test   $0x20,%al
mov    $0x627,%edi
cmove  %ecx,%edi
mov    %edi,0x34(%rdx)
movl   $0x20d,0x38(%rdx)
test   $0x40,%al
mov    $0x627,%edi
cmove  %ecx,%edi
mov    %edi,0x3c(%rdx)
movl   $0x20d,0x40(%rdx)
movd   %eax,%xmm0
pshufd $0x0,%xmm0,%xmm0
movdqa 0xe3d(%rip),%xmm1
pand   %xmm0,%xmm1
pand   0xe41(%rip),%xmm0
pxor   %xmm2,%xmm2
pcmpeqd %xmm2,%xmm0
pcmpeqd %xmm2,%xmm1
packssdw %xmm0,%xmm1
packsswb %xmm1,%xmm1
pmovmskb %xmm1,%edi
test   $0x80,%dil
mov    $0x627,%esi
cmovne %ecx,%esi
mov    %esi,0x44(%rdx)
movl   $0x20d,0x48(%rdx)
test   $0x40,%dil
mov    $0x627,%esi
cmovne %ecx,%esi
mov    %esi,0x4c(%rdx)
movl   $0x20d,0x50(%rdx)
test   $0x20,%dil
mov    $0x627,%esi
cmovne %ecx,%esi
mov    %esi,0x54(%rdx)
movl   $0x20d,0x58(%rdx)
test   $0x10,%dil
mov    $0x627,%esi
cmovne %ecx,%esi
mov    %esi,0x5c(%rdx)
movl   $0x20d,0x60(%rdx)
test   $0x8,%dil
mov    $0x627,%esi
cmovne %ecx,%esi
mov    %esi,0x64(%rdx)
movl   $0x20d,0x68(%rdx)
test   $0x4,%dil
mov    $0x627,%esi
cmovne %ecx,%esi
mov    %esi,0x6c(%rdx)
movl   $0x20d,0x70(%rdx)
test   $0x2,%dil
mov    $0x627,%esi
cmovne %ecx,%esi
mov    %esi,0x74(%rdx)
movl   $0x20d,0x78(%rdx)
test   $0x1,%dil
mov    $0x627,%esi
cmovne %ecx,%esi
mov    %esi,0x7c(%rdx)
test   %ax,%ax
cmovns %ecx,%r8d
movl   $0x20d,0x80(%rdx)
mov    %r8d,0x84(%rdx)
movl   $0x20d,0x88(%rdx)
mov    $0x23,%eax
ret

LLVM IR (-O0):
define i32 @jvc_encode(i32 %0, i32 %1, i32* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32* %2, i32** %6
store i32 525000, i32* %7
%9 = load i32, i32* %5
%10 = shl i32 %9, 8
%11 = and i32 %10, 65280
%12 = load i32, i32* %5
%13 = lshr i32 %12, 8
%14 = and i32 %13, 255
%15 = or i32 %11, %14
store i32 %15, i32* %5
%16 = load i32*, i32** %6
%17 = getelementptr inbounds i32, i32* %16, i32 1
store i32* %17, i32** %6
store i32 8400, i32* %16
%18 = load i32*, i32** %6
%19 = getelementptr inbounds i32, i32* %18, i32 1
store i32* %19, i32** %6
store i32 4200, i32* %18
store i32 0, i32* %8
br label %20
20: ; preds = %38, %3
%21 = load i32, i32* %8
%22 = icmp slt i32 %21, 16
br i1 %22, label %23, label %41
23: ; preds = %20
%24 = load i32*, i32** %6
%25 = getelementptr inbounds i32, i32* %24, i32 1
store i32* %25, i32** %6
store i32 525, i32* %24
%26 = load i32, i32* %5
%27 = and i32 %26, 1
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %23
%30 = load i32*, i32** %6
%31 = getelementptr inbounds i32, i32* %30, i32 1
store i32* %31, i32** %6
store i32 1575, i32* %30
br label %35
32: ; preds = %23
%33 = load i32*, i32** %6
%34 = getelementptr inbounds i32, i32* %33, i32 1
store i32* %34, i32** %6
store i32 525, i32* %33
br label %35
35: ; preds = %32, %29
%36 = load i32, i32* %5
%37 = lshr i32 %36, 1
store i32 %37, i32* %5
br label %38
38: ; preds = %35
%39 = load i32, i32* %8
%40 = add nsw i32 %39, 1
store i32 %40, i32* %8
br label %20
41: ; preds = %20
%42 = load i32*, i32** %6
store i32 525, i32* %42
ret i32 35
}

LLVM IR (-O2):
define i32 @jvc_encode(i32 %0, i32 %1, i32* nocapture writeonly %2) {
%4 = trunc i32 %1 to i16
%5 = tail call i16 @llvm.bswap.i16(i16 %4)
%6 = zext i16 %5 to i32
%7 = getelementptr inbounds i32, i32* %2, i64 1
store i32 8400, i32* %2
store i32 4200, i32* %7
%8 = getelementptr inbounds i32, i32* %2, i64 2
%9 = getelementptr inbounds i32, i32* %2, i64 3
store i32 525, i32* %8
%10 = and i32 %6, 1
%11 = icmp eq i32 %10, 0
%12 = select i1 %11, i32 525, i32 1575
store i32 %12, i32* %9
%13 = getelementptr inbounds i32, i32* %2, i64 4
%14 = getelementptr inbounds i32, i32* %2, i64 5
store i32 525, i32* %13
%15 = and i32 %6, 2
%16 = icmp eq i32 %15, 0
%17 = select i1 %16, i32 525, i32 1575
store i32 %17, i32* %14
%18 = getelementptr inbounds i32, i32* %2, i64 6
%19 = getelementptr inbounds i32, i32* %2, i64 7
store i32 525, i32* %18
%20 = and i32 %6, 4
%21 = icmp eq i32 %20, 0
%22 = select i1 %21, i32 525, i32 1575
store i32 %22, i32* %19
%23 = getelementptr inbounds i32, i32* %2, i64 8
%24 = getelementptr inbounds i32, i32* %2, i64 9
store i32 525, i32* %23
%25 = and i32 %6, 8
%26 = icmp eq i32 %25, 0
%27 = select i1 %26, i32 525, i32 1575
store i32 %27, i32* %24
%28 = getelementptr inbounds i32, i32* %2, i64 10
%29 = getelementptr inbounds i32, i32* %2, i64 11
store i32 525, i32* %28
%30 = and i32 %6, 16
%31 = icmp eq i32 %30, 0
%32 = select i1 %31, i32 525, i32 1575
store i32 %32, i32* %29
%33 = getelementptr inbounds i32, i32* %2, i64 12
%34 = getelementptr inbounds i32, i32* %2, i64 13
store i32 525, i32* %33
%35 = and i32 %6, 32
%36 = icmp eq i32 %35, 0
%37 = select i1 %36, i32 525, i32 1575
store i32 %37, i32* %34
%38 = getelementptr inbounds i32, i32* %2, i64 14
%39 = getelementptr inbounds i32, i32* %2, i64 15
store i32 525, i32* %38
%40 = and i32 %6, 64
%41 = icmp eq i32 %40, 0
%42 = select i1 %41, i32 525, i32 1575
store i32 %42, i32* %39
%43 = getelementptr inbounds i32, i32* %2, i64 16
%44 = getelementptr inbounds i32, i32* %2, i64 17
store i32 525, i32* %43
%45 = insertelement <8 x i32> poison, i32 %6, i64 0
%46 = shufflevector <8 x i32> %45, <8 x i32> poison, <8 x i32> zeroinitializer
%47 = and <8 x i32> %46, <i32 16384, i32 8192, i32 4096, i32 2048, i32 1024, i32 512, i32 256, i32 128>
%48 = icmp eq <8 x i32> %47, zeroinitializer
%49 = extractelement <8 x i1> %48, i64 7
%50 = select i1 %49, i32 525, i32 1575
store i32 %50, i32* %44
%51 = getelementptr inbounds i32, i32* %2, i64 18
%52 = getelementptr inbounds i32, i32* %2, i64 19
store i32 525, i32* %51
%53 = extractelement <8 x i1> %48, i64 6
%54 = select i1 %53, i32 525, i32 1575
store i32 %54, i32* %52
%55 = getelementptr inbounds i32, i32* %2, i64 20
%56 = getelementptr inbounds i32, i32* %2, i64 21
store i32 525, i32* %55
%57 = extractelement <8 x i1> %48, i64 5
%58 = select i1 %57, i32 525, i32 1575
store i32 %58, i32* %56
%59 = getelementptr inbounds i32, i32* %2, i64 22
%60 = getelementptr inbounds i32, i32* %2, i64 23
store i32 525, i32* %59
%61 = extractelement <8 x i1> %48, i64 4
%62 = select i1 %61, i32 525, i32 1575
store i32 %62, i32* %60
%63 = getelementptr inbounds i32, i32* %2, i64 24
%64 = getelementptr inbounds i32, i32* %2, i64 25
store i32 525, i32* %63
%65 = extractelement <8 x i1> %48, i64 3
%66 = select i1 %65, i32 525, i32 1575
store i32 %66, i32* %64
%67 = getelementptr inbounds i32, i32* %2, i64 26
%68 = getelementptr inbounds i32, i32* %2, i64 27
store i32 525, i32* %67
%69 = extractelement <8 x i1> %48, i64 2
%70 = select i1 %69, i32 525, i32 1575
store i32 %70, i32* %68
%71 = getelementptr inbounds i32, i32* %2, i64 28
%72 = getelementptr inbounds i32, i32* %2, i64 29
store i32 525, i32* %71
%73 = extractelement <8 x i1> %48, i64 1
%74 = select i1 %73, i32 525, i32 1575
store i32 %74, i32* %72
%75 = getelementptr inbounds i32, i32* %2, i64 30
%76 = getelementptr inbounds i32, i32* %2, i64 31
store i32 525, i32* %75
%77 = extractelement <8 x i1> %48, i64 0
%78 = select i1 %77, i32 525, i32 1575
store i32 %78, i32* %76
%79 = getelementptr inbounds i32, i32* %2, i64 32
%80 = getelementptr inbounds i32, i32* %2, i64 33
store i32 525, i32* %79
%81 = icmp sgt i16 %5, -1
%82 = select i1 %81, i32 525, i32 1575
store i32 %82, i32* %80
%83 = getelementptr inbounds i32, i32* %2, i64 34
store i32 525, i32* %83
ret i32 35
}