#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 */
typedef int uint16_t;
typedef int int16_t;

/* Variables and functions */
int CharToInt(char *);
int CntBits(int);
int ExtractDay(int);
int ExtractMonth(int);
int ExtractYear(int);
int ROL(int);
int ROR(int);
scalar_t__ TestBit(int, int);
int ToDate(unsigned char, unsigned char, int);
int /*<<< orphan*/ printf(char *, ...);
int tolower(char);
int toupper(char);
int main() {
  char lower = 'e';
  char upper = 'E';
  printf("toupper(%c) = %c\n", lower, toupper(lower));
  printf("tolower(%c) = %c\n\n", upper, tolower(upper));
  char *number = "123";
  printf("CharToInt(\"%s\") = %d\n\n", number, CharToInt(number));
  unsigned char month = 7;
  unsigned char day = 9;
  uint16_t year = 2014;
  uint16_t date = ToDate(month, day, year);
  printf("Date in: %d/%d/%d\n", month, day, year);
  printf("Packed value: 0x%X\n", date);
  printf("Date out: %d/%d/%d\n\n", ExtractMonth(date), ExtractDay(date),
         ExtractYear(date));
  int nbits = CntBits(date);
  printf("Bits set in 0x%X: %d\n\n", date, nbits);
  int bit = 4;
  int n = 2;
  printf("TestBit(0x%X, %d) = %s\n\n", bit, n,
         TestBit(bit, n) ? "true" : "false");
  int16_t rotate = -3;
  printf("ROR(0x%X) = %d\n", rotate, ROR(rotate));
  printf("ROL(0x%X) = %d\n\n", rotate, ROL(rotate));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
movb   $0x65,-0x5(%rbp)
movb   $0x45,-0x6(%rbp)
movsbl -0x5(%rbp),%eax
mov    %eax,-0x58(%rbp)
movsbl -0x5(%rbp),%edi
call   1030 <toupper@plt>
mov    -0x58(%rbp),%esi
mov    %eax,%edx
lea    0xe0d(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movsbl -0x6(%rbp),%eax
mov    %eax,-0x54(%rbp)
movsbl -0x6(%rbp),%edi
call   10b0 <tolower@plt>
mov    -0x54(%rbp),%esi
mov    %eax,%edx
lea    0xdfc(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    0xe01(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x10(%rbp),%rdi
call   1080 <CharToInt@plt>
mov    -0x50(%rbp),%rsi
mov    %eax,%edx
lea    0xde3(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movb   $0x7,-0x11(%rbp)
movb   $0x9,-0x12(%rbp)
movl   $0x7de,-0x18(%rbp)
mov    -0x11(%rbp),%cl
mov    -0x12(%rbp),%al
mov    -0x18(%rbp),%edx
movzbl %cl,%edi
movzbl %al,%esi
call   10a0 <ToDate@plt>
mov    %eax,-0x1c(%rbp)
movzbl -0x11(%rbp),%esi
movzbl -0x12(%rbp),%edx
mov    -0x18(%rbp),%ecx
lea    0xdbb(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x1c(%rbp),%esi
lea    0xdbd(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x1c(%rbp),%edi
call   10d0 <ExtractMonth@plt>
mov    %eax,-0x44(%rbp)
mov    -0x1c(%rbp),%edi
call   1040 <ExtractDay@plt>
mov    %eax,-0x40(%rbp)
mov    -0x1c(%rbp),%edi
call   1050 <ExtractYear@plt>
mov    -0x44(%rbp),%esi
mov    -0x40(%rbp),%edx
mov    %eax,%ecx
lea    0xd9d(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x1c(%rbp),%edi
call   1060 <CntBits@plt>
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%esi
mov    -0x20(%rbp),%edx
lea    0xd93(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x4,-0x24(%rbp)
movl   $0x2,-0x28(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x28(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x24(%rbp),%edi
mov    -0x28(%rbp),%esi
call   1090 <TestBit@plt>
mov    -0x3c(%rbp),%esi
mov    -0x38(%rbp),%edx
mov    %rax,%rdi
lea    0xd8c(%rip),%rcx
lea    0xd80(%rip),%rax
cmp    $0x0,%rdi
cmovne %rax,%rcx
lea    0xd58(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0xfffffffd,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x2c(%rbp),%edi
call   10e0 <ROR@plt>
mov    -0x34(%rbp),%esi
mov    %eax,%edx
lea    0xd54(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x2c(%rbp),%edi
call   10c0 <ROL@plt>
mov    -0x30(%rbp),%esi
mov    %eax,%edx
lea    0xd43(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    $0x65,%edi
call   1030 <toupper@plt>
lea    0xe2b(%rip),%rdi
mov    $0x65,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0x45,%edi
call   10b0 <tolower@plt>
lea    0xe1e(%rip),%rdi
mov    $0x45,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xe1c(%rip),%rbx
mov    %rbx,%rdi
call   1080 <CharToInt@plt>
lea    0xe11(%rip),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0x7,%edi
mov    $0x9,%esi
mov    $0x7de,%edx
call   10a0 <ToDate@plt>
mov    %eax,%ebx
lea    0xdff(%rip),%rdi
mov    $0x7,%esi
mov    $0x9,%edx
mov    $0x7de,%ecx
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xdf5(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %ebx,%edi
call   10d0 <ExtractMonth@plt>
mov    %eax,%r14d
mov    %ebx,%edi
call   1040 <ExtractDay@plt>
mov    %eax,%ebp
mov    %ebx,%edi
call   1050 <ExtractYear@plt>
lea    0xddf(%rip),%rdi
mov    %r14d,%esi
mov    %ebp,%edx
mov    %eax,%ecx
xor    %eax,%eax
call   1070 <printf@plt>
mov    %ebx,%edi
call   1060 <CntBits@plt>
lea    0xdd8(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0x4,%edi
mov    $0x2,%esi
call   1090 <TestBit@plt>
test   %rax,%rax
lea    0xde9(%rip),%rax
lea    0xddd(%rip),%rcx
cmove  %rax,%rcx
lea    0xdb9(%rip),%rdi
mov    $0x4,%esi
mov    $0x2,%edx
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0xfffffffd,%edi
call   10e0 <ROR@plt>
lea    0xdbb(%rip),%rdi
mov    $0xfffffffd,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0xfffffffd,%edi
call   10c0 <ROL@plt>
lea    0xdac(%rip),%rdi
mov    $0xfffffffd,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1070 <printf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [18 x i8] c"toupper(%c) = %c\0A\00"
@.str.1 = [19 x i8] c"tolower(%c) = %c\0A\0A\00"
@.str.2 = [4 x i8] c"123\00"
@.str.3 = [23 x i8] c"CharToInt(\22%s\22) = %d\0A\0A\00"
@.str.4 = [19 x i8] c"Date in: %d/%d/%d\0A\00"
@.str.5 = [20 x i8] c"Packed value: 0x%X\0A\00"
@.str.6 = [21 x i8] c"Date out: %d/%d/%d\0A\0A\00"
@.str.7 = [23 x i8] c"Bits set in 0x%X: %d\0A\0A\00"
@.str.8 = [25 x i8] c"TestBit(0x%X, %d) = %s\0A\0A\00"
@.str.9 = [5 x i8] c"true\00"
@.str.10 = [6 x i8] c"false\00"
@.str.11 = [16 x i8] c"ROR(0x%X) = %d\0A\00"
@.str.12 = [17 x i8] c"ROL(0x%X) = %d\0A\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8
%3 = alloca i8
%4 = alloca i8*
%5 = alloca i8
%6 = alloca i8
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i32 0, i32* %1
store i8 101, i8* %2
store i8 69, i8* %3
%13 = load i8, i8* %2
%14 = sext i8 %13 to i32
%15 = load i8, i8* %2
%16 = call i32 @toupper(i8 signext %15)
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %14, i32 %16)
%18 = load i8, i8* %3
%19 = sext i8 %18 to i32
%20 = load i8, i8* %3
%21 = call i32 @tolower(i8 signext %20)
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %19, i32 %21)
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8** %4
%23 = load i8*, i8** %4
%24 = load i8*, i8** %4
%25 = call i32 @CharToInt(i8* %24)
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i8* %23, i32 %25)
store i8 7, i8* %5
store i8 9, i8* %6
store i32 2014, i32* %7
%27 = load i8, i8* %5
%28 = load i8, i8* %6
%29 = load i32, i32* %7
%30 = call i32 @ToDate(i8 zeroext %27, i8 zeroext %28, i32 %29)
store i32 %30, i32* %8
%31 = load i8, i8* %5
%32 = zext i8 %31 to i32
%33 = load i8, i8* %6
%34 = zext i8 %33 to i32
%35 = load i32, i32* %7
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i32 %32, i32 %34, i32 %35)
%37 = load i32, i32* %8
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0), i32 %37)
%39 = load i32, i32* %8
%40 = call i32 @ExtractMonth(i32 %39)
%41 = load i32, i32* %8
%42 = call i32 @ExtractDay(i32 %41)
%43 = load i32, i32* %8
%44 = call i32 @ExtractYear(i32 %43)
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0), i32 %40, i32 %42, i32 %44)
%46 = load i32, i32* %8
%47 = call i32 @CntBits(i32 %46)
store i32 %47, i32* %9
%48 = load i32, i32* %8
%49 = load i32, i32* %9
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0), i32 %48, i32 %49)
store i32 4, i32* %10
store i32 2, i32* %11
%51 = load i32, i32* %10
%52 = load i32, i32* %11
%53 = load i32, i32* %10
%54 = load i32, i32* %11
%55 = call i64 @TestBit(i32 %53, i32 %54)
%56 = icmp ne i64 %55, 0
%57 = zext i1 %56 to i64
%58 = select i1 %56, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.10, i64 0, i64 0)
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.8, i64 0, i64 0), i32 %51, i32 %52, i8* %58)
store i32 -3, i32* %12
%60 = load i32, i32* %12
%61 = load i32, i32* %12
%62 = call i32 @ROR(i32 %61)
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.11, i64 0, i64 0), i32 %60, i32 %62)
%64 = load i32, i32* %12
%65 = load i32, i32* %12
%66 = call i32 @ROL(i32 %65)
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.12, i64 0, i64 0), i32 %64, i32 %66)
ret i32 0
}

