#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 */
unsigned int find_digits(unsigned int);
int is_prime(unsigned int);
unsigned int pow(int, unsigned int);
bool is_circular_prime(unsigned num) {
  unsigned len = find_digits(num);
  unsigned tmp = num;
  unsigned res = 0;
  unsigned r = 0;
  unsigned f = 0;
  for (unsigned i = 0; i < len; i++) {
    r = tmp / 10;
    f = tmp % 10;
    res = f * pow(10, len - 1) + r;
    if (is_prime(res) != true)
      return false;
    tmp = res;
  }
  return true;
}


x86 assembly (clang, -O0):
<is_circular_prime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
call   1040 <find_digits@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0xc(%rbp),%eax
jae    11e7 <is_circular_prime+0xb7>
mov    -0x10(%rbp),%eax
mov    $0xa,%ecx
xor    %edx,%edx
div    %ecx
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%eax
mov    $0xa,%ecx
xor    %edx,%edx
div    %ecx
mov    %edx,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0xc(%rbp),%esi
sub    $0x1,%esi
mov    $0xa,%edi
call   1050 <pow@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
imul   %ecx,%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1030 <is_prime@plt>
cmp    $0x1,%eax
je     11d3 <is_circular_prime+0xa3>
movl   $0x0,-0x4(%rbp)
jmp    11ee <is_circular_prime+0xbe>
mov    -0x14(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1168 <is_circular_prime+0x38>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_circular_prime>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edi,%r13d
call   1040 <find_digits@plt>
test   %eax,%eax
je     11f2 <is_circular_prime+0xc2>
mov    %eax,%r15d
lea    -0x1(%r15),%r14d
mov    %r13d,%ebx
mov    $0xcccccccd,%eax
imul   %rax,%rbx
shr    $0x23,%rbx
lea    (%rbx,%rbx,1),%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%r13d
mov    $0xa,%edi
mov    %r14d,%esi
call   1050 <pow@plt>
mov    %eax,%ebp
imul   %r13d,%ebp
add    %ebx,%ebp
mov    %ebp,%edi
call   1030 <is_prime@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x1,%ecx
jne    11f7 <is_circular_prime+0xc7>
mov    $0x1,%ecx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %ecx,%r13d
cmp    %ecx,%r15d
je     11e8 <is_circular_prime+0xb8>
mov    %ebp,%r12d
mov    $0xcccccccd,%eax
imul   %rax,%r12
shr    $0x23,%r12
lea    (%r12,%r12,1),%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%ebp
mov    $0xa,%edi
mov    %r14d,%esi
call   1050 <pow@plt>
mov    %eax,%ebx
imul   %ebp,%ebx
add    %r12d,%ebx
mov    %ebx,%edi
call   1030 <is_prime@plt>
lea    0x1(%r13),%ecx
mov    %ebx,%ebp
cmp    $0x1,%eax
je     11a0 <is_circular_prime+0x70>
xor    %eax,%eax
cmp    %r15d,%r13d
setae  %al
jmp    11f7 <is_circular_prime+0xc7>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @is_circular_prime(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %3
%10 = load i32, i32* %3
%11 = call i32 @find_digits(i32 %10)
store i32 %11, i32* %4
%12 = load i32, i32* %3
store i32 %12, i32* %5
store i32 0, i32* %6
store i32 0, i32* %7
store i32 0, i32* %8
store i32 0, i32* %9
br label %13
13: ; preds = %35, %1
%14 = load i32, i32* %9
%15 = load i32, i32* %4
%16 = icmp ult i32 %14, %15
br i1 %16, label %17, label %38
17: ; preds = %13
%18 = load i32, i32* %5
%19 = udiv i32 %18, 10
store i32 %19, i32* %7
%20 = load i32, i32* %5
%21 = urem i32 %20, 10
store i32 %21, i32* %8
%22 = load i32, i32* %8
%23 = load i32, i32* %4
%24 = sub i32 %23, 1
%25 = call i32 @pow(i32 10, i32 %24)
%26 = mul i32 %22, %25
%27 = load i32, i32* %7
%28 = add i32 %26, %27
store i32 %28, i32* %6
%29 = load i32, i32* %6
%30 = call i32 @is_prime(i32 %29)
%31 = icmp ne i32 %30, 1
br i1 %31, label %32, label %33
32: ; preds = %17
store i32 0, i32* %2
br label %39
33: ; preds = %17
%34 = load i32, i32* %6
store i32 %34, i32* %5
br label %35
35: ; preds = %33
%36 = load i32, i32* %9
%37 = add i32 %36, 1
store i32 %37, i32* %9
br label %13
38: ; preds = %13
store i32 1, i32* %2
br label %39
39: ; preds = %38, %32
%40 = load i32, i32* %2
ret i32 %40
}

LLVM IR (-O2):
define i32 @is_circular_prime(i32 %0) {
%2 = tail call i32 @find_digits(i32 %0)
%3 = icmp eq i32 %2, 0
br i1 %3, label %29, label %4
4: ; preds = %1
%5 = add i32 %2, -1
%6 = udiv i32 %0, 10
%7 = urem i32 %0, 10
%8 = tail call i32 @pow(i32 10, i32 %5)
%9 = mul i32 %8, %7
%10 = add i32 %9, %6
%11 = tail call i32 @is_prime(i32 %10)
%12 = icmp eq i32 %11, 1
br i1 %12, label %13, label %29
13: ; preds = %4, %17
%14 = phi i32 [ %25, %17 ], [ 1, %4 ]
%15 = phi i32 [ %22, %17 ], [ %10, %4 ]
%16 = icmp eq i32 %14, %2
br i1 %16, label %26, label %17
17: ; preds = %13
%18 = udiv i32 %15, 10
%19 = urem i32 %15, 10
%20 = tail call i32 @pow(i32 10, i32 %5)
%21 = mul i32 %20, %19
%22 = add i32 %21, %18
%23 = tail call i32 @is_prime(i32 %22)
%24 = icmp eq i32 %23, 1
%25 = add nuw i32 %14, 1
br i1 %24, label %13, label %26
26: ; preds = %13, %17
%27 = icmp uge i32 %14, %2
%28 = zext i1 %27 to i32
br label %29
29: ; preds = %26, %4, %1
%30 = phi i32 [ 1, %1 ], [ 0, %4 ], [ %28, %26 ]
ret i32 %30
}