#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 is_prime(unsigned int);
unsigned int num_digits(unsigned int);
unsigned int pow(int, unsigned int);
int /*<<< orphan*/ printf(char *, unsigned int);
bool is_truncatable(unsigned num) {
  unsigned tmp = num;
  unsigned rnum = 0;
  unsigned l = num_digits(num);
  if (is_prime(num) == false)
    return false;
  for (unsigned i = 1; i < l; i++) {
    if (is_prime(num / pow(10, i)) == false)
      return false;
  }
  for (unsigned i = l - 1; i >= 1; i--) {
    rnum = tmp % (unsigned)pow(10, i);
    if (is_prime(rnum) == false)
      return false;
    tmp = rnum;
  }
  printf("Prime number: %u\n", num);
  return true;
}


x86 assembly (clang, -O0):
<is_truncatable>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%edi
call   1060 <num_digits@plt>
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%edi
call   1040 <is_prime@plt>
cmp    $0x0,%eax
jne    1180 <is_truncatable+0x40>
movl   $0x0,-0x4(%rbp)
jmp    1257 <is_truncatable+0x117>
movl   $0x1,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jae    11de <is_truncatable+0x9e>
mov    -0x8(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%esi
mov    $0xa,%edi
call   1050 <pow@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
xor    %edx,%edx
div    %ecx
mov    %eax,%edi
call   1040 <is_prime@plt>
cmp    $0x0,%eax
jne    11cb <is_truncatable+0x8b>
movl   $0x0,-0x4(%rbp)
jmp    1257 <is_truncatable+0x117>
jmp    11d0 <is_truncatable+0x90>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1187 <is_truncatable+0x47>
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x1,-0x1c(%rbp)
jb     1241 <is_truncatable+0x101>
mov    -0xc(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x1c(%rbp),%esi
mov    $0xa,%edi
call   1050 <pow@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
xor    %edx,%edx
div    %ecx
mov    %edx,-0x10(%rbp)
mov    -0x10(%rbp),%edi
call   1040 <is_prime@plt>
cmp    $0x0,%eax
jne    122d <is_truncatable+0xed>
movl   $0x0,-0x4(%rbp)
jmp    1257 <is_truncatable+0x117>
mov    -0x10(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
jmp    11e7 <is_truncatable+0xa7>
mov    -0x8(%rbp),%esi
lea    0xdb5(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_truncatable>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edi,%r14d
call   1060 <num_digits@plt>
mov    %eax,%r15d
mov    %r14d,%edi
call   1040 <is_prime@plt>
test   %eax,%eax
je     11dc <is_truncatable+0x9c>
cmp    $0x2,%r15d
jb     1198 <is_truncatable+0x58>
mov    $0x1,%ebp
xor    %r12d,%r12d
nopl   (%rax)
mov    $0xa,%edi
mov    %ebp,%esi
call   1050 <pow@plt>
mov    %eax,%ecx
mov    %r14d,%eax
xor    %edx,%edx
div    %ecx
mov    %eax,%edi
call   1040 <is_prime@plt>
test   %eax,%eax
je     11f6 <is_truncatable+0xb6>
add    $0x1,%ebp
cmp    %ebp,%r15d
jne    1170 <is_truncatable+0x30>
add    $0xffffffff,%r15d
mov    %r14d,%ebp
mov    %r15d,%ebx
xor    %r12d,%r12d
cs nopw 0x0(%rax,%rax,1)
nop
sub    $0x1,%ebx
jb     11e1 <is_truncatable+0xa1>
mov    $0xa,%edi
mov    %r15d,%esi
call   1050 <pow@plt>
mov    %eax,%ecx
mov    %ebp,%eax
xor    %edx,%edx
div    %ecx
mov    %edx,%ebp
mov    %edx,%edi
call   1040 <is_prime@plt>
mov    %ebx,%r15d
test   %eax,%eax
jne    11b0 <is_truncatable+0x70>
jmp    11f6 <is_truncatable+0xb6>
xor    %r12d,%r12d
jmp    11f6 <is_truncatable+0xb6>
lea    0xe18(%rip),%rdi
mov    %r14d,%esi
call   1030 <printf@plt>
mov    $0x1,%r12d
mov    %r12d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [18 x i8] c"Prime number: %u\0A\00"
define i32 @is_truncatable(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %3
%9 = load i32, i32* %3
store i32 %9, i32* %4
store i32 0, i32* %5
%10 = load i32, i32* %3
%11 = call i32 @num_digits(i32 %10)
store i32 %11, i32* %6
%12 = load i32, i32* %3
%13 = call i32 @is_prime(i32 %12)
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %1
store i32 0, i32* %2
br label %56
16: ; preds = %1
store i32 1, i32* %7
br label %17
17: ; preds = %30, %16
%18 = load i32, i32* %7
%19 = load i32, i32* %6
%20 = icmp ult i32 %18, %19
br i1 %20, label %21, label %33
21: ; preds = %17
%22 = load i32, i32* %3
%23 = load i32, i32* %7
%24 = call i32 @pow(i32 10, i32 %23)
%25 = udiv i32 %22, %24
%26 = call i32 @is_prime(i32 %25)
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %21
store i32 0, i32* %2
br label %56
29: ; preds = %21
br label %30
30: ; preds = %29
%31 = load i32, i32* %7
%32 = add i32 %31, 1
store i32 %32, i32* %7
br label %17
33: ; preds = %17
%34 = load i32, i32* %6
%35 = sub i32 %34, 1
store i32 %35, i32* %8
br label %36
36: ; preds = %50, %33
%37 = load i32, i32* %8
%38 = icmp uge i32 %37, 1
br i1 %38, label %39, label %53
39: ; preds = %36
%40 = load i32, i32* %4
%41 = load i32, i32* %8
%42 = call i32 @pow(i32 10, i32 %41)
%43 = urem i32 %40, %42
store i32 %43, i32* %5
%44 = load i32, i32* %5
%45 = call i32 @is_prime(i32 %44)
%46 = icmp eq i32 %45, 0
br i1 %46, label %47, label %48
47: ; preds = %39
store i32 0, i32* %2
br label %56
48: ; preds = %39
%49 = load i32, i32* %5
store i32 %49, i32* %4
br label %50
50: ; preds = %48
%51 = load i32, i32* %8
%52 = add i32 %51, -1
store i32 %52, i32* %8
br label %36
53: ; preds = %36
%54 = load i32, i32* %3
%55 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %54)
store i32 1, i32* %2
br label %56
56: ; preds = %53, %47, %28, %15
%57 = load i32, i32* %2
ret i32 %57
}

LLVM IR (-O2):
@.str = [18 x i8] c"Prime number: %u\0A\00"
define i32 @is_truncatable(i32 %0) {
%2 = tail call i32 @num_digits(i32 %0)
%3 = tail call i32 @is_prime(i32 %0)
%4 = icmp eq i32 %3, 0
br i1 %4, label %29, label %5
5: ; preds = %1
%6 = icmp ugt i32 %2, 1
br i1 %6, label %10, label %7
7: ; preds = %8, %5
br label %17
8: ; preds = %10
%9 = icmp eq i32 %16, %2
br i1 %9, label %7, label %10
10: ; preds = %5, %8
%11 = phi i32 [ %16, %8 ], [ 1, %5 ]
%12 = tail call i32 @pow(i32 10, i32 %11)
%13 = udiv i32 %0, %12
%14 = tail call i32 @is_prime(i32 %13)
%15 = icmp eq i32 %14, 0
%16 = add nuw i32 %11, 1
br i1 %15, label %29, label %8
17: ; preds = %7, %22
%18 = phi i32 [ %24, %22 ], [ %0, %7 ]
%19 = phi i32 [ %20, %22 ], [ %2, %7 ]
%20 = add i32 %19, -1
%21 = icmp eq i32 %20, 0
br i1 %21, label %27, label %22
22: ; preds = %17
%23 = tail call i32 @pow(i32 10, i32 %20)
%24 = urem i32 %18, %23
%25 = tail call i32 @is_prime(i32 %24)
%26 = icmp eq i32 %25, 0
br i1 %26, label %29, label %17
27: ; preds = %17
%28 = tail call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %0)
br label %29
29: ; preds = %10, %22, %1, %27
%30 = phi i32 [ 1, %27 ], [ 0, %1 ], [ 0, %22 ], [ 0, %10 ]
ret i32 %30
}