#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 *get_bits_int(int n) {
  int num_of_bits = sizeof(int) * 8;
  char *bits_of_numbers = (char *)malloc(num_of_bits + 1);
  short bit;
  int i;
  for (i = 0; i < num_of_bits; i++) {
    bit = n & 1;
    bits_of_numbers[num_of_bits - i - 1] = '0' + bit;
    n = n >> 1;
  }
  bits_of_numbers[num_of_bits] = '\0';
  return bits_of_numbers;
}


x86 assembly (clang, -O0):
<get_bits_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x20,-0x8(%rbp)
mov    -0x8(%rbp),%edi
add    $0x1,%edi
call   1030 <malloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1181 <get_bits_int+0x71>
mov    -0x4(%rbp),%eax
and    $0x1,%eax
mov    %ax,-0x12(%rbp)
movswl -0x12(%rbp),%eax
add    $0x30,%eax
mov    %al,%dl
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%ecx
sub    -0x18(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x4(%rbp),%eax
sar    $0x1,%eax
mov    %eax,-0x4(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1138 <get_bits_int+0x28>
mov    -0x10(%rbp),%rax
movslq -0x8(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_bits_int>:
push   %rbx
mov    %edi,%ebx
mov    $0x21,%edi
call   1030 <malloc@plt>
mov    $0x20,%ecx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %ebx,%edx
and    $0x1,%dl
or     $0x30,%dl
mov    %dl,-0x1(%rax,%rcx,1)
mov    %ebx,%edx
shr    %dl
and    $0x1,%dl
or     $0x30,%dl
mov    %dl,-0x2(%rax,%rcx,1)
sar    $0x2,%ebx
add    $0xfffffffffffffffe,%rcx
jne    1130 <get_bits_int+0x20>
movb   $0x0,0x20(%rax)
pop    %rbx
ret

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

LLVM IR (-O2):
define i8* @get_bits_int(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 [ 0, %1 ], [ %19, %4 ]
%6 = phi i32 [ %0, %1 ], [ %18, %4 ]
%7 = trunc i32 %6 to i8
%8 = and i8 %7, 1
%9 = or i8 %8, 48
%10 = sub nuw nsw i64 31, %5
%11 = getelementptr inbounds i8, i8* %3, i64 %10
store i8 %9, i8* %11
%12 = trunc i32 %6 to i8
%13 = lshr i8 %12, 1
%14 = and i8 %13, 1
%15 = or i8 %14, 48
%16 = sub nsw i64 30, %5
%17 = getelementptr inbounds i8, i8* %3, i64 %16
store i8 %15, i8* %17
%18 = ashr i32 %6, 2
%19 = add nuw nsw i64 %5, 2
%20 = icmp eq i64 %19, 32
br i1 %20, label %21, label %4
21: ; preds = %4
%22 = getelementptr inbounds i8, i8* %3, i64 32
store i8 0, i8* %22
ret i8* %3
}