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

/* Variables and functions */
void print_bin(char *buffer, uint8_t val, int n) {
  int i;
  for (i = 0; i < n; i++) {
    if ((val >> (n - i - 1)) & 0x1) {
      buffer[i] = '1';
    } else {
      buffer[i] = '0';
    }
  }
}


x86 assembly (clang, -O0):
<print_bin>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    116b <print_bin+0x6b>
mov    -0xc(%rbp),%eax
mov    -0x10(%rbp),%ecx
sub    -0x14(%rbp),%ecx
sub    $0x1,%ecx
sar    %cl,%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     114c <print_bin+0x4c>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x31,(%rax,%rcx,1)
jmp    1158 <print_bin+0x58>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x30,(%rax,%rcx,1)
jmp    115d <print_bin+0x5d>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1115 <print_bin+0x15>
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_bin>:
test   %edx,%edx
jle    15c7 <print_bin+0x4c7>
mov    %edx,%r8d
cmp    $0x10,%edx
jae    1117 <print_bin+0x17>
xor    %ecx,%ecx
jmp    159b <print_bin+0x49b>
mov    %r8d,%ecx
and    $0xfffffff0,%ecx
movd   %edx,%xmm0
pshufd $0x0,%xmm0,%xmm5
movd   %esi,%xmm0
pshufd $0x0,%xmm0,%xmm6
lea    -0x10(%rcx),%rax
mov    %rax,%r9
shr    $0x4,%r9
add    $0x1,%r9
test   %rax,%rax
je     15c8 <print_bin+0x4c8>
mov    %r9,%rax
and    $0xfffffffffffffffe,%rax
movdqa 0xeea(%rip),%xmm4
movdqa 0xef2(%rip),%xmm2
movdqa 0xef9(%rip),%xmm12
movdqa 0xf00(%rip),%xmm14
xor    %r10d,%r10d
movdqa 0xf14(%rip),%xmm13
movdqa 0xefb(%rip),%xmm10
cs nopw 0x0(%rax,%rax,1)
nop
movdqa %xmm2,-0x18(%rsp)
movdqa %xmm4,-0x58(%rsp)
movdqa %xmm2,%xmm15
movdqa %xmm12,%xmm7
movdqa %xmm12,-0x28(%rsp)
movdqa %xmm14,%xmm9
movdqa %xmm14,%xmm2
pcmpeqd %xmm3,%xmm3
pxor   %xmm3,%xmm2
pxor   %xmm3,%xmm7
movdqa %xmm15,%xmm0
pxor   %xmm3,%xmm0
movdqa %xmm4,%xmm1
pxor   %xmm3,%xmm1
paddd  %xmm5,%xmm1
paddd  %xmm5,%xmm0
paddd  %xmm5,%xmm7
paddd  %xmm5,%xmm2
pslld  $0x17,%xmm2
paddd  %xmm10,%xmm2
cvttps2dq %xmm2,%xmm2
pshufd $0xf5,%xmm2,%xmm11
pmuludq %xmm13,%xmm2
pshufd $0xe8,%xmm2,%xmm8
pmuludq %xmm13,%xmm11
pshufd $0xe8,%xmm11,%xmm2
punpckldq %xmm2,%xmm8
pslld  $0x17,%xmm7
paddd  %xmm10,%xmm7
cvttps2dq %xmm7,%xmm2
pshufd $0xf5,%xmm2,%xmm3
pmuludq %xmm13,%xmm2
pshufd $0xe8,%xmm2,%xmm7
pmuludq %xmm13,%xmm3
pshufd $0xe8,%xmm3,%xmm2
punpckldq %xmm2,%xmm7
pslld  $0x17,%xmm0
paddd  %xmm10,%xmm0
cvttps2dq %xmm0,%xmm0
pshufd $0xf5,%xmm0,%xmm2
pmuludq %xmm13,%xmm0
pshufd $0xe8,%xmm0,%xmm0
pmuludq %xmm13,%xmm2
pshufd $0xe8,%xmm2,%xmm2
punpckldq %xmm2,%xmm0
pslld  $0x17,%xmm1
paddd  %xmm10,%xmm1
cvttps2dq %xmm1,%xmm1
pshufd $0xf5,%xmm1,%xmm2
pmuludq %xmm13,%xmm1
pshufd $0xe8,%xmm1,%xmm1
pmuludq %xmm13,%xmm2
pshufd $0xe8,%xmm2,%xmm2
punpckldq %xmm2,%xmm1
pand   %xmm6,%xmm1
pand   %xmm6,%xmm0
pand   %xmm6,%xmm7
pand   %xmm6,%xmm8
pxor   %xmm11,%xmm11
pcmpeqd %xmm11,%xmm8
pcmpeqd %xmm11,%xmm7
packssdw %xmm7,%xmm8
pcmpeqd %xmm11,%xmm0
pcmpeqd %xmm11,%xmm1
packssdw %xmm1,%xmm0
packsswb %xmm0,%xmm8
movdqa 0xdcc(%rip),%xmm0
paddb  %xmm0,%xmm8
movdqu %xmm8,(%rdi,%r10,1)
movdqa %xmm4,%xmm8
movdqa %xmm5,%xmm1
psubd  %xmm4,%xmm1
movdqa 0xdbc(%rip),%xmm4
paddd  %xmm4,%xmm1
movdqa %xmm5,%xmm2
movdqa %xmm15,-0x38(%rsp)
psubd  %xmm15,%xmm2
movdqa -0x28(%rsp),%xmm15
paddd  %xmm4,%xmm2
movdqa %xmm5,%xmm0
psubd  %xmm15,%xmm0
paddd  %xmm4,%xmm0
movdqa %xmm5,%xmm3
movdqa %xmm14,-0x48(%rsp)
psubd  %xmm14,%xmm3
paddd  %xmm4,%xmm3
pslld  $0x17,%xmm3
paddd  %xmm10,%xmm3
cvttps2dq %xmm3,%xmm3
pshufd $0xf5,%xmm3,%xmm4
pmuludq %xmm13,%xmm3
pshufd $0xe8,%xmm3,%xmm7
pmuludq %xmm13,%xmm4
pshufd $0xe8,%xmm4,%xmm3
punpckldq %xmm3,%xmm7
pslld  $0x17,%xmm0
paddd  %xmm10,%xmm0
cvttps2dq %xmm0,%xmm0
pshufd $0xf5,%xmm0,%xmm3
pmuludq %xmm13,%xmm0
pshufd $0xe8,%xmm0,%xmm0
pmuludq %xmm13,%xmm3
pshufd $0xe8,%xmm3,%xmm3
punpckldq %xmm3,%xmm0
pslld  $0x17,%xmm2
paddd  %xmm10,%xmm2
cvttps2dq %xmm2,%xmm2
pshufd $0xf5,%xmm2,%xmm3
pmuludq %xmm13,%xmm2
pshufd $0xe8,%xmm2,%xmm2
pmuludq %xmm13,%xmm3
pshufd $0xe8,%xmm3,%xmm3
punpckldq %xmm3,%xmm2
pslld  $0x17,%xmm1
paddd  %xmm10,%xmm1
cvttps2dq %xmm1,%xmm1
pshufd $0xf5,%xmm1,%xmm3
pmuludq %xmm13,%xmm1
pshufd $0xe8,%xmm1,%xmm1
pmuludq %xmm13,%xmm3
pshufd $0xe8,%xmm3,%xmm3
punpckldq %xmm3,%xmm1
pand   %xmm6,%xmm0
pand   %xmm6,%xmm7
pcmpeqd %xmm11,%xmm7
pcmpeqd %xmm11,%xmm0
packssdw %xmm0,%xmm7
pand   %xmm6,%xmm1
pand   %xmm6,%xmm2
pcmpeqd %xmm11,%xmm2
pcmpeqd %xmm11,%xmm1
packssdw %xmm1,%xmm2
packsswb %xmm2,%xmm7
movdqa -0x18(%rsp),%xmm2
paddb  0xc82(%rip),%xmm7
movdqu %xmm7,0x10(%rdi,%r10,1)
add    $0x20,%r10
movdqa 0xc8f(%rip),%xmm0
paddd  %xmm0,%xmm14
paddd  %xmm0,%xmm12
paddd  %xmm0,%xmm2
movdqa -0x58(%rsp),%xmm1
paddd  %xmm0,%xmm1
movdqa %xmm1,-0x58(%rsp)
movdqa -0x58(%rsp),%xmm4
add    $0xfffffffffffffffe,%rax
jne    1190 <print_bin+0x90>
movdqa 0xc69(%rip),%xmm2
movdqa %xmm2,%xmm0
psubd  -0x48(%rsp),%xmm0
movdqa %xmm2,%xmm4
psubd  %xmm15,%xmm4
movdqa %xmm2,%xmm3
psubd  -0x38(%rsp),%xmm3
psubd  %xmm8,%xmm2
test   $0x1,%r9b
je     1596 <print_bin+0x496>
paddd  %xmm5,%xmm2
paddd  %xmm5,%xmm3
paddd  %xmm5,%xmm4
paddd  %xmm5,%xmm0
pslld  $0x17,%xmm0
movdqa 0xbcf(%rip),%xmm8
paddd  %xmm8,%xmm0
cvttps2dq %xmm0,%xmm0
movdqa 0xbce(%rip),%xmm5
pshufd $0xf5,%xmm0,%xmm7
pmuludq %xmm5,%xmm0
pshufd $0xe8,%xmm0,%xmm1
pmuludq %xmm5,%xmm7
pshufd $0xe8,%xmm7,%xmm0
punpckldq %xmm0,%xmm1
pslld  $0x17,%xmm4
paddd  %xmm8,%xmm4
cvttps2dq %xmm4,%xmm0
pshufd $0xf5,%xmm0,%xmm7
pmuludq %xmm5,%xmm0
pshufd $0xe8,%xmm0,%xmm4
pmuludq %xmm5,%xmm7
pshufd $0xe8,%xmm7,%xmm0
punpckldq %xmm0,%xmm4
pslld  $0x17,%xmm3
paddd  %xmm8,%xmm3
cvttps2dq %xmm3,%xmm0
pshufd $0xf5,%xmm0,%xmm3
pmuludq %xmm5,%xmm0
pshufd $0xe8,%xmm0,%xmm0
pmuludq %xmm5,%xmm3
pshufd $0xe8,%xmm3,%xmm3
punpckldq %xmm3,%xmm0
pslld  $0x17,%xmm2
paddd  %xmm8,%xmm2
cvttps2dq %xmm2,%xmm2
pshufd $0xf5,%xmm2,%xmm3
pmuludq %xmm5,%xmm2
pshufd $0xe8,%xmm2,%xmm2
pmuludq %xmm5,%xmm3
pshufd $0xe8,%xmm3,%xmm3
punpckldq %xmm3,%xmm2
pand   %xmm6,%xmm2
pand   %xmm6,%xmm0
pand   %xmm6,%xmm4
pand   %xmm6,%xmm1
pxor   %xmm3,%xmm3
pcmpeqd %xmm3,%xmm1
pcmpeqd %xmm3,%xmm4
packssdw %xmm4,%xmm1
pcmpeqd %xmm3,%xmm0
pcmpeqd %xmm3,%xmm2
packssdw %xmm2,%xmm0
packsswb %xmm0,%xmm1
paddb  0xb10(%rip),%xmm1
movdqu %xmm1,(%rdi,%r10,1)
cmp    %r8,%rcx
je     15c7 <print_bin+0x4c7>
mov    %ecx,%eax
not    %eax
add    %edx,%eax
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
bt     %eax,%esi
mov    $0x31,%dl
adc    $0xff,%dl
mov    %dl,(%rdi,%rcx,1)
add    $0x1,%rcx
add    $0xffffffff,%eax
cmp    %rcx,%r8
jne    15b0 <print_bin+0x4b0>
ret
movdqa 0xa30(%rip),%xmm2
movdqa 0xa38(%rip),%xmm3
movdqa 0xa40(%rip),%xmm4
movdqa 0xa48(%rip),%xmm0
xor    %r10d,%r10d
test   $0x1,%r9b
jne    1493 <print_bin+0x393>
jmp    1596 <print_bin+0x496>

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

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