#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 UINT_MAX;
int /*<<< orphan*/ printf(char *, unsigned int, ...);
scalar_t__ unsigned_check_overflow(unsigned int, unsigned int);
int main(void) {
  unsigned val1 = 4294967294U;
  unsigned val2 = 1;
  unsigned val3 = 2;
  printf("Max unsigned value: %u\n", UINT_MAX);
  if (unsigned_check_overflow(val1, val2))
    printf("%u + %u = %d\n", val1, val2, 1);
  if (unsigned_check_overflow(val1, val3) == 0)
    printf("%u + %u = %d (overflow)\n", val1, val3, 0);
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xfffffffe,-0x8(%rbp)
movl   $0x1,-0xc(%rbp)
movl   $0x2,-0x10(%rbp)
mov    0x2e9d(%rip),%rax
mov    (%rax),%esi
lea    0xeac(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1030 <unsigned_check_overflow@plt>
cmp    $0x0,%rax
je     1189 <main+0x69>
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
lea    0xe9b(%rip),%rdi
mov    $0x1,%ecx
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%esi
call   1030 <unsigned_check_overflow@plt>
cmp    $0x0,%rax
jne    11b4 <main+0x94>
mov    -0x8(%rbp),%esi
mov    -0x10(%rbp),%edx
lea    0xe7b(%rip),%rdi
xor    %ecx,%ecx
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2e1d(%rip),%rax
mov    (%rax),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
mov    0x2ec0(%rip),%rax
mov    (%rax),%esi
lea    0xecf(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xfffffffe,%edi
mov    $0x1,%esi
call   1030 <unsigned_check_overflow@plt>
test   %rax,%rax
je     1169 <main+0x49>
lea    0xec5(%rip),%rdi
mov    $0xfffffffe,%esi
mov    $0x1,%edx
mov    $0x1,%ecx
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xfffffffe,%edi
mov    $0x2,%esi
call   1030 <unsigned_check_overflow@plt>
test   %rax,%rax
jne    1197 <main+0x77>
lea    0xea2(%rip),%rdi
mov    $0xfffffffe,%esi
mov    $0x2,%edx
xor    %ecx,%ecx
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2e3a(%rip),%rax
mov    (%rax),%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [24 x i8] c"Max unsigned value: %u\0A\00"
@UINT_MAX = global i32 0
@.str.1 = [14 x i8] c"%u + %u = %d\0A\00"
@.str.2 = [25 x i8] c"%u + %u = %d (overflow)\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
store i32 -2, i32* %2
store i32 1, i32* %3
store i32 2, i32* %4
%5 = load i32, i32* @UINT_MAX
%6 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = load i32, i32* %2
%8 = load i32, i32* %3
%9 = call i64 @unsigned_check_overflow(i32 %7, i32 %8)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %15
11: ; preds = %0
%12 = load i32, i32* %2
%13 = load i32, i32* %3
%14 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %12, i32 %13, i32 1)
br label %15
15: ; preds = %11, %0
%16 = load i32, i32* %2
%17 = load i32, i32* %4
%18 = call i64 @unsigned_check_overflow(i32 %16, i32 %17)
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %24
20: ; preds = %15
%21 = load i32, i32* %2
%22 = load i32, i32* %4
%23 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i32 %21, i32 %22, i32 0)
br label %24
24: ; preds = %20, %15
%25 = load i32, i32* @EXIT_SUCCESS
ret i32 %25
}

LLVM IR (-O2):
@.str = [24 x i8] c"Max unsigned value: %u\0A\00"
@UINT_MAX = global i32 0
@.str.1 = [14 x i8] c"%u + %u = %d\0A\00"
@.str.2 = [25 x i8] c"%u + %u = %d (overflow)\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = load i32, i32* @UINT_MAX
%2 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = tail call i64 @unsigned_check_overflow(i32 -2, i32 1)
%4 = icmp eq i64 %3, 0
br i1 %4, label %7, label %5
5: ; preds = %0
%6 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 -2, i32 1, i32 1)
br label %7
7: ; preds = %5, %0
%8 = tail call i64 @unsigned_check_overflow(i32 -2, i32 2)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i32 -2, i32 2, i32 0)
br label %12
12: ; preds = %10, %7
%13 = load i32, i32* @EXIT_SUCCESS
ret i32 %13
}