#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 countChars(char *, char);
int getLine(char *, char *, int);
int /*<<< orphan*/ intToBinary(int, char *, int);
int /*<<< orphan*/ printf(char *, ...);
int sscanf(char *, char *, int *);
int main() {
  int valueCount;
  char valueCount_Buffer[10];
  valueCount = getLine("number to process > ", valueCount_Buffer, 10);
  if (valueCount == 1) {
    printf("error: input was too long! : [%s]\n", valueCount_Buffer);
    return 1;
  }
  int intvar;
  if (sscanf(valueCount_Buffer, "%i", &intvar) != 1) {
    printf("error: not an integer!\n");
    return 1;
  }
  char binary_Buffer[30];
  binary_Buffer[29] = '\0';
  intToBinary(intvar, binary_Buffer, 29);
  int bitCount = countChars(binary_Buffer, '1');
  printf("binary form of your number is %s\n", binary_Buffer);
  printf("bit count of your number is %d\n", bitCount);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x12(%rbp),%rsi
lea    0xe96(%rip),%rdi
mov    $0xa,%edx
call   1060 <getLine@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    119f <main+0x4f>
lea    -0x12(%rbp),%rsi
lea    0xe89(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1226 <main+0xd6>
lea    -0x12(%rbp),%rdi
lea    0xe8e(%rip),%rsi
lea    -0x18(%rbp),%rdx
call   1050 <sscanf@plt>
cmp    $0x1,%eax
je     11d6 <main+0x86>
lea    0xe78(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1226 <main+0xd6>
movb   $0x0,-0x23(%rbp)
mov    -0x18(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    $0x1d,%edx
call   1070 <intToBinary@plt>
lea    -0x40(%rbp),%rdi
mov    $0x31,%esi
call   1040 <countChars@plt>
mov    %eax,-0x44(%rbp)
lea    -0x40(%rbp),%rsi
lea    0xe4c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x44(%rbp),%esi
lea    0xe5d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x30,%rsp
lea    0xe91(%rip),%rdi
lea    0x6(%rsp),%rsi
mov    $0xa,%edx
call   1070 <getLine@plt>
cmp    $0x1,%eax
jne    1198 <main+0x38>
lea    0xe8b(%rip),%rdi
lea    0x6(%rsp),%rsi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    120b <main+0xab>
lea    0xe99(%rip),%rsi
lea    0x6(%rsp),%rdi
mov    %rsp,%rdx
call   1060 <sscanf@plt>
cmp    $0x1,%eax
jne    11ff <main+0x9f>
movb   $0x0,0x2d(%rsp)
mov    (%rsp),%edi
lea    0x10(%rsp),%r14
mov    %r14,%rsi
mov    $0x1d,%edx
call   1080 <intToBinary@plt>
mov    %r14,%rdi
mov    $0x31,%esi
call   1050 <countChars@plt>
mov    %eax,%ebp
lea    0xe5a(%rip),%rdi
xor    %ebx,%ebx
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe69(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1210 <main+0xb0>
lea    0xe77(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [21 x i8] c"number to process > \00"
@.str.1 = [35 x i8] c"error: input was too long! : [%s]\0A\00"
@.str.2 = [3 x i8] c"%i\00"
@.str.3 = [24 x i8] c"error: not an integer!\0A\00"
@.str.4 = [34 x i8] c"binary form of your number is %s\0A\00"
@.str.5 = [32 x i8] c"bit count of your number is %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [10 x i8]
%4 = alloca i32
%5 = alloca [30 x i8]
%6 = alloca i32
store i32 0, i32* %1
%7 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%8 = call i32 @getLine(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %7, i32 10)
store i32 %8, i32* %2
%9 = load i32, i32* %2
%10 = icmp eq i32 %9, 1
br i1 %10, label %11, label %14
11: ; preds = %0
%12 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i8* %12)
store i32 1, i32* %1
br label %31
14: ; preds = %0
%15 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%16 = call i32 @sscanf(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %4)
%17 = icmp ne i32 %16, 1
br i1 %17, label %18, label %20
18: ; preds = %14
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %1
br label %31
20: ; preds = %14
%21 = getelementptr inbounds [30 x i8], [30 x i8]* %5, i64 0, i64 29
store i8 0, i8* %21
%22 = load i32, i32* %4
%23 = getelementptr inbounds [30 x i8], [30 x i8]* %5, i64 0, i64 0
%24 = call i32 @intToBinary(i32 %22, i8* %23, i32 29)
%25 = getelementptr inbounds [30 x i8], [30 x i8]* %5, i64 0, i64 0
%26 = call i32 @countChars(i8* %25, i8 signext 49)
store i32 %26, i32* %6
%27 = getelementptr inbounds [30 x i8], [30 x i8]* %5, i64 0, i64 0
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0), i8* %27)
%29 = load i32, i32* %6
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0), i32 %29)
store i32 0, i32* %1
br label %31
31: ; preds = %20, %18, %11
%32 = load i32, i32* %1
ret i32 %32
}

LLVM IR (-O2):
@.str = [21 x i8] c"number to process > \00"
@.str.1 = [35 x i8] c"error: input was too long! : [%s]\0A\00"
@.str.2 = [3 x i8] c"%i\00"
@.str.4 = [34 x i8] c"binary form of your number is %s\0A\00"
@.str.5 = [32 x i8] c"bit count of your number is %d\0A\00"
@str = [23 x i8] c"error: not an integer!\00"
define i32 @main() {
%1 = alloca [10 x i8]
%2 = alloca i32
%3 = alloca [30 x i8]
%4 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 0
%5 = call i32 @getLine(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %4, i32 10)
%6 = icmp eq i32 %5, 1
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i8* %4)
br label %25
9: ; preds = %0
%10 = bitcast i32* %2 to i8*
%11 = call i32 @sscanf(i8* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%12 = icmp eq i32 %11, 1
br i1 %12, label %15, label %13
13: ; preds = %9
%14 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
br label %23
15: ; preds = %9
%16 = getelementptr inbounds [30 x i8], [30 x i8]* %3, i64 0, i64 0
%17 = getelementptr inbounds [30 x i8], [30 x i8]* %3, i64 0, i64 29
store i8 0, i8* %17
%18 = load i32, i32* %2
%19 = call i32 @intToBinary(i32 %18, i8* %16, i32 29)
%20 = call i32 @countChars(i8* %16, i8 signext 49)
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0), i8* %16)
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0), i32 %20)
br label %23
23: ; preds = %15, %13
%24 = phi i32 [ 1, %13 ], [ 0, %15 ]
br label %25
25: ; preds = %23, %7
%26 = phi i32 [ 1, %7 ], [ %24, %23 ]
ret i32 %26
}