#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 monthLength(int, int);
int /*<<< orphan*/ printHeader(int, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *, int *);
int weekDay(int, int, int);
int main(void) {
  int year, month, day, currentWeekDay, currentMonthLength, spacer;
  printf("Digite o Mes e o Ano:");
  scanf("%d %d", &month, &year);
  printHeader(month, year);
  currentMonthLength = monthLength(month, year);
  for (day = 1; day <= currentMonthLength; day++) {
    currentWeekDay = weekDay(day, month, year);
    if (day == 1)
      for (spacer = 1; spacer < currentWeekDay; spacer++)
        printf("    ");
    printf("%3d ", day);
    if (currentWeekDay == 7)
      printf("\n");
  }
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xea2(%rip),%rdi
lea    -0xc(%rbp),%rsi
lea    -0x8(%rbp),%rdx
call   1050 <scanf@plt>
mov    -0xc(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1060 <printHeader@plt>
mov    -0xc(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1030 <monthLength@plt>
mov    %eax,-0x18(%rbp)
movl   $0x1,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x18(%rbp),%eax
jg     1238 <main+0xe8>
mov    -0x10(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    -0x8(%rbp),%edx
call   1070 <weekDay@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x1,-0x10(%rbp)
jne    11fc <main+0xac>
movl   $0x1,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11f7 <main+0xa7>
lea    0xe3a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11cf <main+0x7f>
jmp    11fc <main+0xac>
mov    -0x10(%rbp),%esi
lea    0xe1b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x7,-0x14(%rbp)
jne    1225 <main+0xd5>
lea    0xe08(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    122a <main+0xda>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11a1 <main+0x51>
lea    0xde7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xe8e(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe96(%rip),%rdi
mov    %rsp,%rsi
lea    0x4(%rsp),%rdx
call   1060 <scanf@plt>
mov    (%rsp),%edi
mov    0x4(%rsp),%esi
call   1070 <printHeader@plt>
mov    (%rsp),%edi
mov    0x4(%rsp),%esi
call   1040 <monthLength@plt>
test   %eax,%eax
jle    122e <main+0xce>
mov    %eax,%r14d
mov    $0x1,%r13d
lea    0xe5f(%rip),%rbx
lea    0xe5d(%rip),%r15
jmp    11dc <main+0x7c>
cs nopw 0x0(%rax,%rax,1)
lea    0x1(%r13),%eax
cmp    %r14d,%r13d
mov    %eax,%r13d
je     122e <main+0xce>
mov    (%rsp),%esi
mov    0x4(%rsp),%edx
mov    %r13d,%edi
call   1080 <weekDay@plt>
mov    %eax,%r12d
cmp    $0x1,%r13d
jne    120f <main+0xaf>
cmp    $0x2,%r12d
jl     120f <main+0xaf>
lea    -0x1(%r12),%ebp
nop
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0xffffffff,%ebp
jne    1200 <main+0xa0>
mov    %r15,%rdi
mov    %r13d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
cmp    $0x7,%r12d
jne    11d0 <main+0x70>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    11d0 <main+0x70>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [22 x i8] c"Digite o Mes e o Ano:\00"
@.str.1 = [6 x i8] c"%d %d\00"
@.str.2 = [5 x i8] c" \00"
@.str.3 = [5 x i8] c"%3d \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32* %2, i32* %1)
%7 = load i32, i32* %2
%8 = load i32, i32* %1
%9 = call i32 @printHeader(i32 %7, i32 %8)
%10 = load i32, i32* %2
%11 = load i32, i32* %1
%12 = call i32 @monthLength(i32 %10, i32 %11)
%13 = icmp slt i32 %12, 1
br i1 %13, label %35, label %14
14: ; preds = %0, %32
%15 = phi i32 [ %33, %32 ], [ 1, %0 ]
%16 = load i32, i32* %2
%17 = load i32, i32* %1
%18 = call i32 @weekDay(i32 %15, i32 %16, i32 %17)
%19 = icmp eq i32 %15, 1
%20 = icmp sgt i32 %18, 1
%21 = select i1 %19, i1 %20, i1 false
br i1 %21, label %22, label %27
22: ; preds = %14, %22
%23 = phi i32 [ %25, %22 ], [ 1, %14 ]
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%25 = add nuw nsw i32 %23, 1
%26 = icmp eq i32 %25, %18
br i1 %26, label %27, label %22
27: ; preds = %22, %14
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %15)
%29 = icmp eq i32 %18, 7
br i1 %29, label %30, label %32
30: ; preds = %27
%31 = call i32 @putchar(i32 10)
br label %32
32: ; preds = %27, %30
%33 = add nuw i32 %15, 1
%34 = icmp eq i32 %15, %12
br i1 %34, label %35, label %14
35: ; preds = %32, %0
%36 = call i32 @putchar(i32 10)
ret i32 0
}