LLVM IR (-O2):
@.str = [18 x i8] c"toupper(%c) = %c\0A\00"
@.str.1 = [19 x i8] c"tolower(%c) = %c\0A\0A\00"
@.str.2 = [4 x i8] c"123\00"
@.str.3 = [23 x i8] c"CharToInt(\22%s\22) = %d\0A\0A\00"
@.str.4 = [19 x i8] c"Date in: %d/%d/%d\0A\00"
@.str.5 = [20 x i8] c"Packed value: 0x%X\0A\00"
@.str.6 = [21 x i8] c"Date out: %d/%d/%d\0A\0A\00"
@.str.7 = [23 x i8] c"Bits set in 0x%X: %d\0A\0A\00"
@.str.8 = [25 x i8] c"TestBit(0x%X, %d) = %s\0A\0A\00"
@.str.9 = [5 x i8] c"true\00"
@.str.10 = [6 x i8] c"false\00"
@.str.11 = [16 x i8] c"ROR(0x%X) = %d\0A\00"
@.str.12 = [17 x i8] c"ROL(0x%X) = %d\0A\0A\00"
define i32 @main() {
%1 = tail call i32 @toupper(i8 signext 101)
%2 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 101, i32 %1)
%3 = tail call i32 @tolower(i8 signext 69)
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 69, i32 %3)
%5 = tail call i32 @CharToInt(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %5)
%7 = tail call i32 @ToDate(i8 zeroext 7, i8 zeroext 9, i32 2014)
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i32 7, i32 9, i32 2014)
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0), i32 %7)
%10 = tail call i32 @ExtractMonth(i32 %7)
%11 = tail call i32 @ExtractDay(i32 %7)
%12 = tail call i32 @ExtractYear(i32 %7)
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0), i32 %10, i32 %11, i32 %12)
%14 = tail call i32 @CntBits(i32 %7)
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0), i32 %7, i32 %14)
%16 = tail call i64 @TestBit(i32 4, i32 2)
%17 = icmp eq i64 %16, 0
%18 = select i1 %17, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0)
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.8, i64 0, i64 0), i32 4, i32 2, i8* %18)
%20 = tail call i32 @ROR(i32 -3)
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.11, i64 0, i64 0), i32 -3, i32 %20)
%22 = tail call i32 @ROL(i32 -3)
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.12, i64 0, i64 0), i32 -3, i32 %22)
ret i32 0
}