#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 u_int64_t;

/* Variables and functions */
int fls64(int);
int polygcd(int, int);
int polymmult(int, int, int);
int polyirreducible(u_int64_t f) {
  u_int64_t u = 2;
  int i;
  int m = (fls64(f) - 1) >> 1;
  for (i = 0; i < m; i++) {
    u = polymmult(u, u, f);
    if (polygcd(f, u ^ 2) != 1)
      return 0;
  }
  return 1;
}


x86 assembly (clang, -O0):
<polyirreducible>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
movl   $0x2,-0xc(%rbp)
mov    -0x8(%rbp),%edi
call   1040 <fls64@plt>
sub    $0x1,%eax
sar    $0x1,%eax
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11ad <polyirreducible+0x7d>
mov    -0xc(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    -0x8(%rbp),%edx
call   1030 <polymmult@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
xor    $0x2,%esi
call   1050 <polygcd@plt>
cmp    $0x1,%eax
je     119a <polyirreducible+0x6a>
movl   $0x0,-0x4(%rbp)
jmp    11b4 <polyirreducible+0x84>
jmp    119f <polyirreducible+0x6f>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    115a <polyirreducible+0x2a>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<polyirreducible>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%r15d
call   1040 <fls64@plt>
mov    $0x1,%r14d
cmp    $0x3,%eax
jl     118a <polyirreducible+0x5a>
mov    %eax,%ebx
add    $0xffffffff,%ebx
shr    %ebx
mov    $0x2,%ebp
cs nopw 0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %ebp,%esi
mov    %r15d,%edx
call   1030 <polymmult@plt>
mov    %eax,%ebp
mov    %eax,%esi
xor    $0x2,%esi
mov    %r15d,%edi
call   1050 <polygcd@plt>
cmp    $0x1,%eax
jne    1187 <polyirreducible+0x57>
add    $0xffffffff,%ebx
jne    1160 <polyirreducible+0x30>
jmp    118a <polyirreducible+0x5a>
xor    %r14d,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @polyirreducible(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %3
store i32 2, i32* %4
%7 = load i32, i32* %3
%8 = call i32 @fls64(i32 %7)
%9 = sub nsw i32 %8, 1
%10 = ashr i32 %9, 1
store i32 %10, i32* %6
store i32 0, i32* %5
br label %11
11: ; preds = %27, %1
%12 = load i32, i32* %5
%13 = load i32, i32* %6
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %30
15: ; preds = %11
%16 = load i32, i32* %4
%17 = load i32, i32* %4
%18 = load i32, i32* %3
%19 = call i32 @polymmult(i32 %16, i32 %17, i32 %18)
store i32 %19, i32* %4
%20 = load i32, i32* %3
%21 = load i32, i32* %4
%22 = xor i32 %21, 2
%23 = call i32 @polygcd(i32 %20, i32 %22)
%24 = icmp ne i32 %23, 1
br i1 %24, label %25, label %26
25: ; preds = %15
store i32 0, i32* %2
br label %31
26: ; preds = %15
br label %27
27: ; preds = %26
%28 = load i32, i32* %5
%29 = add nsw i32 %28, 1
store i32 %29, i32* %5
br label %11
30: ; preds = %11
store i32 1, i32* %2
br label %31
31: ; preds = %30, %25
%32 = load i32, i32* %2
ret i32 %32
}

LLVM IR (-O2):
define i32 @polyirreducible(i32 %0) {
%2 = tail call i32 @fls64(i32 %0)
%3 = icmp sgt i32 %2, 2
br i1 %3, label %4, label %17
4: ; preds = %1
%5 = add nsw i32 %2, -1
%6 = lshr i32 %5, 1
br label %9
7: ; preds = %9
%8 = icmp eq i32 %16, %6
br i1 %8, label %17, label %9
9: ; preds = %4, %7
%10 = phi i32 [ %16, %7 ], [ 0, %4 ]
%11 = phi i32 [ %12, %7 ], [ 2, %4 ]
%12 = tail call i32 @polymmult(i32 %11, i32 %11, i32 %0)
%13 = xor i32 %12, 2
%14 = tail call i32 @polygcd(i32 %0, i32 %13)
%15 = icmp eq i32 %14, 1
%16 = add nuw nsw i32 %10, 1
br i1 %15, label %7, label %17
17: ; preds = %9, %7, %1
%18 = phi i32 [ 1, %1 ], [ 1, %7 ], [ 0, %9 ]
ret i32 %18
}