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


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xffffffff,-0x8(%rbp)
movl   $0x80000000,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    -0x8(%rbp),%ecx
sub    %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
sub    %ecx,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    $0x7fffffff,%esi
movswl %ax,%edi
call   1030 <check@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x80000001,%esi
movswl %ax,%edi
call   1030 <check@plt>
movl   $0x1,-0x8(%rbp)
movl   $0x7fffffff,-0xc(%rbp)
mov    -0x8(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    %ecx,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    $0x80000002,%esi
movswl %ax,%edi
call   1030 <check@plt>
mov    -0xc(%rbp),%eax
mov    -0x8(%rbp),%ecx
sub    %ecx,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    $0x7ffffffe,%esi
movswl %ax,%edi
call   1030 <check@plt>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%eax
mov    $0x7ffffffe,%esi
movswl %ax,%edi
call   1030 <check@plt>
movb   $0x80,-0x11(%rbp)
movb   $0x1,-0x12(%rbp)
mov    -0x11(%rbp),%al
movsbl %al,%eax
mov    -0x12(%rbp),%cl
movsbl %cl,%ecx
sub    %ecx,%eax
mov    %al,-0x13(%rbp)
mov    -0x13(%rbp),%al
movsbl %al,%eax
mov    $0x7f,%esi
movswl %ax,%edi
call   1030 <check@plt>
mov    -0x11(%rbp),%al
add    $0xff,%al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
movsbl %al,%eax
mov    $0x7f,%esi
movswl %ax,%edi
call   1030 <check@plt>
movw   $0x8000,-0x16(%rbp)
movw   $0x1,-0x18(%rbp)
mov    -0x16(%rbp),%ax
cwtl
mov    -0x18(%rbp),%cx
movswl %cx,%ecx
sub    %ecx,%eax
mov    %ax,-0x1a(%rbp)
mov    -0x1a(%rbp),%ax
mov    $0x7fff,%esi
movswl %ax,%edi
call   1030 <check@plt>
mov    -0x16(%rbp),%ax
add    $0xffff,%ax
mov    %ax,-0x16(%rbp)
mov    -0x16(%rbp),%ax
mov    $0x7fff,%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   $0xffffffff,0x10(%rsp)
ff
movl   $0x80000000,0x8(%rsp)
80
mov    0x8(%rsp),%eax
sub    0x10(%rsp),%eax
mov    %eax,0x4(%rsp)
mov    0x4(%rsp),%eax
movswl %ax,%edi
mov    $0x80000001,%esi
call   1030 <check@plt>
mov    0x10(%rsp),%eax
sub    0x8(%rsp),%eax
mov    %eax,0x4(%rsp)
mov    0x4(%rsp),%eax
movswl %ax,%edi
mov    $0x7fffffff,%esi
call   1030 <check@plt>
addl   $0x1,0x8(%rsp)
mov    0x8(%rsp),%eax
movswl %ax,%edi
mov    $0x80000001,%esi
call   1030 <check@plt>
movl   $0x1,0x10(%rsp)
movl   $0x7fffffff,0x8(%rsp)
7f
mov    0x10(%rsp),%eax
sub    0x8(%rsp),%eax
mov    %eax,0x4(%rsp)
mov    0x4(%rsp),%eax
movswl %ax,%edi
mov    $0x80000002,%esi
call   1030 <check@plt>
mov    0x8(%rsp),%eax
sub    0x10(%rsp),%eax
mov    %eax,0x4(%rsp)
mov    0x4(%rsp),%eax
movswl %ax,%edi
mov    $0x7ffffffe,%esi
call   1030 <check@plt>
addl   $0xffffffff,0x8(%rsp)
mov    0x4(%rsp),%eax
movswl %ax,%edi
mov    $0x7ffffffe,%esi
call   1030 <check@plt>
movb   $0x80,0x3(%rsp)
movb   $0x1,0xf(%rsp)
mov    0x3(%rsp),%al
sub    0xf(%rsp),%al
mov    %al,0xe(%rsp)
movsbl 0xe(%rsp),%edi
mov    $0x7f,%esi
call   1030 <check@plt>
addb   $0xff,0x3(%rsp)
movsbl 0x3(%rsp),%edi
mov    $0x7f,%esi
call   1030 <check@plt>
movw   $0x8000,0xc(%rsp)
movw   $0x1,0x16(%rsp)
movzwl 0xc(%rsp),%eax
sub    0x16(%rsp),%ax
mov    %ax,0x14(%rsp)
movswl 0x14(%rsp),%edi
mov    $0x7fff,%esi
call   1030 <check@plt>
addw   $0xffff,0xc(%rsp)
movswl 0xc(%rsp),%edi
mov    $0x7fff,%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 -1, i32* %2
store volatile i32 -2147483648, i32* %3
%11 = load volatile i32, i32* %3
%12 = load volatile i32, i32* %2
%13 = sub 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 -2147483647)
%17 = load volatile i32, i32* %2
%18 = load volatile i32, i32* %3
%19 = sub 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 2147483647)
%23 = load volatile i32, i32* %3
%24 = add nsw i32 %23, 1
store volatile i32 %24, i32* %3
%25 = load volatile i32, i32* %3
%26 = trunc i32 %25 to i16
%27 = call i32 @check(i16 signext %26, i32 -2147483647)
store volatile i32 1, i32* %2
store volatile i32 2147483647, i32* %3
%28 = load volatile i32, i32* %2
%29 = load volatile i32, i32* %3
%30 = sub 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 -2147483646)
%34 = load volatile i32, i32* %3
%35 = load volatile i32, i32* %2
%36 = sub 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 2147483646)
%40 = load volatile i32, i32* %3
%41 = add nsw i32 %40, -1
store volatile i32 %41, i32* %3
%42 = load volatile i32, i32* %4
%43 = trunc i32 %42 to i16
%44 = call i32 @check(i16 signext %43, i32 2147483646)
store volatile i8 -128, 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 = sub 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 127)
%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 127)
store volatile i16 -32768, 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 = sub 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 32767)
%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 32767)
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 -1, i32* %1
%11 = bitcast i32* %2 to i8*
store volatile i32 -2147483648, i32* %2
%12 = bitcast i32* %3 to i8*
%13 = load volatile i32, i32* %2
%14 = load volatile i32, i32* %1
%15 = sub nsw i32 %13, %14
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 -2147483647)
%19 = load volatile i32, i32* %1
%20 = load volatile i32, i32* %2
%21 = sub nsw i32 %19, %20
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 2147483647)
%25 = load volatile i32, i32* %2
%26 = add nsw i32 %25, 1
store volatile i32 %26, i32* %2
%27 = load volatile i32, i32* %2
%28 = trunc i32 %27 to i16
%29 = tail call i32 @check(i16 signext %28, i32 -2147483647)
store volatile i32 1, i32* %1
store volatile i32 2147483647, i32* %2
%30 = load volatile i32, i32* %1
%31 = load volatile i32, i32* %2
%32 = sub nsw i32 %30, %31
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 -2147483646)
%36 = load volatile i32, i32* %2
%37 = load volatile i32, i32* %1
%38 = sub nsw i32 %36, %37
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 2147483646)
%42 = load volatile i32, i32* %2
%43 = add nsw i32 %42, -1
store volatile i32 %43, i32* %2
%44 = load volatile i32, i32* %3
%45 = trunc i32 %44 to i16
%46 = tail call i32 @check(i16 signext %45, i32 2147483646)
store volatile i8 -128, i8* %4
store volatile i8 1, i8* %5
%47 = load volatile i8, i8* %4
%48 = load volatile i8, i8* %5
%49 = sub i8 %47, %48
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 127)
%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 127)
%58 = bitcast i16* %7 to i8*
store volatile i16 -32768, 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 = sub i16 %61, %62
store volatile i16 %63, i16* %9
%64 = load volatile i16, i16* %9
%65 = tail call i32 @check(i16 signext %64, i32 32767)
%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 32767)
ret i32 0
}