#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 printMonth(int startDay, int daysInMonth, char *month) {
  int i;
  int currentDay = startDay;
  printf("---------------------------------------------------\n");
  printf("\t\t%s\n", month);
  printf("---------------------------------------------------\n");
  printf("SUN\tMON\tTUE\tWED\tTHU\tFRI\tSAT\n\n");
  for (i = 1; i < startDay; i++) {
    printf("\t");
  }
  for (i = 1; i <= daysInMonth; i++) {
    printf("%d\t", i);
    if (currentDay % 7 == 0)
      printf("\n");
    currentDay++;
  }
  printf("\n\n");
  currentDay = currentDay % 7;
  if (currentDay == 0)
    currentDay = 7;
  return currentDay;
}


x86 assembly (clang, -O0):
<printMonth>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x18(%rbp)
lea    0xed1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rsi
lea    0xef4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeb1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xede(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1193 <printMonth+0x83>
lea    0xedd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    116b <printMonth+0x5b>
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     11f0 <printMonth+0xe0>
mov    -0x14(%rbp),%esi
lea    0xea9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
mov    $0x7,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11d9 <printMonth+0xc9>
lea    0xe85(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    119a <printMonth+0x8a>
lea    0xe5f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
mov    $0x7,%ecx
cltd
idiv   %ecx
mov    %edx,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jne    121d <printMonth+0x10d>
movl   $0x7,-0x18(%rbp)
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printMonth>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %esi,%r14d
mov    %edi,%r15d
lea    0xebf(%rip),%rbp
mov    %rbp,%rdi
call   1040 <puts@plt>
lea    0xea6(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbp,%rdi
call   1040 <puts@plt>
lea    0xecb(%rip),%rdi
call   1040 <puts@plt>
cmp    $0x2,%r15d
jl     119f <printMonth+0x6f>
lea    -0x1(%r15),%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    $0x9,%edi
call   1030 <putchar@plt>
add    $0xffffffff,%ebx
jne    1190 <printMonth+0x60>
test   %r14d,%r14d
jle    1206 <printMonth+0xd6>
mov    %r14d,%r13d
neg    %r13d
mov    $0x1,%ebx
lea    0xe50(%rip),%r12
mov    %r15d,%ebp
jmp    11d6 <printMonth+0xa6>
nopl   0x0(%rax,%rax,1)
add    $0x1,%ebp
lea    (%rbx,%r13,1),%eax
add    $0x1,%eax
mov    %ebx,%ecx
add    $0x1,%ecx
mov    %ecx,%ebx
cmp    $0x1,%eax
je     1200 <printMonth+0xd0>
mov    %r12,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
imul   $0xb6db6db7,%ebp,%eax
add    $0x12492492,%eax
cmp    $0x24924924,%eax
ja     11c0 <printMonth+0x90>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    11c0 <printMonth+0x90>
add    %r15d,%r14d
mov    %r14d,%r15d
lea    0xe4c(%rip),%rdi
call   1040 <puts@plt>
movslq %r15d,%rax
imul   $0xffffffff92492493,%rax,%rcx
shr    $0x20,%rcx
add    %eax,%ecx
mov    %ecx,%edx
shr    $0x1f,%edx
sar    $0x2,%ecx
add    %edx,%ecx
lea    0x0(,%rcx,8),%edx
sub    %edx,%ecx
add    %eax,%ecx
mov    $0x7,%eax
cmovne %ecx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [53 x i8] c"---------------------------------------------------\0A\00"
@.str.1 = [6 x i8] c"\09\09%s\0A\00"
@.str.2 = [30 x i8] c"SUN\09MON\09TUE\09WED\09THU\09FRI\09SAT\0A\0A\00"
@.str.3 = [2 x i8] c"\09\00"
@.str.4 = [4 x i8] c"%d\09\00"
@.str.5 = [2 x i8] c"\0A\00"
@.str.6 = [3 x i8] c"\0A\0A\00"
define i32 @printMonth(i32 %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%9 = load i32, i32* %4
store i32 %9, i32* %8
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0))
%11 = load i8*, i8** %6
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %11)
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0))
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %7
br label %15
15: ; preds = %21, %3
%16 = load i32, i32* %7
%17 = load i32, i32* %4
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %24
19: ; preds = %15
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %21
21: ; preds = %19
%22 = load i32, i32* %7
%23 = add nsw i32 %22, 1
store i32 %23, i32* %7
br label %15
24: ; preds = %15
store i32 1, i32* %7
br label %25
25: ; preds = %40, %24
%26 = load i32, i32* %7
%27 = load i32, i32* %5
%28 = icmp sle i32 %26, %27
br i1 %28, label %29, label %43
29: ; preds = %25
%30 = load i32, i32* %7
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %30)
%32 = load i32, i32* %8
%33 = srem i32 %32, 7
%34 = icmp eq i32 %33, 0
br i1 %34, label %35, label %37
35: ; preds = %29
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
br label %37
37: ; preds = %35, %29
%38 = load i32, i32* %8
%39 = add nsw i32 %38, 1
store i32 %39, i32* %8
br label %40
40: ; preds = %37
%41 = load i32, i32* %7
%42 = add nsw i32 %41, 1
store i32 %42, i32* %7
br label %25
43: ; preds = %25
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
%45 = load i32, i32* %8
%46 = srem i32 %45, 7
store i32 %46, i32* %8
%47 = load i32, i32* %8
%48 = icmp eq i32 %47, 0
br i1 %48, label %49, label %50
49: ; preds = %43
store i32 7, i32* %8
br label %50
50: ; preds = %49, %43
%51 = load i32, i32* %8
ret i32 %51
}

LLVM IR (-O2):
@.str.1 = [6 x i8] c"\09\09%s\0A\00"
@.str.4 = [4 x i8] c"%d\09\00"
@str.7 = [52 x i8] c"---------------------------------------------------\00"
@str.8 = [29 x i8] c"SUN\09MON\09TUE\09WED\09THU\09FRI\09SAT\0A\00"
@str.9 = [2 x i8] c"\0A\00"
define i32 @printMonth(i32 %0, i32 %1, i8* %2) {
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @str.7, i64 0, i64 0))
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %2)
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @str.7, i64 0, i64 0))
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str.8, i64 0, i64 0))
%8 = icmp sgt i32 %0, 1
br i1 %8, label %11, label %9
9: ; preds = %11, %3
%10 = icmp slt i32 %1, 1
br i1 %10, label %30, label %16
11: ; preds = %3, %11
%12 = phi i32 [ %14, %11 ], [ 1, %3 ]
%13 = tail call i32 @putchar(i32 9)
%14 = add nuw nsw i32 %12, 1
%15 = icmp eq i32 %14, %0
br i1 %15, label %9, label %11
16: ; preds = %9, %24
%17 = phi i32 [ %25, %24 ], [ %0, %9 ]
%18 = phi i32 [ %26, %24 ], [ 1, %9 ]
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %18)
%20 = srem i32 %17, 7
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %16
%23 = tail call i32 @putchar(i32 10)
br label %24
24: ; preds = %22, %16
%25 = add nsw i32 %17, 1
%26 = add nuw i32 %18, 1
%27 = icmp eq i32 %18, %1
br i1 %27, label %28, label %16
28: ; preds = %24
%29 = add i32 %1, %0
br label %30
30: ; preds = %28, %9
%31 = phi i32 [ %0, %9 ], [ %29, %28 ]
%32 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str.9, i64 0, i64 0))
%33 = srem i32 %31, 7
%34 = icmp eq i32 %33, 0
%35 = select i1 %34, i32 7, i32 %33
ret i32 %35
}