#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 n) {
  int i, square = 0;
  for (i = 0; i < n / 2; i++) {
    if (n == i * i) {
      square = i;
      break;
    }
  }
  if (square == 0) {
    printf("0");
    printf("\nThis number does not have an exact square");
  }
  if (square != 0) {
    printf("1");
    printf("\n %d=%d^2", n, square);
  }
}


x86 assembly (clang, -O0):
<exact_square>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-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
jge    1177 <exact_square+0x67>
mov    -0x8(%rbp),%eax
mov    -0xc(%rbp),%ecx
imul   -0xc(%rbp),%ecx
cmp    %ecx,%eax
jne    1164 <exact_square+0x54>
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
jmp    1177 <exact_square+0x67>
jmp    1169 <exact_square+0x59>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1129 <exact_square+0x19>
cmpl   $0x0,-0x10(%rbp)
jne    119d <exact_square+0x8d>
lea    0xe78(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe6c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x0,-0x10(%rbp)
je     11c9 <exact_square+0xb9>
lea    0xe7f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%esi
mov    -0x10(%rbp),%edx
lea    0xe6d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<exact_square>:
push   %rbp
push   %rbx
push   %rax
cmp    $0x2,%edi
jl     1174 <exact_square+0x54>
mov    %edi,%ebx
mov    %edi,%eax
shr    $0x1f,%eax
add    %edi,%eax
sar    %eax
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
mov    %ebp,%ecx
imul   %ebp,%ecx
cmp    %ebx,%ecx
je     1152 <exact_square+0x32>
add    $0x1,%ebp
cmp    %ebp,%eax
jne    1140 <exact_square+0x20>
jmp    1174 <exact_square+0x54>
test   %ebp,%ebp
je     1174 <exact_square+0x54>
mov    $0x31,%edi
call   1030 <putchar@plt>
lea    0xec4(%rip),%rdi
mov    %ebx,%esi
mov    %ebp,%edx
xor    %eax,%eax
call   1040 <printf@plt>
jmp    118c <exact_square+0x6c>
mov    $0x30,%edi
call   1030 <putchar@plt>
lea    0xe7b(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"0\00"
@.str.1 = [43 x i8] c"\0AThis number does not have an exact square\00"
@.str.2 = [2 x i8] c"1\00"
@.str.3 = [10 x i8] c"\0A %d=%d^2\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 0, i32* %5
store i32 0, i32* %4
br label %6
6: ; preds = %20, %1
%7 = load i32, i32* %4
%8 = load i32, i32* %3
%9 = sdiv i32 %8, 2
%10 = icmp slt i32 %7, %9
br i1 %10, label %11, label %23
11: ; preds = %6
%12 = load i32, i32* %3
%13 = load i32, i32* %4
%14 = load i32, i32* %4
%15 = mul nsw i32 %13, %14
%16 = icmp eq i32 %12, %15
br i1 %16, label %17, label %19
17: ; preds = %11
%18 = load i32, i32* %4
store i32 %18, i32* %5
br label %23
19: ; preds = %11
br label %20
20: ; preds = %19
%21 = load i32, i32* %4
%22 = add nsw i32 %21, 1
store i32 %22, i32* %4
br label %6
23: ; preds = %17, %6
%24 = load i32, i32* %5
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %23
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0))
br label %29
29: ; preds = %26, %23
%30 = load i32, i32* %5
%31 = icmp ne i32 %30, 0
br i1 %31, label %32, label %37
32: ; preds = %29
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%34 = load i32, i32* %3
%35 = load i32, i32* %5
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 %34, i32 %35)
br label %37
37: ; preds = %32, %29
%38 = load i32, i32* %2
ret i32 %38
}

LLVM IR (-O2):
@.str.1 = [43 x i8] c"\0AThis number does not have an exact square\00"
@.str.3 = [10 x i8] c"\0A %d=%d^2\00"
define i32 @exact_square(i32 %0) {
%2 = sdiv i32 %0, 2
%3 = icmp sgt i32 %0, 1
br i1 %3, label %4, label %13
4: ; preds = %1, %8
%5 = phi i32 [ %9, %8 ], [ 0, %1 ]
%6 = mul nsw i32 %5, %5
%7 = icmp eq i32 %6, %0
br i1 %7, label %11, label %8
8: ; preds = %4
%9 = add nuw nsw i32 %5, 1
%10 = icmp eq i32 %9, %2
br i1 %10, label %13, label %4
11: ; preds = %4
%12 = icmp eq i32 %5, 0
br i1 %12, label %13, label %16
13: ; preds = %8, %1, %11
%14 = tail call i32 @putchar(i32 48)
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0))
br label %19
16: ; preds = %11
%17 = tail call i32 @putchar(i32 49)
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 %0, i32 %5)
br label %19
19: ; preds = %13, %16
ret i32 undef
}