#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 */
short getchar();
int /*<<< orphan*/ printf(char *, ...);
main() {
  short var, count = 0;
  printf("Enter a character: ");
  var = getchar();
  count += var % 2;
  while (var = var / 2)
    count += var % 2;
  printf("The number of 1's in the given character: %d\n", count);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movw   $0x0,-0x8(%rbp)
lea    0xec4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %ax,-0x6(%rbp)
movswl -0x6(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
movswl -0x8(%rbp),%eax
add    %edx,%eax
mov    %ax,-0x8(%rbp)
movswl -0x6(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %ax,-0x6(%rbp)
cmp    $0x0,%ax
je     1199 <main+0x79>
movswl -0x6(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
movswl -0x8(%rbp),%eax
add    %edx,%eax
mov    %ax,-0x8(%rbp)
jmp    1164 <main+0x44>
movswl -0x8(%rbp),%esi
lea    0xe70(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0xed8(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
call   1040 <getchar@plt>
movzwl %ax,%edx
mov    %edx,%ecx
shr    $0xf,%ecx
add    %edx,%ecx
and    $0xfffffffe,%ecx
mov    %edx,%esi
sub    %ecx,%esi
movzwl %si,%ecx
add    $0x1,%edx
cmp    $0x3,%dx
jb     1191 <main+0x71>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movzwl %ax,%eax
mov    %eax,%edx
shr    $0xf,%edx
add    %eax,%edx
movswl %dx,%eax
movzwl %ax,%edx
sar    %eax
shr    $0xf,%edx
add    %eax,%edx
and    $0xfffffffe,%edx
mov    %eax,%esi
sub    %edx,%esi
movzwl %si,%edx
movswl %cx,%ecx
add    %edx,%ecx
mov    %eax,%edx
add    $0x1,%edx
cmp    $0x2,%dx
ja     1160 <main+0x40>
movswl %cx,%esi
lea    0xe79(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [20 x i8] c"Enter a character: \00"
@.str.1 = [46 x i8] c"The number of 1's in the given character: %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i16
%3 = alloca i16
store i32 0, i32* %1
store i16 0, i16* %3
%4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%5 = call signext i16 (...) @getchar()
store i16 %5, i16* %2
%6 = load i16, i16* %2
%7 = sext i16 %6 to i32
%8 = srem i32 %7, 2
%9 = load i16, i16* %3
%10 = sext i16 %9 to i32
%11 = add nsw i32 %10, %8
%12 = trunc i32 %11 to i16
store i16 %12, i16* %3
br label %13
13: ; preds = %19, %0
%14 = load i16, i16* %2
%15 = sext i16 %14 to i32
%16 = sdiv i32 %15, 2
%17 = trunc i32 %16 to i16
store i16 %17, i16* %2
%18 = icmp ne i16 %17, 0
br i1 %18, label %19, label %27
19: ; preds = %13
%20 = load i16, i16* %2
%21 = sext i16 %20 to i32
%22 = srem i32 %21, 2
%23 = load i16, i16* %3
%24 = sext i16 %23 to i32
%25 = add nsw i32 %24, %22
%26 = trunc i32 %25 to i16
store i16 %26, i16* %3
br label %13
27: ; preds = %13
%28 = load i16, i16* %3
%29 = sext i16 %28 to i32
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0), i32 %29)
%31 = load i32, i32* %1
ret i32 %31
}

LLVM IR (-O2):
@.str = [20 x i8] c"Enter a character: \00"
@.str.1 = [46 x i8] c"The number of 1's in the given character: %d\0A\00"
define i32 @main() {
%1 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%2 = tail call signext i16 (...) @getchar()
%3 = srem i16 %2, 2
%4 = zext i16 %3 to i32
%5 = add i16 %2, 1
%6 = icmp ult i16 %5, 3
br i1 %6, label %18, label %7
7: ; preds = %0, %7
%8 = phi i16 [ %10, %7 ], [ %2, %0 ]
%9 = phi i32 [ %15, %7 ], [ %4, %0 ]
%10 = sdiv i16 %8, 2
%11 = srem i16 %10, 2
%12 = zext i16 %11 to i32
%13 = shl i32 %9, 16
%14 = ashr exact i32 %13, 16
%15 = add nsw i32 %14, %12
%16 = add nsw i16 %10, 1
%17 = icmp ult i16 %16, 3
br i1 %17, label %18, label %7
18: ; preds = %7, %0
%19 = phi i32 [ %4, %0 ], [ %15, %7 ]
%20 = shl i32 %19, 16
%21 = ashr exact i32 %20, 16
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0), i32 %21)
ret i32 0
}