#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;
  long 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 -10000000 and \nthe upper bound"
         "should not be more than +10000000.\nEnter the "
         "limits (enter 0 for both limits to quit):\n"
         "lower limit: ");
  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 (enter 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    $0x0,%al
call   1060 <printf@plt>
mov    $0x0,%al
call   1030 <get_long@plt>
mov    %rax,-0x20(%rbp)
lea    0xf71(%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    11ac <main+0x6c>
cmpq   $0x0,-0x28(%rbp)
setne  %al
mov    %al,-0x31(%rbp)
mov    -0x31(%rbp),%al
test   $0x1,%al
jne    11bc <main+0x7c>
jmp    1272 <main+0x132>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    $0xffffffffff676980,%rdx
mov    $0x989680,%ecx
call   1040 <bad_limits@plt>
cmp    $0x0,%rax
je     11f2 <main+0xb2>
lea    0xf18(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    122d <main+0xed>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1050 <sum_squares@plt>
movsd  %xmm0,-0x30(%rbp)
lea    0xf06(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
movsd  -0x30(%rbp),%xmm0
lea    0xf13(%rip),%rdi
mov    $0x1,%al
call   1060 <printf@plt>
lea    0xf1c(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xea0(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x0,%al
call   1030 <get_long@plt>
mov    %rax,-0x20(%rbp)
lea    0xe95(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x0,%al
call   1030 <get_long@plt>
mov    %rax,-0x28(%rbp)
jmp    1191 <main+0x51>
lea    0xf0c(%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
xor    %eax,%eax
call   1070 <printf@plt>
xor    %eax,%eax
call   1040 <get_long@plt>
mov    %rax,%rbp
lea    0xf76(%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     1259 <main+0x109>
lea    0xfa5(%rip),%r12
lea    0xf3d(%rip),%r13
lea    0xf44(%rip),%rbx
lea    0xfc4(%rip),%r14
jmp    122f <main+0xdf>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbp,%rdi
mov    %r15,%rsi
call   1060 <sum_squares@plt>
movsd  %xmm0,(%rsp)
lea    0xf27(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xf41(%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     1259 <main+0x109>
mov    $0x989680,%ecx
mov    %rbp,%rdi
mov    %r15,%rsi
mov    $0xffffffffff676980,%rdx
call   1050 <bad_limits@plt>
test   %rax,%rax
je     11c0 <main+0x70>
mov    %r14,%rdi
call   1030 <puts@plt>
jmp    11f7 <main+0xa7>
lea    0xedd(%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 = [240 x i8] c"This program computes the sum of the squares of integers in a range.\0AThe lower bound should not be less than -10000000 and \0Athe upper boundshould not be more than +10000000.\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 = [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 = [53 x i8] c"Enter the limits (enter 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 ([240 x i8], [240 x i8]* @.str, i64 0, i64 0))
%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 ([53 x i8], [53 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 = [240 x i8] c"This program computes the sum of the squares of integers in a range.\0AThe lower bound should not be less than -10000000 and \0Athe upper boundshould not be more than +10000000.\0AEnter the limits (enter 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 = [52 x i8] c"Enter the limits (enter 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 ([240 x i8], [240 x i8]* @.str, i64 0, i64 0))
%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 ([52 x i8], [52 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
}