#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*/ check(short volatile, int);
int main(void) {
  volatile int j = 0x7fffffff;
  volatile int i = -1;
  volatile int k = j + i;
  check(k, 2147483646);
  k = i + j;
  check(k, 2147483646);
  j--;
  check(j, 2147483646);
  i = 1;
  j = (-0x7fffffff - 1);
  k = i + j;
  check(k, -2147483647);
  k = j + i;
  check(k, -2147483647);
  j++;
  check(j, -2147483647);
  volatile signed char a = 0x7f;
  volatile signed char b = 1;
  volatile signed char c = a + b;
  check(c, -128);
  a++;
  check(a, -128);
  volatile short d = 0x7fff;
  volatile short e = 1;
  volatile short f = d + e;
  check(f, -32768);
  d++;
  check(d, -32768);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x7fffffff,-0x8(%rbp)
movl   $0xffffffff,-0xc(%rbp)
mov    -0x8(%rbp),%eax
mov    -0xc(%rbp),%ecx
add    %ecx,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    $0x7ffffffe,%esi
movswl %ax,%edi
call   1030 <check@plt>
mov    -0xc(%rbp),%eax
mov    -0x8(%rbp),%ecx
add    %ecx,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    $0x7ffffffe,%esi
movswl %ax,%edi
call   1030 <check@plt>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    $0x7ffffffe,%esi
movswl %ax,%edi
call   1030 <check@plt>
movl   $0x1,-0xc(%rbp)
movl   $0x80000000,-0x8(%rbp)
mov    -0xc(%rbp),%eax
mov    -0x8(%rbp),%ecx
add    %ecx,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    $0x80000001,%esi
movswl %ax,%edi
call   1030 <check@plt>
mov    -0x8(%rbp),%eax
mov    -0xc(%rbp),%ecx
add    %ecx,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    $0x80000001,%esi
movswl %ax,%edi
call   1030 <check@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    $0x80000001,%esi
movswl %ax,%edi
call   1030 <check@plt>
movb   $0x7f,-0x11(%rbp)
movb   $0x1,-0x12(%rbp)
mov    -0x11(%rbp),%al
movsbl %al,%eax
mov    -0x12(%rbp),%cl
movsbl %cl,%ecx
add    %ecx,%eax
mov    %al,-0x13(%rbp)
mov    -0x13(%rbp),%al
movsbl %al,%eax
mov    $0xffffff80,%esi
movswl %ax,%edi
call   1030 <check@plt>
mov    -0x11(%rbp),%al
add    $0x1,%al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
movsbl %al,%eax
mov    $0xffffff80,%esi
movswl %ax,%edi
call   1030 <check@plt>
movw   $0x7fff,-0x16(%rbp)
movw   $0x1,-0x18(%rbp)
mov    -0x16(%rbp),%ax
cwtl
mov    -0x18(%rbp),%cx
movswl %cx,%ecx
add    %ecx,%eax
mov    %ax,-0x1a(%rbp)
mov    -0x1a(%rbp),%ax
mov    $0xffff8000,%esi
movswl %ax,%edi
call   1030 <check@plt>
mov    -0x16(%rbp),%ax
add    $0x1,%ax
mov    %ax,-0x16(%rbp)
mov    -0x16(%rbp),%ax
mov    $0xffff8000,%esi
movswl %ax,%edi
call   1030 <check@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x18,%rsp
movl   $0x7fffffff,0x4(%rsp)
7f
movl   $0xffffffff,0x10(%rsp)
ff
mov    0x4(%rsp),%eax
add    0x10(%rsp),%eax
mov    %eax,0x8(%rsp)
mov    0x8(%rsp),%eax
movswl %ax,%edi
mov    $0x7ffffffe,%esi
call   1030 <check@plt>
mov    0x10(%rsp),%eax
add    0x4(%rsp),%eax
mov    %eax,0x8(%rsp)
mov    0x8(%rsp),%eax
movswl %ax,%edi
mov    $0x7ffffffe,%esi
call   1030 <check@plt>
addl   $0xffffffff,0x4(%rsp)
mov    0x4(%rsp),%eax
movswl %ax,%edi
mov    $0x7ffffffe,%esi
call   1030 <check@plt>
movl   $0x1,0x10(%rsp)
movl   $0x80000000,0x4(%rsp)
80
mov    0x10(%rsp),%eax
add    0x4(%rsp),%eax
mov    %eax,0x8(%rsp)
mov    0x8(%rsp),%eax
movswl %ax,%edi
mov    $0x80000001,%esi
call   1030 <check@plt>
mov    0x4(%rsp),%eax
add    0x10(%rsp),%eax
mov    %eax,0x8(%rsp)
mov    0x8(%rsp),%eax
movswl %ax,%edi
mov    $0x80000001,%esi
call   1030 <check@plt>
addl   $0x1,0x4(%rsp)
mov    0x4(%rsp),%eax
movswl %ax,%edi
mov    $0x80000001,%esi
call   1030 <check@plt>
movb   $0x7f,0x3(%rsp)
movb   $0x1,0xf(%rsp)
mov    0x3(%rsp),%al
add    0xf(%rsp),%al
mov    %al,0xe(%rsp)
movsbl 0xe(%rsp),%edi
mov    $0xffffff80,%esi
call   1030 <check@plt>
addb   $0x1,0x3(%rsp)
movsbl 0x3(%rsp),%edi
mov    $0xffffff80,%esi
call   1030 <check@plt>
movw   $0x7fff,0xc(%rsp)
movw   $0x1,0x16(%rsp)
movzwl 0xc(%rsp),%eax
add    0x16(%rsp),%ax
mov    %ax,0x14(%rsp)
movswl 0x14(%rsp),%edi
mov    $0xffff8000,%esi
call   1030 <check@plt>
addw   $0x1,0xc(%rsp)
movswl 0xc(%rsp),%edi
mov    $0xffff8000,%esi
call   1030 <check@plt>
xor    %eax,%eax
add    $0x18,%rsp
ret

LLVM IR (-O0):
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8
%6 = alloca i8
%7 = alloca i8
%8 = alloca i16
%9 = alloca i16
%10 = alloca i16
store i32 0, i32* %1
store volatile i32 2147483647, i32* %2
store volatile i32 -1, i32* %3
%11 = load volatile i32, i32* %2
%12 = load volatile i32, i32* %3
%13 = add nsw i32 %11, %12
store volatile i32 %13, i32* %4
%14 = load volatile i32, i32* %4
%15 = trunc i32 %14 to i16
%16 = call i32 @check(i16 signext %15, i32 2147483646)
%17 = load volatile i32, i32* %3
%18 = load volatile i32, i32* %2
%19 = add nsw i32 %17, %18
store volatile i32 %19, i32* %4
%20 = load volatile i32, i32* %4
%21 = trunc i32 %20 to i16
%22 = call i32 @check(i16 signext %21, i32 2147483646)
%23 = load volatile i32, i32* %2
%24 = add nsw i32 %23, -1
store volatile i32 %24, i32* %2
%25 = load volatile i32, i32* %2
%26 = trunc i32 %25 to i16
%27 = call i32 @check(i16 signext %26, i32 2147483646)
store volatile i32 1, i32* %3
store volatile i32 -2147483648, i32* %2
%28 = load volatile i32, i32* %3
%29 = load volatile i32, i32* %2
%30 = add nsw i32 %28, %29
store volatile i32 %30, i32* %4
%31 = load volatile i32, i32* %4
%32 = trunc i32 %31 to i16
%33 = call i32 @check(i16 signext %32, i32 -2147483647)
%34 = load volatile i32, i32* %2
%35 = load volatile i32, i32* %3
%36 = add nsw i32 %34, %35
store volatile i32 %36, i32* %4
%37 = load volatile i32, i32* %4
%38 = trunc i32 %37 to i16
%39 = call i32 @check(i16 signext %38, i32 -2147483647)
%40 = load volatile i32, i32* %2
%41 = add nsw i32 %40, 1
store volatile i32 %41, i32* %2
%42 = load volatile i32, i32* %2
%43 = trunc i32 %42 to i16
%44 = call i32 @check(i16 signext %43, i32 -2147483647)
store volatile i8 127, i8* %5
store volatile i8 1, i8* %6
%45 = load volatile i8, i8* %5
%46 = sext i8 %45 to i32
%47 = load volatile i8, i8* %6
%48 = sext i8 %47 to i32
%49 = add nsw i32 %46, %48
%50 = trunc i32 %49 to i8
store volatile i8 %50, i8* %7
%51 = load volatile i8, i8* %7
%52 = sext i8 %51 to i16
%53 = call i32 @check(i16 signext %52, i32 -128)
%54 = load volatile i8, i8* %5
%55 = add i8 %54, 1
store volatile i8 %55, i8* %5
%56 = load volatile i8, i8* %5
%57 = sext i8 %56 to i16
%58 = call i32 @check(i16 signext %57, i32 -128)
store volatile i16 32767, i16* %8
store volatile i16 1, i16* %9
%59 = load volatile i16, i16* %8
%60 = sext i16 %59 to i32
%61 = load volatile i16, i16* %9
%62 = sext i16 %61 to i32
%63 = add nsw i32 %60, %62
%64 = trunc i32 %63 to i16
store volatile i16 %64, i16* %10
%65 = load volatile i16, i16* %10
%66 = call i32 @check(i16 signext %65, i32 -32768)
%67 = load volatile i16, i16* %8
%68 = add i16 %67, 1
store volatile i16 %68, i16* %8
%69 = load volatile i16, i16* %8
%70 = call i32 @check(i16 signext %69, i32 -32768)
ret i32 0
}

