#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 scalar_t__ val;

/* Variables and functions */
int append_int(char *in, int in_len, int val, int val_len) {
  int in_len_copy = in_len;
  for (int i = val_len - 1; i >= 0; i--) {
    in[in_len_copy] = ((unsigned int)(val) & (1U << (unsigned int)(i))) != 0U;
    in_len_copy++;
  }
  return in_len_copy;
}


x86 assembly (clang, -O0):
<append_int>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jl     116a <append_int+0x6a>
mov    -0x10(%rbp),%eax
mov    -0x1c(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
and    %ecx,%eax
cmp    $0x0,%eax
setne  %al
and    $0x1,%al
movzbl %al,%eax
mov    %al,%dl
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
jmp    1120 <append_int+0x20>
mov    -0x18(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<append_int>:
mov    %esi,%eax
test   %ecx,%ecx
jle    158b <append_int+0x48b>
push   %rbx
cltq
lea    -0x1(%rcx),%r9d
cmp    $0xf,%r9d
jb     1560 <append_int+0x460>
add    $0x1,%r9
mov    %r9,%r8
and    $0xfffffffffffffff0,%r8
movd   %ecx,%xmm0
pshufd $0x0,%xmm0,%xmm4
movdqa 0xec8(%rip),%xmm14
paddd  %xmm4,%xmm14
movdqa 0xeca(%rip),%xmm10
paddd  %xmm4,%xmm10
movdqa 0xecc(%rip),%xmm11
paddd  %xmm4,%xmm11
paddd  0xecf(%rip),%xmm4
movd   %edx,%xmm0
pshufd $0x0,%xmm0,%xmm13
lea    -0x10(%r8),%rsi
mov    %rsi,%r10
shr    $0x4,%r10
add    $0x1,%r10
test   %rsi,%rsi
je     158c <append_int+0x48c>
mov    %r10,%rsi
and    $0xfffffffffffffffe,%rsi
lea    (%rax,%rdi,1),%rbx
add    $0x10,%rbx
xor    %r11d,%r11d
pcmpeqd %xmm15,%xmm15
movdqa 0xe9d(%rip),%xmm8
movdqa 0xea5(%rip),%xmm7
pxor   %xmm12,%xmm12
movdqa %xmm14,%xmm1
paddd  %xmm15,%xmm1
movdqa %xmm10,%xmm5
paddd  %xmm15,%xmm5
movdqa %xmm11,%xmm0
paddd  %xmm15,%xmm0
movdqa %xmm4,%xmm6
paddd  %xmm15,%xmm6
pslld  $0x17,%xmm6
paddd  %xmm8,%xmm6
cvttps2dq %xmm6,%xmm6
pshufd $0xf5,%xmm6,%xmm9
pmuludq %xmm7,%xmm6
pshufd $0xe8,%xmm6,%xmm6
pmuludq %xmm7,%xmm9
pshufd $0xe8,%xmm9,%xmm2
punpckldq %xmm2,%xmm6
pslld  $0x17,%xmm0
paddd  %xmm8,%xmm0
cvttps2dq %xmm0,%xmm0
pshufd $0xf5,%xmm0,%xmm2
pmuludq %xmm7,%xmm0
pshufd $0xe8,%xmm0,%xmm0
pmuludq %xmm7,%xmm2
pshufd $0xe8,%xmm2,%xmm2
punpckldq %xmm2,%xmm0
pslld  $0x17,%xmm5
paddd  %xmm8,%xmm5
cvttps2dq %xmm5,%xmm2
pshufd $0xf5,%xmm2,%xmm3
pmuludq %xmm7,%xmm2
pshufd $0xe8,%xmm2,%xmm5
pmuludq %xmm7,%xmm3
pshufd $0xe8,%xmm3,%xmm2
punpckldq %xmm2,%xmm5
pslld  $0x17,%xmm1
paddd  %xmm8,%xmm1
cvttps2dq %xmm1,%xmm1
pshufd $0xf5,%xmm1,%xmm2
pmuludq %xmm7,%xmm1
pshufd $0xe8,%xmm1,%xmm1
pmuludq %xmm7,%xmm2
pshufd $0xe8,%xmm2,%xmm2
punpckldq %xmm2,%xmm1
pand   %xmm13,%xmm1
pand   %xmm13,%xmm5
pand   %xmm13,%xmm0
pand   %xmm13,%xmm6
pcmpeqd %xmm12,%xmm6
pxor   %xmm15,%xmm6
pcmpeqd %xmm12,%xmm0
pxor   %xmm15,%xmm0
packssdw %xmm0,%xmm6
pcmpeqd %xmm12,%xmm5
pxor   %xmm15,%xmm5
pcmpeqd %xmm12,%xmm1
pxor   %xmm15,%xmm1
packssdw %xmm1,%xmm5
packsswb %xmm5,%xmm6
movdqa 0xd91(%rip),%xmm9
pand   %xmm9,%xmm6
movdqu %xmm6,-0x10(%rbx,%r11,1)
movdqa %xmm14,%xmm1
movdqa 0xd88(%rip),%xmm3
paddd  %xmm3,%xmm1
movdqa %xmm10,%xmm5
paddd  %xmm3,%xmm5
movdqa %xmm11,%xmm0
paddd  %xmm3,%xmm0
movdqa %xmm4,%xmm2
paddd  %xmm3,%xmm2
pslld  $0x17,%xmm2
paddd  %xmm8,%xmm2
cvttps2dq %xmm2,%xmm2
pshufd $0xf5,%xmm2,%xmm3
pmuludq %xmm7,%xmm2
pshufd $0xe8,%xmm2,%xmm6
pmuludq %xmm7,%xmm3
pshufd $0xe8,%xmm3,%xmm2
punpckldq %xmm2,%xmm6
pslld  $0x17,%xmm0
paddd  %xmm8,%xmm0
cvttps2dq %xmm0,%xmm0
pshufd $0xf5,%xmm0,%xmm2
pmuludq %xmm7,%xmm0
pshufd $0xe8,%xmm0,%xmm0
pmuludq %xmm7,%xmm2
pshufd $0xe8,%xmm2,%xmm2
punpckldq %xmm2,%xmm0
pslld  $0x17,%xmm5
paddd  %xmm8,%xmm5
cvttps2dq %xmm5,%xmm2
pshufd $0xf5,%xmm2,%xmm3
pmuludq %xmm7,%xmm2
pshufd $0xe8,%xmm2,%xmm5
pmuludq %xmm7,%xmm3
pshufd $0xe8,%xmm3,%xmm2
punpckldq %xmm2,%xmm5
pslld  $0x17,%xmm1
paddd  %xmm8,%xmm1
cvttps2dq %xmm1,%xmm1
pshufd $0xf5,%xmm1,%xmm2
pmuludq %xmm7,%xmm1
pshufd $0xe8,%xmm1,%xmm1
pmuludq %xmm7,%xmm2
pshufd $0xe8,%xmm2,%xmm2
punpckldq %xmm2,%xmm1
pand   %xmm13,%xmm0
pand   %xmm13,%xmm6
pcmpeqd %xmm12,%xmm6
pxor   %xmm15,%xmm6
pcmpeqd %xmm12,%xmm0
pxor   %xmm15,%xmm0
packssdw %xmm0,%xmm6
pand   %xmm13,%xmm1
pand   %xmm13,%xmm5
pcmpeqd %xmm12,%xmm5
pxor   %xmm15,%xmm5
pcmpeqd %xmm12,%xmm1
pxor   %xmm15,%xmm1
packssdw %xmm1,%xmm5
packsswb %xmm5,%xmm6
pand   %xmm9,%xmm6
movdqu %xmm6,(%rbx,%r11,1)
add    $0x20,%r11
movdqa 0xc77(%rip),%xmm0
paddd  %xmm0,%xmm4
paddd  %xmm0,%xmm11
paddd  %xmm0,%xmm10
paddd  %xmm0,%xmm14
add    $0xfffffffffffffffe,%rsi
jne    11b0 <append_int+0xb0>
test   $0x1,%r10b
je     1555 <append_int+0x455>
add    %rax,%r11
pcmpeqd %xmm5,%xmm5
paddd  %xmm5,%xmm14
paddd  %xmm5,%xmm10
paddd  %xmm5,%xmm11
paddd  %xmm5,%xmm4
pslld  $0x17,%xmm4
movdqa 0xbe9(%rip),%xmm7
paddd  %xmm7,%xmm4
cvttps2dq %xmm4,%xmm0
movdqa 0xbe9(%rip),%xmm6
pshufd $0xf5,%xmm0,%xmm1
pmuludq %xmm6,%xmm0
pshufd $0xe8,%xmm0,%xmm4
pmuludq %xmm6,%xmm1
pshufd $0xe8,%xmm1,%xmm0
punpckldq %xmm0,%xmm4
pslld  $0x17,%xmm11
paddd  %xmm7,%xmm11
cvttps2dq %xmm11,%xmm0
pshufd $0xf5,%xmm0,%xmm2
pmuludq %xmm6,%xmm0
pshufd $0xe8,%xmm0,%xmm1
pmuludq %xmm6,%xmm2
pshufd $0xe8,%xmm2,%xmm0
punpckldq %xmm0,%xmm1
pslld  $0x17,%xmm10
paddd  %xmm7,%xmm10
cvttps2dq %xmm10,%xmm0
pshufd $0xf5,%xmm0,%xmm2
pmuludq %xmm6,%xmm0
pshufd $0xe8,%xmm0,%xmm0
pmuludq %xmm6,%xmm2
pshufd $0xe8,%xmm2,%xmm2
punpckldq %xmm2,%xmm0
pslld  $0x17,%xmm14
paddd  %xmm7,%xmm14
cvttps2dq %xmm14,%xmm2
pshufd $0xf5,%xmm2,%xmm3
pmuludq %xmm6,%xmm2
pshufd $0xe8,%xmm2,%xmm2
pmuludq %xmm6,%xmm3
pshufd $0xe8,%xmm3,%xmm3
punpckldq %xmm3,%xmm2
pand   %xmm13,%xmm2
pand   %xmm13,%xmm0
pand   %xmm13,%xmm1
pand   %xmm13,%xmm4
pxor   %xmm3,%xmm3
pcmpeqd %xmm3,%xmm4
pxor   %xmm5,%xmm4
pcmpeqd %xmm3,%xmm1
pxor   %xmm5,%xmm1
packssdw %xmm1,%xmm4
pcmpeqd %xmm3,%xmm0
pxor   %xmm5,%xmm0
pcmpeqd %xmm3,%xmm2
pxor   %xmm5,%xmm2
packssdw %xmm2,%xmm0
packsswb %xmm0,%xmm4
pand   0xb11(%rip),%xmm4
movdqu %xmm4,(%rdi,%r11,1)
add    %r8,%rax
cmp    %r8,%r9
je     158a <append_int+0x48a>
sub    %r8d,%ecx
add    $0x1,%ecx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
lea    -0x2(%rcx),%esi
movzbl %sil,%esi
bt     %esi,%edx
setb   (%rdi,%rax,1)
add    $0x1,%rax
add    $0xffffffff,%ecx
cmp    $0x1,%ecx
ja     1570 <append_int+0x470>
pop    %rbx
ret
xor    %r11d,%r11d
test   $0x1,%r10b
jne    1430 <append_int+0x330>
jmp    1555 <append_int+0x455>

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

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