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

/* Variables and functions */
void u32_to_bin(uint32_t in, char s[]) {
  int i;
  for (i = 1; i <= 32; i++) {
    s[32 - i] = in & (1 << (i - 1)) ? '1' : '0';
  }
}


x86 assembly (clang, -O0):
<u32_to_bin>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
cmpl   $0x20,-0x14(%rbp)
jg     1160 <u32_to_bin+0x60>
mov    -0x4(%rbp),%edx
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
mov    $0x1,%eax
shl    %cl,%eax
and    %eax,%edx
mov    $0x30,%eax
mov    $0x31,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %al,%dl
mov    -0x10(%rbp),%rax
mov    $0x20,%ecx
sub    -0x14(%rbp),%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1112 <u32_to_bin+0x12>
pop    %rbp
ret

x86 assembly (clang, -O2):
<u32_to_bin>:
movd   %edi,%xmm0
pshufd $0x0,%xmm0,%xmm1
movdqa 0xeef(%rip),%xmm3
pand   %xmm1,%xmm3
movdqa 0xef3(%rip),%xmm2
pand   %xmm1,%xmm2
movdqa 0xef7(%rip),%xmm4
pand   %xmm1,%xmm4
movdqa 0xefb(%rip),%xmm5
pand   %xmm1,%xmm5
pxor   %xmm0,%xmm0
pcmpeqd %xmm0,%xmm5
pcmpeqd %xmm0,%xmm4
packssdw %xmm5,%xmm4
pcmpeqd %xmm0,%xmm2
pcmpeqd %xmm0,%xmm3
packssdw %xmm2,%xmm3
packsswb %xmm4,%xmm3
movdqa 0xedf(%rip),%xmm2
paddb  %xmm2,%xmm3
movdqa %xmm3,%xmm4
punpcklbw %xmm0,%xmm4
pshufd $0x4e,%xmm4,%xmm4
pshuflw $0x1b,%xmm4,%xmm4
pshufhw $0x1b,%xmm4,%xmm4
punpckhbw %xmm0,%xmm3
pshufd $0x4e,%xmm3,%xmm3
pshuflw $0x1b,%xmm3,%xmm3
pshufhw $0x1b,%xmm3,%xmm3
packuswb %xmm4,%xmm3
movdqu %xmm3,0x10(%rsi)
movdqa 0xeb0(%rip),%xmm3
pand   %xmm1,%xmm3
movdqa 0xeb4(%rip),%xmm4
pand   %xmm1,%xmm4
movdqa 0xeb8(%rip),%xmm5
pand   %xmm1,%xmm5
pand   0xebc(%rip),%xmm1
pcmpeqd %xmm0,%xmm1
pcmpeqd %xmm0,%xmm5
packssdw %xmm1,%xmm5
pcmpeqd %xmm0,%xmm4
pcmpeqd %xmm0,%xmm3
packssdw %xmm4,%xmm3
packsswb %xmm5,%xmm3
paddb  %xmm2,%xmm3
movdqa %xmm3,%xmm1
punpcklbw %xmm0,%xmm1
pshufd $0x4e,%xmm1,%xmm1
pshuflw $0x1b,%xmm1,%xmm1
pshufhw $0x1b,%xmm1,%xmm1
punpckhbw %xmm0,%xmm3
pshufd $0x4e,%xmm3,%xmm0
pshuflw $0x1b,%xmm0,%xmm0
pshufhw $0x1b,%xmm0,%xmm0
packuswb %xmm1,%xmm0
movdqu %xmm0,(%rsi)
ret

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

LLVM IR (-O2):
define void @u32_to_bin(i32 %0, i8* nocapture writeonly %1) {
%3 = insertelement <16 x i32> poison, i32 %0, i64 0
%4 = shufflevector <16 x i32> %3, <16 x i32> poison, <16 x i32> zeroinitializer
%5 = and <16 x i32> %4, <i32 1, i32 2, i32 4, i32 8, i32 16, i32 32, i32 64, i32 128, i32 256, i32 512, i32 1024, i32 2048, i32 4096, i32 8192, i32 16384, i32 32768>
%6 = icmp eq <16 x i32> %5, zeroinitializer
%7 = select <16 x i1> %6, <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>
%8 = shufflevector <16 x i8> %7, <16 x i8> poison, <16 x i32> <i32 15, i32 14, i32 13, i32 12, i32 11, i32 10, i32 9, i32 8, i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>
%9 = getelementptr inbounds i8, i8* %1, i64 16
%10 = bitcast i8* %9 to <16 x i8>*
store <16 x i8> %8, <16 x i8>* %10
%11 = and <16 x i32> %4, <i32 65536, i32 131072, i32 262144, i32 524288, i32 1048576, i32 2097152, i32 4194304, i32 8388608, i32 16777216, i32 33554432, i32 67108864, i32 134217728, i32 268435456, i32 536870912, i32 1073741824, i32 -2147483648>
%12 = icmp eq <16 x i32> %11, zeroinitializer
%13 = select <16 x i1> %12, <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>
%14 = shufflevector <16 x i8> %13, <16 x i8> poison, <16 x i32> <i32 15, i32 14, i32 13, i32 12, i32 11, i32 10, i32 9, i32 8, i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>
%15 = bitcast i8* %1 to <16 x i8>*
store <16 x i8> %14, <16 x i8>* %15
ret void
}