#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*/ mpz_t;

/* Variables and functions */
int /*<<< orphan*/ gmp_printf(char *, int /*<<< orphan*/);
int /*<<< orphan*/ mpz_add_ui(int /*<<< orphan*/, int /*<<< orphan*/,
                              unsigned int);
int /*<<< orphan*/ mpz_init(int /*<<< orphan*/);
int /*<<< orphan*/ mpz_mul_ui(int /*<<< orphan*/, int /*<<< orphan*/, int);
int ca2d_rule_gol() {
  int unsigned len = 1 << 9;
  int unsigned sum, out;
  mpz_t rule;
  mpz_init(rule);
  for (int i = len - 1; i >= 0; i--) {
    sum = 0;
    for (int unsigned b = 0; b < 9; b++) {
      sum += ((i & 0b111101111) >> b) & 0x1;
    }
    if (sum == 3)
      out = 1;
    else if (sum == 2)
      out = (i & 0b000010000) >> 4;
    else
      out = 0;
    mpz_mul_ui(rule, rule, 2);
    mpz_add_ui(rule, rule, out);
  }
  gmp_printf("RULE GoL = 0x%ZX\n", rule);
  return (0);
}


x86 assembly (clang, -O0):
<ca2d_rule_gol>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x200,-0x4(%rbp)
mov    -0x10(%rbp),%edi
call   1040 <mpz_init@plt>
mov    -0x4(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jl     120f <ca2d_rule_gol+0xcf>
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x9,-0x18(%rbp)
jae    11a6 <ca2d_rule_gol+0x66>
mov    -0x14(%rbp),%eax
and    $0x1ef,%eax
mov    -0x18(%rbp),%ecx
sar    %cl,%eax
and    $0x1,%eax
add    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1178 <ca2d_rule_gol+0x38>
cmpl   $0x3,-0x8(%rbp)
jne    11bc <ca2d_rule_gol+0x7c>
movl   $0x1,-0xc(%rbp)
jmp    11e3 <ca2d_rule_gol+0xa3>
cmpl   $0x2,-0x8(%rbp)
jne    11d7 <ca2d_rule_gol+0x97>
mov    -0x14(%rbp),%eax
and    $0x10,%eax
sar    $0x4,%eax
mov    %eax,-0xc(%rbp)
jmp    11de <ca2d_rule_gol+0x9e>
movl   $0x0,-0xc(%rbp)
jmp    11e3 <ca2d_rule_gol+0xa3>
mov    -0x10(%rbp),%edi
mov    -0x10(%rbp),%esi
mov    $0x2,%edx
call   1060 <mpz_mul_ui@plt>
mov    -0x10(%rbp),%edi
mov    -0x10(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1030 <mpz_add_ui@plt>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    1160 <ca2d_rule_gol+0x20>
mov    -0x10(%rbp),%esi
lea    0xde7(%rip),%rdi
call   1050 <gmp_printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ca2d_rule_gol>:
push   %rbp
push   %rbx
push   %rax
call   1040 <mpz_init@plt>
mov    $0x1ff,%ebp
jmp    116e <ca2d_rule_gol+0x2e>
nop
mov    %ebp,%ebx
shr    $0x4,%ebx
and    $0x1,%ebx
mov    $0x2,%edx
call   1060 <mpz_mul_ui@plt>
mov    %ebx,%edx
call   1030 <mpz_add_ui@plt>
add    $0xffffffff,%ebp
jae    11cb <ca2d_rule_gol+0x8b>
mov    %ebp,%eax
and    $0x1,%eax
mov    %ebp,%ecx
shr    %ecx
and    $0x1,%ecx
add    %eax,%ecx
mov    %ebp,%eax
shr    $0x2,%eax
and    $0x1,%eax
add    %ecx,%eax
mov    %ebp,%ecx
shr    $0x3,%ecx
and    $0x1,%ecx
add    %eax,%ecx
mov    %ebp,%eax
shr    $0x5,%eax
and    $0x1,%eax
add    %ecx,%eax
mov    %ebp,%ecx
shr    $0x6,%ecx
and    $0x1,%ecx
add    %eax,%ecx
mov    %ebp,%edx
shr    $0x7,%edx
and    $0x1,%edx
add    %ecx,%edx
mov    %ebp,%eax
shr    $0x8,%eax
and    $0x1,%eax
add    %edx,%eax
cmp    $0x2,%eax
je     1150 <ca2d_rule_gol+0x10>
mov    $0x1,%ebx
cmp    $0x3,%eax
je     1158 <ca2d_rule_gol+0x18>
xor    %ebx,%ebx
jmp    1158 <ca2d_rule_gol+0x18>
lea    0xe2e(%rip),%rdi
call   1050 <gmp_printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [18 x i8] c"RULE GoL = 0x%ZX\0A\00"
define i32 @ca2d_rule_gol() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 512, i32* %1
%7 = load i32, i32* %4
%8 = call i32 @mpz_init(i32 %7)
%9 = load i32, i32* %1
%10 = sub i32 %9, 1
store i32 %10, i32* %5
br label %11
11: ; preds = %50, %0
%12 = load i32, i32* %5
%13 = icmp sge i32 %12, 0
br i1 %13, label %14, label %53
14: ; preds = %11
store i32 0, i32* %2
store i32 0, i32* %6
br label %15
15: ; preds = %26, %14
%16 = load i32, i32* %6
%17 = icmp ult i32 %16, 9
br i1 %17, label %18, label %29
18: ; preds = %15
%19 = load i32, i32* %5
%20 = and i32 %19, 495
%21 = load i32, i32* %6
%22 = ashr i32 %20, %21
%23 = and i32 %22, 1
%24 = load i32, i32* %2
%25 = add i32 %24, %23
store i32 %25, i32* %2
br label %26
26: ; preds = %18
%27 = load i32, i32* %6
%28 = add i32 %27, 1
store i32 %28, i32* %6
br label %15
29: ; preds = %15
%30 = load i32, i32* %2
%31 = icmp eq i32 %30, 3
br i1 %31, label %32, label %33
32: ; preds = %29
store i32 1, i32* %3
br label %42
33: ; preds = %29
%34 = load i32, i32* %2
%35 = icmp eq i32 %34, 2
br i1 %35, label %36, label %40
36: ; preds = %33
%37 = load i32, i32* %5
%38 = and i32 %37, 16
%39 = ashr i32 %38, 4
store i32 %39, i32* %3
br label %41
40: ; preds = %33
store i32 0, i32* %3
br label %41
41: ; preds = %40, %36
br label %42
42: ; preds = %41, %32
%43 = load i32, i32* %4
%44 = load i32, i32* %4
%45 = call i32 @mpz_mul_ui(i32 %43, i32 %44, i32 2)
%46 = load i32, i32* %4
%47 = load i32, i32* %4
%48 = load i32, i32* %3
%49 = call i32 @mpz_add_ui(i32 %46, i32 %47, i32 %48)
br label %50
50: ; preds = %42
%51 = load i32, i32* %5
%52 = add nsw i32 %51, -1
store i32 %52, i32* %5
br label %11
53: ; preds = %11
%54 = load i32, i32* %4
%55 = call i32 @gmp_printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %54)
ret i32 0
}

