#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");
  printf("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 \n");
      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>
lea    0xf6e(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x0,%al
call   1030 <get_long@plt>
mov    %rax,-0x20(%rbp)
lea    0xf62(%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    11ba <main+0x7a>
cmpq   $0x0,-0x28(%rbp)
setne  %al
mov    %al,-0x31(%rbp)
mov    -0x31(%rbp),%al
test   $0x1,%al
jne    11ca <main+0x8a>
jmp    1280 <main+0x140>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    $0xffffffffff676980,%rdx
mov    $0x989680,%ecx
call   1040 <bad_limits@plt>
cmp    $0x0,%rax
je     1200 <main+0xc0>
lea    0xf08(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    123b <main+0xfb>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1050 <sum_squares@plt>
movsd  %xmm0,-0x30(%rbp)
lea    0xef6(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
movsd  -0x30(%rbp),%xmm0
lea    0xf04(%rip),%rdi
mov    $0x1,%al
call   1060 <printf@plt>
lea    0xe6b(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xe92(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x0,%al
call   1030 <get_long@plt>
mov    %rax,-0x20(%rbp)
lea    0xe86(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x0,%al
call   1030 <get_long@plt>
mov    %rax,-0x28(%rbp)
jmp    119f <main+0x5f>
lea    0xec8(%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    0xecf(%rip),%rdi
call   1030 <puts@plt>
lea    0xe92(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
xor    %eax,%eax
call   1040 <get_long@plt>
mov    %rax,%rbp
lea    0xe87(%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     1267 <main+0x117>
lea    0xf34(%rip),%r12
lea    0xe4f(%rip),%r13
lea    0xe55(%rip),%rbx
lea    0xf81(%rip),%r14
jmp    123d <main+0xed>
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    0xf31(%rip),%rdi
call   1030 <puts@plt>
lea    0xe27(%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     1267 <main+0x117>
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    1205 <main+0xb5>
lea    0xea4(%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 = [226 x i8] c"This program computes the sum of the squares ofintegers in a range.\0AThe lower bound should not be less than -10000000 and\0Athe upper bound should not be more than +10000000.\0AEnter the limits (enter 0 for both limits to quit):\0A\00"
@.str.1 = [13 x i8] c"lower limit:\00"
@.str.2 = [13 x i8] c"upper limit:\00"
@.str.3 = [19 x i8] c"Please try again.\0A\00"
@.str.4 = [41 x i8] c"The sum of the squares of the integers \0A\00"
@.str.5 = [23 x i8] c"from %ld to %ld is %g\0A\00"
@.str.6 = [53 x i8] c"Enter the limits (enter 0 for both limits to quit):\0A\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 ([226 x i8], [226 x i8]* @.str, i64 0, i64 0))
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%9 = call i64 (...) @get_long()
store i64 %9, i64* %4
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%11 = call i64 (...) @get_long()
store i64 %11, i64* %5
br label %12
12: ; preds = %36, %0
%13 = load i64, i64* %4
%14 = icmp ne i64 %13, 0
br i1 %14, label %18, label %15
15: ; preds = %12
%16 = load i64, i64* %5
%17 = icmp ne i64 %16, 0
br label %18
18: ; preds = %15, %12
%19 = phi i1 [ true, %12 ], [ %17, %15 ]
br i1 %19, label %20, label %42
20: ; preds = %18
%21 = load i64, i64* %4
%22 = load i64, i64* %5
%23 = call i64 @bad_limits(i64 %21, i64 %22, i64 -10000000, i64 10000000)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %20
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
br label %36
27: ; preds = %20
%28 = load i64, i64* %4
%29 = load i64, i64* %5
%30 = call double @sum_squares(i64 %28, i64 %29)
store double %30, double* %6
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.4, i64 0, i64 0))
%32 = load i64, i64* %4
%33 = load i64, i64* %5
%34 = load double, double* %6
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i64 %32, i64 %33, double %34)
br label %36
36: ; preds = %27, %25
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.6, i64 0, i64 0))
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%39 = call i64 (...) @get_long()
store i64 %39, i64* %4
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%41 = call i64 (...) @get_long()
store i64 %41, i64* %5
br label %12
42: ; preds = %18
%43 = 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.1 = [13 x i8] c"lower limit:\00"
@.str.2 = [13 x i8] c"upper limit:\00"
@.str.5 = [23 x i8] c"from %ld to %ld is %g\0A\00"
@str = [225 x i8] c"This program computes the sum of the squares ofintegers in a range.\0AThe lower bound should not be less than -10000000 and\0Athe upper bound should not be more than +10000000.\0AEnter the limits (enter 0 for both limits to quit):\00"
@str.8 = [6 x i8] c"Done!\00"
@str.9 = [40 x i8] c"The sum of the squares of the integers \00"
@str.10 = [52 x i8] c"Enter the limits (enter 0 for both limits to quit):\00"
@str.11 = [18 x i8] c"Please try again.\00"
define i32 @main() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([225 x i8], [225 x i8]* @str, i64 0, i64 0))
%2 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%3 = tail call i64 (...) @get_long()
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%5 = tail call i64 (...) @get_long()
%6 = icmp ne i64 %3, 0
%7 = icmp ne i64 %5, 0
%8 = select i1 %6, i1 true, i1 %7
br i1 %8, label %9, label %29
9: ; preds = %0, %20
%10 = phi i64 [ %23, %20 ], [ %3, %0 ]
%11 = phi i64 [ %25, %20 ], [ %5, %0 ]
%12 = tail call i64 @bad_limits(i64 %10, i64 %11, i64 -10000000, i64 10000000)
%13 = icmp eq i64 %12, 0
br i1 %13, label %16, label %14
14: ; preds = %9
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.11, i64 0, i64 0))
br label %20
16: ; preds = %9
%17 = tail call double @sum_squares(i64 %10, i64 %11)
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str.9, i64 0, i64 0))
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i64 %10, i64 %11, double %17)
br label %20
20: ; preds = %16, %14
%21 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @str.10, i64 0, i64 0))
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%23 = tail call i64 (...) @get_long()
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%25 = tail call i64 (...) @get_long()
%26 = icmp ne i64 %23, 0
%27 = icmp ne i64 %25, 0
%28 = select i1 %26, i1 true, i1 %27
br i1 %28, label %9, label %29
29: ; preds = %20, %0
%30 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str.8, i64 0, i64 0))
ret i32 0
}