#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 */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ malloc(int);
char *decimal_to_binary(int n) {
  int c, d, count;
  char *pointer;
  count = 0;
  pointer = (char *)malloc(32 + 1);
  if (pointer == NULL)
    exit(EXIT_FAILURE);
  for (c = 31; c >= 0; c--) {
    d = n >> c;
    if (d & 1)
      *(pointer + count) = 1 + '0';
    else
      *(pointer + count) = 0 + '0';
    count++;
  }
  *(pointer + count) = '\0';
  return pointer;
}


x86 assembly (clang, -O0):
<decimal_to_binary>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x10(%rbp)
mov    $0x21,%edi
call   1030 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1159 <decimal_to_binary+0x39>
mov    0x2e8e(%rip),%rax
mov    (%rax),%edi
call   1040 <exit@plt>
movl   $0x1f,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jl     11b8 <decimal_to_binary+0x98>
mov    -0x4(%rbp),%eax
mov    -0x8(%rbp),%ecx
sar    %cl,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     1195 <decimal_to_binary+0x75>
mov    -0x18(%rbp),%rax
movslq -0x10(%rbp),%rcx
movb   $0x31,(%rax,%rcx,1)
jmp    11a1 <decimal_to_binary+0x81>
mov    -0x18(%rbp),%rax
movslq -0x10(%rbp),%rcx
movb   $0x30,(%rax,%rcx,1)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
jmp    1160 <decimal_to_binary+0x40>
mov    -0x18(%rbp),%rax
movslq -0x10(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<decimal_to_binary>:
push   %rbx
mov    %edi,%ebx
mov    $0x21,%edi
call   1030 <malloc@plt>
test   %rax,%rax
je     11f6 <decimal_to_binary+0xd6>
movd   %ebx,%xmm0
pshufd $0x0,%xmm0,%xmm0
movdqa 0xeb9(%rip),%xmm2
pand   %xmm0,%xmm2
movdqa 0xebd(%rip),%xmm3
pand   %xmm0,%xmm3
movdqa 0xec1(%rip),%xmm4
pand   %xmm0,%xmm4
movdqa 0xec5(%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 0xea9(%rip),%xmm3
paddb  %xmm3,%xmm2
movdqu %xmm2,(%rax)
movdqa 0xea9(%rip),%xmm2
pand   %xmm0,%xmm2
movdqa 0xead(%rip),%xmm4
pand   %xmm0,%xmm4
movdqa 0xeb1(%rip),%xmm5
pand   %xmm0,%xmm5
pand   0xeb5(%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)
movb   $0x0,0x20(%rax)
pop    %rbx
ret
mov    0x2de3(%rip),%rax
mov    (%rax),%edi
call   1040 <exit@plt>

LLVM IR (-O0):
@EXIT_FAILURE = global i32 0
define i8* @decimal_to_binary(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
store i32 %0, i32* %2
store i32 0, i32* %5
%7 = call i64 @malloc(i32 33)
%8 = inttoptr i64 %7 to i8*
store i8* %8, i8** %6
%9 = load i8*, i8** %6
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %14
11: ; preds = %1
%12 = load i32, i32* @EXIT_FAILURE
%13 = call i32 @exit(i32 %12)
unreachable
14: ; preds = %1
store i32 31, i32* %3
br label %15
15: ; preds = %38, %14
%16 = load i32, i32* %3
%17 = icmp sge i32 %16, 0
br i1 %17, label %18, label %41
18: ; preds = %15
%19 = load i32, i32* %2
%20 = load i32, i32* %3
%21 = ashr i32 %19, %20
store i32 %21, i32* %4
%22 = load i32, i32* %4
%23 = and i32 %22, 1
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %30
25: ; preds = %18
%26 = load i8*, i8** %6
%27 = load i32, i32* %5
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %26, i64 %28
store i8 49, i8* %29
br label %35
30: ; preds = %18
%31 = load i8*, i8** %6
%32 = load i32, i32* %5
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %31, i64 %33
store i8 48, i8* %34
br label %35
35: ; preds = %30, %25
%36 = load i32, i32* %5
%37 = add nsw i32 %36, 1
store i32 %37, i32* %5
br label %38
38: ; preds = %35
%39 = load i32, i32* %3
%40 = add nsw i32 %39, -1
store i32 %40, i32* %3
br label %15
41: ; preds = %15
%42 = load i8*, i8** %6
%43 = load i32, i32* %5
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8, i8* %42, i64 %44
store i8 0, i8* %45
%46 = load i8*, i8** %6
ret i8* %46
}

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
define i8* @decimal_to_binary(i32 %0) {
%2 = tail call i64 @malloc(i32 33)
%3 = inttoptr i64 %2 to i8*
%4 = icmp eq i64 %2, 0
br i1 %4, label %18, label %5
5: ; preds = %1
%6 = insertelement <16 x i32> poison, i32 %0, i64 0
%7 = shufflevector <16 x i32> %6, <16 x i32> poison, <16 x i32> zeroinitializer
%8 = and <16 x i32> %7, <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>
%9 = icmp eq <16 x i32> %8, zeroinitializer
%10 = select <16 x i1> %9, <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>
%11 = inttoptr i64 %2 to <16 x i8>*
store <16 x i8> %10, <16 x i8>* %11
%12 = and <16 x i32> %7, <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>
%13 = icmp eq <16 x i32> %12, zeroinitializer
%14 = select <16 x i1> %13, <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>
%15 = getelementptr inbounds i8, i8* %3, i64 16
%16 = bitcast i8* %15 to <16 x i8>*
store <16 x i8> %14, <16 x i8>* %16
%17 = getelementptr inbounds i8, i8* %3, i64 32
store i8 0, i8* %17
ret i8* %3
18: ; preds = %1
%19 = load i32, i32* @EXIT_FAILURE
%20 = tail call i32 @exit(i32 %19)
unreachable
}