#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__ EOF;
int /*<<< orphan*/ printf(char *, ...);
int rrange(int, int);
scalar_t__ scanf(char *, float *);
float sqrt(int);
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
float to1place(float);
int main() {
  srand(time(NULL));
  int guess = 1;
  int num = rrange(2, 500);
  float root = to1place(sqrt(num));
  printf("Welcome to the guessing game!\n");
  printf("In this game, you have 12 guesses to try and figure out the quare "
         "root of");
  printf("a given number.\n");
  printf("If you enter a square root that's correct to at least one decimal "
         "place,\n");
  printf("you'll win.\n");
  printf("====================================================\n");
  printf("What is the square root of %i?\n", num);
  do {
    float sr = 0;
    do {
      printf("Please enter guess %i: ", guess);
      if (scanf("%f", &sr) != EOF)
        break;
      printf("Please enter a number.\n");
    } while (1);
    float temp = to1place(sr);
    if (sr < root) {
      printf("You'll have to guess higher!\n");
    } else if (sr > root) {
      printf("You'll have to guess lower!\n");
    } else if (root == sr) {
      printf("You got it!\n");
      return 0;
    }
    guess++;
  } while (guess <= 12);
  printf("You lost.\n");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1060 <time@plt>
mov    %eax,%edi
call   1050 <srand@plt>
movl   $0x1,-0x8(%rbp)
mov    $0x2,%edi
mov    $0x1f4,%esi
call   1070 <rrange@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
call   1090 <sqrt@plt>
call   1030 <to1place@plt>
movss  %xmm0,-0x10(%rbp)
lea    0xe3f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe50(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe8c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe8f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xecb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xeca(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0xc(%rbp),%esi
lea    0xeef(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xorps  %xmm0,%xmm0
movss  %xmm0,-0x14(%rbp)
mov    -0x8(%rbp),%esi
lea    0xef6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xf00(%rip),%rdi
lea    -0x14(%rbp),%rsi
call   1080 <scanf@plt>
mov    0x2d99(%rip),%rcx
cmp    (%rcx),%rax
je     125d <main+0xed>
jmp    127a <main+0x10a>
lea    0xede(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%al
test   $0x1,%al
jne    1227 <main+0xb7>
jmp    127a <main+0x10a>
movss  -0x14(%rbp),%xmm0
call   1030 <to1place@plt>
movss  %xmm0,-0x18(%rbp)
movss  -0x14(%rbp),%xmm1
movss  -0x10(%rbp),%xmm0
ucomiss %xmm1,%xmm0
jbe    12af <main+0x13f>
lea    0xeb7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    130a <main+0x19a>
movss  -0x14(%rbp),%xmm0
ucomiss -0x10(%rbp),%xmm0
jbe    12d1 <main+0x161>
lea    0xeb3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1305 <main+0x195>
movss  -0x10(%rbp),%xmm0
ucomiss -0x14(%rbp),%xmm0
jne    1300 <main+0x190>
jp     1300 <main+0x190>
lea    0xea8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    132b <main+0x1bb>
jmp    1305 <main+0x195>
jmp    130a <main+0x19a>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
cmpl   $0xc,-0x8(%rbp)
jle    121f <main+0xaf>
lea    0xe7e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %edi,%edi
call   1070 <time@plt>
mov    %eax,%edi
call   1060 <srand@plt>
mov    $0x2,%edi
mov    $0x1f4,%esi
call   1080 <rrange@plt>
mov    %eax,%ebx
mov    %eax,%edi
call   10a0 <sqrt@plt>
call   1040 <to1place@plt>
movss  %xmm0,0x4(%rsp)
lea    0xec2(%rip),%rdi
call   1030 <puts@plt>
lea    0xe31(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xec6(%rip),%rdi
call   1030 <puts@plt>
lea    0xeca(%rip),%rdi
call   1030 <puts@plt>
lea    0xf07(%rip),%rdi
call   1030 <puts@plt>
lea    0xf07(%rip),%rdi
call   1030 <puts@plt>
lea    0xe3d(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%ebx
lea    0xe48(%rip),%r14
lea    0xe59(%rip),%r15
mov    %rsp,%r12
mov    0x2db5(%rip),%rbp
lea    0xf03(%rip),%r13
jmp    1251 <main+0xd1>
nopl   0x0(%rax)
call   1030 <puts@plt>
add    $0x1,%ebx
cmp    $0xd,%ebx
je     12cd <main+0x14d>
movl   $0x0,(%rsp)
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1090 <scanf@plt>
cmp    0x0(%rbp),%rax
jne    1290 <main+0x110>
mov    %r13,%rdi
call   1030 <puts@plt>
jmp    1260 <main+0xe0>
nopw   0x0(%rax,%rax,1)
movss  (%rsp),%xmm0
call   1040 <to1place@plt>
movss  (%rsp),%xmm0
movss  0x4(%rsp),%xmm1
ucomiss %xmm0,%xmm1
lea    0xed7(%rip),%rdi
ja     1240 <main+0xc0>
ucomiss %xmm1,%xmm0
lea    0xeaf(%rip),%rdi
ja     1240 <main+0xc0>
ucomiss %xmm0,%xmm1
jne    1245 <main+0xc5>
jp     1245 <main+0xc5>
lea    0xe93(%rip),%rdi
jmp    12d4 <main+0x154>
lea    0xe80(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [31 x i8] c"Welcome to the guessing game!\0A\00"
@.str.1 = [74 x i8] c"In this game, you have 12 guesses to try and figure out the quare root of\00"
@.str.2 = [17 x i8] c"a given number.\0A\00"
@.str.3 = [74 x i8] c"If you enter a square root that's correct to at least one decimal place,\0A\00"
@.str.4 = [13 x i8] c"you'll win.\0A\00"
@.str.5 = [54 x i8] c"====================================================\0A\00"
@.str.6 = [32 x i8] c"What is the square root of %i?\0A\00"
@.str.7 = [24 x i8] c"Please enter guess %i: \00"
@.str.8 = [3 x i8] c"%f\00"
@EOF = global i64 0
@.str.9 = [24 x i8] c"Please enter a number.\0A\00"
@.str.10 = [30 x i8] c"You'll have to guess higher!\0A\00"
@.str.11 = [29 x i8] c"You'll have to guess lower!\0A\00"
@.str.12 = [13 x i8] c"You got it!\0A\00"
@.str.13 = [11 x i8] c"You lost.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca float
%5 = alloca float
%6 = alloca float
store i32 0, i32* %1
%7 = call i32 @time(i32* null)
%8 = call i32 @srand(i32 %7)
store i32 1, i32* %2
%9 = call i32 @rrange(i32 2, i32 500)
store i32 %9, i32* %3
%10 = load i32, i32* %3
%11 = call float @sqrt(i32 %10)
%12 = call float @to1place(float %11)
store float %12, float* %4
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([74 x i8], [74 x i8]* @.str.1, i64 0, i64 0))
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([74 x i8], [74 x i8]* @.str.3, i64 0, i64 0))
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.5, i64 0, i64 0))
%19 = load i32, i32* %3
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.6, i64 0, i64 0), i32 %19)
br label %21
21: ; preds = %57, %0
store float 0.000000e+00, float* %5
br label %22
22: ; preds = %31, %21
%23 = load i32, i32* %2
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.7, i64 0, i64 0), i32 %23)
%25 = call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), float* %5)
%26 = load i64, i64* @EOF
%27 = icmp ne i64 %25, %26
br i1 %27, label %28, label %29
28: ; preds = %22
br label %32
29: ; preds = %22
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.9, i64 0, i64 0))
br label %31
31: ; preds = %29
br i1 true, label %22, label %32
32: ; preds = %31, %28
%33 = load float, float* %5
%34 = call float @to1place(float %33)
store float %34, float* %6
%35 = load float, float* %5
%36 = load float, float* %4
%37 = fcmp olt float %35, %36
br i1 %37, label %38, label %40
38: ; preds = %32
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.10, i64 0, i64 0))
br label %54
40: ; preds = %32
%41 = load float, float* %5
%42 = load float, float* %4
%43 = fcmp ogt float %41, %42
br i1 %43, label %44, label %46
44: ; preds = %40
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.11, i64 0, i64 0))
br label %53
46: ; preds = %40
%47 = load float, float* %4
%48 = load float, float* %5
%49 = fcmp oeq float %47, %48
br i1 %49, label %50, label %52
50: ; preds = %46
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.12, i64 0, i64 0))
store i32 0, i32* %1
br label %62
52: ; preds = %46
br label %53
53: ; preds = %52, %44
br label %54
54: ; preds = %53, %38
%55 = load i32, i32* %2
%56 = add nsw i32 %55, 1
store i32 %56, i32* %2
br label %57
57: ; preds = %54
%58 = load i32, i32* %2
%59 = icmp sle i32 %58, 12
br i1 %59, label %21, label %60
60: ; preds = %57
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.13, i64 0, i64 0))
br label %62
62: ; preds = %60, %50
%63 = load i32, i32* %1
ret i32 %63
}

