#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 cardinality(char);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, char *);
void countbits(char *filename, int *nullen, int *einsen) {
  FILE *file;
  int ch;
  file = fopen(filename, "rb");
  if (file == NULL) {
    printf("Fehler beim Öffnen der Datei: %s\n", filename);
    exit(1);
  }
  while ((ch = fgetc(file)) >= 0) {
    ch = cardinality((char)ch);
    *einsen += ch;
    *nullen += 8 - ch;
  }
  fclose(file);
  return;
}


x86 assembly (clang, -O0):
<countbits>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe81(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11ad <countbits+0x4d>
mov    -0x8(%rbp),%rsi
lea    0xe65(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
jmp    11b2 <countbits+0x52>
mov    -0x20(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
jl     11f5 <countbits+0x95>
mov    -0x24(%rbp),%eax
movsbl %al,%edi
call   1060 <cardinality@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%ecx
mov    -0x18(%rbp),%rax
add    (%rax),%ecx
mov    %ecx,(%rax)
mov    $0x8,%ecx
sub    -0x24(%rbp),%ecx
mov    -0x10(%rbp),%rax
add    (%rax),%ecx
mov    %ecx,(%rax)
jmp    11b2 <countbits+0x52>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<countbits>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%r12
lea    0xe88(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11c5 <countbits+0x65>
mov    %rax,%r15
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r15,%rdi
call   1050 <fgetc@plt>
test   %eax,%eax
js     11b2 <countbits+0x52>
movsbl %al,%edi
call   1060 <cardinality@plt>
add    %eax,(%r14)
mov    (%rbx),%ecx
sub    %eax,%ecx
add    $0x8,%ecx
mov    %ecx,(%rbx)
jmp    1190 <countbits+0x30>
mov    %r15,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <fclose@plt>
lea    0xe37(%rip),%rdi
mov    %r12,%rsi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@.str.1 = [35 x i8] c"Fehler beim \C3\96ffnen der Datei: %s\0A\00"
define void @countbits(i8* %0, i32* %1, i32* %2) {
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32
store i8* %0, i8** %4
store i32* %1, i32** %5
store i32* %2, i32** %6
%9 = load i8*, i8** %4
%10 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %10, i32** %7
%11 = load i32*, i32** %7
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %17
13: ; preds = %3
%14 = load i8*, i8** %4
%15 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i8* %14)
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %3
br label %18
18: ; preds = %22, %17
%19 = load i32*, i32** %7
%20 = call i32 @fgetc(i32* %19)
store i32 %20, i32* %8
%21 = icmp sge i32 %20, 0
br i1 %21, label %22, label %35
22: ; preds = %18
%23 = load i32, i32* %8
%24 = trunc i32 %23 to i8
%25 = call i32 @cardinality(i8 signext %24)
store i32 %25, i32* %8
%26 = load i32, i32* %8
%27 = load i32*, i32** %6
%28 = load i32, i32* %27
%29 = add nsw i32 %28, %26
store i32 %29, i32* %27
%30 = load i32, i32* %8
%31 = sub nsw i32 8, %30
%32 = load i32*, i32** %5
%33 = load i32, i32* %32
%34 = add nsw i32 %33, %31
store i32 %34, i32* %32
br label %18
35: ; preds = %18
%36 = load i32*, i32** %7
%37 = call i32 @fclose(i32* %36)
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@.str.1 = [35 x i8] c"Fehler beim \C3\96ffnen der Datei: %s\0A\00"
define void @countbits(i8* %0, i32* nocapture %1, i32* nocapture %2) {
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %9, label %6
6: ; preds = %3
%7 = tail call i32 @fgetc(i32* %4)
%8 = icmp sgt i32 %7, -1
br i1 %8, label %12, label %23
9: ; preds = %3
%10 = tail call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %6, %12
%13 = phi i32 [ %21, %12 ], [ %7, %6 ]
%14 = trunc i32 %13 to i8
%15 = tail call i32 @cardinality(i8 signext %14)
%16 = load i32, i32* %2
%17 = add nsw i32 %16, %15
store i32 %17, i32* %2
%18 = sub i32 8, %15
%19 = load i32, i32* %1
%20 = add nsw i32 %18, %19
store i32 %20, i32* %1
%21 = tail call i32 @fgetc(i32* %4)
%22 = icmp sgt i32 %21, -1
br i1 %22, label %12, label %23
23: ; preds = %12, %6
%24 = tail call i32 @fclose(i32* %4)
ret void
}