#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 scalar_t__ uint32_t;

/* Variables and functions */
scalar_t__ circulate(scalar_t__);
int /*<<< orphan*/ is_prime(scalar_t__);
int /*<<< orphan*/ possibly_circular(scalar_t__);
int circular_prime(uint32_t i) {
  if (!possibly_circular(i) || !is_prime(i))
    return 0;
  uint32_t rotated = circulate(i);
  for (; i != rotated; rotated = circulate(rotated)) {
    if (!is_prime(rotated))
      break;
  }
  return (i == rotated);
}


x86 assembly (clang, -O0):
<circular_prime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <possibly_circular@plt>
cmp    $0x0,%eax
je     1160 <circular_prime+0x30>
mov    -0x10(%rbp),%rdi
call   1040 <is_prime@plt>
cmp    $0x0,%eax
jne    116c <circular_prime+0x3c>
movl   $0x0,-0x4(%rbp)
jmp    11c8 <circular_prime+0x98>
mov    -0x10(%rbp),%rdi
call   1030 <circulate@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
cmp    -0x18(%rbp),%rax
je     11b5 <circular_prime+0x85>
mov    -0x18(%rbp),%rdi
call   1040 <is_prime@plt>
cmp    $0x0,%eax
jne    119e <circular_prime+0x6e>
jmp    11b5 <circular_prime+0x85>
jmp    11a3 <circular_prime+0x73>
mov    -0x18(%rbp),%rdi
call   1030 <circulate@plt>
mov    %rax,-0x18(%rbp)
jmp    1179 <circular_prime+0x49>
mov    -0x10(%rbp),%rax
cmp    -0x18(%rbp),%rax
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<circular_prime>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r15
call   1050 <possibly_circular@plt>
xor    %r14d,%r14d
test   %eax,%eax
je     1197 <circular_prime+0x67>
mov    %r15,%rdi
call   1040 <is_prime@plt>
test   %eax,%eax
je     1197 <circular_prime+0x67>
mov    %r15,%rdi
call   1030 <circulate@plt>
mov    $0x1,%r14d
cmp    %r15,%rax
je     1197 <circular_prime+0x67>
mov    %rax,%rbp
nopl   0x0(%rax,%rax,1)
mov    %rbp,%rdi
call   1040 <is_prime@plt>
mov    %eax,%ebx
test   %eax,%eax
je     118e <circular_prime+0x5e>
mov    %rbp,%rdi
call   1030 <circulate@plt>
mov    %rax,%rbp
cmp    %r15,%rax
jne    1170 <circular_prime+0x40>
xor    %r14d,%r14d
test   %ebx,%ebx
setne  %r14b
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @circular_prime(i64 %0) {
%2 = alloca i32
%3 = alloca i64
%4 = alloca i64
store i64 %0, i64* %3
%5 = load i64, i64* %3
%6 = call i32 @possibly_circular(i64 %5)
%7 = icmp ne i32 %6, 0
br i1 %7, label %8, label %12
8: ; preds = %1
%9 = load i64, i64* %3
%10 = call i32 @is_prime(i64 %9)
%11 = icmp ne i32 %10, 0
br i1 %11, label %13, label %12
12: ; preds = %8, %1
store i32 0, i32* %2
br label %34
13: ; preds = %8
%14 = load i64, i64* %3
%15 = call i64 @circulate(i64 %14)
store i64 %15, i64* %4
br label %16
16: ; preds = %26, %13
%17 = load i64, i64* %3
%18 = load i64, i64* %4
%19 = icmp ne i64 %17, %18
br i1 %19, label %20, label %29
20: ; preds = %16
%21 = load i64, i64* %4
%22 = call i32 @is_prime(i64 %21)
%23 = icmp ne i32 %22, 0
br i1 %23, label %25, label %24
24: ; preds = %20
br label %29
25: ; preds = %20
br label %26
26: ; preds = %25
%27 = load i64, i64* %4
%28 = call i64 @circulate(i64 %27)
store i64 %28, i64* %4
br label %16
29: ; preds = %24, %16
%30 = load i64, i64* %3
%31 = load i64, i64* %4
%32 = icmp eq i64 %30, %31
%33 = zext i1 %32 to i32
store i32 %33, i32* %2
br label %34
34: ; preds = %29, %12
%35 = load i32, i32* %2
ret i32 %35
}

LLVM IR (-O2):
define i32 @circular_prime(i64 %0) {
%2 = tail call i32 @possibly_circular(i64 %0)
%3 = icmp eq i32 %2, 0
br i1 %3, label %20, label %4
4: ; preds = %1
%5 = tail call i32 @is_prime(i64 %0)
%6 = icmp eq i32 %5, 0
br i1 %6, label %20, label %7
7: ; preds = %4
%8 = tail call i64 @circulate(i64 %0)
%9 = icmp eq i64 %8, %0
br i1 %9, label %20, label %10
10: ; preds = %7, %14
%11 = phi i64 [ %15, %14 ], [ %8, %7 ]
%12 = tail call i32 @is_prime(i64 %11)
%13 = icmp eq i32 %12, 0
br i1 %13, label %17, label %14
14: ; preds = %10
%15 = tail call i64 @circulate(i64 %11)
%16 = icmp eq i64 %15, %0
br i1 %16, label %17, label %10
17: ; preds = %10, %14
%18 = xor i1 %13, true
%19 = zext i1 %18 to i32
br label %20
20: ; preds = %7, %17, %1, %4
%21 = phi i32 [ 0, %4 ], [ 0, %1 ], [ 1, %7 ], [ %19, %17 ]
ret i32 %21
}