#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 */
typedef int /*<<< orphan*/ tests;

/* Variables and functions */
int perfect_square(unsigned int, unsigned int *);
int /*<<< orphan*/ printf(char *, ...);
int main(void) {
  unsigned res;
  unsigned tests[] = {1,  2,  3,   4,    10,   15,   20,   25,
                      90, 99, 100, 2000, 1000, 3000, 5000, 9801};
  size_t i;
  for (i = 0; i < sizeof(tests) / sizeof(tests[0]); i++) {
    int is_perfect = perfect_square(tests[i], &res);
    printf("perfect_square(%u) = ", tests[i]);
    if (!is_perfect) {
      printf("false\n");
    } else {
      printf("true (sqrt = %u)\n", res);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x50(%rbp),%rdi
lea    0xeb6(%rip),%rsi
mov    $0x40,%edx
call   1040 <memcpy@plt>
movq   $0x0,-0x58(%rbp)
cmpq   $0x10,-0x58(%rbp)
jae    11d5 <main+0xa5>
mov    -0x58(%rbp),%rax
mov    -0x50(%rbp,%rax,4),%edi
lea    -0x8(%rbp),%rsi
call   1050 <perfect_square@plt>
mov    %eax,-0x5c(%rbp)
mov    -0x58(%rbp),%rax
mov    -0x50(%rbp,%rax,4),%esi
lea    0xeb6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x0,-0x5c(%rbp)
jne    11ae <main+0x7e>
lea    0xeb4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11bf <main+0x8f>
mov    -0x8(%rbp),%esi
lea    0xea5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11c4 <main+0x94>
mov    -0x58(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x58(%rbp)
jmp    115c <main+0x2c>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xebe(%rip),%r15
lea    0x4(%rsp),%r14
lea    0xef2(%rip),%r13
xor    %r12d,%r12d
jmp    117c <main+0x4c>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    0x4(%rsp),%esi
lea    0xeeb(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x4,%r12
cmp    $0x40,%r12
je     11aa <main+0x7a>
mov    (%r12,%r15,1),%ebp
mov    %ebp,%edi
mov    %r14,%rsi
call   1050 <perfect_square@plt>
mov    %eax,%ebx
mov    %r13,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
test   %ebx,%ebx
jne    1160 <main+0x30>
lea    0xec5(%rip),%rdi
call   1030 <puts@plt>
jmp    1172 <main+0x42>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.main.tests = [16 x i32] [i32 1, i32 2, i32 3, i32 4, i32 10, i32 15, i32 20, i32 25, i32 90, i32 99, i32 100, i32 2000, i32 1000, i32 3000, i32 5000, i32 9801]
@.str = [22 x i8] c"perfect_square(%u) = \00"
@.str.1 = [7 x i8] c"false\0A\00"
@.str.2 = [18 x i8] c"true (sqrt = %u)\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [16 x i32]
%4 = alloca i64
%5 = alloca i32
store i32 0, i32* %1
%6 = bitcast [16 x i32]* %3 to i8*
store i64 0, i64* %4
br label %7
7: ; preds = %27, %0
%8 = load i64, i64* %4
%9 = icmp ult i64 %8, 16
br i1 %9, label %10, label %30
10: ; preds = %7
%11 = load i64, i64* %4
%12 = getelementptr inbounds [16 x i32], [16 x i32]* %3, i64 0, i64 %11
%13 = load i32, i32* %12
%14 = call i32 @perfect_square(i32 %13, i32* %2)
store i32 %14, i32* %5
%15 = load i64, i64* %4
%16 = getelementptr inbounds [16 x i32], [16 x i32]* %3, i64 0, i64 %15
%17 = load i32, i32* %16
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %17)
%19 = load i32, i32* %5
%20 = icmp ne i32 %19, 0
br i1 %20, label %23, label %21
21: ; preds = %10
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %26
23: ; preds = %10
%24 = load i32, i32* %2
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 %24)
br label %26
26: ; preds = %23, %21
br label %27
27: ; preds = %26
%28 = load i64, i64* %4
%29 = add i64 %28, 1
store i64 %29, i64* %4
br label %7
30: ; preds = %7
ret i32 0
}

LLVM IR (-O2):
@__const.main.tests = [16 x i32] [i32 1, i32 2, i32 3, i32 4, i32 10, i32 15, i32 20, i32 25, i32 90, i32 99, i32 100, i32 2000, i32 1000, i32 3000, i32 5000, i32 9801]
@.str = [22 x i8] c"perfect_square(%u) = \00"
@.str.2 = [18 x i8] c"true (sqrt = %u)\0A\00"
@str = [6 x i8] c"false\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
br label %3
3: ; preds = %0, %15
%4 = phi i64 [ 0, %0 ], [ %16, %15 ]
%5 = getelementptr inbounds [16 x i32], [16 x i32]* @__const.main.tests, i64 0, i64 %4
%6 = load i32, i32* %5
%7 = call i32 @perfect_square(i32 %6, i32* %1)
%8 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %6)
%9 = icmp eq i32 %7, 0
br i1 %9, label %10, label %12
10: ; preds = %3
%11 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str, i64 0, i64 0))
br label %15
12: ; preds = %3
%13 = load i32, i32* %1
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 %13)
br label %15
15: ; preds = %12, %10
%16 = add nuw nsw i64 %4, 1
%17 = icmp eq i64 %16, 16
br i1 %17, label %18, label %3
18: ; preds = %15
ret i32 0
}