#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 */
__attribute__((visibility("hidden"))) void
bin_append_posn(const int arg, const int length, char *binary, size_t posn) {
  int i;
  int start;
  start = 0x01 << (length - 1);
  for (i = 0; i < length; i++) {
    binary[posn + i] = '0';
    if (arg & (start >> i)) {
      binary[posn + i] = '1';
    }
  }
}


x86 assembly (clang, -O0):
<bin_append_posn>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
mov    $0x1,%eax
shl    %cl,%eax
mov    %eax,-0x20(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1186 <bin_append_posn+0x86>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
movslq -0x1c(%rbp),%rdx
add    %rdx,%rcx
movb   $0x30,(%rax,%rcx,1)
mov    -0x4(%rbp),%eax
mov    -0x20(%rbp),%edx
mov    -0x1c(%rbp),%ecx
sar    %cl,%edx
mov    %edx,%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     1173 <bin_append_posn+0x73>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
movslq -0x1c(%rbp),%rdx
add    %rdx,%rcx
movb   $0x31,(%rax,%rcx,1)
jmp    1178 <bin_append_posn+0x78>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1129 <bin_append_posn+0x29>
pop    %rbp
ret

x86 assembly (clang, -O2):
<bin_append_posn>:
push   %rbx
mov    %rcx,%r8
lea    -0x1(%rsi),%ecx
mov    $0x1,%r11d
shl    %cl,%r11d
test   %esi,%esi
jle    165a <bin_append_posn+0x55a>
mov    %esi,%r9d
cmp    $0x10,%esi
jae    1127 <bin_append_posn+0x27>
xor    %ecx,%ecx
jmp    163d <bin_append_posn+0x53d>
mov    %r9d,%ecx
and    $0xfffffff0,%ecx
movd   %r11d,%xmm0
pshufd $0x0,%xmm0,%xmm8
movd   %edi,%xmm0
pshufd $0x0,%xmm0,%xmm12
lea    -0x10(%rcx),%rax
mov    %rax,%r10
shr    $0x4,%r10
add    $0x1,%r10
test   %rax,%rax
je     165c <bin_append_posn+0x55c>
mov    %r10,%rax
and    $0xfffffffffffffffe,%rax
lea    (%r8,%rdx,1),%rbx
add    $0x10,%rbx
movdqa 0xe8e(%rip),%xmm13
movdqa 0xe95(%rip),%xmm14
movdqa 0xe9c(%rip),%xmm15
movdqa 0xea4(%rip),%xmm5
xor    %esi,%esi
pxor   %xmm11,%xmm11
movdqa 0xec4(%rip),%xmm10
movdqa 0xe9b(%rip),%xmm9
cs nopw 0x0(%rax,%rax,1)
nop
pshuflw $0xfe,%xmm5,%xmm0
movdqa %xmm8,%xmm2
psrad  %xmm0,%xmm2
pshuflw $0x54,%xmm5,%xmm0
movdqa %xmm8,%xmm1
psrad  %xmm0,%xmm1
punpcklqdq %xmm2,%xmm1
pshufd $0xee,%xmm5,%xmm0
pshuflw $0xfe,%xmm0,%xmm2
movdqa %xmm8,%xmm3
psrad  %xmm2,%xmm3
pshuflw $0x54,%xmm0,%xmm0
movdqa %xmm8,%xmm2
psrad  %xmm0,%xmm2
punpckhqdq %xmm3,%xmm2
shufps $0xcc,%xmm2,%xmm1
pshuflw $0xfe,%xmm15,%xmm0
movdqa %xmm8,%xmm3
psrad  %xmm0,%xmm3
pshuflw $0x54,%xmm15,%xmm0
movdqa %xmm8,%xmm2
psrad  %xmm0,%xmm2
punpcklqdq %xmm3,%xmm2
pshufd $0xee,%xmm15,%xmm0
pshuflw $0xfe,%xmm0,%xmm3
movdqa %xmm8,%xmm6
psrad  %xmm3,%xmm6
pshuflw $0x54,%xmm0,%xmm0
movdqa %xmm8,%xmm3
psrad  %xmm0,%xmm3
punpckhqdq %xmm6,%xmm3
shufps $0xcc,%xmm3,%xmm2
pshuflw $0xfe,%xmm14,%xmm0
movdqa %xmm8,%xmm3
psrad  %xmm0,%xmm3
pshuflw $0x54,%xmm14,%xmm0
movdqa %xmm8,%xmm6
psrad  %xmm0,%xmm6
punpcklqdq %xmm3,%xmm6
pshufd $0xee,%xmm14,%xmm0
pshuflw $0xfe,%xmm0,%xmm3
movdqa %xmm8,%xmm4
psrad  %xmm3,%xmm4
pshuflw $0x54,%xmm0,%xmm0
movdqa %xmm8,%xmm3
psrad  %xmm0,%xmm3
punpckhqdq %xmm4,%xmm3
shufps $0xcc,%xmm3,%xmm6
pshuflw $0xfe,%xmm13,%xmm0
movdqa %xmm8,%xmm3
psrad  %xmm0,%xmm3
pshuflw $0x54,%xmm13,%xmm4
movdqa %xmm8,%xmm0
psrad  %xmm4,%xmm0
punpcklqdq %xmm3,%xmm0
pshufd $0xee,%xmm13,%xmm3
pshuflw $0xfe,%xmm3,%xmm4
movdqa %xmm8,%xmm7
psrad  %xmm4,%xmm7
pshuflw $0x54,%xmm3,%xmm3
movdqa %xmm8,%xmm4
psrad  %xmm3,%xmm4
punpckhqdq %xmm7,%xmm4
shufps $0xcc,%xmm4,%xmm0
andps  %xmm12,%xmm0
andps  %xmm12,%xmm6
andps  %xmm12,%xmm2
andps  %xmm12,%xmm1
pcmpeqd %xmm11,%xmm1
pcmpeqd %xmm11,%xmm2
packssdw %xmm2,%xmm1
pcmpeqd %xmm11,%xmm6
pcmpeqd %xmm11,%xmm0
packssdw %xmm0,%xmm6
packsswb %xmm6,%xmm1
paddb  %xmm9,%xmm1
movdqu %xmm1,-0x10(%rbx,%rsi,1)
movdqa %xmm13,%xmm2
movdqa 0xd2b(%rip),%xmm1
paddd  %xmm1,%xmm2
movdqa %xmm14,%xmm3
paddd  %xmm1,%xmm3
movdqa %xmm15,%xmm0
paddd  %xmm1,%xmm0
movdqa %xmm5,%xmm4
paddd  %xmm1,%xmm4
pshuflw $0xfe,%xmm4,%xmm1
movdqa %xmm8,%xmm6
psrad  %xmm1,%xmm6
pshuflw $0x54,%xmm4,%xmm7
movdqa %xmm8,%xmm1
psrad  %xmm7,%xmm1
punpcklqdq %xmm6,%xmm1
pshufd $0xee,%xmm4,%xmm4
pshuflw $0xfe,%xmm4,%xmm6
movdqa %xmm8,%xmm7
psrad  %xmm6,%xmm7
pshuflw $0x54,%xmm4,%xmm4
movdqa %xmm8,%xmm6
psrad  %xmm4,%xmm6
punpckhqdq %xmm7,%xmm6
shufps $0xcc,%xmm6,%xmm1
pshuflw $0xfe,%xmm0,%xmm4
movdqa %xmm8,%xmm7
psrad  %xmm4,%xmm7
pshuflw $0x54,%xmm0,%xmm4
movdqa %xmm8,%xmm6
psrad  %xmm4,%xmm6
punpcklqdq %xmm7,%xmm6
pshufd $0xee,%xmm0,%xmm0
pshuflw $0xfe,%xmm0,%xmm4
movdqa %xmm8,%xmm7
psrad  %xmm4,%xmm7
pshuflw $0x54,%xmm0,%xmm0
movdqa %xmm8,%xmm4
psrad  %xmm0,%xmm4
punpckhqdq %xmm7,%xmm4
shufps $0xcc,%xmm4,%xmm6
pshuflw $0xfe,%xmm3,%xmm0
movdqa %xmm8,%xmm4
psrad  %xmm0,%xmm4
pshuflw $0x54,%xmm3,%xmm7
movdqa %xmm8,%xmm0
psrad  %xmm7,%xmm0
punpcklqdq %xmm4,%xmm0
pshufd $0xee,%xmm3,%xmm3
pshuflw $0xfe,%xmm3,%xmm4
movdqa %xmm8,%xmm7
psrad  %xmm4,%xmm7
pshuflw $0x54,%xmm3,%xmm3
movdqa %xmm8,%xmm4
psrad  %xmm3,%xmm4
punpckhqdq %xmm7,%xmm4
shufps $0xcc,%xmm4,%xmm0
pshuflw $0xfe,%xmm2,%xmm3
movdqa %xmm8,%xmm4
psrad  %xmm3,%xmm4
pshuflw $0x54,%xmm2,%xmm7
movdqa %xmm8,%xmm3
psrad  %xmm7,%xmm3
punpcklqdq %xmm4,%xmm3
pshufd $0xee,%xmm2,%xmm2
pshuflw $0xfe,%xmm2,%xmm4
movdqa %xmm8,%xmm7
psrad  %xmm4,%xmm7
pshuflw $0x54,%xmm2,%xmm2
movdqa %xmm8,%xmm4
psrad  %xmm2,%xmm4
punpckhqdq %xmm7,%xmm4
shufps $0xcc,%xmm4,%xmm3
andps  %xmm12,%xmm6
andps  %xmm12,%xmm1
pcmpeqd %xmm11,%xmm1
pcmpeqd %xmm11,%xmm6
packssdw %xmm6,%xmm1
andps  %xmm12,%xmm3
andps  %xmm12,%xmm0
pcmpeqd %xmm11,%xmm0
pcmpeqd %xmm11,%xmm3
packssdw %xmm3,%xmm0
packsswb %xmm0,%xmm1
paddb  %xmm9,%xmm1
movdqu %xmm1,(%rbx,%rsi,1)
add    $0x20,%rsi
paddd  %xmm10,%xmm5
paddd  %xmm10,%xmm15
paddd  %xmm10,%xmm14
paddd  %xmm10,%xmm13
add    $0xfffffffffffffffe,%rax
jne    11b0 <bin_append_posn+0xb0>
test   $0x1,%r10b
je     1638 <bin_append_posn+0x538>
add    %r8,%rsi
pshuflw $0xfe,%xmm5,%xmm0
movdqa %xmm8,%xmm2
psrad  %xmm0,%xmm2
pshuflw $0x54,%xmm5,%xmm0
movdqa %xmm8,%xmm1
psrad  %xmm0,%xmm1
punpcklqdq %xmm2,%xmm1
pshufd $0xee,%xmm5,%xmm0
pshuflw $0xfe,%xmm0,%xmm2
movdqa %xmm8,%xmm3
psrad  %xmm2,%xmm3
pshuflw $0x54,%xmm0,%xmm0
movdqa %xmm8,%xmm2
psrad  %xmm0,%xmm2
punpckhqdq %xmm3,%xmm2
shufps $0xcc,%xmm2,%xmm1
pshuflw $0xfe,%xmm15,%xmm0
movdqa %xmm8,%xmm3
psrad  %xmm0,%xmm3
pshuflw $0x54,%xmm15,%xmm0
movdqa %xmm8,%xmm2
psrad  %xmm0,%xmm2
punpcklqdq %xmm3,%xmm2
pshufd $0xee,%xmm15,%xmm0
pshuflw $0xfe,%xmm0,%xmm3
movdqa %xmm8,%xmm4
psrad  %xmm3,%xmm4
pshuflw $0x54,%xmm0,%xmm0
movdqa %xmm8,%xmm3
psrad  %xmm0,%xmm3
punpckhqdq %xmm4,%xmm3
shufps $0xcc,%xmm3,%xmm2
pshuflw $0xfe,%xmm14,%xmm0
movdqa %xmm8,%xmm3
psrad  %xmm0,%xmm3
pshuflw $0x54,%xmm14,%xmm4
movdqa %xmm8,%xmm0
psrad  %xmm4,%xmm0
punpcklqdq %xmm3,%xmm0
pshufd $0xee,%xmm14,%xmm3
pshuflw $0xfe,%xmm3,%xmm4
movdqa %xmm8,%xmm5
psrad  %xmm4,%xmm5
pshuflw $0x54,%xmm3,%xmm3
movdqa %xmm8,%xmm4
psrad  %xmm3,%xmm4
punpckhqdq %xmm5,%xmm4
shufps $0xcc,%xmm4,%xmm0
pshuflw $0xfe,%xmm13,%xmm3
movdqa %xmm8,%xmm4
psrad  %xmm3,%xmm4
pshuflw $0x54,%xmm13,%xmm5
movdqa %xmm8,%xmm3
psrad  %xmm5,%xmm3
punpcklqdq %xmm4,%xmm3
pshufd $0xee,%xmm13,%xmm4
pshuflw $0xfe,%xmm4,%xmm5
movdqa %xmm8,%xmm6
psrad  %xmm5,%xmm6
pshuflw $0x54,%xmm4,%xmm4
psrad  %xmm4,%xmm8
punpckhqdq %xmm6,%xmm8
shufps $0xcc,%xmm8,%xmm3
andps  %xmm12,%xmm3
andps  %xmm12,%xmm0
andps  %xmm12,%xmm2
andps  %xmm12,%xmm1
pxor   %xmm4,%xmm4
pcmpeqd %xmm4,%xmm1
pcmpeqd %xmm4,%xmm2
packssdw %xmm2,%xmm1
pcmpeqd %xmm4,%xmm0
pcmpeqd %xmm4,%xmm3
packssdw %xmm3,%xmm0
packsswb %xmm0,%xmm1
paddb  0xa0d(%rip),%xmm1
movdqu %xmm1,(%rdx,%rsi,1)
cmp    %r9,%rcx
je     165a <bin_append_posn+0x55a>
add    %r8,%rdx
mov    %r11d,%eax
sar    %cl,%eax
and    %edi,%eax
cmp    $0x1,%eax
mov    $0x31,%al
sbb    $0x0,%al
mov    %al,(%rdx,%rcx,1)
add    $0x1,%rcx
cmp    %rcx,%r9
jne    1640 <bin_append_posn+0x540>
pop    %rbx
ret
movdqa 0x99b(%rip),%xmm13
movdqa 0x9a2(%rip),%xmm14
movdqa 0x9a9(%rip),%xmm15
movdqa 0x9b1(%rip),%xmm5
xor    %esi,%esi
test   $0x1,%r10b
jne    14cd <bin_append_posn+0x3cd>
jmp    1638 <bin_append_posn+0x538>

LLVM IR (-O0):
define hidden void @bin_append_posn(i32 %0, i32 %1, i8* %2, i64 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32
%10 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i8* %2, i8** %7
store i64 %3, i64* %8
%11 = load i32, i32* %6
%12 = sub nsw i32 %11, 1
%13 = shl i32 1, %12
store i32 %13, i32* %10
store i32 0, i32* %9
br label %14
14: ; preds = %39, %4
%15 = load i32, i32* %9
%16 = load i32, i32* %6
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %42
18: ; preds = %14
%19 = load i8*, i8** %7
%20 = load i64, i64* %8
%21 = load i32, i32* %9
%22 = sext i32 %21 to i64
%23 = add i64 %20, %22
%24 = getelementptr inbounds i8, i8* %19, i64 %23
store i8 48, i8* %24
%25 = load i32, i32* %5
%26 = load i32, i32* %10
%27 = load i32, i32* %9
%28 = ashr i32 %26, %27
%29 = and i32 %25, %28
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %38
31: ; preds = %18
%32 = load i8*, i8** %7
%33 = load i64, i64* %8
%34 = load i32, i32* %9
%35 = sext i32 %34 to i64
%36 = add i64 %33, %35
%37 = getelementptr inbounds i8, i8* %32, i64 %36
store i8 49, i8* %37
br label %38
38: ; preds = %31, %18
br label %39
39: ; preds = %38
%40 = load i32, i32* %9
%41 = add nsw i32 %40, 1
store i32 %41, i32* %9
br label %14
42: ; preds = %14
ret void
}

LLVM IR (-O2):
define hidden void @bin_append_posn(i32 %0, i32 %1, i8* nocapture writeonly %2, i64 %3) {
%5 = add nsw i32 %1, -1
%6 = shl nuw i32 1, %5
%7 = icmp sgt i32 %1, 0
br i1 %7, label %8, label %75
8: ; preds = %4
%9 = zext i32 %1 to i64
%10 = icmp ult i32 %1, 16
br i1 %10, label %62, label %11
11: ; preds = %8
%12 = and i64 %9, 4294967280
%13 = insertelement <16 x i32> poison, i32 %6, i64 0
%14 = shufflevector <16 x i32> %13, <16 x i32> poison, <16 x i32> zeroinitializer
%15 = insertelement <16 x i32> poison, i32 %0, i64 0
%16 = shufflevector <16 x i32> %15, <16 x i32> poison, <16 x i32> zeroinitializer
%17 = add nsw i64 %12, -16
%18 = lshr exact i64 %17, 4
%19 = add nuw nsw i64 %18, 1
%20 = and i64 %19, 1
%21 = icmp eq i64 %17, 0
br i1 %21, label %48, label %22
22: ; preds = %11
%23 = and i64 %19, 2305843009213693950
br label %24
24: ; preds = %24, %22
%25 = phi i64 [ 0, %22 ], [ %44, %24 ]
%26 = phi <16 x i32> [ <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15>, %22 ], [ %45, %24 ]
%27 = phi i64 [ 0, %22 ], [ %46, %24 ]
%28 = add i64 %25, %3
%29 = getelementptr inbounds i8, i8* %2, i64 %28
%30 = ashr <16 x i32> %14, %26
%31 = and <16 x i32> %30, %16
%32 = icmp eq <16 x i32> %31, zeroinitializer
%33 = select <16 x i1> %32, <16 x i8> <i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48>, <16 x i8> <i8 49, i8 49, i8 49, i8 49, i8 49, i8 49, i8 49, i8 49, i8 49, i8 49, i8 49, i8 49, i8 49, i8 49, i8 49, i8 49>
%34 = bitcast i8* %29 to <16 x i8>*
store <16 x i8> %33, <16 x i8>* %34
%35 = or i64 %25, 16
%36 = add <16 x i32> %26, <i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16>
%37 = add i64 %35, %3
%38 = getelementptr inbounds i8, i8* %2, i64 %37
%39 = ashr <16 x i32> %14, %36
%40 = and <16 x i32> %39, %16
%41 = icmp eq <16 x i32> %40, zeroinitializer
%42 = select <16 x i1> %41, <16 x i8> <i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48>, <16 x i8> <i8 49, i8 49, i8 49, i8 49, i8 49, i8 49, i8 49, i8 49, i8 49, i8 49, i8 49, i8 49, i8 49, i8 49, i8 49, i8 49>
%43 = bitcast i8* %38 to <16 x i8>*
store <16 x i8> %42, <16 x i8>* %43
%44 = add nuw i64 %25, 32
%45 = add <16 x i32> %26, <i32 32, i32 32, i32 32, i32 32, i32 32, i32 32, i32 32, i32 32, i32 32, i32 32, i32 32, i32 32, i32 32, i32 32, i32 32, i32 32>
%46 = add i64 %27, 2
%47 = icmp eq i64 %46, %23
br i1 %47, label %48, label %24
48: ; preds = %24, %11
%49 = phi i64 [ 0, %11 ], [ %44, %24 ]
%50 = phi <16 x i32> [ <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15>, %11 ], [ %45, %24 ]
%51 = icmp eq i64 %20, 0
br i1 %51, label %60, label %52
52: ; preds = %48
%53 = add i64 %49, %3
%54 = getelementptr inbounds i8, i8* %2, i64 %53
%55 = ashr <16 x i32> %14, %50
%56 = and <16 x i32> %55, %16
%57 = icmp eq <16 x i32> %56, zeroinitializer
%58 = select <16 x i1> %57, <16 x i8> <i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48>, <16 x i8> <i8 49, i8 49, i8 49, i8 49, i8 49, i8 49, i8 49, i8 49, i8 49, i8 49, i8 49, i8 49, i8 49, i8 49, i8 49, i8 49>
%59 = bitcast i8* %54 to <16 x i8>*
store <16 x i8> %58, <16 x i8>* %59
br label %60
60: ; preds = %48, %52
%61 = icmp eq i64 %12, %9
br i1 %61, label %75, label %62
62: ; preds = %8, %60
%63 = phi i64 [ 0, %8 ], [ %12, %60 ]
br label %64
64: ; preds = %62, %64
%65 = phi i64 [ %73, %64 ], [ %63, %62 ]
%66 = add i64 %65, %3
%67 = getelementptr inbounds i8, i8* %2, i64 %66
%68 = trunc i64 %65 to i32
%69 = ashr i32 %6, %68
%70 = and i32 %69, %0
%71 = icmp eq i32 %70, 0
%72 = select i1 %71, i8 48, i8 49
store i8 %72, i8* %67
%73 = add nuw nsw i64 %65, 1
%74 = icmp eq i64 %73, %9
br i1 %74, label %75, label %64
75: ; preds = %64, %60, %4
ret void
}