#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 INT_MAX;
int INT_MIN;
int /*<<< orphan*/ puts(char *);
void check_overflow(int num1, int num2) {
  if ((num2 > 0 && num1 > INT_MAX - num2) ||
      (num2 < 0 && num1 < INT_MIN - num2)) {
    puts("Warning: An addition over/under-flowed.");
  }
}


x86 assembly (clang, -O0):
<check_overflow>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jle    113f <check_overflow+0x2f>
mov    -0x4(%rbp),%eax
mov    0x2eb6(%rip),%rcx
mov    (%rcx),%ecx
sub    -0x8(%rbp),%ecx
cmp    %ecx,%eax
jg     1160 <check_overflow+0x50>
cmpl   $0x0,-0x8(%rbp)
jge    116c <check_overflow+0x5c>
mov    -0x4(%rbp),%eax
mov    0x2e8d(%rip),%rcx
mov    (%rcx),%ecx
sub    -0x8(%rbp),%ecx
cmp    %ecx,%eax
jge    116c <check_overflow+0x5c>
lea    0xe99(%rip),%rdi
call   1030 <puts@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_overflow>:
test   %esi,%esi
jle    1125 <check_overflow+0x15>
mov    0x2ecd(%rip),%rax
mov    (%rax),%eax
sub    %esi,%eax
cmp    %edi,%eax
jl     1136 <check_overflow+0x26>
jmp    1142 <check_overflow+0x32>
jns    1142 <check_overflow+0x32>
mov    0x2eb2(%rip),%rax
mov    (%rax),%eax
sub    %esi,%eax
cmp    %edi,%eax
jle    1142 <check_overflow+0x32>
lea    0xec3(%rip),%rdi
jmp    1030 <puts@plt>
ret

LLVM IR (-O0):
@INT_MAX = global i32 0
@INT_MIN = global i32 0
@.str = [40 x i8] c"Warning: An addition over/under-flowed.\00"
define void @check_overflow(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%5 = load i32, i32* %4
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %13
7: ; preds = %2
%8 = load i32, i32* %3
%9 = load i32, i32* @INT_MAX
%10 = load i32, i32* %4
%11 = sub nsw i32 %9, %10
%12 = icmp sgt i32 %8, %11
br i1 %12, label %22, label %13
13: ; preds = %7, %2
%14 = load i32, i32* %4
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %24
16: ; preds = %13
%17 = load i32, i32* %3
%18 = load i32, i32* @INT_MIN
%19 = load i32, i32* %4
%20 = sub nsw i32 %18, %19
%21 = icmp slt i32 %17, %20
br i1 %21, label %22, label %24
22: ; preds = %16, %7
%23 = call i32 @puts(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
br label %24
24: ; preds = %22, %16, %13
ret void
}

LLVM IR (-O2):
@INT_MAX = global i32 0
@INT_MIN = global i32 0
@.str = [40 x i8] c"Warning: An addition over/under-flowed.\00"
define void @check_overflow(i32 %0, i32 %1) {
%3 = icmp sgt i32 %1, 0
br i1 %3, label %4, label %8
4: ; preds = %2
%5 = load i32, i32* @INT_MAX
%6 = sub nsw i32 %5, %1
%7 = icmp slt i32 %6, %0
br i1 %7, label %14, label %16
8: ; preds = %2
%9 = icmp slt i32 %1, 0
br i1 %9, label %10, label %16
10: ; preds = %8
%11 = load i32, i32* @INT_MIN
%12 = sub nsw i32 %11, %1
%13 = icmp sgt i32 %12, %0
br i1 %13, label %14, label %16
14: ; preds = %10, %4
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
br label %16
16: ; preds = %4, %14, %10, %8
ret void
}