void int_to_binary(const int x, char b[33]) {
  char *p = b;
  unsigned int z;
  for (z = (1 << 31); z > 0; z >>= 1) {
    *p++ = (x & z) ? '1' : '0';
  }
  *p = '\0';
}


x86 assembly (clang, -O0):
<int_to_binary>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
movl   $0x80000000,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jbe    115b <int_to_binary+0x5b>
mov    -0x4(%rbp),%edx
and    -0x1c(%rbp),%edx
mov    $0x30,%eax
mov    $0x31,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
mov    -0x1c(%rbp),%eax
shr    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    111a <int_to_binary+0x1a>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<int_to_binary>:
mov    $0x80000000,%eax
mov    $0x80000000,%r9d
nopl   0x0(%rax,%rax,1)
mov    %eax,%edx
and    %edi,%edx
cmp    $0x1,%edx
mov    $0x31,%r8b
sbb    $0x0,%r8b
mov    %eax,%edx
shr    %edx
and    %edi,%edx
cmp    $0x1,%edx
mov    $0x31,%r10b
sbb    $0x0,%r10b
mov    %eax,%edx
shr    $0x2,%edx
and    %edi,%edx
cmp    $0x1,%edx
mov    %rsi,%rdx
mov    %r8b,(%rsi)
mov    $0x31,%cl
sbb    $0x0,%cl
mov    %r10b,0x1(%rsi)
mov    %cl,0x2(%rsi)
mov    %eax,%ecx
shr    $0x3,%ecx
and    %edi,%ecx
cmp    $0x1,%ecx
mov    $0x31,%cl
sbb    $0x0,%cl
mov    %cl,0x3(%rsi)
shr    $0x4,%r9d
add    $0x4,%rsi
cmp    $0xf,%eax
mov    %r9d,%eax
ja     1110 <int_to_binary+0x10>
movb   $0x0,0x4(%rdx)
ret

LLVM IR (-O0):
define void @int_to_binary(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
store i32 %0, i32* %3
store i8* %1, i8** %4
%7 = load i8*, i8** %4
store i8* %7, i8** %5
store i32 -2147483648, i32* %6
br label %8
8: ; preds = %21, %2
%9 = load i32, i32* %6
%10 = icmp ugt i32 %9, 0
br i1 %10, label %11, label %24
11: ; preds = %8
%12 = load i32, i32* %3
%13 = load i32, i32* %6
%14 = and i32 %12, %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** %5
%20 = getelementptr inbounds i8, i8* %19, i32 1
store i8* %20, i8** %5
store i8 %18, i8* %19
br label %21
21: ; preds = %11
%22 = load i32, i32* %6
%23 = lshr i32 %22, 1
store i32 %23, i32* %6
br label %8
24: ; preds = %8
%25 = load i8*, i8** %5
store i8 0, i8* %25
ret void
}

LLVM IR (-O2):
define void @int_to_binary(i32 %0, i8* nocapture writeonly %1) {
br label %3
3: ; preds = %3, %2
%4 = phi i32 [ -2147483648, %2 ], [ %25, %3 ]
%5 = phi i8* [ %1, %2 ], [ %24, %3 ]
%6 = and i32 %4, %0
%7 = icmp eq i32 %6, 0
%8 = select i1 %7, i8 48, i8 49
%9 = getelementptr inbounds i8, i8* %5, i64 1
store i8 %8, i8* %5
%10 = lshr i32 %4, 1
%11 = and i32 %10, %0
%12 = icmp eq i32 %11, 0
%13 = select i1 %12, i8 48, i8 49
%14 = getelementptr inbounds i8, i8* %5, i64 2
store i8 %13, i8* %9
%15 = lshr i32 %4, 2
%16 = and i32 %15, %0
%17 = icmp eq i32 %16, 0
%18 = select i1 %17, i8 48, i8 49
%19 = getelementptr inbounds i8, i8* %5, i64 3
store i8 %18, i8* %14
%20 = lshr i32 %4, 3
%21 = and i32 %20, %0
%22 = icmp eq i32 %21, 0
%23 = select i1 %22, i8 48, i8 49
%24 = getelementptr inbounds i8, i8* %5, i64 4
store i8 %23, i8* %19
%25 = lshr i32 %4, 4
%26 = icmp ult i32 %4, 16
br i1 %26, label %27, label %3
27: ; preds = %3
store i8 0, i8* %24
ret void
}