#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 /*<<< orphan*/ scanf(char *, int *);
int main() {
  int daysinmonth = 0;
  int weekday = 0;
  int calendarstart = 0;
  int i = 0;
  printf("Enter number of days in month: ");
  scanf("%d", &daysinmonth);
  printf("Enter starting day of the week (1=Monday, 7=Sunday): ");
  scanf("%d", &weekday);
  printf("\n");
  for (i = 1; i <= daysinmonth; i++) {
    if (weekday > 1) {
      while (calendarstart < weekday - 1) {
        printf("   ");
        calendarstart++;
      }
    }
    printf("%2d ", i);
    if ((i + weekday - 1) % 7 == 0) {
      printf("\n");
    }
  }
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
lea    0xeae(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xec0(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
lea    0xeb3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xea2(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1040 <scanf@plt>
lea    0xecb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     1235 <main+0x115>
cmpl   $0x1,-0xc(%rbp)
jle    11e9 <main+0xc9>
jmp    11b7 <main+0x97>
mov    -0x10(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    11e4 <main+0xc4>
lea    0xe8c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11b7 <main+0x97>
jmp    11e9 <main+0xc9>
mov    -0x14(%rbp),%esi
lea    0xe6c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    -0xc(%rbp),%eax
sub    $0x1,%eax
mov    $0x7,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1222 <main+0x102>
lea    0xe3e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1227 <main+0x107>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    119c <main+0x7c>
lea    0xe1d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
movl   $0x0,0x4(%rsp)
movl   $0x0,(%rsp)
lea    0xeb3(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xec5(%rip),%rbx
lea    0x4(%rsp),%rsi
mov    %rbx,%rdi
call   1050 <scanf@plt>
lea    0xeb4(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1050 <scanf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
cmpl   $0x0,0x4(%rsp)
jle    121c <main+0xec>
mov    $0x1,%r14d
lea    0xeb6(%rip),%rbx
lea    0xeb3(%rip),%r15
xor    %ebp,%ebp
jmp    11e3 <main+0xb3>
xchg   %ax,%ax
mov    %r15,%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%rsp),%eax
add    %r14d,%eax
imul   $0xb6db6db7,%eax,%eax
add    $0x5b6db6db,%eax
cmp    $0x24924924,%eax
jbe    1210 <main+0xe0>
lea    0x1(%r14),%eax
cmp    0x4(%rsp),%r14d
mov    %eax,%r14d
jge    121c <main+0xec>
mov    (%rsp),%eax
cmp    $0x2,%eax
jl     11b0 <main+0x80>
nopl   0x0(%rax,%rax,1)
add    $0xffffffff,%eax
cmp    %eax,%ebp
jge    11b0 <main+0x80>
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%ebp
mov    (%rsp),%eax
jmp    11f0 <main+0xc0>
nopl   0x0(%rax)
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    11d5 <main+0xa5>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [32 x i8] c"Enter number of days in month: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [54 x i8] c"Enter starting day of the week (1=Monday, 7=Sunday): \00"
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [4 x i8] c" \00"
@.str.5 = [5 x i8] c"%2d \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %2
store i32 0, i32* %3
store i32 0, i32* %4
store i32 0, i32* %5
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.2, i64 0, i64 0))
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %5
br label %11
11: ; preds = %41, %0
%12 = load i32, i32* %5
%13 = load i32, i32* %2
%14 = icmp sle i32 %12, %13
br i1 %14, label %15, label %44
15: ; preds = %11
%16 = load i32, i32* %3
%17 = icmp sgt i32 %16, 1
br i1 %17, label %18, label %29
18: ; preds = %15
br label %19
19: ; preds = %24, %18
%20 = load i32, i32* %4
%21 = load i32, i32* %3
%22 = sub nsw i32 %21, 1
%23 = icmp slt i32 %20, %22
br i1 %23, label %24, label %28
24: ; preds = %19
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%26 = load i32, i32* %4
%27 = add nsw i32 %26, 1
store i32 %27, i32* %4
br label %19
28: ; preds = %19
br label %29
29: ; preds = %28, %15
%30 = load i32, i32* %5
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 %30)
%32 = load i32, i32* %5
%33 = load i32, i32* %3
%34 = add nsw i32 %32, %33
%35 = sub nsw i32 %34, 1
%36 = srem i32 %35, 7
%37 = icmp eq i32 %36, 0
br i1 %37, label %38, label %40
38: ; preds = %29
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %40
40: ; preds = %38, %29
br label %41
41: ; preds = %40
%42 = load i32, i32* %5
%43 = add nsw i32 %42, 1
store i32 %43, i32* %5
br label %11
44: ; preds = %11
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [32 x i8] c"Enter number of days in month: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [54 x i8] c"Enter starting day of the week (1=Monday, 7=Sunday): \00"
@.str.4 = [4 x i8] c" \00"
@.str.5 = [5 x i8] c"%2d \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
store i32 0, i32* %1
%4 = bitcast i32* %2 to i8*
store i32 0, i32* %2
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%7 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([54 x i8], [54 x i8]* @.str.2, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%9 = call i32 @putchar(i32 10)
%10 = load i32, i32* %1
%11 = icmp slt i32 %10, 1
br i1 %11, label %41, label %12
12: ; preds = %0, %37
%13 = phi i32 [ %38, %37 ], [ 1, %0 ]
%14 = phi i32 [ %28, %37 ], [ 0, %0 ]
%15 = load i32, i32* %2
%16 = icmp sgt i32 %15, 1
%17 = add nsw i32 %15, -1
%18 = icmp slt i32 %14, %17
%19 = select i1 %16, i1 %18, i1 false
br i1 %19, label %20, label %27
20: ; preds = %12, %20
%21 = phi i32 [ %23, %20 ], [ %14, %12 ]
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%23 = add nsw i32 %21, 1
%24 = load i32, i32* %2
%25 = add nsw i32 %24, -1
%26 = icmp slt i32 %23, %25
br i1 %26, label %20, label %27
27: ; preds = %20, %12
%28 = phi i32 [ %14, %12 ], [ %23, %20 ]
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 %13)
%30 = load i32, i32* %2
%31 = add nsw i32 %13, -1
%32 = add i32 %31, %30
%33 = srem i32 %32, 7
%34 = icmp eq i32 %33, 0
br i1 %34, label %35, label %37
35: ; preds = %27
%36 = call i32 @putchar(i32 10)
br label %37
37: ; preds = %27, %35
%38 = add nuw nsw i32 %13, 1
%39 = load i32, i32* %1
%40 = icmp slt i32 %13, %39
br i1 %40, label %12, label %41
41: ; preds = %37, %0
%42 = call i32 @putchar(i32 10)
ret i32 0
}