#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 check_overflow(int, int);
int /*<<< orphan*/ printf(char *, int, int, int);
int main(void) {
  int val1 = 900000000;
  int val2 = 2;
  int val3 = val2 + 1;
  int res1 = check_overflow(val1, val2);
  int res2 = check_overflow(val1, val3);
  if (res1)
    printf("%d * %d = %d\n", val1, val2, val1 * val2);
  else
    printf("%d * %d = %d (Err: Integer Overflow)\n", val1, val2, val1 * val2);
  if (res2)
    printf("%d * %d = %d\n", val1, val3, val1 * val3);
  else
    printf("%d * %d = %d (Err: Integer Overflow)\n", val1, val3, val1 * val3);
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x35a4e900,-0x8(%rbp)
movl   $0x2,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1030 <check_overflow@plt>
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%esi
call   1030 <check_overflow@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     118a <main+0x6a>
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
mov    -0x8(%rbp),%ecx
imul   -0xc(%rbp),%ecx
lea    0xe80(%rip),%rdi
call   1040 <printf@plt>
jmp    11a3 <main+0x83>
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
mov    -0x8(%rbp),%ecx
imul   -0xc(%rbp),%ecx
lea    0xe70(%rip),%rdi
call   1040 <printf@plt>
cmpl   $0x0,-0x18(%rbp)
je     11cb <main+0xab>
mov    -0x8(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x8(%rbp),%ecx
imul   -0x10(%rbp),%ecx
lea    0xe3f(%rip),%rdi
call   1040 <printf@plt>
jmp    11e4 <main+0xc4>
mov    -0x8(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x8(%rbp),%ecx
imul   -0x10(%rbp),%ecx
lea    0xe2f(%rip),%rdi
call   1040 <printf@plt>
mov    0x2df5(%rip),%rax
mov    (%rax),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    $0x35a4e900,%edi
mov    $0x2,%esi
call   1030 <check_overflow@plt>
mov    %eax,%ebx
mov    $0x35a4e900,%edi
mov    $0x3,%esi
call   1030 <check_overflow@plt>
mov    %eax,%ebp
test   %ebx,%ebx
lea    0xebf(%rip),%r14
lea    0xeaa(%rip),%rbx
mov    %rbx,%rdi
cmove  %r14,%rdi
mov    $0x35a4e900,%esi
mov    $0x2,%edx
mov    $0x6b49d200,%ecx
call   1040 <printf@plt>
test   %ebp,%ebp
cmove  %r14,%rbx
mov    %rbx,%rdi
mov    $0x35a4e900,%esi
mov    $0x3,%edx
mov    $0xa0eebb00,%ecx
call   1040 <printf@plt>
mov    0x2e4b(%rip),%rax
mov    (%rax),%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"%d * %d = %d\0A\00"
@.str.1 = [38 x i8] c"%d * %d = %d (Err: Integer 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
store i32 0, i32* %1
store i32 900000000, i32* %2
store i32 2, i32* %3
%7 = load i32, i32* %3
%8 = add nsw i32 %7, 1
store i32 %8, i32* %4
%9 = load i32, i32* %2
%10 = load i32, i32* %3
%11 = call i32 @check_overflow(i32 %9, i32 %10)
store i32 %11, i32* %5
%12 = load i32, i32* %2
%13 = load i32, i32* %4
%14 = call i32 @check_overflow(i32 %12, i32 %13)
store i32 %14, i32* %6
%15 = load i32, i32* %5
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %24
17: ; preds = %0
%18 = load i32, i32* %2
%19 = load i32, i32* %3
%20 = load i32, i32* %2
%21 = load i32, i32* %3
%22 = mul nsw i32 %20, %21
%23 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %18, i32 %19, i32 %22)
br label %31
24: ; preds = %0
%25 = load i32, i32* %2
%26 = load i32, i32* %3
%27 = load i32, i32* %2
%28 = load i32, i32* %3
%29 = mul nsw i32 %27, %28
%30 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i32 %25, i32 %26, i32 %29)
br label %31
31: ; preds = %24, %17
%32 = load i32, i32* %6
%33 = icmp ne i32 %32, 0
br i1 %33, label %34, label %41
34: ; preds = %31
%35 = load i32, i32* %2
%36 = load i32, i32* %4
%37 = load i32, i32* %2
%38 = load i32, i32* %4
%39 = mul nsw i32 %37, %38
%40 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %35, i32 %36, i32 %39)
br label %48
41: ; preds = %31
%42 = load i32, i32* %2
%43 = load i32, i32* %4
%44 = load i32, i32* %2
%45 = load i32, i32* %4
%46 = mul nsw i32 %44, %45
%47 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i32 %42, i32 %43, i32 %46)
br label %48
48: ; preds = %41, %34
%49 = load i32, i32* @EXIT_SUCCESS
ret i32 %49
}

LLVM IR (-O2):
@.str = [14 x i8] c"%d * %d = %d\0A\00"
@.str.1 = [38 x i8] c"%d * %d = %d (Err: Integer Overflow)\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = tail call i32 @check_overflow(i32 900000000, i32 2)
%2 = tail call i32 @check_overflow(i32 900000000, i32 3)
%3 = icmp eq i32 %1, 0
%4 = select i1 %3, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0)
%5 = tail call i32 @printf(i8* %4, i32 900000000, i32 2, i32 1800000000)
%6 = icmp eq i32 %2, 0
%7 = select i1 %6, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0)
%8 = tail call i32 @printf(i8* %7, i32 900000000, i32 3, i32 -1594967296)
%9 = load i32, i32* @EXIT_SUCCESS
ret i32 %9
}