#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);
int exact_square(int res, int ch) {
  int counter;
  for (counter = 0; counter <= ch; counter++) {
    if (ch < 1) {
      res = 0;
      break;
    }
    if (counter * counter == ch) {
      res = 1;
      break;
    } else
      res = 0;
  }
  printf("%d", res);
}


x86 assembly (clang, -O0):
<exact_square>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jg     117d <exact_square+0x6d>
cmpl   $0x1,-0xc(%rbp)
jge    1147 <exact_square+0x37>
movl   $0x0,-0x8(%rbp)
jmp    117d <exact_square+0x6d>
mov    -0x10(%rbp),%eax
imul   -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jne    1163 <exact_square+0x53>
movl   $0x1,-0x8(%rbp)
jmp    117d <exact_square+0x6d>
movl   $0x0,-0x8(%rbp)
jmp    116f <exact_square+0x5f>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1125 <exact_square+0x15>
mov    -0x8(%rbp),%esi
lea    0xe79(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<exact_square>:
mov    %edi,%eax
test   %esi,%esi
js     1139 <exact_square+0x29>
je     1130 <exact_square+0x20>
lea    0x1(%rsi),%eax
xor    %ecx,%ecx
nopl   (%rax)
mov    %ecx,%edx
imul   %ecx,%edx
cmp    %esi,%edx
je     1134 <exact_square+0x24>
add    $0x1,%ecx
cmp    %ecx,%eax
jne    1120 <exact_square+0x10>
xor    %eax,%eax
jmp    1139 <exact_square+0x29>
mov    $0x1,%eax
lea    0xec0(%rip),%rdi
mov    %eax,%esi
jmp    1030 <printf@plt>

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

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
define i32 @exact_square(i32 %0, i32 %1) {
%3 = icmp slt i32 %1, 0
br i1 %3, label %13, label %4
4: ; preds = %2
%5 = icmp eq i32 %1, 0
br i1 %5, label %13, label %9
6: ; preds = %9
%7 = add nuw i32 %10, 1
%8 = icmp eq i32 %10, %1
br i1 %8, label %13, label %9
9: ; preds = %4, %6
%10 = phi i32 [ %7, %6 ], [ 0, %4 ]
%11 = mul nsw i32 %10, %10
%12 = icmp eq i32 %11, %1
br i1 %12, label %13, label %6
13: ; preds = %6, %9, %4, %2
%14 = phi i32 [ %0, %2 ], [ 0, %4 ], [ 1, %9 ], [ 0, %6 ]
%15 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %14)
ret i32 undef
}