#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*/ printf(char *, ...);
int main(void) {
  int a = 0x7fffffff;
  int b = 3;
  size_t sum = a + b;
  if (a + b < 0) {
    printf("oops.. %d + %d = %d\n", a, b, a + b);
    printf("oops.. %d + %d = %zu\n", a, b, sum);
  }
  if (a > 0x7fffffff - b) {
    printf("There are integer overflow\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x7fffffff,-0x8(%rbp)
movl   $0x3,-0xc(%rbp)
mov    -0x8(%rbp),%eax
add    -0xc(%rbp),%eax
cltq
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%eax
add    -0xc(%rbp),%eax
cmp    $0x0,%eax
jge    117a <main+0x6a>
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
mov    -0x8(%rbp),%ecx
add    -0xc(%rbp),%ecx
lea    0xea5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
mov    -0x18(%rbp),%rcx
lea    0xea2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
mov    $0x7fffffff,%ecx
sub    -0xc(%rbp),%ecx
cmp    %ecx,%eax
jle    119b <main+0x8b>
lea    0xe97(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0xed8(%rip),%rdi
mov    $0x7fffffff,%esi
mov    $0x3,%edx
mov    $0x80000002,%ecx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xed0(%rip),%rdi
mov    $0x7fffffff,%esi
mov    $0x3,%edx
mov    $0xffffffff80000002,%rcx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xec7(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [21 x i8] c"oops.. %d + %d = %d\0A\00"
@.str.1 = [22 x i8] c"oops.. %d + %d = %zu\0A\00"
@.str.2 = [28 x i8] c"There are integer overflow\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i64
store i32 0, i32* %1
store i32 2147483647, i32* %2
store i32 3, i32* %3
%5 = load i32, i32* %2
%6 = load i32, i32* %3
%7 = add nsw i32 %5, %6
%8 = sext i32 %7 to i64
store i64 %8, i64* %4
%9 = load i32, i32* %2
%10 = load i32, i32* %3
%11 = add nsw i32 %9, %10
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %24
13: ; preds = %0
%14 = load i32, i32* %2
%15 = load i32, i32* %3
%16 = load i32, i32* %2
%17 = load i32, i32* %3
%18 = add nsw i32 %16, %17
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %14, i32 %15, i32 %18)
%20 = load i32, i32* %2
%21 = load i32, i32* %3
%22 = load i64, i64* %4
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %20, i32 %21, i64 %22)
br label %24
24: ; preds = %13, %0
%25 = load i32, i32* %2
%26 = load i32, i32* %3
%27 = sub nsw i32 2147483647, %26
%28 = icmp sgt i32 %25, %27
br i1 %28, label %29, label %31
29: ; preds = %24
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
br label %31
31: ; preds = %29, %24
ret i32 0
}

LLVM IR (-O2):
@.str = [21 x i8] c"oops.. %d + %d = %d\0A\00"
@.str.1 = [22 x i8] c"oops.. %d + %d = %zu\0A\00"
@str = [27 x i8] c"There are integer overflow\00"
define i32 @main() {
%1 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 2147483647, i32 3, i32 -2147483646)
%2 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 2147483647, i32 3, i64 -2147483646)
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str, i64 0, i64 0))
ret i32 0
}