#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 abs(int);
int is_multiple_of_three(int n) {
  int odd_bits_cnt = 0;
  int even_bits_cnt = 0;
  if (n < 0)
    n = -n;
  if (n == 0)
    return 1;
  if (n == 1)
    return 0;
  while (n) {
    if (n & 0x1) {
      odd_bits_cnt++;
    }
    n >>= 1;
    if (n & 0x1) {
      even_bits_cnt++;
    }
    n >>= 1;
  }
  return is_multiple_of_three(abs(odd_bits_cnt - even_bits_cnt));
}


x86 assembly (clang, -O0):
<is_multiple_of_three>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    114b <is_multiple_of_three+0x2b>
xor    %eax,%eax
sub    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    1161 <is_multiple_of_three+0x41>
movl   $0x1,-0x4(%rbp)
jmp    11e2 <is_multiple_of_three+0xc2>
cmpl   $0x1,-0x8(%rbp)
jne    1177 <is_multiple_of_three+0x57>
movl   $0x0,-0x4(%rbp)
jmp    11e2 <is_multiple_of_three+0xc2>
jmp    117c <is_multiple_of_three+0x5c>
cmpl   $0x0,-0x8(%rbp)
je     11cd <is_multiple_of_three+0xad>
mov    -0x8(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     119e <is_multiple_of_three+0x7e>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%eax
sar    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     11bf <is_multiple_of_three+0x9f>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
sar    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    117c <is_multiple_of_three+0x5c>
mov    -0xc(%rbp),%edi
sub    -0x10(%rbp),%edi
call   1030 <abs@plt>
mov    %eax,%edi
call   1040 <is_multiple_of_three@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_multiple_of_three>:
mov    %edi,%eax
neg    %eax
cmovs  %edi,%eax
test   %eax,%eax
je     1145 <is_multiple_of_three+0x45>
cmp    $0x1,%eax
je     114b <is_multiple_of_three+0x4b>
xor    %edx,%edx
xor    %ecx,%ecx
mov    %eax,%esi
cs nopw 0x0(%rax,%rax,1)
mov    %eax,%edi
and    $0x1,%edi
add    %edi,%ecx
mov    %eax,%edi
shr    %edi
and    $0x1,%edi
add    %edi,%edx
shr    $0x2,%esi
cmp    $0x3,%eax
mov    %esi,%eax
ja     1120 <is_multiple_of_three+0x20>
sub    %edx,%ecx
mov    %ecx,%edi
neg    %edi
cmovs  %ecx,%edi
jmp    1100 <is_multiple_of_three>
mov    $0x1,%eax
ret
xor    %eax,%eax
ret

LLVM IR (-O0):
define i32 @is_multiple_of_three(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %3
store i32 0, i32* %4
store i32 0, i32* %5
%6 = load i32, i32* %3
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %1
%9 = load i32, i32* %3
%10 = sub nsw i32 0, %9
store i32 %10, i32* %3
br label %11
11: ; preds = %8, %1
%12 = load i32, i32* %3
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %11
store i32 1, i32* %2
br label %48
15: ; preds = %11
%16 = load i32, i32* %3
%17 = icmp eq i32 %16, 1
br i1 %17, label %18, label %19
18: ; preds = %15
store i32 0, i32* %2
br label %48
19: ; preds = %15
br label %20
20: ; preds = %39, %19
%21 = load i32, i32* %3
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %42
23: ; preds = %20
%24 = load i32, i32* %3
%25 = and i32 %24, 1
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %23
%28 = load i32, i32* %4
%29 = add nsw i32 %28, 1
store i32 %29, i32* %4
br label %30
30: ; preds = %27, %23
%31 = load i32, i32* %3
%32 = ashr i32 %31, 1
store i32 %32, i32* %3
%33 = load i32, i32* %3
%34 = and i32 %33, 1
%35 = icmp ne i32 %34, 0
br i1 %35, label %36, label %39
36: ; preds = %30
%37 = load i32, i32* %5
%38 = add nsw i32 %37, 1
store i32 %38, i32* %5
br label %39
39: ; preds = %36, %30
%40 = load i32, i32* %3
%41 = ashr i32 %40, 1
store i32 %41, i32* %3
br label %20
42: ; preds = %20
%43 = load i32, i32* %4
%44 = load i32, i32* %5
%45 = sub nsw i32 %43, %44
%46 = call i32 @abs(i32 %45)
%47 = call i32 @is_multiple_of_three(i32 %46)
store i32 %47, i32* %2
br label %48
48: ; preds = %42, %18, %14
%49 = load i32, i32* %2
ret i32 %49
}

LLVM IR (-O2):
define i32 @is_multiple_of_three(i32 %0) {
br label %2
2: ; preds = %16, %1
%3 = phi i32 [ %0, %1 ], [ %18, %16 ]
%4 = tail call i32 @llvm.abs.i32(i32 %3, i1 true)
switch i32 %4, label %5 [
i32 0, label %19
i32 1, label %20
]
5: ; preds = %2, %5
%6 = phi i32 [ %13, %5 ], [ 0, %2 ]
%7 = phi i32 [ %10, %5 ], [ 0, %2 ]
%8 = phi i32 [ %14, %5 ], [ %4, %2 ]
%9 = and i32 %8, 1
%10 = add nuw nsw i32 %7, %9
%11 = lshr i32 %8, 1
%12 = and i32 %11, 1
%13 = add nuw nsw i32 %6, %12
%14 = lshr i32 %8, 2
%15 = icmp ult i32 %8, 4
br i1 %15, label %16, label %5
16: ; preds = %5
%17 = sub nsw i32 %10, %13
%18 = tail call i32 @llvm.abs.i32(i32 %17, i1 true)
br label %2
19: ; preds = %2
br label %20
20: ; preds = %2, %19
%21 = phi i32 [ 1, %19 ], [ 0, %2 ]
ret i32 %21
}