#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 FirstDayOfMonth(int, int);
int /*<<< orphan*/ IndentFirstLine(int);
int MonthDays(int, int);
char *MonthName(int);
int /*<<< orphan*/ printf(char *, ...);
void PrintCalendarMonth(int month, int year) {
  int weekday, nDays, day;
  printf("    %s %d\n", MonthName(month), year);
  printf(" Su Mo Tu We Th Fr Sa\n");
  nDays = MonthDays(month, year);
  weekday = FirstDayOfMonth(month, year);
  IndentFirstLine(weekday);
  for (day = 1; day <= nDays; day++) {
    printf(" %2d", day);
    if (weekday == 6)
      printf("\n");
    weekday = (weekday + 1) % 7;
  }
  if (weekday != 0)
    printf("\n");
}


x86 assembly (clang, -O0):
<PrintCalendarMonth>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%edi
call   1030 <MonthName@plt>
mov    %rax,%rsi
mov    -0x8(%rbp),%edx
lea    0xe8d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe8a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1070 <MonthDays@plt>
mov    %eax,-0x10(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1040 <FirstDayOfMonth@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
call   1060 <IndentFirstLine@plt>
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x10(%rbp),%eax
jg     1207 <PrintCalendarMonth+0xb7>
mov    -0x14(%rbp),%esi
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
cmpl   $0x6,-0xc(%rbp)
jne    11e8 <PrintCalendarMonth+0x98>
lea    0xe3f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    $0x7,%ecx
cltd
idiv   %ecx
mov    %edx,-0xc(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11b3 <PrintCalendarMonth+0x63>
cmpl   $0x0,-0xc(%rbp)
je     121f <PrintCalendarMonth+0xcf>
lea    0xe08(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<PrintCalendarMonth>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%ebx
mov    %edi,%ebp
call   1040 <MonthName@plt>
lea    0xe78(%rip),%rdi
mov    %rax,%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xe75(%rip),%rdi
call   1050 <puts@plt>
mov    %ebp,%edi
mov    %ebx,%esi
call   1090 <MonthDays@plt>
mov    %eax,%r14d
mov    %ebp,%edi
mov    %ebx,%esi
call   1060 <FirstDayOfMonth@plt>
mov    %eax,%ebx
mov    %eax,%edi
call   1080 <IndentFirstLine@plt>
test   %r14d,%r14d
jle    1242 <PrintCalendarMonth+0xd2>
neg    %r14d
mov    $0x1,%r12d
lea    0xe38(%rip),%r15
jmp    1224 <PrintCalendarMonth+0xb4>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %ebx,%eax
add    $0x1,%eax
cltq
imul   $0xffffffff92492493,%rax,%rax
shr    $0x20,%rax
add    %ebx,%eax
add    $0x1,%eax
mov    %eax,%ecx
shr    $0x1f,%ecx
sar    $0x2,%eax
add    %ecx,%eax
lea    0x0(,%rax,8),%ecx
sub    %ecx,%eax
add    %eax,%ebx
add    $0x1,%ebx
lea    (%r14,%r12,1),%eax
add    $0x1,%eax
mov    %r12d,%ecx
add    $0x1,%ecx
mov    %ecx,%r12d
cmp    $0x1,%eax
je     1242 <PrintCalendarMonth+0xd2>
mov    %r15,%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1070 <printf@plt>
cmp    $0x6,%ebx
jne    11e0 <PrintCalendarMonth+0x70>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    11e0 <PrintCalendarMonth+0x70>
test   %ebx,%ebx
je     1258 <PrintCalendarMonth+0xe8>
mov    $0xa,%edi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <putchar@plt>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c" %s %d\0A\00"
@.str.1 = [23 x i8] c" Su Mo Tu We Th Fr Sa\0A\00"
@.str.2 = [5 x i8] c" %2d\00"
@.str.3 = [2 x i8] c"\0A\00"
define void @PrintCalendarMonth(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%8 = load i32, i32* %3
%9 = call i8* @MonthName(i32 %8)
%10 = load i32, i32* %4
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %9, i32 %10)
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
%13 = load i32, i32* %3
%14 = load i32, i32* %4
%15 = call i32 @MonthDays(i32 %13, i32 %14)
store i32 %15, i32* %6
%16 = load i32, i32* %3
%17 = load i32, i32* %4
%18 = call i32 @FirstDayOfMonth(i32 %16, i32 %17)
store i32 %18, i32* %5
%19 = load i32, i32* %5
%20 = call i32 @IndentFirstLine(i32 %19)
store i32 1, i32* %7
br label %21
21: ; preds = %36, %2
%22 = load i32, i32* %7
%23 = load i32, i32* %6
%24 = icmp sle i32 %22, %23
br i1 %24, label %25, label %39
25: ; preds = %21
%26 = load i32, i32* %7
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %26)
%28 = load i32, i32* %5
%29 = icmp eq i32 %28, 6
br i1 %29, label %30, label %32
30: ; preds = %25
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %32
32: ; preds = %30, %25
%33 = load i32, i32* %5
%34 = add nsw i32 %33, 1
%35 = srem i32 %34, 7
store i32 %35, i32* %5
br label %36
36: ; preds = %32
%37 = load i32, i32* %7
%38 = add nsw i32 %37, 1
store i32 %38, i32* %7
br label %21
39: ; preds = %21
%40 = load i32, i32* %5
%41 = icmp ne i32 %40, 0
br i1 %41, label %42, label %44
42: ; preds = %39
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %44
44: ; preds = %42, %39
ret void
}

LLVM IR (-O2):
@.str = [11 x i8] c" %s %d\0A\00"
@.str.2 = [5 x i8] c" %2d\00"
@str = [22 x i8] c" Su Mo Tu We Th Fr Sa\00"
define void @PrintCalendarMonth(i32 %0, i32 %1) {
%3 = tail call i8* @MonthName(i32 %0)
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %3, i32 %1)
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
%6 = tail call i32 @MonthDays(i32 %0, i32 %1)
%7 = tail call i32 @FirstDayOfMonth(i32 %0, i32 %1)
%8 = tail call i32 @IndentFirstLine(i32 %7)
%9 = icmp slt i32 %6, 1
br i1 %9, label %22, label %10
10: ; preds = %2, %17
%11 = phi i32 [ %20, %17 ], [ 1, %2 ]
%12 = phi i32 [ %19, %17 ], [ %7, %2 ]
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %11)
%14 = icmp eq i32 %12, 6
br i1 %14, label %15, label %17
15: ; preds = %10
%16 = tail call i32 @putchar(i32 10)
br label %17
17: ; preds = %15, %10
%18 = add nsw i32 %12, 1
%19 = srem i32 %18, 7
%20 = add nuw i32 %11, 1
%21 = icmp eq i32 %11, %6
br i1 %21, label %22, label %10
22: ; preds = %17, %2
%23 = phi i32 [ %7, %2 ], [ %19, %17 ]
%24 = icmp eq i32 %23, 0
br i1 %24, label %27, label %25
25: ; preds = %22
%26 = tail call i32 @putchar(i32 10)
br label %27
27: ; preds = %25, %22
ret void
}