#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 */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ printf(char *);
int iterate_get_sum(int min, int max) {
  int i, total;
  total = 0;
  for (i = min; i <= max; i++) {
    if (total + i < total) {
      printf("Error: sum too large!\n");
      exit(1);
    }
    total += i;
  }
  return total;
}


x86 assembly (clang, -O0):
<iterate_get_sum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     1183 <iterate_get_sum+0x63>
mov    -0x10(%rbp),%eax
add    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    116c <iterate_get_sum+0x4c>
lea    0xea3(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1040 <exit@plt>
mov    -0xc(%rbp),%eax
add    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    113b <iterate_get_sum+0x1b>
mov    -0x10(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<iterate_get_sum>:
xor    %eax,%eax
cmp    %esi,%edi
jg     113d <iterate_get_sum+0x1d>
add    $0x1,%esi
xor    %eax,%eax
mov    %edi,%ecx
nopl   (%rax)
test   %edi,%edi
js     113e <iterate_get_sum+0x1e>
add    %ecx,%eax
add    $0x1,%ecx
cmp    %ecx,%esi
jne    1130 <iterate_get_sum+0x10>
ret
push   %rax
lea    0xeba(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1040 <exit@plt>

LLVM IR (-O0):
@.str = [23 x i8] c"Error: sum too large!\0A\00"
define i32 @iterate_get_sum(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
store i32 0, i32* %6
%7 = load i32, i32* %3
store i32 %7, i32* %5
br label %8
8: ; preds = %25, %2
%9 = load i32, i32* %5
%10 = load i32, i32* %4
%11 = icmp sle i32 %9, %10
br i1 %11, label %12, label %28
12: ; preds = %8
%13 = load i32, i32* %6
%14 = load i32, i32* %5
%15 = add nsw i32 %13, %14
%16 = load i32, i32* %6
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %21
18: ; preds = %12
%19 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %12
%22 = load i32, i32* %5
%23 = load i32, i32* %6
%24 = add nsw i32 %23, %22
store i32 %24, i32* %6
br label %25
25: ; preds = %21
%26 = load i32, i32* %5
%27 = add nsw i32 %26, 1
store i32 %27, i32* %5
br label %8
28: ; preds = %8
%29 = load i32, i32* %6
ret i32 %29
}

LLVM IR (-O2):
@str = [22 x i8] c"Error: sum too large!\00"
define i32 @iterate_get_sum(i32 %0, i32 %1) {
%3 = icmp sgt i32 %0, %1
br i1 %3, label %16, label %4
4: ; preds = %2
%5 = icmp slt i32 %0, 0
br label %6
6: ; preds = %4, %12
%7 = phi i32 [ %13, %12 ], [ 0, %4 ]
%8 = phi i32 [ %14, %12 ], [ %0, %4 ]
br i1 %5, label %9, label %12
9: ; preds = %6
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %6
%13 = add nsw i32 %7, %8
%14 = add i32 %8, 1
%15 = icmp eq i32 %8, %1
br i1 %15, label %16, label %6
16: ; preds = %12, %2
%17 = phi i32 [ 0, %2 ], [ %13, %12 ]
ret i32 %17
}