#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 EXIT_SUCCESS;
int INT_MAX;
int INT_MIN;
int check_overflow(int, int);
int /*<<< orphan*/ printf(char *, int, ...);
int sum(int, int);
int main(void) {
  int val1 = 2147483646;
  int val2 = 1;
  int val3 = 2;
  printf("MAX_INT: %11d\n", INT_MAX);
  printf("MIN_INT: %11d\n", INT_MIN);
  int res1 = check_overflow(val1, val2);
  printf("%d + %d = %11d (returns: %d)\n", val1, val2, val1 + val2, res1);
  int res2 = check_overflow(val1, val3);
  printf("%d + %d = %11d (resturns: %d - overflow)\n", val1, val3, val1 + val3,
         res2);
  int res3 = sum(val1, val2);
  printf("%d + %d = %11d (returns: %d)\n", val1, val2, val1 + val2, res3);
  int res4 = sum(val1, val3);
  printf("%d + %d = %11d (resturns: %d - overflow)\n", val1, val3, val1 + val3,
         res4);
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x7ffffffe,-0x8(%rbp)
movl   $0x1,-0xc(%rbp)
movl   $0x2,-0x10(%rbp)
mov    0x2e8d(%rip),%rax
mov    (%rax),%esi
lea    0xe9c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2e6e(%rip),%rax
mov    (%rax),%esi
lea    0xe94(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1030 <check_overflow@plt>
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
mov    -0x8(%rbp),%ecx
add    -0xc(%rbp),%ecx
mov    -0x14(%rbp),%r8d
lea    0xe77(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%esi
call   1030 <check_overflow@plt>
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x8(%rbp),%ecx
add    -0x10(%rbp),%ecx
mov    -0x18(%rbp),%r8d
lea    0xe69(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1050 <sum@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
mov    -0x8(%rbp),%ecx
add    -0xc(%rbp),%ecx
mov    -0x1c(%rbp),%r8d
lea    0xe1f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%esi
call   1050 <sum@plt>
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x8(%rbp),%ecx
add    -0x10(%rbp),%ecx
mov    -0x20(%rbp),%r8d
lea    0xe11(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2d97(%rip),%rax
mov    (%rax),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    0x2ead(%rip),%rax
mov    (%rax),%esi
lea    0xebc(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2e8e(%rip),%rax
mov    (%rax),%esi
lea    0xeb4(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x7ffffffe,%edi
mov    $0x1,%esi
call   1030 <check_overflow@plt>
lea    0xea6(%rip),%r14
mov    %r14,%rdi
mov    $0x7ffffffe,%esi
mov    $0x1,%edx
mov    $0x7fffffff,%ecx
mov    %eax,%r8d
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x7ffffffe,%edi
mov    $0x2,%esi
call   1030 <check_overflow@plt>
lea    0xe92(%rip),%rbx
mov    %rbx,%rdi
mov    $0x7ffffffe,%esi
mov    $0x2,%edx
mov    $0x80000000,%ecx
mov    %eax,%r8d
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x7ffffffe,%edi
mov    $0x1,%esi
call   1050 <sum@plt>
mov    %r14,%rdi
mov    $0x7ffffffe,%esi
mov    $0x1,%edx
mov    $0x7fffffff,%ecx
mov    %eax,%r8d
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x7ffffffe,%edi
mov    $0x2,%esi
call   1050 <sum@plt>
mov    %rbx,%rdi
mov    $0x7ffffffe,%esi
mov    $0x2,%edx
mov    $0x80000000,%ecx
mov    %eax,%r8d
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2dad(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [15 x i8] c"MAX_INT: %11d\0A\00"
@INT_MAX = global i32 0
@.str.1 = [15 x i8] c"MIN_INT: %11d\0A\00"
@INT_MIN = global i32 0
@.str.2 = [30 x i8] c"%d + %d = %11d (returns: %d)\0A\00"
@.str.3 = [42 x i8] c"%d + %d = %11d (resturns: %d - overflow)\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %1
store i32 2147483646, i32* %2
store i32 1, i32* %3
store i32 2, i32* %4
%9 = load i32, i32* @INT_MAX
%10 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = load i32, i32* @INT_MIN
%12 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %11)
%13 = load i32, i32* %2
%14 = load i32, i32* %3
%15 = call i32 @check_overflow(i32 %13, i32 %14)
store i32 %15, i32* %5
%16 = load i32, i32* %2
%17 = load i32, i32* %3
%18 = load i32, i32* %2
%19 = load i32, i32* %3
%20 = add nsw i32 %18, %19
%21 = load i32, i32* %5
%22 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i32 %16, i32 %17, i32 %20, i32 %21)
%23 = load i32, i32* %2
%24 = load i32, i32* %4
%25 = call i32 @check_overflow(i32 %23, i32 %24)
store i32 %25, i32* %6
%26 = load i32, i32* %2
%27 = load i32, i32* %4
%28 = load i32, i32* %2
%29 = load i32, i32* %4
%30 = add nsw i32 %28, %29
%31 = load i32, i32* %6
%32 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0), i32 %26, i32 %27, i32 %30, i32 %31)
%33 = load i32, i32* %2
%34 = load i32, i32* %3
%35 = call i32 @sum(i32 %33, i32 %34)
store i32 %35, i32* %7
%36 = load i32, i32* %2
%37 = load i32, i32* %3
%38 = load i32, i32* %2
%39 = load i32, i32* %3
%40 = add nsw i32 %38, %39
%41 = load i32, i32* %7
%42 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i32 %36, i32 %37, i32 %40, i32 %41)
%43 = load i32, i32* %2
%44 = load i32, i32* %4
%45 = call i32 @sum(i32 %43, i32 %44)
store i32 %45, i32* %8
%46 = load i32, i32* %2
%47 = load i32, i32* %4
%48 = load i32, i32* %2
%49 = load i32, i32* %4
%50 = add nsw i32 %48, %49
%51 = load i32, i32* %8
%52 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0), i32 %46, i32 %47, i32 %50, i32 %51)
%53 = load i32, i32* @EXIT_SUCCESS
ret i32 %53
}

LLVM IR (-O2):
@.str = [15 x i8] c"MAX_INT: %11d\0A\00"
@INT_MAX = global i32 0
@.str.1 = [15 x i8] c"MIN_INT: %11d\0A\00"
@INT_MIN = global i32 0
@.str.2 = [30 x i8] c"%d + %d = %11d (returns: %d)\0A\00"
@.str.3 = [42 x i8] c"%d + %d = %11d (resturns: %d - overflow)\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = load i32, i32* @INT_MAX
%2 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = load i32, i32* @INT_MIN
%4 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %3)
%5 = tail call i32 @check_overflow(i32 2147483646, i32 1)
%6 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i32 2147483646, i32 1, i32 2147483647, i32 %5)
%7 = tail call i32 @check_overflow(i32 2147483646, i32 2)
%8 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0), i32 2147483646, i32 2, i32 -2147483648, i32 %7)
%9 = tail call i32 @sum(i32 2147483646, i32 1)
%10 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i32 2147483646, i32 1, i32 2147483647, i32 %9)
%11 = tail call i32 @sum(i32 2147483646, i32 2)
%12 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0), i32 2147483646, i32 2, i32 -2147483648, i32 %11)
%13 = load i32, i32* @EXIT_SUCCESS
ret i32 %13
}