#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*/ printf(char *, ...);
int main() {
  unsigned short int allbits = -1;
  short int signedallbits = allbits;
  int unsignedtosigned = allbits;
  unsigned int unsignedtounsigned = allbits;
  int signedtosigned = signedallbits;
  unsigned int signedtounsigned = signedallbits;
  printf("unsignedtosigned: %d\n", unsignedtosigned);
  printf("unsignedtounsigned: %u\n", unsignedtounsigned);
  printf("signedtosigned: %d\n", signedtosigned);
  printf("signedtounsigned: %u\n", signedtounsigned);
  if (unsignedtosigned == 65535 && unsignedtounsigned == 65535 &&
      signedtosigned == -1 && signedtounsigned == 4294967295) {
    printf("UNSAFE \n");
    goto ERROR;
  }
  printf("SAFE\n");
  return (0);
ERROR:
  return (-1);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movw   $0xffff,-0x6(%rbp)
mov    -0x6(%rbp),%ax
mov    %ax,-0x8(%rbp)
movzwl -0x6(%rbp),%eax
mov    %eax,-0xc(%rbp)
movzwl -0x6(%rbp),%eax
mov    %eax,-0x10(%rbp)
movswl -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
movswl -0x8(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0xc(%rbp),%esi
lea    0xead(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%esi
lea    0xeb2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%esi
lea    0xe8d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%esi
lea    0xe92(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0xffff,-0xc(%rbp)
jne    11d5 <main+0xc5>
cmpl   $0xffff,-0x10(%rbp)
jne    11d5 <main+0xc5>
cmpl   $0xffffffff,-0x14(%rbp)
jne    11d5 <main+0xc5>
mov    -0x18(%rbp),%eax
mov    $0xffffffff,%ecx
cmp    %rcx,%rax
jne    11d5 <main+0xc5>
lea    0xe65(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11ef <main+0xdf>
lea    0xe5b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11f6 <main+0xe6>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0xed8(%rip),%rdi
mov    $0xffff,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xedb(%rip),%rdi
mov    $0xffff,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xeb4(%rip),%rdi
mov    $0xffffffff,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xeb7(%rip),%rdi
mov    $0xffffffff,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xeba(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [22 x i8] c"unsignedtosigned: %d\0A\00"
@.str.1 = [24 x i8] c"unsignedtounsigned: %u\0A\00"
@.str.2 = [20 x i8] c"signedtosigned: %d\0A\00"
@.str.3 = [22 x i8] c"signedtounsigned: %u\0A\00"
@.str.4 = [9 x i8] c"UNSAFE \0A\00"
@.str.5 = [6 x i8] c"SAFE\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i16
%3 = alloca i16
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
store i16 -1, i16* %2
%8 = load i16, i16* %2
store i16 %8, i16* %3
%9 = load i16, i16* %2
%10 = zext i16 %9 to i32
store i32 %10, i32* %4
%11 = load i16, i16* %2
%12 = zext i16 %11 to i32
store i32 %12, i32* %5
%13 = load i16, i16* %3
%14 = sext i16 %13 to i32
store i32 %14, i32* %6
%15 = load i16, i16* %3
%16 = sext i16 %15 to i32
store i32 %16, i32* %7
%17 = load i32, i32* %4
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %17)
%19 = load i32, i32* %5
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 %19)
%21 = load i32, i32* %6
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %21)
%23 = load i32, i32* %7
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32 %23)
%25 = load i32, i32* %4
%26 = icmp eq i32 %25, 65535
br i1 %26, label %27, label %39
27: ; preds = %0
%28 = load i32, i32* %5
%29 = icmp eq i32 %28, 65535
br i1 %29, label %30, label %39
30: ; preds = %27
%31 = load i32, i32* %6
%32 = icmp eq i32 %31, -1
br i1 %32, label %33, label %39
33: ; preds = %30
%34 = load i32, i32* %7
%35 = zext i32 %34 to i64
%36 = icmp eq i64 %35, 4294967295
br i1 %36, label %37, label %39
37: ; preds = %33
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
br label %41
39: ; preds = %33, %30, %27, %0
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %1
br label %42
41: ; preds = %37
store i32 -1, i32* %1
br label %42
42: ; preds = %41, %39
%43 = load i32, i32* %1
ret i32 %43
}

LLVM IR (-O2):
@.str = [22 x i8] c"unsignedtosigned: %d\0A\00"
@.str.1 = [24 x i8] c"unsignedtounsigned: %u\0A\00"
@.str.2 = [20 x i8] c"signedtosigned: %d\0A\00"
@.str.3 = [22 x i8] c"signedtounsigned: %u\0A\00"
@str = [8 x i8] c"UNSAFE \00"
define i32 @main() {
%1 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 65535)
%2 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 65535)
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 -1)
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32 -1)
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str, i64 0, i64 0))
ret i32 -1
}