#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 /*<<< orphan*/ printf(char *, unsigned short);
int main(void) {
  unsigned short us_num1 = ~0;
  unsigned short us_num2 = 65536;
  unsigned short us_num3 = us_num1 + 1;
  printf("(unsigned short) max value = %d\n", us_num1);
  printf("(unsigned short) 65536 = %d (overflow)\n", us_num2);
  printf("(unsigned short) max value + 1 = %d (overflow)\n", us_num3);
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movw   $0xffff,-0x6(%rbp)
movw   $0x0,-0x8(%rbp)
movzwl -0x6(%rbp),%eax
add    $0x1,%eax
mov    %ax,-0xa(%rbp)
lea    0xec3(%rip),%rdi
movzwl -0x6(%rbp),%esi
call   1030 <printf@plt>
lea    0xed4(%rip),%rdi
movzwl -0x8(%rbp),%esi
call   1030 <printf@plt>
lea    0xeec(%rip),%rdi
movzwl -0xa(%rbp),%esi
call   1030 <printf@plt>
mov    0x2e73(%rip),%rax
mov    (%rax),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0xee8(%rip),%rdi
mov    $0xffff,%esi
call   1030 <printf@plt>
lea    0xef8(%rip),%rdi
xor    %esi,%esi
call   1030 <printf@plt>
lea    0xf12(%rip),%rdi
xor    %esi,%esi
call   1030 <printf@plt>
mov    0x2e9b(%rip),%rax
mov    (%rax),%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [33 x i8] c"(unsigned short) max value = %d\0A\00"
@.str.1 = [40 x i8] c"(unsigned short) 65536 = %d (overflow)\0A\00"
@.str.2 = [48 x i8] c"(unsigned short) max value + 1 = %d (overflow)\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i16
%3 = alloca i16
%4 = alloca i16
store i32 0, i32* %1
store i16 -1, i16* %2
store i16 0, i16* %3
%5 = load i16, i16* %2
%6 = zext i16 %5 to i32
%7 = add nsw i32 %6, 1
%8 = trunc i32 %7 to i16
store i16 %8, i16* %4
%9 = load i16, i16* %2
%10 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i16 zeroext %9)
%11 = load i16, i16* %3
%12 = call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), i16 zeroext %11)
%13 = load i16, i16* %4
%14 = call i32 @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.2, i64 0, i64 0), i16 zeroext %13)
%15 = load i32, i32* @EXIT_SUCCESS
ret i32 %15
}

LLVM IR (-O2):
@.str = [33 x i8] c"(unsigned short) max value = %d\0A\00"
@.str.1 = [40 x i8] c"(unsigned short) 65536 = %d (overflow)\0A\00"
@.str.2 = [48 x i8] c"(unsigned short) max value + 1 = %d (overflow)\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = tail call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i16 zeroext -1)
%2 = tail call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), i16 zeroext 0)
%3 = tail call i32 @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.2, i64 0, i64 0), i16 zeroext 0)
%4 = load i32, i32* @EXIT_SUCCESS
ret i32 %4
}