#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 /*<<< orphan*/ is_prime(int);
int /*<<< orphan*/ rotate(char *, int);
int sprintf(char *, char *, int);
int /*<<< orphan*/ sscanf(char *, char *, int *);
bool is_circular_prime(int prime) {
  if (!is_prime(prime))
    return false;
  if (prime < 10)
    return true;
  char digits[64];
  int len = sprintf(digits, "%i", prime);
  rotate(digits, len);
  for (int i = 1; i < len; i++) {
    int n;
    sscanf(digits, "%i", &n);
    if (!is_prime(n)) {
      return false;
    }
    rotate(digits, len);
  }
  return true;
}


x86 assembly (clang, -O0):
<is_circular_prime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
call   1030 <is_prime@plt>
cmp    $0x0,%eax
jne    1168 <is_circular_prime+0x28>
movl   $0x0,-0x4(%rbp)
jmp    1205 <is_circular_prime+0xc5>
cmpl   $0xa,-0x8(%rbp)
jge    117e <is_circular_prime+0x3e>
movl   $0x1,-0x4(%rbp)
jmp    1205 <is_circular_prime+0xc5>
lea    -0x50(%rbp),%rdi
mov    -0x8(%rbp),%edx
lea    0xe74(%rip),%rsi
call   1060 <sprintf@plt>
mov    %eax,-0x54(%rbp)
lea    -0x50(%rbp),%rdi
mov    -0x54(%rbp),%esi
call   1040 <rotate@plt>
movl   $0x1,-0x58(%rbp)
mov    -0x58(%rbp),%eax
cmp    -0x54(%rbp),%eax
jge    11fe <is_circular_prime+0xbe>
lea    -0x50(%rbp),%rdi
lea    0xe42(%rip),%rsi
lea    -0x5c(%rbp),%rdx
call   1050 <sscanf@plt>
mov    -0x5c(%rbp),%edi
call   1030 <is_prime@plt>
cmp    $0x0,%eax
jne    11e4 <is_circular_prime+0xa4>
movl   $0x0,-0x4(%rbp)
jmp    1205 <is_circular_prime+0xc5>
lea    -0x50(%rbp),%rdi
mov    -0x54(%rbp),%esi
call   1040 <rotate@plt>
mov    -0x58(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x58(%rbp)
jmp    11a7 <is_circular_prime+0x67>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_circular_prime>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x50,%rsp
mov    %edi,%ebx
call   1030 <is_prime@plt>
test   %eax,%eax
je     1206 <is_circular_prime+0xc6>
mov    $0x1,%eax
cmp    $0xa,%ebx
jl     121a <is_circular_prime+0xda>
lea    0xe90(%rip),%rsi
lea    0x10(%rsp),%r14
mov    %r14,%rdi
mov    %ebx,%edx
call   1060 <sprintf@plt>
mov    %eax,%ebx
mov    %r14,%rdi
mov    %eax,%esi
call   1040 <rotate@plt>
cmp    $0x2,%ebx
jl     120a <is_circular_prime+0xca>
lea    0xe65(%rip),%rsi
lea    0x10(%rsp),%rdi
lea    0xc(%rsp),%rdx
call   1050 <sscanf@plt>
mov    0xc(%rsp),%edi
call   1030 <is_prime@plt>
test   %eax,%eax
je     120e <is_circular_prime+0xce>
mov    $0x2,%ebp
lea    0x10(%rsp),%r14
lea    0xe38(%rip),%r15
lea    0xc(%rsp),%r12
nopl   (%rax)
mov    %r14,%rdi
mov    %ebx,%esi
call   1040 <rotate@plt>
cmp    %ebp,%ebx
je     1212 <is_circular_prime+0xd2>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1050 <sscanf@plt>
mov    0xc(%rsp),%edi
call   1030 <is_prime@plt>
add    $0x1,%ebp
test   %eax,%eax
jne    11d0 <is_circular_prime+0x90>
add    $0xffffffff,%ebp
cmp    %ebx,%ebp
setl   %al
jmp    1215 <is_circular_prime+0xd5>
xor    %eax,%eax
jmp    121a <is_circular_prime+0xda>
xor    %eax,%eax
jmp    1215 <is_circular_prime+0xd5>
mov    $0x1,%al
jmp    1215 <is_circular_prime+0xd5>
setg   %al
xor    $0x1,%al
movzbl %al,%eax
add    $0x50,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%i\00"
define i32 @is_circular_prime(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [64 x i8]
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %3
%8 = load i32, i32* %3
%9 = call i32 @is_prime(i32 %8)
%10 = icmp ne i32 %9, 0
br i1 %10, label %12, label %11
11: ; preds = %1
store i32 0, i32* %2
br label %42
12: ; preds = %1
%13 = load i32, i32* %3
%14 = icmp slt i32 %13, 10
br i1 %14, label %15, label %16
15: ; preds = %12
store i32 1, i32* %2
br label %42
16: ; preds = %12
%17 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%18 = load i32, i32* %3
%19 = call i32 @sprintf(i8* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %18)
store i32 %19, i32* %5
%20 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%21 = load i32, i32* %5
%22 = call i32 @rotate(i8* %20, i32 %21)
store i32 1, i32* %6
br label %23
23: ; preds = %38, %16
%24 = load i32, i32* %6
%25 = load i32, i32* %5
%26 = icmp slt i32 %24, %25
br i1 %26, label %27, label %41
27: ; preds = %23
%28 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%29 = call i32 @sscanf(i8* %28, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %7)
%30 = load i32, i32* %7
%31 = call i32 @is_prime(i32 %30)
%32 = icmp ne i32 %31, 0
br i1 %32, label %34, label %33
33: ; preds = %27
store i32 0, i32* %2
br label %42
34: ; preds = %27
%35 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%36 = load i32, i32* %5
%37 = call i32 @rotate(i8* %35, i32 %36)
br label %38
38: ; preds = %34
%39 = load i32, i32* %6
%40 = add nsw i32 %39, 1
store i32 %40, i32* %6
br label %23
41: ; preds = %23
store i32 1, i32* %2
br label %42
42: ; preds = %41, %33, %15, %11
%43 = load i32, i32* %2
ret i32 %43
}

LLVM IR (-O2):
@.str = [3 x i8] c"%i\00"
define i32 @is_circular_prime(i32 %0) {
%2 = alloca [64 x i8]
%3 = alloca i32
%4 = tail call i32 @is_prime(i32 %0)
%5 = icmp eq i32 %4, 0
br i1 %5, label %39, label %6
6: ; preds = %1
%7 = icmp slt i32 %0, 10
br i1 %7, label %39, label %8
8: ; preds = %6
%9 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%10 = call i32 @sprintf(i8* %9, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %0)
%11 = call i32 @rotate(i8* %9, i32 %10)
%12 = icmp sgt i32 %10, 1
br i1 %12, label %13, label %35
13: ; preds = %8
%14 = bitcast i32* %3 to i8*
%15 = call i32 @sscanf(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%16 = load i32, i32* %3
%17 = call i32 @is_prime(i32 %16)
%18 = icmp eq i32 %17, 0
br i1 %18, label %31, label %24
19: ; preds = %24
%20 = call i32 @sscanf(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%21 = load i32, i32* %3
%22 = call i32 @is_prime(i32 %21)
%23 = icmp eq i32 %22, 0
br i1 %23, label %29, label %24
24: ; preds = %13, %19
%25 = phi i32 [ %27, %19 ], [ 1, %13 ]
%26 = call i32 @rotate(i8* %9, i32 %10)
%27 = add nuw nsw i32 %25, 1
%28 = icmp eq i32 %27, %10
br i1 %28, label %33, label %19
29: ; preds = %19
%30 = icmp slt i32 %27, %10
br label %31
31: ; preds = %29, %13
%32 = phi i1 [ true, %13 ], [ %30, %29 ]
br label %35
33: ; preds = %24
%34 = icmp slt i32 %27, %10
br label %35
35: ; preds = %33, %8, %31
%36 = phi i1 [ %32, %31 ], [ false, %8 ], [ %34, %33 ]
%37 = xor i1 %36, true
%38 = zext i1 %37 to i32
br label %39
39: ; preds = %6, %1, %35
%40 = phi i32 [ %38, %35 ], [ 0, %1 ], [ 1, %6 ]
ret i32 %40
}