LLVM IR (-O2):
@.str = [18 x i8] c"RULE GoL = 0x%ZX\0A\00"
define i32 @ca2d_rule_gol() {
%1 = tail call i32 @mpz_init(i32 undef)
br label %2
2: ; preds = %0, %32
%3 = phi i32 [ 511, %0 ], [ %36, %32 ]
%4 = and i32 %3, 1
%5 = lshr i32 %3, 1
%6 = and i32 %5, 1
%7 = add nuw nsw i32 %6, %4
%8 = lshr i32 %3, 2
%9 = and i32 %8, 1
%10 = add nuw nsw i32 %9, %7
%11 = lshr i32 %3, 3
%12 = and i32 %11, 1
%13 = add nuw nsw i32 %12, %10
%14 = lshr i32 %3, 5
%15 = and i32 %14, 1
%16 = add nuw nsw i32 %15, %13
%17 = lshr i32 %3, 6
%18 = and i32 %17, 1
%19 = add nuw nsw i32 %18, %16
%20 = lshr i32 %3, 7
%21 = and i32 %20, 1
%22 = add nuw nsw i32 %21, %19
%23 = lshr i32 %3, 8
%24 = and i32 %23, 1
%25 = add nuw nsw i32 %24, %22
switch i32 %25, label %31 [
i32 3, label %32
i32 2, label %28
]
26: ; preds = %32
%27 = tail call i32 @gmp_printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 undef)
ret i32 0
28: ; preds = %2
%29 = lshr i32 %3, 4
%30 = and i32 %29, 1
br label %32
31: ; preds = %2
br label %32
32: ; preds = %2, %28, %31
%33 = phi i32 [ %30, %28 ], [ 0, %31 ], [ 1, %2 ]
%34 = tail call i32 @mpz_mul_ui(i32 undef, i32 undef, i32 2)
%35 = tail call i32 @mpz_add_ui(i32 undef, i32 undef, i32 %33)
%36 = add nsw i32 %3, -1
%37 = icmp eq i32 %3, 0
br i1 %37, label %26, label %2
}