#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*/ printf(char *, ...);
int countBinary(int n) {
  char t[32];
  int i, count;
  printf("Its binary form of number is:");
  t[0] = n & 1;
  for (count = 1; n >>= 1; count++)
    t[count] = n & 1;
  for (i = count - 1; i >= 0; i--)
    printf("%d", t[i]);
  return count;
}


x86 assembly (clang, -O0):
<countBinary>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
lea    0xede(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
and    $0x1,%eax
mov    %al,-0x30(%rbp)
movl   $0x1,-0x38(%rbp)
mov    -0x4(%rbp),%eax
sar    $0x1,%eax
mov    %eax,-0x4(%rbp)
cmp    $0x0,%eax
je     1169 <countBinary+0x59>
mov    -0x4(%rbp),%eax
and    $0x1,%eax
mov    %al,%cl
movslq -0x38(%rbp),%rax
mov    %cl,-0x30(%rbp,%rax,1)
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    1139 <countBinary+0x29>
mov    -0x38(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jl     11a1 <countBinary+0x91>
movslq -0x34(%rbp),%rax
movsbl -0x30(%rbp,%rax,1),%esi
lea    0xe92(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x34(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x34(%rbp)
jmp    1172 <countBinary+0x62>
mov    -0x38(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<countBinary>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %edi,%ebp
lea    0xedd(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %ebp,%eax
and    $0x1,%al
mov    %al,(%rsp)
mov    $0x1,%r15d
cmp    $0x2,%ebp
jb     1166 <countBinary+0x56>
mov    $0x1,%r15d
mov    %ebp,%eax
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
sar    %eax
mov    %eax,%ecx
and    $0x1,%cl
mov    %cl,(%rsp,%r15,1)
add    $0x1,%r15
cmp    $0x4,%ebp
mov    %eax,%ebp
jae    1150 <countBinary+0x40>
lea    0x1(%r15),%ebp
lea    -0x1(%r15),%eax
lea    (%rsp,%rax,1),%rbx
lea    0xea5(%rip),%r14
nopl   0x0(%rax)
movsbl (%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0xffffffff,%ebp
add    $0xffffffffffffffff,%rbx
cmp    $0x1,%ebp
jg     1180 <countBinary+0x70>
mov    %r15d,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [30 x i8] c"Its binary form of number is:\00"
@.str.1 = [3 x i8] c"%d\00"
define i32 @countBinary(i32 %0) {
%2 = alloca i32
%3 = alloca [32 x i8]
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %2
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%7 = load i32, i32* %2
%8 = and i32 %7, 1
%9 = trunc i32 %8 to i8
%10 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
store i8 %9, i8* %10
store i32 1, i32* %5
br label %11
11: ; preds = %22, %1
%12 = load i32, i32* %2
%13 = ashr i32 %12, 1
store i32 %13, i32* %2
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %25
15: ; preds = %11
%16 = load i32, i32* %2
%17 = and i32 %16, 1
%18 = trunc i32 %17 to i8
%19 = load i32, i32* %5
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 %20
store i8 %18, i8* %21
br label %22
22: ; preds = %15
%23 = load i32, i32* %5
%24 = add nsw i32 %23, 1
store i32 %24, i32* %5
br label %11
25: ; preds = %11
%26 = load i32, i32* %5
%27 = sub nsw i32 %26, 1
store i32 %27, i32* %4
br label %28
28: ; preds = %38, %25
%29 = load i32, i32* %4
%30 = icmp sge i32 %29, 0
br i1 %30, label %31, label %41
31: ; preds = %28
%32 = load i32, i32* %4
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 %33
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %36)
br label %38
38: ; preds = %31
%39 = load i32, i32* %4
%40 = add nsw i32 %39, -1
store i32 %40, i32* %4
br label %28
41: ; preds = %28
%42 = load i32, i32* %5
ret i32 %42
}

LLVM IR (-O2):
@.str = [30 x i8] c"Its binary form of number is:\00"
@.str.1 = [3 x i8] c"%d\00"
define i32 @countBinary(i32 %0) {
%2 = alloca [32 x i8]
%3 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%5 = trunc i32 %0 to i8
%6 = and i8 %5, 1
store i8 %6, i8* %3
%7 = icmp ult i32 %0, 2
br i1 %7, label %10, label %13
8: ; preds = %13
%9 = trunc i64 %20 to i32
br label %10
10: ; preds = %8, %1
%11 = phi i32 [ 1, %1 ], [ %9, %8 ]
%12 = zext i32 %11 to i64
br label %22
13: ; preds = %1, %13
%14 = phi i64 [ %20, %13 ], [ 1, %1 ]
%15 = phi i32 [ %16, %13 ], [ %0, %1 ]
%16 = ashr i32 %15, 1
%17 = trunc i32 %16 to i8
%18 = and i8 %17, 1
%19 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 %14
store i8 %18, i8* %19
%20 = add nuw i64 %14, 1
%21 = icmp ult i32 %15, 4
br i1 %21, label %8, label %13
22: ; preds = %10, %22
%23 = phi i64 [ %12, %10 ], [ %24, %22 ]
%24 = add nsw i64 %23, -1
%25 = and i64 %24, 4294967295
%26 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 %25
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %28)
%30 = trunc i64 %23 to i32
%31 = icmp sgt i32 %30, 1
br i1 %31, label %22, label %32
32: ; preds = %22
ret i32 %11
}