#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 */

/* Variables and functions */
char *calloc(int, int);
char *int2bin(int input) {
  input = input >> (32 - sizeof(int) * 8);
  char *result = calloc(33, sizeof(char));
  result[32] = 0;
  for (int i = 0; i < 32; i++) {
    int bit = (input >> (31 - i)) & 1;
    if (bit) {
      result[i] = '1';
    } else {
      result[i] = '0';
    }
  }
  return result;
}


x86 assembly (clang, -O0):
<int2bin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
sar    $0x0,%eax
mov    %eax,-0x4(%rbp)
mov    $0x21,%edi
mov    $0x1,%esi
call   1030 <calloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movb   $0x0,0x20(%rax)
movl   $0x0,-0x14(%rbp)
cmpl   $0x20,-0x14(%rbp)
jge    119d <int2bin+0x8d>
mov    -0x4(%rbp),%eax
mov    $0x1f,%ecx
sub    -0x14(%rbp),%ecx
sar    %cl,%eax
and    $0x1,%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     117e <int2bin+0x6e>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x31,(%rax,%rcx,1)
jmp    118a <int2bin+0x7a>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x30,(%rax,%rcx,1)
jmp    118f <int2bin+0x7f>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1146 <int2bin+0x36>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<int2bin>:
push   %rbx
mov    %edi,%ebx
mov    $0x21,%edi
mov    $0x1,%esi
call   1030 <calloc@plt>
movd   %ebx,%xmm0
pshufd $0x0,%xmm0,%xmm0
movdqa 0xecd(%rip),%xmm2
pand   %xmm0,%xmm2
movdqa 0xed1(%rip),%xmm3
pand   %xmm0,%xmm3
movdqa 0xed5(%rip),%xmm4
pand   %xmm0,%xmm4
movdqa 0xed9(%rip),%xmm5
pand   %xmm0,%xmm5
pxor   %xmm1,%xmm1
pcmpeqd %xmm1,%xmm5
pcmpeqd %xmm1,%xmm4
packssdw %xmm5,%xmm4
pcmpeqd %xmm1,%xmm3
pcmpeqd %xmm1,%xmm2
packssdw %xmm3,%xmm2
packsswb %xmm4,%xmm2
movdqa 0xebd(%rip),%xmm3
paddb  %xmm3,%xmm2
movdqu %xmm2,(%rax)
movdqa 0xebd(%rip),%xmm2
pand   %xmm0,%xmm2
movdqa 0xec1(%rip),%xmm4
pand   %xmm0,%xmm4
movdqa 0xec5(%rip),%xmm5
pand   %xmm0,%xmm5
pand   0xec9(%rip),%xmm0
pcmpeqd %xmm1,%xmm0
pcmpeqd %xmm1,%xmm5
packssdw %xmm0,%xmm5
pcmpeqd %xmm1,%xmm4
pcmpeqd %xmm1,%xmm2
packssdw %xmm4,%xmm2
packsswb %xmm5,%xmm2
paddb  %xmm3,%xmm2
movdqu %xmm2,0x10(%rax)
pop    %rbx
ret

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

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