#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__ bad_limits(int, int, int const, int const);
int get_int();
int /*<<< orphan*/ printf(char *, ...);
double sum_squares(int, int);
int main(void) {
  const int MIN = -1000;
  const int MAX = +1000;
  int start;
  int stop;
  double answer;
  printf(
      "This program computes the sum of the squares of integers in a range.\n"
      "The lower bound should not be less than -1000 and the upper bound "
      "should not be more than +1000.\n"
      "Enter the limits (enter 0 for both limits to quit):\nlower limit: ");
  start = get_int();
  printf("upper limit: ");
  stop = get_int();
  while (start != 0 || stop != 0) {
    if (bad_limits(start, stop, MIN, MAX))
      printf("Please try again.\n");
    else {
      answer = sum_squares(start, stop);
      printf("The sum of the squares of the integers from %d to %d is %g\n",
             start, stop, answer);
    }
    printf("Enter the limits (enter 0 for both limits to quit): \n");
    printf("lower limit: ");
    start = get_int();
    printf("upper limit: ");
    stop = get_int();
  }
  printf("Done.\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xfffffc18,-0x8(%rbp)
movl   $0x3e8,-0xc(%rbp)
lea    0xe9c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1060 <get_int@plt>
mov    %eax,-0x10(%rbp)
lea    0xf6c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1060 <get_int@plt>
mov    %eax,-0x14(%rbp)
mov    $0x1,%al
cmpl   $0x0,-0x10(%rbp)
mov    %al,-0x21(%rbp)
jne    11a6 <main+0x66>
cmpl   $0x0,-0x14(%rbp)
setne  %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    11b6 <main+0x76>
jmp    1254 <main+0x114>
mov    -0x10(%rbp),%edi
mov    -0x14(%rbp),%esi
mov    $0xfffffc18,%edx
mov    $0x3e8,%ecx
call   1030 <bad_limits@plt>
cmp    $0x0,%rax
je     11e8 <main+0xa8>
lea    0xf1a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1211 <main+0xd1>
mov    -0x10(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1040 <sum_squares@plt>
movsd  %xmm0,-0x20(%rbp)
mov    -0x10(%rbp),%esi
mov    -0x14(%rbp),%edx
movsd  -0x20(%rbp),%xmm0
lea    0xeff(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
lea    0xf2d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xeb4(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1060 <get_int@plt>
mov    %eax,-0x10(%rbp)
lea    0xeaa(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1060 <get_int@plt>
mov    %eax,-0x14(%rbp)
jmp    118d <main+0x4d>
lea    0xf20(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xe9e(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
call   1070 <get_int@plt>
mov    %eax,%ebp
lea    0xf6f(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
call   1070 <get_int@plt>
mov    %eax,%r14d
mov    %ebp,%eax
or     %r14d,%eax
je     1236 <main+0xe6>
lea    0xf9c(%rip),%r15
lea    0xf37(%rip),%r12
lea    0xf3e(%rip),%rbx
lea    0xfbc(%rip),%r13
jmp    1213 <main+0xc3>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %ebp,%edi
mov    %r14d,%esi
call   1050 <sum_squares@plt>
lea    0xf25(%rip),%rdi
mov    %ebp,%esi
mov    %r14d,%edx
mov    $0x1,%al
call   1060 <printf@plt>
mov    %r15,%rdi
call   1030 <puts@plt>
mov    %r12,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
call   1070 <get_int@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
call   1070 <get_int@plt>
mov    %eax,%r14d
mov    %ebp,%eax
or     %r14d,%eax
je     1236 <main+0xe6>
mov    %ebp,%edi
mov    %r14d,%esi
mov    $0xfffffc18,%edx
mov    $0x3e8,%ecx
call   1040 <bad_limits@plt>
test   %rax,%rax
je     11c0 <main+0x70>
mov    %r13,%rdi
call   1030 <puts@plt>
jmp    11dd <main+0x8d>
lea    0xef5(%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 = [232 x i8] c"This program computes the sum of the squares of integers in a range.\0AThe lower bound should not be less than -1000 and the upper bound should not be more than +1000.\0AEnter the limits (enter 0 for both limits to quit):\0Alower limit: \00"
@.str.1 = [14 x i8] c"upper limit: \00"
@.str.2 = [19 x i8] c"Please try again.\0A\00"
@.str.3 = [60 x i8] c"The sum of the squares of the integers from %d to %d is %g\0A\00"
@.str.4 = [54 x i8] c"Enter the limits (enter 0 for both limits to quit): \0A\00"
@.str.5 = [14 x i8] c"lower limit: \00"
@.str.6 = [7 x i8] c"Done.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca double
store i32 0, i32* %1
store i32 -1000, i32* %2
store i32 1000, i32* %3
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([232 x i8], [232 x i8]* @.str, i64 0, i64 0))
%8 = call i32 (...) @get_int()
store i32 %8, i32* %4
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%10 = call i32 (...) @get_int()
store i32 %10, i32* %5
br label %11
11: ; preds = %34, %0
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, 0
br i1 %13, label %17, label %14
14: ; preds = %11
%15 = load i32, i32* %5
%16 = icmp ne i32 %15, 0
br label %17
17: ; preds = %14, %11
%18 = phi i1 [ true, %11 ], [ %16, %14 ]
br i1 %18, label %19, label %40
19: ; preds = %17
%20 = load i32, i32* %4
%21 = load i32, i32* %5
%22 = call i64 @bad_limits(i32 %20, i32 %21, i32 -1000, i32 1000)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %19
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
br label %34
26: ; preds = %19
%27 = load i32, i32* %4
%28 = load i32, i32* %5
%29 = call double @sum_squares(i32 %27, i32 %28)
store double %29, double* %6
%30 = load i32, i32* %4
%31 = load i32, i32* %5
%32 = load double, double* %6
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.3, i64 0, i64 0), i32 %30, i32 %31, double %32)
br label %34
34: ; preds = %26, %24
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.4, i64 0, i64 0))
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0))
%37 = call i32 (...) @get_int()
store i32 %37, i32* %4
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%39 = call i32 (...) @get_int()
store i32 %39, i32* %5
br label %11
40: ; preds = %17
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [232 x i8] c"This program computes the sum of the squares of integers in a range.\0AThe lower bound should not be less than -1000 and the upper bound should not be more than +1000.\0AEnter the limits (enter 0 for both limits to quit):\0Alower limit: \00"
@.str.1 = [14 x i8] c"upper limit: \00"
@.str.3 = [60 x i8] c"The sum of the squares of the integers from %d to %d is %g\0A\00"
@.str.5 = [14 x i8] c"lower limit: \00"
@str = [6 x i8] c"Done.\00"
@str.7 = [53 x i8] c"Enter the limits (enter 0 for both limits to quit): \00"
@str.8 = [18 x i8] c"Please try again.\00"
define i32 @main() {
%1 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([232 x i8], [232 x i8]* @.str, i64 0, i64 0))
%2 = tail call i32 (...) @get_int()
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%4 = tail call i32 (...) @get_int()
%5 = icmp ne i32 %2, 0
%6 = icmp ne i32 %4, 0
%7 = select i1 %5, i1 true, i1 %6
br i1 %7, label %8, label %27
8: ; preds = %0, %18
%9 = phi i32 [ %21, %18 ], [ %2, %0 ]
%10 = phi i32 [ %23, %18 ], [ %4, %0 ]
%11 = tail call i64 @bad_limits(i32 %9, i32 %10, i32 -1000, i32 1000)
%12 = icmp eq i64 %11, 0
br i1 %12, label %15, label %13
13: ; preds = %8
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.8, i64 0, i64 0))
br label %18
15: ; preds = %8
%16 = tail call double @sum_squares(i32 %9, i32 %10)
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([60 x i8], [60 x i8]* @.str.3, i64 0, i64 0), i32 %9, i32 %10, double %16)
br label %18
18: ; preds = %15, %13
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @str.7, i64 0, i64 0))
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0))
%21 = tail call i32 (...) @get_int()
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%23 = tail call i32 (...) @get_int()
%24 = icmp ne i32 %21, 0
%25 = icmp ne i32 %23, 0
%26 = select i1 %24, i1 true, i1 %25
br i1 %26, label %8, label %27
27: ; preds = %18, %0
%28 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str, i64 0, i64 0))
ret i32 0
}