#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(long, long, long const, long const);
long get_long();
int /*<<< orphan*/ printf(char *, ...);
double sum_squares(long, long);
int main(void) {
  const long MIN = -10000000L;
  const long MAX = 10000000L;
  long start, stop;
  double answer;
  printf("This program computes the sum of the squares of"
         "integers in a range.\nThe lower bound should not "
         "be less than %ld and\n the upper bound "
         "should not be more then %ld.\nEnter the limits "
         "(0 for both limits to quit):\nlower limit: ",
         MIN, MAX);
  start = get_long();
  printf("upper limit: ");
  stop = get_long();
  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 ");
      printf("from %ld to %ld is %g\n", start, stop, answer);
    }
    printf("Enter the limits (0 for both limits to quit):\n");
    printf("lower limit: ");
    start = get_long();
    printf("upper limit: ");
    stop = get_long();
  }
  printf("Done.\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0xffffffffff676980,-0x10(%rbp)
ff
movq   $0x989680,-0x18(%rbp)
lea    0xe9a(%rip),%rdi
mov    $0xffffffffff676980,%rsi
mov    $0x989680,%edx
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x0,%al
call   1030 <get_long@plt>
mov    %rax,-0x20(%rbp)
lea    0xf53(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x0,%al
call   1030 <get_long@plt>
mov    %rax,-0x28(%rbp)
mov    $0x1,%al
cmpq   $0x0,-0x20(%rbp)
mov    %al,-0x31(%rbp)
jne    11b8 <main+0x78>
cmpq   $0x0,-0x28(%rbp)
setne  %al
mov    %al,-0x31(%rbp)
mov    -0x31(%rbp),%al
test   $0x1,%al
jne    11c8 <main+0x88>
jmp    127e <main+0x13e>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    $0xffffffffff676980,%rdx
mov    $0x989680,%ecx
call   1040 <bad_limits@plt>
cmp    $0x0,%rax
je     11fe <main+0xbe>
lea    0xefa(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    1239 <main+0xf9>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1050 <sum_squares@plt>
movsd  %xmm0,-0x30(%rbp)
lea    0xee8(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
movsd  -0x30(%rbp),%xmm0
lea    0xef5(%rip),%rdi
mov    $0x1,%al
call   1060 <printf@plt>
lea    0xefe(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xe82(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x0,%al
call   1030 <get_long@plt>
mov    %rax,-0x20(%rbp)
lea    0xe77(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x0,%al
call   1030 <get_long@plt>
mov    %rax,-0x28(%rbp)
jmp    119d <main+0x5d>
lea    0xee8(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x40,%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
mov    $0x989680,%edx
mov    $0xffffffffff676980,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
xor    %eax,%eax
call   1040 <get_long@plt>
mov    %rax,%rbp
lea    0xf58(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
xor    %eax,%eax
call   1040 <get_long@plt>
mov    %rax,%r15
mov    %rbp,%rax
or     %r15,%rax
je     1269 <main+0x119>
lea    0xf87(%rip),%r12
lea    0xf1f(%rip),%r13
lea    0xf26(%rip),%rbx
lea    0xfa0(%rip),%r14
jmp    123f <main+0xef>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbp,%rdi
mov    %r15,%rsi
call   1060 <sum_squares@plt>
movsd  %xmm0,(%rsp)
lea    0xf05(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xf1f(%rip),%rdi
mov    %rbp,%rsi
mov    %r15,%rdx
movsd  (%rsp),%xmm0
mov    $0x1,%al
call   1070 <printf@plt>
mov    %r12,%rdi
call   1030 <puts@plt>
mov    %r13,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
xor    %eax,%eax
call   1040 <get_long@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
xor    %eax,%eax
call   1040 <get_long@plt>
mov    %rax,%r15
mov    %rbp,%rax
or     %r15,%rax
je     1269 <main+0x119>
mov    $0x989680,%ecx
mov    %rbp,%rdi
mov    %r15,%rsi
mov    $0xffffffffff676980,%rdx
call   1050 <bad_limits@plt>
test   %rax,%rax
je     11d0 <main+0x80>
mov    %r14,%rdi
call   1030 <puts@plt>
jmp    1207 <main+0xb7>
lea    0xebb(%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 = [222 x i8] c"This program computes the sum of the squares ofintegers in a range.\0AThe lower bound should not be less than %ld and\0A the upper bound should not be more then %ld.\0AEnter the limits (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 = [40 x i8] c"The sum of the squares of the integers \00"
@.str.4 = [23 x i8] c"from %ld to %ld is %g\0A\00"
@.str.5 = [47 x i8] c"Enter the limits (0 for both limits to quit):\0A\00"
@.str.6 = [14 x i8] c"lower limit: \00"
@.str.7 = [7 x i8] c"Done.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
%6 = alloca double
store i32 0, i32* %1
store i64 -10000000, i64* %2
store i64 10000000, i64* %3
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([222 x i8], [222 x i8]* @.str, i64 0, i64 0), i64 -10000000, i64 10000000)
%8 = call i64 (...) @get_long()
store i64 %8, i64* %4
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%10 = call i64 (...) @get_long()
store i64 %10, i64* %5
br label %11
11: ; preds = %35, %0
%12 = load i64, i64* %4
%13 = icmp ne i64 %12, 0
br i1 %13, label %17, label %14
14: ; preds = %11
%15 = load i64, i64* %5
%16 = icmp ne i64 %15, 0
br label %17
17: ; preds = %14, %11
%18 = phi i1 [ true, %11 ], [ %16, %14 ]
br i1 %18, label %19, label %41
19: ; preds = %17
%20 = load i64, i64* %4
%21 = load i64, i64* %5
%22 = call i64 @bad_limits(i64 %20, i64 %21, i64 -10000000, i64 10000000)
%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 %35
26: ; preds = %19
%27 = load i64, i64* %4
%28 = load i64, i64* %5
%29 = call double @sum_squares(i64 %27, i64 %28)
store double %29, double* %6
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0))
%31 = load i64, i64* %4
%32 = load i64, i64* %5
%33 = load double, double* %6
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i64 %31, i64 %32, double %33)
br label %35
35: ; preds = %26, %24
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.5, i64 0, i64 0))
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0))
%38 = call i64 (...) @get_long()
store i64 %38, i64* %4
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%40 = call i64 (...) @get_long()
store i64 %40, i64* %5
br label %11
41: ; preds = %17
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0))
ret i32 0
}

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