LLVM IR (-O2):
@.str.1 = [74 x i8] c"In this game, you have 12 guesses to try and figure out the quare root of\00"
@.str.6 = [32 x i8] c"What is the square root of %i?\0A\00"
@.str.7 = [24 x i8] c"Please enter guess %i: \00"
@.str.8 = [3 x i8] c"%f\00"
@EOF = global i64 0
@str = [30 x i8] c"Welcome to the guessing game!\00"
@str.14 = [16 x i8] c"a given number.\00"
@str.15 = [73 x i8] c"If you enter a square root that's correct to at least one decimal place,\00"
@str.16 = [12 x i8] c"you'll win.\00"
@str.17 = [53 x i8] c"====================================================\00"
@str.18 = [23 x i8] c"Please enter a number.\00"
@str.19 = [10 x i8] c"You lost.\00"
@str.20 = [12 x i8] c"You got it!\00"
@str.21 = [28 x i8] c"You'll have to guess lower!\00"
@str.22 = [29 x i8] c"You'll have to guess higher!\00"
define i32 @main() {
%1 = alloca float
%2 = tail call i32 @time(i32* null)
%3 = tail call i32 @srand(i32 %2)
%4 = tail call i32 @rrange(i32 2, i32 500)
%5 = tail call float @sqrt(i32 %4)
%6 = tail call float @to1place(float %5)
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str, i64 0, i64 0))
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([74 x i8], [74 x i8]* @.str.1, i64 0, i64 0))
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.14, i64 0, i64 0))
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([73 x i8], [73 x i8]* @str.15, i64 0, i64 0))
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.16, i64 0, i64 0))
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @str.17, i64 0, i64 0))
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.6, i64 0, i64 0), i32 %4)
%14 = bitcast float* %1 to i8*
br label %15
15: ; preds = %41, %0
%16 = phi i32 [ 1, %0 ], [ %42, %41 ]
store float 0.000000e+00, float* %1
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.7, i64 0, i64 0), i32 %16)
%18 = call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), float* %1)
%19 = load i64, i64* @EOF
%20 = icmp eq i64 %18, %19
br i1 %20, label %21, label %27
21: ; preds = %15, %21
%22 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.18, i64 0, i64 0))
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.7, i64 0, i64 0), i32 %16)
%24 = call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), float* %1)
%25 = load i64, i64* @EOF
%26 = icmp eq i64 %24, %25
br i1 %26, label %21, label %27
27: ; preds = %21, %15
%28 = load float, float* %1
%29 = call float @to1place(float %28)
%30 = load float, float* %1
%31 = fcmp olt float %30, %6
br i1 %31, label %38, label %32
32: ; preds = %27
%33 = fcmp ogt float %30, %6
br i1 %33, label %38, label %34
34: ; preds = %32
%35 = fcmp oeq float %6, %30
br i1 %35, label %36, label %41
36: ; preds = %34
%37 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.20, i64 0, i64 0))
br label %46
38: ; preds = %32, %27
%39 = phi i8* [ getelementptr inbounds ([29 x i8], [29 x i8]* @str.22, i64 0, i64 0), %27 ], [ getelementptr inbounds ([28 x i8], [28 x i8]* @str.21, i64 0, i64 0), %32 ]
%40 = call i32 @puts(i8* dereferenceable(1) %39)
br label %41
41: ; preds = %38, %34
%42 = add nuw nsw i32 %16, 1
%43 = icmp eq i32 %42, 13
br i1 %43, label %44, label %15
44: ; preds = %41
%45 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str.19, i64 0, i64 0))
br label %46
46: ; preds = %36, %44
ret i32 0
}