#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 */
scalar_t__ EOF;
int bitcount(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int, int);
scalar_t__ fscanf(int /*<<< orphan*/ *, char *, int *);
int /*<<< orphan*/ perror(char *);
int main(int argc, char *argv[]) {
  FILE *in, *out;
  in = fopen("input.dat", "r");
  if (in == NULL) {
    perror("input.dat");
    return 1;
  }
  out = fopen("output.dat", "w");
  if (out == NULL) {
    perror("output.dat");
    return 1;
  }
  int x, y;
  while (fscanf(in, "%x", &x) != EOF) {
    y = bitcount(x);
    fprintf(out, "bitcount(0x%x) is %d\n", x, y);
  }
  fclose(in);
  fclose(out);
  return 0;
}


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)
lea    0xe83(%rip),%rdi
lea    0xe86(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11b0 <main+0x50>
lea    0xe61(%rip),%rdi
call   1080 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1252 <main+0xf2>
lea    0xe55(%rip),%rdi
lea    0xe59(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11ea <main+0x8a>
lea    0xe33(%rip),%rdi
call   1080 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1252 <main+0xf2>
jmp    11ef <main+0x8f>
mov    -0x18(%rbp),%rdi
lea    0xe1f(%rip),%rsi
lea    -0x24(%rbp),%rdx
call   1040 <fscanf@plt>
mov    0x2dde(%rip),%rcx
cmp    (%rcx),%rax
je     1239 <main+0xd9>
mov    -0x24(%rbp),%edi
call   1050 <bitcount@plt>
mov    %eax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%edx
mov    -0x28(%rbp),%ecx
lea    0xded(%rip),%rsi
call   1060 <fprintf@plt>
jmp    11ef <main+0x8f>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xe8e(%rip),%rdi
lea    0xe91(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     122f <main+0xcf>
mov    %rax,%r14
lea    0xe7b(%rip),%rdi
lea    0xe7f(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1238 <main+0xd8>
mov    %rax,%rbx
lea    0xe69(%rip),%rsi
lea    0x4(%rsp),%rdx
mov    %r14,%rdi
call   1040 <fscanf@plt>
mov    0x2e24(%rip),%rbp
cmp    0x0(%rbp),%rax
je     120e <main+0xae>
lea    0xe4b(%rip),%r15
lea    0xe41(%rip),%r12
lea    0x4(%rsp),%r13
nopl   (%rax)
mov    0x4(%rsp),%edi
call   1050 <bitcount@plt>
mov    0x4(%rsp),%edx
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %eax,%ecx
call   1060 <fprintf@plt>
mov    %r14,%rdi
mov    %r12,%rsi
mov    %r13,%rdx
call   1040 <fscanf@plt>
cmp    0x0(%rbp),%rax
jne    11e0 <main+0x80>
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdca(%rip),%rdi
jmp    123f <main+0xdf>
lea    0xdcd(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%eax
jmp    1220 <main+0xc0>

LLVM IR (-O0):
@.str = [10 x i8] c"input.dat\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [11 x i8] c"output.dat\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [3 x i8] c"%x\00"
@EOF = global i64 0
@.str.5 = [22 x i8] c"bitcount(0x%x) is %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %10, i32** %6
%11 = load i32*, i32** %6
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %39
15: ; preds = %2
%16 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %16, i32** %7
%17 = load i32*, i32** %7
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %21
19: ; preds = %15
%20 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %39
21: ; preds = %15
br label %22
22: ; preds = %27, %21
%23 = load i32*, i32** %6
%24 = call i64 @fscanf(i32* %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %8)
%25 = load i64, i64* @EOF
%26 = icmp ne i64 %24, %25
br i1 %26, label %27, label %34
27: ; preds = %22
%28 = load i32, i32* %8
%29 = call i32 @bitcount(i32 %28)
store i32 %29, i32* %9
%30 = load i32*, i32** %7
%31 = load i32, i32* %8
%32 = load i32, i32* %9
%33 = call i32 @fprintf(i32* %30, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0), i32 %31, i32 %32)
br label %22
34: ; preds = %22
%35 = load i32*, i32** %6
%36 = call i32 @fclose(i32* %35)
%37 = load i32*, i32** %7
%38 = call i32 @fclose(i32* %37)
store i32 0, i32* %3
br label %39
39: ; preds = %34, %19, %13
%40 = load i32, i32* %3
ret i32 %40
}

LLVM IR (-O2):
@.str = [10 x i8] c"input.dat\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [11 x i8] c"output.dat\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [3 x i8] c"%x\00"
@EOF = global i64 0
@.str.5 = [22 x i8] c"bitcount(0x%x) is %d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %29
8: ; preds = %2
%9 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = tail call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
br label %29
13: ; preds = %8
%14 = bitcast i32* %3 to i8*
%15 = call i64 @fscanf(i32* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %3)
%16 = load i64, i64* @EOF
%17 = icmp eq i64 %15, %16
br i1 %17, label %26, label %18
18: ; preds = %13, %18
%19 = load i32, i32* %3
%20 = call i32 @bitcount(i32 %19)
%21 = load i32, i32* %3
%22 = call i32 @fprintf(i32* %9, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0), i32 %21, i32 %20)
%23 = call i64 @fscanf(i32* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %3)
%24 = load i64, i64* @EOF
%25 = icmp eq i64 %23, %24
br i1 %25, label %26, label %18
26: ; preds = %18, %13
%27 = call i32 @fclose(i32* %4)
%28 = call i32 @fclose(i32* %9)
br label %29
29: ; preds = %26, %11, %6
%30 = phi i32 [ 1, %6 ], [ 1, %11 ], [ 0, %26 ]
ret i32 %30
}