#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(void) {
  int daysInMonth, dayOfWeek;
  printf("Enter number of days in the month: ");
  scanf("%d", &daysInMonth);
  printf("Enter starting day of the week (1=Sun, 7=Sat): ");
  scanf("%d", &dayOfWeek);
  for (int i = 1; i < dayOfWeek; i++) {
    printf("   ");
  }
  for (int i = 1; i <= daysInMonth; i++, dayOfWeek++) {
    if (dayOfWeek == 8) {
      printf("\n");
      dayOfWeek = 1;
    }
    printf("%3d", i);
  }
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xee0(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
lea    0xed3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xec2(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1040 <scanf@plt>
movl   $0x1,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    119a <main+0x7a>
lea    0xed2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1172 <main+0x52>
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     11f4 <main+0xd4>
cmpl   $0x8,-0xc(%rbp)
jne    11cc <main+0xac>
lea    0xe9d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0xc(%rbp)
mov    -0x14(%rbp),%esi
lea    0xe87(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11a1 <main+0x81>
lea    0xe60(%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   %rbx
push   %rax
lea    0xec6(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xedc(%rip),%rbx
lea    0x4(%rsp),%rsi
mov    %rbx,%rdi
call   1050 <scanf@plt>
lea    0xecb(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1050 <scanf@plt>
mov    (%rsp),%eax
cmp    $0x2,%eax
jl     11a4 <main+0x74>
mov    $0x1,%ebp
lea    0xed5(%rip),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%ebp
mov    (%rsp),%eax
cmp    %eax,%ebp
jl     1190 <main+0x60>
cmpl   $0x0,0x4(%rsp)
jle    11f6 <main+0xc6>
lea    0xea9(%rip),%rbx
xor    %ebp,%ebp
jmp    11db <main+0xab>
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%rsp),%eax
add    $0x1,%eax
mov    %eax,(%rsp)
cmp    0x4(%rsp),%ebp
jge    11f6 <main+0xc6>
add    $0x1,%ebp
cmp    $0x8,%eax
jne    11c0 <main+0x90>
mov    $0xa,%edi
call   1030 <putchar@plt>
movl   $0x1,(%rsp)
jmp    11c0 <main+0x90>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [36 x i8] c"Enter number of days in the month: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [48 x i8] c"Enter starting day of the week (1=Sun, 7=Sat): \00"
@.str.3 = [4 x i8] c" \00"
@.str.4 = [2 x i8] c"\0A\00"
@.str.5 = [4 x i8] c"%3d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 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 ([48 x i8], [48 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)
store i32 1, i32* %4
br label %10
10: ; preds = %16, %0
%11 = load i32, i32* %4
%12 = load i32, i32* %3
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %19
14: ; preds = %10
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
br label %16
16: ; preds = %14
%17 = load i32, i32* %4
%18 = add nsw i32 %17, 1
store i32 %18, i32* %4
br label %10
19: ; preds = %10
store i32 1, i32* %5
br label %20
20: ; preds = %32, %19
%21 = load i32, i32* %5
%22 = load i32, i32* %2
%23 = icmp sle i32 %21, %22
br i1 %23, label %24, label %37
24: ; preds = %20
%25 = load i32, i32* %3
%26 = icmp eq i32 %25, 8
br i1 %26, label %27, label %29
27: ; preds = %24
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %3
br label %29
29: ; preds = %27, %24
%30 = load i32, i32* %5
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %30)
br label %32
32: ; preds = %29
%33 = load i32, i32* %5
%34 = add nsw i32 %33, 1
store i32 %34, i32* %5
%35 = load i32, i32* %3
%36 = add nsw i32 %35, 1
store i32 %36, i32* %3
br label %20
37: ; preds = %20
%38 = 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 = [36 x i8] c"Enter number of days in the month: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [48 x i8] c"Enter starting day of the week (1=Sun, 7=Sat): \00"
@.str.3 = [4 x i8] c" \00"
@.str.5 = [4 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 ([36 x i8], [36 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 ([48 x i8], [48 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 = load i32, i32* %2
%10 = icmp sgt i32 %9, 1
br i1 %10, label %15, label %11
11: ; preds = %15, %0
%12 = phi i32 [ %9, %0 ], [ %19, %15 ]
%13 = load i32, i32* %1
%14 = icmp slt i32 %13, 1
br i1 %14, label %21, label %23
15: ; preds = %0, %15
%16 = phi i32 [ %18, %15 ], [ 1, %0 ]
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%18 = add nuw nsw i32 %16, 1
%19 = load i32, i32* %2
%20 = icmp slt i32 %18, %19
br i1 %20, label %15, label %11
21: ; preds = %29, %11
%22 = call i32 @putchar(i32 10)
ret i32 0
23: ; preds = %11, %29
%24 = phi i32 [ %33, %29 ], [ %12, %11 ]
%25 = phi i32 [ %31, %29 ], [ 1, %11 ]
%26 = icmp eq i32 %24, 8
br i1 %26, label %27, label %29
27: ; preds = %23
%28 = call i32 @putchar(i32 10)
store i32 1, i32* %2
br label %29
29: ; preds = %27, %23
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %25)
%31 = add nuw nsw i32 %25, 1
%32 = load i32, i32* %2
%33 = add nsw i32 %32, 1
store i32 %33, i32* %2
%34 = load i32, i32* %1
%35 = icmp slt i32 %25, %34
br i1 %35, label %23, label %21
}