#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 */
scalar_t__ hamming_weight(char);
int int_hamming_weight(int c) {
  int ret = 0;
  char *tmp = (char *)(&c);
  for (int i = 0; i < sizeof(int); i++) {
    ret += hamming_weight(tmp[i]);
  }
  return ret;
}


x86 assembly (clang, -O0):
<int_hamming_weight>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
lea    -0x4(%rbp),%rax
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movslq -0x14(%rbp),%rax
cmp    $0x4,%rax
jae    116b <int_hamming_weight+0x5b>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <hamming_weight@plt>
mov    %rax,%rcx
movslq -0x8(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x8(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1131 <int_hamming_weight+0x21>
mov    -0x8(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<int_hamming_weight>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edi,%ebx
mov    %edi,%ebp
shr    $0x8,%ebp
mov    %edi,%r12d
shr    $0x10,%r12d
movsbl %bl,%edi
call   1030 <hamming_weight@plt>
mov    %rax,%r14
movsbl %bpl,%edi
call   1030 <hamming_weight@plt>
mov    %rax,%r15
add    %r14d,%r15d
movsbl %r12b,%edi
call   1030 <hamming_weight@plt>
mov    %rax,%r14
add    %r15d,%r14d
sar    $0x18,%ebx
mov    %ebx,%edi
call   1030 <hamming_weight@plt>
add    %r14d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @int_hamming_weight(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %3
%6 = bitcast i32* %2 to i8*
store i8* %6, i8** %4
store i32 0, i32* %5
br label %7
7: ; preds = %22, %1
%8 = load i32, i32* %5
%9 = sext i32 %8 to i64
%10 = icmp ult i64 %9, 4
br i1 %10, label %11, label %25
11: ; preds = %7
%12 = load i8*, i8** %4
%13 = load i32, i32* %5
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %12, i64 %14
%16 = load i8, i8* %15
%17 = call i64 @hamming_weight(i8 signext %16)
%18 = load i32, i32* %3
%19 = sext i32 %18 to i64
%20 = add nsw i64 %19, %17
%21 = trunc i64 %20 to i32
store i32 %21, i32* %3
br label %22
22: ; preds = %11
%23 = load i32, i32* %5
%24 = add nsw i32 %23, 1
store i32 %24, i32* %5
br label %7
25: ; preds = %7
%26 = load i32, i32* %3
ret i32 %26
}

LLVM IR (-O2):
define i32 @int_hamming_weight(i32 %0) {
%2 = trunc i32 %0 to i8
%3 = lshr i32 %0, 8
%4 = trunc i32 %3 to i8
%5 = lshr i32 %0, 16
%6 = trunc i32 %5 to i8
%7 = lshr i32 %0, 24
%8 = trunc i32 %7 to i8
%9 = tail call i64 @hamming_weight(i8 signext %2)
%10 = trunc i64 %9 to i32
%11 = tail call i64 @hamming_weight(i8 signext %4)
%12 = trunc i64 %11 to i32
%13 = add i32 %10, %12
%14 = tail call i64 @hamming_weight(i8 signext %6)
%15 = trunc i64 %14 to i32
%16 = add i32 %13, %15
%17 = tail call i64 @hamming_weight(i8 signext %8)
%18 = trunc i64 %17 to i32
%19 = add i32 %16, %18
ret i32 %19
}