#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int EOF;
int /*<<< orphan*/ exit(int);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ hamming_weight(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ *stdin;
int main(int argc, char *argv[]) {
  FILE *input = stdin;
  if (argv[1][0] != '-') {
    input = fopen(argv[1], "rb");
    if (input == 0) {
      printf("Could not open provided infile");
      exit(1);
    }
  }
  long long total = 0l;
  while (1) {
    int in = fgetc(input);
    if (in == EOF) {
      break;
    }
    total += hamming_weight(in);
  }
  printf("%lld", total);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e7b(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
je     11c8 <main+0x78>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe69(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11c3 <main+0x73>
lea    0xe51(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
jmp    11c8 <main+0x78>
movq   $0x0,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    0x2dfa(%rip),%rcx
cmp    (%rcx),%eax
jne    11f3 <main+0xa3>
jmp    1208 <main+0xb8>
mov    -0x24(%rbp),%edi
call   1050 <hamming_weight@plt>
add    -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    11d0 <main+0x80>
mov    -0x20(%rbp),%rsi
lea    0xe0f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
mov    0x8(%rsi),%rdi
cmpb   $0x2d,(%rdi)
jne    116a <main+0x1a>
mov    0x2e83(%rip),%rax
mov    (%rax),%r14
jmp    117e <main+0x2e>
lea    0xe8f(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%r14
test   %rax,%rax
je     11d0 <main+0x80>
mov    %r14,%rdi
call   1040 <fgetc@plt>
mov    0x2e53(%rip),%r15
cmp    (%r15),%eax
jne    1196 <main+0x46>
xor    %ebx,%ebx
jmp    11b7 <main+0x67>
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
mov    %eax,%edi
call   1050 <hamming_weight@plt>
add    %rax,%rbx
mov    %r14,%rdi
call   1040 <fgetc@plt>
cmp    (%r15),%eax
jne    11a0 <main+0x50>
lea    0xe64(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe2c(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@stdin = global i32* null
@.str = [3 x i8] c"rb\00"
@.str.1 = [31 x i8] c"Could not open provided infile\00"
@EOF = global i32 0
@.str.2 = [5 x i8] c"%lld\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i64
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32*, i32** @stdin
store i32* %9, i32** %6
%10 = load i8**, i8*** %5
%11 = getelementptr inbounds i8*, i8** %10, i64 1
%12 = load i8*, i8** %11
%13 = getelementptr inbounds i8, i8* %12, i64 0
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp ne i32 %15, 45
br i1 %16, label %17, label %28
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i32* @fopen(i8* %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %21, i32** %6
%22 = load i32*, i32** %6
%23 = icmp eq i32* %22, null
br i1 %23, label %24, label %27
24: ; preds = %17
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
%26 = call i32 @exit(i32 1)
unreachable
27: ; preds = %17
br label %28
28: ; preds = %27, %2
store i64 0, i64* %7
br label %29
29: ; preds = %28, %36
%30 = load i32*, i32** %6
%31 = call i32 @fgetc(i32* %30)
store i32 %31, i32* %8
%32 = load i32, i32* %8
%33 = load i32, i32* @EOF
%34 = icmp eq i32 %32, %33
br i1 %34, label %35, label %36
35: ; preds = %29
br label %41
36: ; preds = %29
%37 = load i32, i32* %8
%38 = call i64 @hamming_weight(i32 %37)
%39 = load i64, i64* %7
%40 = add nsw i64 %39, %38
store i64 %40, i64* %7
br label %29
41: ; preds = %35
%42 = load i64, i64* %7
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i64 %42)
%44 = load i32, i32* %3
ret i32 %44
}

LLVM IR (-O2):
@stdin = global i32* null
@.str = [3 x i8] c"rb\00"
@.str.1 = [31 x i8] c"Could not open provided infile\00"
@EOF = global i32 0
@.str.2 = [5 x i8] c"%lld\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = load i32*, i32** @stdin
%4 = getelementptr inbounds i8*, i8** %1, i64 1
%5 = load i8*, i8** %4
%6 = load i8, i8* %5
%7 = icmp eq i8 %6, 45
br i1 %7, label %14, label %8
8: ; preds = %2
%9 = tail call i32* @fopen(i8* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %14
11: ; preds = %8
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
%13 = tail call i32 @exit(i32 1)
unreachable
14: ; preds = %8, %2
%15 = phi i32* [ %9, %8 ], [ %3, %2 ]
%16 = tail call i32 @fgetc(i32* %15)
%17 = load i32, i32* @EOF
%18 = icmp eq i32 %16, %17
br i1 %18, label %27, label %19
19: ; preds = %14, %19
%20 = phi i32 [ %24, %19 ], [ %16, %14 ]
%21 = phi i64 [ %23, %19 ], [ 0, %14 ]
%22 = tail call i64 @hamming_weight(i32 %20)
%23 = add nsw i64 %22, %21
%24 = tail call i32 @fgetc(i32* %15)
%25 = load i32, i32* @EOF
%26 = icmp eq i32 %24, %25
br i1 %26, label %27, label %19
27: ; preds = %19, %14
%28 = phi i64 [ 0, %14 ], [ %23, %19 ]
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i64 %28)
ret i32 0
}