char *convertDecimalTo10BitBinary(unsigned int dec) {
  static char convResult[11];
  unsigned int mask = 512;
  int index = 9;
  while (index >= 0) {
    if ((dec & mask) != 0)
      convResult[index] = '1';
    else
      convResult[index] = '0';
    index--;
    mask >>= 1;
  }
  convResult[10] = '\0';
  return convResult;
}


x86 assembly (clang, -O0):
<convertDecimalTo10BitBinary>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
movl   $0x200,-0x8(%rbp)
movl   $0x9,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jl     1168 <convertDecimalTo10BitBinary+0x68>
mov    -0x4(%rbp),%eax
and    -0x8(%rbp),%eax
cmp    $0x0,%eax
je     1142 <convertDecimalTo10BitBinary+0x42>
movslq -0xc(%rbp),%rcx
lea    0x2ee8(%rip),%rax
movb   $0x31,(%rax,%rcx,1)
jmp    1151 <convertDecimalTo10BitBinary+0x51>
movslq -0xc(%rbp),%rcx
lea    0x2ed4(%rip),%rax
movb   $0x30,(%rax,%rcx,1)
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%eax
shr    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1115 <convertDecimalTo10BitBinary+0x15>
movb   $0x0,0x2ebc(%rip)
lea    0x2eab(%rip),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<convertDecimalTo10BitBinary>:
mov    %edi,%eax
and    $0x200,%eax
cmp    $0x1,%eax
mov    $0x31,%cl
mov    $0x31,%al
sbb    $0x0,%al
mov    %al,0x2f14(%rip)
movd   %edi,%xmm0
and    $0x100,%edi
cmp    $0x1,%edi
sbb    $0x0,%cl
lea    0x2ef4(%rip),%rax
mov    %cl,0x2ef6(%rip)
pshufd $0x0,%xmm0,%xmm0
movdqa 0xec0(%rip),%xmm1
pand   %xmm0,%xmm1
pand   0xec4(%rip),%xmm0
pxor   %xmm2,%xmm2
pcmpeqd %xmm2,%xmm0
pcmpeqd %xmm2,%xmm1
packssdw %xmm0,%xmm1
packsswb %xmm1,%xmm1
pmovmskb %xmm1,%esi
mov    %esi,%r10d
and    $0x2,%r10b
shr    %r10b
mov    %esi,%edi
and    $0x4,%dil
shr    $0x2,%dil
mov    %esi,%r8d
and    $0x8,%r8b
shr    $0x3,%r8b
mov    %esi,%r9d
and    $0x10,%r9b
shr    $0x4,%r9b
mov    %esi,%r11d
and    $0x20,%r11b
shr    $0x5,%r11b
mov    %esi,%ecx
and    $0x40,%cl
shr    $0x6,%cl
mov    %esi,%edx
sar    $0x7,%dl
add    $0x31,%dl
mov    %dl,0x2e79(%rip)
xor    $0x31,%cl
mov    %cl,0x2e6f(%rip)
xor    $0x31,%r11b
mov    %r11b,0x2e63(%rip)
xor    $0x31,%r9b
mov    %r9b,0x2e57(%rip)
xor    $0x31,%r8b
mov    %r8b,0x2e4b(%rip)
xor    $0x31,%dil
mov    %dil,0x2e3f(%rip)
xor    $0x31,%r10b
mov    %r10b,0x2e33(%rip)
and    $0x1,%sil
xor    $0x31,%sil
mov    %sil,0x2e23(%rip)
movb   $0x0,0x2e26(%rip)
ret

