#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 *, ...);
void printCalendar(int numDays, int dayOfWeek) {
  int i, j;
  printf("\nSun Mon Tue Wed Thu Fri Sat\n");
  for (i = 0; i < dayOfWeek; i++)
    printf("    ");
  j = dayOfWeek;
  for (i = 1; i <= numDays; i++) {
    printf(" %2d ", i);
    j++;
    if (j > 6) {
      printf("\n");
      j = 0;
    }
  }
}


x86 assembly (clang, -O0):
<printCalendar>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
lea    0xedb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    115b <printCalendar+0x4b>
lea    0xed8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1133 <printCalendar+0x23>
mov    -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
movl   $0x1,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x4(%rbp),%eax
jg     11c0 <printCalendar+0xb0>
mov    -0xc(%rbp),%esi
lea    0xea5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x6,-0x10(%rbp)
jle    11ad <printCalendar+0x9d>
lea    0xe7d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x10(%rbp)
jmp    11b2 <printCalendar+0xa2>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1168 <printCalendar+0x58>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printCalendar>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%r12d
mov    %edi,%r15d
lea    0xec6(%rip),%rdi
call   1040 <puts@plt>
test   %r12d,%r12d
jle    116f <printCalendar+0x3f>
lea    0xeaa(%rip),%rbx
mov    %r12d,%ebp
nopl   0x0(%rax)
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0xffffffff,%ebp
jne    1160 <printCalendar+0x30>
test   %r15d,%r15d
jle    11c8 <printCalendar+0x98>
neg    %r15d
mov    $0x1,%ebx
lea    0xe82(%rip),%r14
jmp    11b0 <printCalendar+0x80>
cs nopw 0x0(%rax,%rax,1)
nop
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %r12d,%r12d
lea    (%r15,%rbx,1),%eax
add    $0x1,%eax
mov    %ebx,%ecx
add    $0x1,%ecx
mov    %ecx,%ebx
cmp    $0x1,%eax
je     11c8 <printCalendar+0x98>
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
cmp    $0x6,%r12d
jge    1190 <printCalendar+0x60>
add    $0x1,%r12d
jmp    119d <printCalendar+0x6d>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [30 x i8] c"\0ASun Mon Tue Wed Thu Fri Sat\0A\00"
@.str.1 = [5 x i8] c" \00"
@.str.2 = [6 x i8] c" %2d \00"
@.str.3 = [2 x i8] c"\0A\00"
define void @printCalendar(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %5
br label %8
8: ; preds = %14, %2
%9 = load i32, i32* %5
%10 = load i32, i32* %4
%11 = icmp slt i32 %9, %10
br i1 %11, label %12, label %17
12: ; preds = %8
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %14
14: ; preds = %12
%15 = load i32, i32* %5
%16 = add nsw i32 %15, 1
store i32 %16, i32* %5
br label %8
17: ; preds = %8
%18 = load i32, i32* %4
store i32 %18, i32* %6
store i32 1, i32* %5
br label %19
19: ; preds = %33, %17
%20 = load i32, i32* %5
%21 = load i32, i32* %3
%22 = icmp sle i32 %20, %21
br i1 %22, label %23, label %36
23: ; preds = %19
%24 = load i32, i32* %5
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %24)
%26 = load i32, i32* %6
%27 = add nsw i32 %26, 1
store i32 %27, i32* %6
%28 = load i32, i32* %6
%29 = icmp sgt i32 %28, 6
br i1 %29, label %30, label %32
30: ; preds = %23
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %6
br label %32
32: ; preds = %30, %23
br label %33
33: ; preds = %32
%34 = load i32, i32* %5
%35 = add nsw i32 %34, 1
store i32 %35, i32* %5
br label %19
36: ; preds = %19
ret void
}

LLVM IR (-O2):
@.str.1 = [5 x i8] c" \00"
@.str.2 = [6 x i8] c" %2d \00"
@str = [29 x i8] c"\0ASun Mon Tue Wed Thu Fri Sat\00"
define void @printCalendar(i32 %0, i32 %1) {
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str, i64 0, i64 0))
%4 = icmp sgt i32 %1, 0
br i1 %4, label %7, label %5
5: ; preds = %7, %2
%6 = icmp slt i32 %0, 1
br i1 %6, label %24, label %12
7: ; preds = %2, %7
%8 = phi i32 [ %10, %7 ], [ 0, %2 ]
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%10 = add nuw nsw i32 %8, 1
%11 = icmp eq i32 %10, %1
br i1 %11, label %5, label %7
12: ; preds = %5, %20
%13 = phi i32 [ %21, %20 ], [ %1, %5 ]
%14 = phi i32 [ %22, %20 ], [ 1, %5 ]
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %14)
%16 = add nsw i32 %13, 1
%17 = icmp sgt i32 %13, 5
br i1 %17, label %18, label %20
18: ; preds = %12
%19 = tail call i32 @putchar(i32 10)
br label %20
20: ; preds = %12, %18
%21 = phi i32 [ 0, %18 ], [ %16, %12 ]
%22 = add nuw i32 %14, 1
%23 = icmp eq i32 %14, %0
br i1 %23, label %24, label %12
24: ; preds = %20, %5
ret void
}