int trist_upper_bound(n)
int n;
{
  if (n * n < n) {
    static int first_flag = 1;
    if (first_flag) {
      (void)printf("WARNING: trist_upper_bound (n = %d) int overflow!  %s\n", n,
                   "Returning MAXINT.");
      first_flag = 0;
    }
    return ((~(1 << (8 * (int)sizeof(int)) - 1)));
  } else
    return (n * (n - 3) + 1);
}


x86 assembly (clang, -O0):
<trist_upper_bound>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
imul   -0x8(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1166 <trist_upper_bound+0x56>
cmpl   $0x0,0x2ef6(%rip)
je     115a <trist_upper_bound+0x4a>
mov    -0x8(%rbp),%esi
lea    0xebe(%rip),%rdi
lea    0xeee(%rip),%rdx
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,0x2ece(%rip)
movl   $0x7fffffff,-0x4(%rbp)
jmp    1178 <trist_upper_bound+0x68>
mov    -0x8(%rbp),%eax
mov    -0x8(%rbp),%ecx
sub    $0x3,%ecx
imul   %ecx,%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<trist_upper_bound>:
push   %rbx
mov    %edi,%esi
mov    %edi,%eax
imul   %edi,%eax
cmp    %edi,%eax
jge    1148 <trist_upper_bound+0x38>
mov    $0x7fffffff,%ebx
cmpb   $0x0,0x2f04(%rip)
jne    1151 <trist_upper_bound+0x41>
lea    0xecf(%rip),%rdi
lea    0xeff(%rip),%rdx
xor    %eax,%eax
call   1030 <printf@plt>
movb   $0x1,0x2ee6(%rip)
jmp    1151 <trist_upper_bound+0x41>
lea    -0x3(%rsi),%ebx
imul   %esi,%ebx
add    $0x1,%ebx
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@trist_upper_bound.first_flag = internal global i32 1
@.str = [55 x i8] c"WARNING: trist_upper_bound (n = %d) int overflow! %s\0A\00"
@.str.1 = [18 x i8] c"Returning MAXINT.\00"
define i32 @trist_upper_bound(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* %3
%5 = load i32, i32* %3
%6 = mul nsw i32 %4, %5
%7 = load i32, i32* %3
%8 = icmp slt i32 %6, %7
br i1 %8, label %9, label %16
9: ; preds = %1
%10 = load i32, i32* @trist_upper_bound.first_flag
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %9
%13 = load i32, i32* %3
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 %13, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* @trist_upper_bound.first_flag
br label %15
15: ; preds = %12, %9
store i32 2147483647, i32* %2
br label %22
16: ; preds = %1
%17 = load i32, i32* %3
%18 = load i32, i32* %3
%19 = sub nsw i32 %18, 3
%20 = mul nsw i32 %17, %19
%21 = add nsw i32 %20, 1
store i32 %21, i32* %2
br label %22
22: ; preds = %16, %15
%23 = load i32, i32* %2
ret i32 %23
}

LLVM IR (-O2):
@trist_upper_bound.first_flag = internal unnamed_addr global i1 false
@.str = [55 x i8] c"WARNING: trist_upper_bound (n = %d) int overflow! %s\0A\00"
@.str.1 = [18 x i8] c"Returning MAXINT.\00"
define i32 @trist_upper_bound(i32 %0) {
%2 = mul nsw i32 %0, %0
%3 = icmp slt i32 %2, %0
br i1 %3, label %4, label %8
4: ; preds = %1
%5 = load i1, i1* @trist_upper_bound.first_flag
br i1 %5, label %12, label %6
6: ; preds = %4
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 %0, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
store i1 true, i1* @trist_upper_bound.first_flag
br label %12
8: ; preds = %1
%9 = add nsw i32 %0, -3
%10 = mul nsw i32 %9, %0
%11 = add nsw i32 %10, 1
br label %12
12: ; preds = %4, %6, %8
%13 = phi i32 [ %11, %8 ], [ 2147483647, %6 ], [ 2147483647, %4 ]
ret i32 %13
}