#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 */
scalar_t__ malloc(int);
char *toBinary(int num) {
  char *binary = (char *)malloc(sizeof(char) * 33);
  int flag = 1;
  int i;
  for (i = 31; i >= 0; i--) {
    if (num & flag) {
      binary[i] = '1';
    } else {
      binary[i] = '0';
    }
    flag <<= 1;
  }
  binary[32] = '\0';
  return binary;
}


x86 assembly (clang, -O0):
<toBinary>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    $0x21,%edi
call   1030 <malloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
movl   $0x1f,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jl     1184 <toBinary+0x74>
mov    -0x4(%rbp),%eax
and    -0x14(%rbp),%eax
cmp    $0x0,%eax
je     1161 <toBinary+0x51>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movb   $0x31,(%rax,%rcx,1)
jmp    116d <toBinary+0x5d>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movb   $0x30,(%rax,%rcx,1)
mov    -0x14(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x18(%rbp)
jmp    1137 <toBinary+0x27>
mov    -0x10(%rbp),%rax
movb   $0x0,0x20(%rax)
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<toBinary>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
mov    $0x21,%edi
call   1030 <malloc@plt>
mov    $0x1,%ecx
mov    $0x20,%edx
nopl   0x0(%rax)
mov    %ecx,%esi
and    %ebp,%esi
cmp    $0x1,%esi
mov    $0x31,%dil
sbb    $0x0,%dil
lea    (%rcx,%rcx,1),%esi
and    %ebp,%esi
cmp    $0x1,%esi
mov    $0x31,%bl
sbb    $0x0,%bl
mov    %dil,-0x1(%rax,%rdx,1)
mov    %bl,-0x2(%rax,%rdx,1)
shl    $0x2,%ecx
add    $0xfffffffffffffffe,%rdx
jne    1130 <toBinary+0x20>
movb   $0x0,0x20(%rax)
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
define i8* @toBinary(i32 %0) {
%2 = tail call i64 @malloc(i32 33)
%3 = inttoptr i64 %2 to i8*
br label %4
4: ; preds = %4, %1
%5 = phi i64 [ 31, %1 ], [ %18, %4 ]
%6 = phi i32 [ 1, %1 ], [ %17, %4 ]
%7 = and i32 %6, %0
%8 = icmp eq i32 %7, 0
%9 = select i1 %8, i8 48, i8 49
%10 = getelementptr inbounds i8, i8* %3, i64 %5
store i8 %9, i8* %10
%11 = shl i32 %6, 1
%12 = add nsw i64 %5, -1
%13 = and i32 %11, %0
%14 = icmp eq i32 %13, 0
%15 = select i1 %14, i8 48, i8 49
%16 = getelementptr inbounds i8, i8* %3, i64 %12
store i8 %15, i8* %16
%17 = shl i32 %6, 2
%18 = add nsw i64 %5, -2
%19 = icmp eq i64 %12, 0
br i1 %19, label %20, label %4
20: ; preds = %4
%21 = getelementptr inbounds i8, i8* %3, i64 32
store i8 0, i8* %21
ret i8* %3
}