#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 bitcount(unsigned int);
int getbits(unsigned int, int, int);
int /*<<< orphan*/ printf(char *, unsigned int, ...);
int signed_unary(int);
int unsigned_unary(unsigned int);
int main(void) {
  unsigned x = 0;
  int y = 2;
  int num = 7;
  int shift = 2;
  short int signed_short = 0;
  unsigned short int unsigned_short = 0;
  char s_char = 0;
  unsigned char u_char = 0;
  int p = 2;
  int n = 1;
  printf("~u_char: %hu \n", ~u_char);
  printf("%d and ~%d using %%d: %d \n", 0, 0, ~0);
  printf("%u and ~%u using %%u: %u \n", 0, 0, ~0);
  printf("Unsigned ~0: %u \n", ~0U);
  printf("Unsigned ~1: %u \n", ~1U);
  printf("Unsigned ~3: %u \n", ~3U);
  printf("%hd and ~%hd using %%hd: %hd \n", signed_short, signed_short,
         ~signed_short);
  printf("%hu and ~%hu using %%hu: %hu \n", unsigned_short, unsigned_short,
         ~unsigned_short);
  printf("%d << %d = %d \n", num, shift, num << shift);
  printf("%d >> %d = %d \n", num, shift, num >> shift);
  printf("x (%u) is unsigned so ~x is: %u \n", x, unsigned_unary(x));
  printf("y (%d) is int (signed by default) so ~y is: %d \n", y,
         signed_unary(y));
  printf("getbits(%d, %d, %d): %d\n", x, p, n, getbits(x, p, n));
  printf("bitcount(%d) (just duplicating for now): %d\n", x, bitcount(x));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x2,-0xc(%rbp)
movl   $0x7,-0x10(%rbp)
movl   $0x2,-0x14(%rbp)
movw   $0x0,-0x16(%rbp)
movw   $0x0,-0x18(%rbp)
movb   $0x0,-0x19(%rbp)
movb   $0x0,-0x1a(%rbp)
movl   $0x2,-0x20(%rbp)
movl   $0x1,-0x24(%rbp)
movzbl -0x1a(%rbp),%esi
xor    $0xffffffff,%esi
lea    0xe55(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe56(%rip),%rdi
xor    %edx,%edx
mov    $0xffffffff,%ecx
mov    %edx,%esi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe5a(%rip),%rdi
xor    %edx,%edx
mov    $0xffffffff,%ecx
mov    %edx,%esi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe5e(%rip),%rdi
mov    $0xffffffff,%esi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe5d(%rip),%rdi
mov    $0xfffffffe,%esi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe5c(%rip),%rdi
mov    $0xfffffffc,%esi
mov    $0x0,%al
call   1030 <printf@plt>
movswl -0x16(%rbp),%esi
movswl -0x16(%rbp),%edx
movswl -0x16(%rbp),%ecx
xor    $0xffffffff,%ecx
lea    0xe4c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movzwl -0x18(%rbp),%esi
movzwl -0x18(%rbp),%edx
movzwl -0x18(%rbp),%ecx
xor    $0xffffffff,%ecx
lea    0xe4e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    -0x10(%rbp),%eax
mov    -0x14(%rbp),%ecx
shl    %cl,%eax
mov    %eax,%ecx
lea    0xe4f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    -0x10(%rbp),%eax
mov    -0x14(%rbp),%ecx
sar    %cl,%eax
mov    %eax,%ecx
lea    0xe41(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x8(%rbp),%edi
call   1070 <unsigned_unary@plt>
mov    -0x3c(%rbp),%esi
mov    %eax,%edx
lea    0xe30(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0xc(%rbp),%edi
call   1060 <signed_unary@plt>
mov    -0x38(%rbp),%esi
mov    %eax,%edx
lea    0xe31(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x20(%rbp),%esi
mov    -0x24(%rbp),%edx
call   1050 <getbits@plt>
mov    -0x34(%rbp),%esi
mov    -0x30(%rbp),%edx
mov    -0x2c(%rbp),%ecx
mov    %eax,%r8d
lea    0xe28(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x8(%rbp),%edi
call   1040 <bitcount@plt>
mov    -0x28(%rbp),%esi
mov    %eax,%edx
lea    0xe20(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0xea8(%rip),%rdi
mov    $0xffffffff,%esi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xea4(%rip),%rdi
xor    %esi,%esi
xor    %edx,%edx
mov    $0xffffffff,%ecx
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xea8(%rip),%rdi
xor    %esi,%esi
xor    %edx,%edx
mov    $0xffffffff,%ecx
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xeac(%rip),%rdi
mov    $0xffffffff,%esi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xeab(%rip),%rdi
mov    $0xfffffffe,%esi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xeaa(%rip),%rdi
mov    $0xfffffffc,%esi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xea9(%rip),%rdi
xor    %esi,%esi
xor    %edx,%edx
mov    $0xffffffff,%ecx
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xeb1(%rip),%rdi
xor    %esi,%esi
xor    %edx,%edx
mov    $0xffffffff,%ecx
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xeb9(%rip),%rdi
mov    $0x7,%esi
mov    $0x2,%edx
mov    $0x1c,%ecx
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xeac(%rip),%rdi
mov    $0x7,%esi
mov    $0x2,%edx
mov    $0x1,%ecx
xor    %eax,%eax
call   1030 <printf@plt>
xor    %edi,%edi
call   1070 <unsigned_unary@plt>
lea    0xe98(%rip),%rdi
xor    %esi,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x2,%edi
call   1060 <signed_unary@plt>
lea    0xe9e(%rip),%rdi
mov    $0x2,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <printf@plt>
xor    %edi,%edi
mov    $0x2,%esi
mov    $0x1,%edx
call   1050 <getbits@plt>
lea    0xea9(%rip),%rdi
xor    %esi,%esi
mov    $0x2,%edx
mov    $0x1,%ecx
mov    %eax,%r8d
xor    %eax,%eax
call   1030 <printf@plt>
xor    %edi,%edi
call   1040 <bitcount@plt>
lea    0xe9e(%rip),%rdi
xor    %esi,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [15 x i8] c"~u_char: %hu \0A\00"
@.str.1 = [27 x i8] c"%d and ~%d using %%d: %d \0A\00"
@.str.2 = [27 x i8] c"%u and ~%u using %%u: %u \0A\00"
@.str.3 = [18 x i8] c"Unsigned ~0: %u \0A\00"
@.str.4 = [18 x i8] c"Unsigned ~1: %u \0A\00"
@.str.5 = [18 x i8] c"Unsigned ~3: %u \0A\00"
@.str.6 = [31 x i8] c"%hd and ~%hd using %%hd: %hd \0A\00"
@.str.7 = [31 x i8] c"%hu and ~%hu using %%hu: %hu \0A\00"
@.str.8 = [16 x i8] c"%d << %d = %d \0A\00"
@.str.9 = [16 x i8] c"%d >> %d = %d \0A\00"
@.str.10 = [34 x i8] c"x (%u) is unsigned so ~x is: %u \0A\00"
@.str.11 = [49 x i8] c"y (%d) is int (signed by default) so ~y is: %d \0A\00"
@.str.12 = [25 x i8] c"getbits(%d, %d, %d): %d\0A\00"
@.str.13 = [45 x i8] c"bitcount(%d) (just duplicating for now): %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i16
%7 = alloca i16
%8 = alloca i8
%9 = alloca i8
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %2
store i32 2, i32* %3
store i32 7, i32* %4
store i32 2, i32* %5
store i16 0, i16* %6
store i16 0, i16* %7
store i8 0, i8* %8
store i8 0, i8* %9
store i32 2, i32* %10
store i32 1, i32* %11
%12 = load i8, i8* %9
%13 = zext i8 %12 to i32
%14 = xor i32 %13, -1
%15 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %14)
%16 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 0, i32 0, i32 -1)
%17 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i32 0, i32 0, i32 -1)
%18 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i32 -1)
%19 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i32 -2)
%20 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i32 -4)
%21 = load i16, i16* %6
%22 = sext i16 %21 to i32
%23 = load i16, i16* %6
%24 = sext i16 %23 to i32
%25 = load i16, i16* %6
%26 = sext i16 %25 to i32
%27 = xor i32 %26, -1
%28 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.6, i64 0, i64 0), i32 %22, i32 %24, i32 %27)
%29 = load i16, i16* %7
%30 = zext i16 %29 to i32
%31 = load i16, i16* %7
%32 = zext i16 %31 to i32
%33 = load i16, i16* %7
%34 = zext i16 %33 to i32
%35 = xor i32 %34, -1
%36 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.7, i64 0, i64 0), i32 %30, i32 %32, i32 %35)
%37 = load i32, i32* %4
%38 = load i32, i32* %5
%39 = load i32, i32* %4
%40 = load i32, i32* %5
%41 = shl i32 %39, %40
%42 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.8, i64 0, i64 0), i32 %37, i32 %38, i32 %41)
%43 = load i32, i32* %4
%44 = load i32, i32* %5
%45 = load i32, i32* %4
%46 = load i32, i32* %5
%47 = ashr i32 %45, %46
%48 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.9, i64 0, i64 0), i32 %43, i32 %44, i32 %47)
%49 = load i32, i32* %2
%50 = load i32, i32* %2
%51 = call i32 @unsigned_unary(i32 %50)
%52 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.10, i64 0, i64 0), i32 %49, i32 %51)
%53 = load i32, i32* %3
%54 = load i32, i32* %3
%55 = call i32 @signed_unary(i32 %54)
%56 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.11, i64 0, i64 0), i32 %53, i32 %55)
%57 = load i32, i32* %2
%58 = load i32, i32* %10
%59 = load i32, i32* %11
%60 = load i32, i32* %2
%61 = load i32, i32* %10
%62 = load i32, i32* %11
%63 = call i32 @getbits(i32 %60, i32 %61, i32 %62)
%64 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.12, i64 0, i64 0), i32 %57, i32 %58, i32 %59, i32 %63)
%65 = load i32, i32* %2
%66 = load i32, i32* %2
%67 = call i32 @bitcount(i32 %66)
%68 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.13, i64 0, i64 0), i32 %65, i32 %67)
ret i32 0
}

