x86 cpu instructions, 30 bytes
56 89 E6 8B 44 04 3D 00 00 74 0F D1 E8 50 E8 EF FF 8B 4C 04 81 E1 01 00 01 C8 5E C2 02 00
meaning and disassembly:
; input in the stack sp+4
; output in ax
;0i,2Ka,4P
f:
push si
mov si, sp
mov ax, [si+4]
cmp ax, 0
je .z
shr ax, 1
push ax
call f
mov cx, [si+4]
and cx, 1
add ax, cx
.z:
pop si
ret 2
0000000F 56 push si
00000010 89E6 mov si,sp
00000012 8B4404 mov ax,[si+0x4]
00000015 3D0000 cmp ax,0x0
00000018 740F jz 0x29
0000001A D1E8 shr ax,1
0000001C 50 push ax
0000001D E8EFFF call 0xf
00000020 8B4C04 mov cx,[si+0x4]
00000023 81E10100 and cx,0x1
00000027 01C8 add ax,cx
00000029 5E pop si
0000002A C20200 ret 0x2
//30