#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*/ free(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
char *rev(char *);
int /*<<< orphan*/ scanf(char *, int *);
void main() {
  int l, i = 0;
  char *s = (char *)malloc(sizeof(char) * 100);
  printf("enter a number\n");
  scanf("%d", &l);
  while (l > 0) {
    if (l % 2 == 0) {
      s[i] = '0' + '\0';
    } else {
      s[i] = '1' + '\0';
    }
    i++;
    l = l / 2;
  }
  printf("0b%s\n", rev(s));
  free(s);
  s = NULL;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x8(%rbp)
mov    $0x64,%edi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
lea    0xe8c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe8e(%rip),%rdi
lea    -0x4(%rbp),%rsi
call   1070 <scanf@plt>
cmpl   $0x0,-0x4(%rbp)
jle    11e2 <main+0x92>
mov    -0x4(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11ba <main+0x6a>
mov    -0x10(%rbp),%rax
movslq -0x8(%rbp),%rcx
movb   $0x30,(%rax,%rcx,1)
jmp    11c6 <main+0x76>
mov    -0x10(%rbp),%rax
movslq -0x8(%rbp),%rcx
movb   $0x31,(%rax,%rcx,1)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
jmp    118b <main+0x3b>
mov    -0x10(%rbp),%rdi
call   1040 <rev@plt>
mov    %rax,%rsi
lea    0xe1e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x10(%rbp)
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
mov    $0x64,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
lea    0xe90(%rip),%rdi
call   1040 <puts@plt>
lea    0xe7b(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1080 <scanf@plt>
mov    0xc(%rsp),%eax
test   %eax,%eax
jle    11c0 <main+0x60>
mov    %rbx,%rcx
nopw   0x0(%rax,%rax,1)
and    $0x1,%al
or     $0x30,%al
mov    %al,(%rcx)
mov    0xc(%rsp),%edx
mov    %edx,%eax
shr    $0x1f,%eax
add    %edx,%eax
sar    %eax
mov    %eax,0xc(%rsp)
add    $0x1,%rcx
cmp    $0x1,%edx
jg     11a0 <main+0x40>
mov    %rbx,%rdi
call   1050 <rev@plt>
lea    0xe34(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [16 x i8] c"enter a number\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [6 x i8] c"0b%s\0A\00"
define void @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
store i32 0, i32* %2
%4 = call i64 @malloc(i32 100)
%5 = inttoptr i64 %4 to i8*
store i8* %5, i8** %3
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
br label %8
8: ; preds = %25, %0
%9 = load i32, i32* %1
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %30
11: ; preds = %8
%12 = load i32, i32* %1
%13 = srem i32 %12, 2
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %20
15: ; preds = %11
%16 = load i8*, i8** %3
%17 = load i32, i32* %2
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %16, i64 %18
store i8 48, i8* %19
br label %25
20: ; preds = %11
%21 = load i8*, i8** %3
%22 = load i32, i32* %2
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %21, i64 %23
store i8 49, i8* %24
br label %25
25: ; preds = %20, %15
%26 = load i32, i32* %2
%27 = add nsw i32 %26, 1
store i32 %27, i32* %2
%28 = load i32, i32* %1
%29 = sdiv i32 %28, 2
store i32 %29, i32* %1
br label %8
30: ; preds = %8
%31 = load i8*, i8** %3
%32 = call i8* @rev(i8* %31)
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %32)
%34 = load i8*, i8** %3
%35 = call i32 @free(i8* %34)
store i8* null, i8** %3
ret void
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [6 x i8] c"0b%s\0A\00"
@str = [15 x i8] c"enter a number\00"
define void @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i64 @malloc(i32 100)
%4 = inttoptr i64 %3 to i8*
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%7 = load i32, i32* %1
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %20
9: ; preds = %0, %9
%10 = phi i64 [ %16, %9 ], [ 0, %0 ]
%11 = phi i32 [ %18, %9 ], [ %7, %0 ]
%12 = and i32 %11, 1
%13 = icmp eq i32 %12, 0
%14 = select i1 %13, i8 48, i8 49
%15 = getelementptr inbounds i8, i8* %4, i64 %10
store i8 %14, i8* %15
%16 = add nuw i64 %10, 1
%17 = load i32, i32* %1
%18 = sdiv i32 %17, 2
store i32 %18, i32* %1
%19 = icmp sgt i32 %17, 1
br i1 %19, label %9, label %20
20: ; preds = %9, %0
%21 = call i8* @rev(i8* %4)
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %21)
%23 = call i32 @free(i8* %4)
ret void
}