#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 EOF;
int bitcount(unsigned int);
unsigned int clz(int /*<<< orphan*/);
int getchar();
scalar_t__ is_num(int);
scalar_t__ is_ws(int);
int /*<<< orphan*/ printf(char *, unsigned int, ...);
int /*<<< orphan*/ showbits(unsigned int);
int main(void) {
  extern unsigned maxbit;
  maxbit = clz(0);
  int c, in_num = 0;
  unsigned total = 0;
  while ((c = getchar()) != EOF) {
    if (in_num && is_ws(c)) {
      printf("Bit field:\n\t%u = ", total);
      showbits(total);
      printf("Number of 'on' bits:\n\t%u = %u\n", total, bitcount(total));
      in_num = 0;
      total = 0;
    } else if (!in_num && is_num(c)) {
      total = c - '0';
      in_num = 1;
    } else if (in_num && is_num(c)) {
      total = total * 10 + c - '0';
    } else {
      in_num = 0;
      total = 0;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
xor    %edi,%edi
call   1030 <clz@plt>
mov    %eax,%ecx
mov    0x2e41(%rip),%rax
mov    %ecx,(%rax)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    $0x0,%al
call   1080 <getchar@plt>
mov    %eax,-0x8(%rbp)
mov    0x2e38(%rip),%rcx
cmp    (%rcx),%eax
je     129d <main+0x12d>
cmpl   $0x0,-0xc(%rbp)
je     1221 <main+0xb1>
mov    -0x8(%rbp),%edi
call   1050 <is_ws@plt>
cmp    $0x0,%rax
je     1221 <main+0xb1>
mov    -0x10(%rbp),%esi
lea    0xe22(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x10(%rbp),%edi
call   1040 <showbits@plt>
mov    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%edi
call   1070 <bitcount@plt>
mov    -0x14(%rbp),%esi
mov    %eax,%edx
lea    0xe0b(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
jmp    1298 <main+0x128>
cmpl   $0x0,-0xc(%rbp)
jne    1252 <main+0xe2>
mov    -0x8(%rbp),%edi
call   1090 <is_num@plt>
cmp    $0x0,%rax
je     1252 <main+0xe2>
mov    -0x8(%rbp),%eax
sub    $0x30,%eax
mov    %eax,-0x10(%rbp)
movl   $0x1,-0xc(%rbp)
jmp    1293 <main+0x123>
cmpl   $0x0,-0xc(%rbp)
je     1280 <main+0x110>
mov    -0x8(%rbp),%edi
call   1090 <is_num@plt>
cmp    $0x0,%rax
je     1280 <main+0x110>
imul   $0xa,-0x10(%rbp),%eax
add    -0x8(%rbp),%eax
sub    $0x30,%eax
mov    %eax,-0x10(%rbp)
jmp    128e <main+0x11e>
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
jmp    1293 <main+0x123>
jmp    1298 <main+0x128>
jmp    119f <main+0x2f>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %edi,%edi
call   1030 <clz@plt>
mov    0x2e47(%rip),%rcx
mov    %eax,(%rcx)
xor    %eax,%eax
call   1080 <getchar@plt>
mov    0x2e4f(%rip),%r13
cmp    0x0(%r13),%eax
jne    11b0 <main+0x40>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %eax,%ebx
lea    0xe47(%rip),%r14
lea    0xe52(%rip),%r15
xor    %r12d,%r12d
xor    %ebp,%ebp
jmp    11e2 <main+0x72>
nopw   0x0(%rax,%rax,1)
mov    %al,%bpl
xor    %eax,%eax
call   1080 <getchar@plt>
mov    %eax,%ebx
cmp    0x0(%r13),%eax
je     119f <main+0x2f>
mov    %ebx,%edi
test   %ebp,%ebp
je     1230 <main+0xc0>
call   1050 <is_ws@plt>
test   %rax,%rax
je     1250 <main+0xe0>
xor    %ebp,%ebp
mov    %r14,%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r12d,%edi
call   1040 <showbits@plt>
mov    %r12d,%edi
call   1070 <bitcount@plt>
mov    %r15,%rdi
mov    %r12d,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1060 <printf@plt>
xor    %r12d,%r12d
jmp    11d3 <main+0x63>
cs nopw 0x0(%rax,%rax,1)
nop
call   1090 <is_num@plt>
xor    %r12d,%r12d
xor    %ebp,%ebp
test   %rax,%rax
setne  %al
je     11d0 <main+0x60>
add    $0xffffffd0,%ebx
mov    %ebx,%r12d
jmp    11d0 <main+0x60>
nopw   0x0(%rax,%rax,1)
mov    %ebx,%edi
call   1090 <is_num@plt>
test   %rax,%rax
je     1272 <main+0x102>
lea    (%r12,%r12,4),%eax
lea    (%rbx,%rax,2),%r12d
add    $0xffffffd0,%r12d
mov    $0x1,%ebp
jmp    11d3 <main+0x63>
xor    %ebp,%ebp
xor    %r12d,%r12d
jmp    11d3 <main+0x63>

LLVM IR (-O0):
@maxbit = external global i32
@EOF = global i32 0
@.str = [18 x i8] c"Bit field:\0A\09%u = \00"
@.str.1 = [31 x i8] c"Number of 'on' bits:\0A\09%u = %u\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
%5 = call i32 @clz(i32 0)
store i32 %5, i32* @maxbit
store i32 0, i32* %3
store i32 0, i32* %4
br label %6
6: ; preds = %52, %0
%7 = call i32 (...) @getchar()
store i32 %7, i32* %2
%8 = load i32, i32* @EOF
%9 = icmp ne i32 %7, %8
br i1 %9, label %10, label %53
10: ; preds = %6
%11 = load i32, i32* %3
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %26
13: ; preds = %10
%14 = load i32, i32* %2
%15 = call i64 @is_ws(i32 %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %26
17: ; preds = %13
%18 = load i32, i32* %4
%19 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %18)
%20 = load i32, i32* %4
%21 = call i32 @showbits(i32 %20)
%22 = load i32, i32* %4
%23 = load i32, i32* %4
%24 = call i32 @bitcount(i32 %23)
%25 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i32 %22, i32 %24)
store i32 0, i32* %3
store i32 0, i32* %4
br label %52
26: ; preds = %13, %10
%27 = load i32, i32* %3
%28 = icmp ne i32 %27, 0
br i1 %28, label %36, label %29
29: ; preds = %26
%30 = load i32, i32* %2
%31 = call i64 @is_num(i32 %30)
%32 = icmp ne i64 %31, 0
br i1 %32, label %33, label %36
33: ; preds = %29
%34 = load i32, i32* %2
%35 = sub nsw i32 %34, 48
store i32 %35, i32* %4
store i32 1, i32* %3
br label %51
36: ; preds = %29, %26
%37 = load i32, i32* %3
%38 = icmp ne i32 %37, 0
br i1 %38, label %39, label %49
39: ; preds = %36
%40 = load i32, i32* %2
%41 = call i64 @is_num(i32 %40)
%42 = icmp ne i64 %41, 0
br i1 %42, label %43, label %49
43: ; preds = %39
%44 = load i32, i32* %4
%45 = mul i32 %44, 10
%46 = load i32, i32* %2
%47 = add i32 %45, %46
%48 = sub i32 %47, 48
store i32 %48, i32* %4
br label %50
49: ; preds = %39, %36
store i32 0, i32* %3
store i32 0, i32* %4
br label %50
50: ; preds = %49, %43
br label %51
51: ; preds = %50, %33
br label %52
52: ; preds = %51, %17
br label %6
53: ; preds = %6
ret i32 0
}

LLVM IR (-O2):
@maxbit = external global i32
@EOF = global i32 0
@.str = [18 x i8] c"Bit field:\0A\09%u = \00"
@.str.1 = [31 x i8] c"Number of 'on' bits:\0A\09%u = %u\0A\00"
define i32 @main() {
%1 = tail call i32 @clz(i32 0)
store i32 %1, i32* @maxbit
%2 = tail call i32 (...) @getchar()
%3 = load i32, i32* @EOF
%4 = icmp eq i32 %2, %3
br i1 %4, label %38, label %5
5: ; preds = %0, %32
%6 = phi i32 [ %35, %32 ], [ %2, %0 ]
%7 = phi i32 [ %34, %32 ], [ 0, %0 ]
%8 = phi i32 [ %33, %32 ], [ 0, %0 ]
%9 = icmp eq i32 %8, 0
br i1 %9, label %18, label %10
10: ; preds = %5
%11 = tail call i64 @is_ws(i32 %6)
%12 = icmp eq i64 %11, 0
br i1 %12, label %25, label %13
13: ; preds = %10
%14 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %7)
%15 = tail call i32 @showbits(i32 %7)
%16 = tail call i32 @bitcount(i32 %7)
%17 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i32 %7, i32 %16)
br label %32
18: ; preds = %5
%19 = tail call i64 @is_num(i32 %6)
%20 = icmp eq i64 %19, 0
%21 = add nsw i32 %6, -48
%22 = xor i1 %20, true
%23 = zext i1 %22 to i32
%24 = select i1 %20, i32 0, i32 %21
br label %32
25: ; preds = %10
%26 = tail call i64 @is_num(i32 %6)
%27 = icmp eq i64 %26, 0
br i1 %27, label %32, label %28
28: ; preds = %25
%29 = mul i32 %7, 10
%30 = add i32 %6, -48
%31 = add i32 %30, %29
br label %32
32: ; preds = %18, %25, %28, %13
%33 = phi i32 [ 0, %13 ], [ 1, %28 ], [ 0, %25 ], [ %23, %18 ]
%34 = phi i32 [ 0, %13 ], [ %31, %28 ], [ 0, %25 ], [ %24, %18 ]
%35 = tail call i32 (...) @getchar()
%36 = load i32, i32* @EOF
%37 = icmp eq i32 %35, %36
br i1 %37, label %38, label %5
38: ; preds = %32, %0
ret i32 0
}