#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 */
scalar_t__ is_prime(int);
double pow(int, double);
scalar_t__ round(double);
int is_prime_power(int n) {
  if (is_prime(n))
    return 1;
  int root = 2, next;
  double val;
  while ((next = (int)round(val = pow(n, 1.0 / root))) >= 2) {
    root++;
    if ((next < val ? val - next : next - val) > 1E-8)
      continue;
    if (is_prime(next))
      return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<is_prime_power>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
call   1030 <is_prime@plt>
cmp    $0x0,%rax
je     1159 <is_prime_power+0x29>
movl   $0x1,-0x4(%rbp)
jmp    1219 <is_prime_power+0xe9>
movl   $0x2,-0xc(%rbp)
mov    -0x8(%rbp),%edi
cvtsi2sdl -0xc(%rbp),%xmm1
movsd  0xe90(%rip),%xmm0
divsd  %xmm1,%xmm0
call   1040 <pow@plt>
movsd  %xmm0,-0x18(%rbp)
call   1050 <round@plt>
mov    %eax,-0x10(%rbp)
cmp    $0x2,%eax
jl     1212 <is_prime_power+0xe2>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
cvtsi2sdl -0x10(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    11c4 <is_prime_power+0x94>
movsd  -0x18(%rbp),%xmm0
cvtsi2sdl -0x10(%rbp),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    11d3 <is_prime_power+0xa3>
cvtsi2sdl -0x10(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  0xe28(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11ef <is_prime_power+0xbf>
jmp    1160 <is_prime_power+0x30>
mov    -0x10(%rbp),%edi
call   1030 <is_prime@plt>
cmp    $0x0,%rax
je     120d <is_prime_power+0xdd>
movl   $0x1,-0x4(%rbp)
jmp    1219 <is_prime_power+0xe9>
jmp    1160 <is_prime_power+0x30>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_prime_power>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebp
call   1030 <is_prime@plt>
mov    $0x1,%r14d
test   %rax,%rax
jne    11f6 <is_prime_power+0xc6>
movsd  0xeaa(%rip),%xmm0
mov    %ebp,%edi
call   1040 <pow@plt>
movsd  %xmm0,0x8(%rsp)
call   1050 <round@plt>
cmp    $0x2,%eax
jl     11f3 <is_prime_power+0xc3>
mov    $0x3,%ebx
jmp    11ad <is_prime_power+0x7d>
nopl   0x0(%rax,%rax,1)
xorps  %xmm1,%xmm1
cvtsi2sd %ebx,%xmm1
movsd  0xe81(%rip),%xmm0
divsd  %xmm1,%xmm0
mov    %ebp,%edi
call   1040 <pow@plt>
movsd  %xmm0,0x8(%rsp)
call   1050 <round@plt>
add    $0x1,%ebx
cmp    $0x1,%eax
jle    11f3 <is_prime_power+0xc3>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  0x8(%rsp),%xmm3
movapd %xmm3,%xmm1
subsd  %xmm0,%xmm1
movapd %xmm0,%xmm2
subsd  %xmm3,%xmm2
cmpltsd %xmm3,%xmm0
andpd  %xmm0,%xmm1
andnpd %xmm2,%xmm0
orpd   %xmm1,%xmm0
ucomisd 0xe25(%rip),%xmm0
ja     1180 <is_prime_power+0x50>
mov    %eax,%edi
call   1030 <is_prime@plt>
test   %rax,%rax
je     1180 <is_prime_power+0x50>
jmp    11f6 <is_prime_power+0xc6>
xor    %r14d,%r14d
mov    %r14d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @is_prime_power(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca double
store i32 %0, i32* %3
%7 = load i32, i32* %3
%8 = call i64 @is_prime(i32 %7)
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %1
store i32 1, i32* %2
br label %49
11: ; preds = %1
store i32 2, i32* %4
br label %12
12: ; preds = %47, %41, %11
%13 = load i32, i32* %3
%14 = load i32, i32* %4
%15 = sitofp i32 %14 to double
%16 = fdiv double 1.000000e+00, %15
%17 = call double @pow(i32 %13, double %16)
store double %17, double* %6
%18 = call i64 @round(double %17)
%19 = trunc i64 %18 to i32
store i32 %19, i32* %5
%20 = icmp sge i32 %19, 2
br i1 %20, label %21, label %48
21: ; preds = %12
%22 = load i32, i32* %4
%23 = add nsw i32 %22, 1
store i32 %23, i32* %4
%24 = load i32, i32* %5
%25 = sitofp i32 %24 to double
%26 = load double, double* %6
%27 = fcmp olt double %25, %26
br i1 %27, label %28, label %33
28: ; preds = %21
%29 = load double, double* %6
%30 = load i32, i32* %5
%31 = sitofp i32 %30 to double
%32 = fsub double %29, %31
br label %38
33: ; preds = %21
%34 = load i32, i32* %5
%35 = sitofp i32 %34 to double
%36 = load double, double* %6
%37 = fsub double %35, %36
br label %38
38: ; preds = %33, %28
%39 = phi double [ %32, %28 ], [ %37, %33 ]
%40 = fcmp ogt double %39, 1.000000e-08
br i1 %40, label %41, label %42
41: ; preds = %38
br label %12
42: ; preds = %38
%43 = load i32, i32* %5
%44 = call i64 @is_prime(i32 %43)
%45 = icmp ne i64 %44, 0
br i1 %45, label %46, label %47
46: ; preds = %42
store i32 1, i32* %2
br label %49
47: ; preds = %42
br label %12
48: ; preds = %12
store i32 0, i32* %2
br label %49
49: ; preds = %48, %46, %10
%50 = load i32, i32* %2
ret i32 %50
}

LLVM IR (-O2):
define i32 @is_prime_power(i32 %0) {
%2 = tail call i64 @is_prime(i32 %0)
%3 = icmp eq i64 %2, 0
br i1 %3, label %4, label %30
4: ; preds = %1
%5 = tail call double @pow(i32 %0, double 5.000000e-01)
%6 = tail call i64 @round(double %5)
%7 = trunc i64 %6 to i32
%8 = icmp sgt i32 %7, 1
br i1 %8, label %9, label %30
9: ; preds = %4, %20
%10 = phi i32 [ %25, %20 ], [ %7, %4 ]
%11 = phi double [ %23, %20 ], [ %5, %4 ]
%12 = phi i32 [ %13, %20 ], [ 2, %4 ]
%13 = add nuw nsw i32 %12, 1
%14 = sitofp i32 %10 to double
%15 = fcmp ogt double %11, %14
%16 = fsub double %11, %14
%17 = fsub double %14, %11
%18 = select i1 %15, double %16, double %17
%19 = fcmp ogt double %18, 1.000000e-08
br i1 %19, label %20, label %27
20: ; preds = %9, %27
%21 = sitofp i32 %13 to double
%22 = fdiv double 1.000000e+00, %21
%23 = tail call double @pow(i32 %0, double %22)
%24 = tail call i64 @round(double %23)
%25 = trunc i64 %24 to i32
%26 = icmp sgt i32 %25, 1
br i1 %26, label %9, label %30
27: ; preds = %9
%28 = tail call i64 @is_prime(i32 %10)
%29 = icmp eq i64 %28, 0
br i1 %29, label %20, label %30
30: ; preds = %20, %27, %4, %1
%31 = phi i32 [ 1, %1 ], [ 0, %4 ], [ 0, %20 ], [ 1, %27 ]
ret i32 %31
}