LLVM IR (-O0):
@convertDecimalTo10BitBinary.convResult = internal global [11 x i8] zeroinitializer
define i8* @convertDecimalTo10BitBinary(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %2
store i32 512, i32* %3
store i32 9, i32* %4
br label %5
5: ; preds = %21, %1
%6 = load i32, i32* %4
%7 = icmp sge i32 %6, 0
br i1 %7, label %8, label %26
8: ; preds = %5
%9 = load i32, i32* %2
%10 = load i32, i32* %3
%11 = and i32 %9, %10
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %8
%14 = load i32, i32* %4
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [11 x i8], [11 x i8]* @convertDecimalTo10BitBinary.convResult, i64 0, i64 %15
store i8 49, i8* %16
br label %21
17: ; preds = %8
%18 = load i32, i32* %4
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [11 x i8], [11 x i8]* @convertDecimalTo10BitBinary.convResult, i64 0, i64 %19
store i8 48, i8* %20
br label %21
21: ; preds = %17, %13
%22 = load i32, i32* %4
%23 = add nsw i32 %22, -1
store i32 %23, i32* %4
%24 = load i32, i32* %3
%25 = lshr i32 %24, 1
store i32 %25, i32* %3
br label %5
26: ; preds = %5
store i8 0, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @convertDecimalTo10BitBinary.convResult, i64 0, i64 10)
ret i8* getelementptr inbounds ([11 x i8], [11 x i8]* @convertDecimalTo10BitBinary.convResult, i64 0, i64 0)
}

LLVM IR (-O2):
@convertDecimalTo10BitBinary.convResult = internal global [11 x i8] zeroinitializer
define i8* @convertDecimalTo10BitBinary(i32 %0) {
%2 = and i32 %0, 512
%3 = icmp eq i32 %2, 0
%4 = select i1 %3, i8 48, i8 49
store i8 %4, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @convertDecimalTo10BitBinary.convResult, i64 0, i64 9)
%5 = and i32 %0, 256
%6 = icmp eq i32 %5, 0
%7 = select i1 %6, i8 48, i8 49
store i8 %7, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @convertDecimalTo10BitBinary.convResult, i64 0, i64 8)
%8 = insertelement <8 x i32> poison, i32 %0, i64 0
%9 = shufflevector <8 x i32> %8, <8 x i32> poison, <8 x i32> zeroinitializer
%10 = and <8 x i32> %9, <i32 1, i32 2, i32 4, i32 8, i32 16, i32 32, i32 64, i32 128>
%11 = icmp eq <8 x i32> %10, zeroinitializer
%12 = extractelement <8 x i1> %11, i64 7
%13 = select i1 %12, i8 48, i8 49
store i8 %13, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @convertDecimalTo10BitBinary.convResult, i64 0, i64 7)
%14 = extractelement <8 x i1> %11, i64 6
%15 = select i1 %14, i8 48, i8 49
store i8 %15, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @convertDecimalTo10BitBinary.convResult, i64 0, i64 6)
%16 = extractelement <8 x i1> %11, i64 5
%17 = select i1 %16, i8 48, i8 49
store i8 %17, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @convertDecimalTo10BitBinary.convResult, i64 0, i64 5)
%18 = extractelement <8 x i1> %11, i64 4
%19 = select i1 %18, i8 48, i8 49
store i8 %19, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @convertDecimalTo10BitBinary.convResult, i64 0, i64 4)
%20 = extractelement <8 x i1> %11, i64 3
%21 = select i1 %20, i8 48, i8 49
store i8 %21, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @convertDecimalTo10BitBinary.convResult, i64 0, i64 3)
%22 = extractelement <8 x i1> %11, i64 2
%23 = select i1 %22, i8 48, i8 49
store i8 %23, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @convertDecimalTo10BitBinary.convResult, i64 0, i64 2)
%24 = extractelement <8 x i1> %11, i64 1
%25 = select i1 %24, i8 48, i8 49
store i8 %25, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @convertDecimalTo10BitBinary.convResult, i64 0, i64 1)
%26 = extractelement <8 x i1> %11, i64 0
%27 = select i1 %26, i8 48, i8 49
store i8 %27, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @convertDecimalTo10BitBinary.convResult, i64 0, i64 0)
store i8 0, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @convertDecimalTo10BitBinary.convResult, i64 0, i64 10)
ret i8* getelementptr inbounds ([11 x i8], [11 x i8]* @convertDecimalTo10BitBinary.convResult, i64 0, i64 0)
}