LLVM IR (-O2):
@.str = [15 x i8] c"~u_char: %hu \0A\00"
@.str.1 = [27 x i8] c"%d and ~%d using %%d: %d \0A\00"
@.str.2 = [27 x i8] c"%u and ~%u using %%u: %u \0A\00"
@.str.3 = [18 x i8] c"Unsigned ~0: %u \0A\00"
@.str.4 = [18 x i8] c"Unsigned ~1: %u \0A\00"
@.str.5 = [18 x i8] c"Unsigned ~3: %u \0A\00"
@.str.6 = [31 x i8] c"%hd and ~%hd using %%hd: %hd \0A\00"
@.str.7 = [31 x i8] c"%hu and ~%hu using %%hu: %hu \0A\00"
@.str.8 = [16 x i8] c"%d << %d = %d \0A\00"
@.str.9 = [16 x i8] c"%d >> %d = %d \0A\00"
@.str.10 = [34 x i8] c"x (%u) is unsigned so ~x is: %u \0A\00"
@.str.11 = [49 x i8] c"y (%d) is int (signed by default) so ~y is: %d \0A\00"
@.str.12 = [25 x i8] c"getbits(%d, %d, %d): %d\0A\00"
@.str.13 = [45 x i8] c"bitcount(%d) (just duplicating for now): %d\0A\00"
define i32 @main() {
%1 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 -1)
%2 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 0, i32 0, i32 -1)
%3 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i32 0, i32 0, i32 -1)
%4 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i32 -1)
%5 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i32 -2)
%6 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i32 -4)
%7 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.6, i64 0, i64 0), i32 0, i32 0, i32 -1)
%8 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.7, i64 0, i64 0), i32 0, i32 0, i32 -1)
%9 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.8, i64 0, i64 0), i32 7, i32 2, i32 28)
%10 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.9, i64 0, i64 0), i32 7, i32 2, i32 1)
%11 = tail call i32 @unsigned_unary(i32 0)
%12 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.10, i64 0, i64 0), i32 0, i32 %11)
%13 = tail call i32 @signed_unary(i32 2)
%14 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.11, i64 0, i64 0), i32 2, i32 %13)
%15 = tail call i32 @getbits(i32 0, i32 2, i32 1)
%16 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.12, i64 0, i64 0), i32 0, i32 2, i32 1, i32 %15)
%17 = tail call i32 @bitcount(i32 0)
%18 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.13, i64 0, i64 0), i32 0, i32 %17)
ret i32 0
}