LLVM IR (-O2):
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8
%5 = alloca i8
%6 = alloca i8
%7 = alloca i16
%8 = alloca i16
%9 = alloca i16
%10 = bitcast i32* %1 to i8*
store volatile i32 2147483647, i32* %1
%11 = bitcast i32* %2 to i8*
store volatile i32 -1, i32* %2
%12 = bitcast i32* %3 to i8*
%13 = load volatile i32, i32* %1
%14 = load volatile i32, i32* %2
%15 = add nsw i32 %14, %13
store volatile i32 %15, i32* %3
%16 = load volatile i32, i32* %3
%17 = trunc i32 %16 to i16
%18 = tail call i32 @check(i16 signext %17, i32 2147483646)
%19 = load volatile i32, i32* %2
%20 = load volatile i32, i32* %1
%21 = add nsw i32 %20, %19
store volatile i32 %21, i32* %3
%22 = load volatile i32, i32* %3
%23 = trunc i32 %22 to i16
%24 = tail call i32 @check(i16 signext %23, i32 2147483646)
%25 = load volatile i32, i32* %1
%26 = add nsw i32 %25, -1
store volatile i32 %26, i32* %1
%27 = load volatile i32, i32* %1
%28 = trunc i32 %27 to i16
%29 = tail call i32 @check(i16 signext %28, i32 2147483646)
store volatile i32 1, i32* %2
store volatile i32 -2147483648, i32* %1
%30 = load volatile i32, i32* %2
%31 = load volatile i32, i32* %1
%32 = add nsw i32 %31, %30
store volatile i32 %32, i32* %3
%33 = load volatile i32, i32* %3
%34 = trunc i32 %33 to i16
%35 = tail call i32 @check(i16 signext %34, i32 -2147483647)
%36 = load volatile i32, i32* %1
%37 = load volatile i32, i32* %2
%38 = add nsw i32 %37, %36
store volatile i32 %38, i32* %3
%39 = load volatile i32, i32* %3
%40 = trunc i32 %39 to i16
%41 = tail call i32 @check(i16 signext %40, i32 -2147483647)
%42 = load volatile i32, i32* %1
%43 = add nsw i32 %42, 1
store volatile i32 %43, i32* %1
%44 = load volatile i32, i32* %1
%45 = trunc i32 %44 to i16
%46 = tail call i32 @check(i16 signext %45, i32 -2147483647)
store volatile i8 127, i8* %4
store volatile i8 1, i8* %5
%47 = load volatile i8, i8* %4
%48 = load volatile i8, i8* %5
%49 = add i8 %48, %47
store volatile i8 %49, i8* %6
%50 = load volatile i8, i8* %6
%51 = sext i8 %50 to i16
%52 = tail call i32 @check(i16 signext %51, i32 -128)
%53 = load volatile i8, i8* %4
%54 = add i8 %53, 1
store volatile i8 %54, i8* %4
%55 = load volatile i8, i8* %4
%56 = sext i8 %55 to i16
%57 = tail call i32 @check(i16 signext %56, i32 -128)
%58 = bitcast i16* %7 to i8*
store volatile i16 32767, i16* %7
%59 = bitcast i16* %8 to i8*
store volatile i16 1, i16* %8
%60 = bitcast i16* %9 to i8*
%61 = load volatile i16, i16* %7
%62 = load volatile i16, i16* %8
%63 = add i16 %62, %61
store volatile i16 %63, i16* %9
%64 = load volatile i16, i16* %9
%65 = tail call i32 @check(i16 signext %64, i32 -32768)
%66 = load volatile i16, i16* %7
%67 = add i16 %66, 1
store volatile i16 %67, i16* %7
%68 = load volatile i16, i16* %7
%69 = tail call i32 @check(i16 signext %68, i32 -32768)
ret i32 0
}