#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*/ printf(char *, ...);
int exact_square(int num) {
  int count, temp;
  for (count = 1; count <= num / 2; count++) {
    temp = num / count;
    if (temp == count) {
      printf("%d\n", temp);
      printf("%d = %d ^ 2\n", num, temp);
      return 0;
    }
  }
  printf("0\n");
  printf("%d is not a power of any number.\n", num);
  return 0;
}


x86 assembly (clang, -O0):
<exact_square>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
movl   $0x1,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
cmp    %ecx,%eax
jg     119a <exact_square+0x8a>
mov    -0x8(%rbp),%eax
cltd
idivl  -0xc(%rbp)
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jne    1187 <exact_square+0x77>
mov    -0x10(%rbp),%esi
lea    0xea0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%esi
mov    -0x10(%rbp),%edx
lea    0xe90(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11c0 <exact_square+0xb0>
jmp    118c <exact_square+0x7c>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1122 <exact_square+0x12>
lea    0xe70(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%esi
lea    0xe62(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<exact_square>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
cmp    $0x2,%edi
jl     115b <exact_square+0x3b>
mov    %ebp,%ecx
shr    %ecx
neg    %ecx
mov    $0x1,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %ebp,%eax
cltd
idiv   %ebx
cmp    %eax,%ebx
je     1179 <exact_square+0x59>
lea    (%rcx,%rbx,1),%eax
add    $0x1,%eax
mov    %ebx,%edx
add    $0x1,%edx
mov    %edx,%ebx
cmp    $0x1,%eax
jne    1140 <exact_square+0x20>
lea    0xed1(%rip),%rdi
call   1030 <puts@plt>
lea    0xea3(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    119b <exact_square+0x7b>
lea    0xe80(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe74(%rip),%rdi
mov    %ebp,%esi
mov    %ebx,%edx
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%d\0A\00"
@.str.1 = [13 x i8] c"%d = %d ^ 2\0A\00"
@.str.2 = [3 x i8] c"0\0A\00"
@.str.3 = [34 x i8] c"%d is not a power of any number.\0A\00"
define i32 @exact_square(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %3
store i32 1, i32* %4
br label %6
6: ; preds = %25, %1
%7 = load i32, i32* %4
%8 = load i32, i32* %3
%9 = sdiv i32 %8, 2
%10 = icmp sle i32 %7, %9
br i1 %10, label %11, label %28
11: ; preds = %6
%12 = load i32, i32* %3
%13 = load i32, i32* %4
%14 = sdiv i32 %12, %13
store i32 %14, i32* %5
%15 = load i32, i32* %5
%16 = load i32, i32* %4
%17 = icmp eq i32 %15, %16
br i1 %17, label %18, label %24
18: ; preds = %11
%19 = load i32, i32* %5
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %19)
%21 = load i32, i32* %3
%22 = load i32, i32* %5
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %21, i32 %22)
store i32 0, i32* %2
br label %32
24: ; preds = %11
br label %25
25: ; preds = %24
%26 = load i32, i32* %4
%27 = add nsw i32 %26, 1
store i32 %27, i32* %4
br label %6
28: ; preds = %6
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%30 = load i32, i32* %3
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0), i32 %30)
store i32 0, i32* %2
br label %32
32: ; preds = %28, %18
%33 = load i32, i32* %2
ret i32 %33
}

LLVM IR (-O2):
@.str = [4 x i8] c"%d\0A\00"
@.str.1 = [13 x i8] c"%d = %d ^ 2\0A\00"
@.str.3 = [34 x i8] c"%d is not a power of any number.\0A\00"
@str = [2 x i8] c"0\00"
define i32 @exact_square(i32 %0) {
%2 = icmp slt i32 %0, 2
br i1 %2, label %15, label %3
3: ; preds = %1
%4 = lshr i32 %0, 1
br label %8
5: ; preds = %8
%6 = add nuw nsw i32 %9, 1
%7 = icmp eq i32 %9, %4
br i1 %7, label %15, label %8
8: ; preds = %3, %5
%9 = phi i32 [ %6, %5 ], [ 1, %3 ]
%10 = sdiv i32 %0, %9
%11 = icmp eq i32 %10, %9
br i1 %11, label %12, label %5
12: ; preds = %8
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %9)
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %0, i32 %9)
br label %18
15: ; preds = %5, %1
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0))
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0), i32 %0)
br label %18
18: ; preds = %15, %12
ret i32 0
}