#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 i;
  int days;
  int start;
  printf("Enter the number of days this month: ");
  scanf("%d", &days);
  printf("Enter starting day of the week (1=Sun, 7=Sat): ");
  scanf("%d", &start);
  for (i = 1; i < start; i++) {
    printf("   ");
  }
  for (int j = 1; j <= days; i++, j++) {
    printf("%3d", j);
    if (i % 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)
lea    0xeca(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xee2(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1040 <scanf@plt>
lea    0xed5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xec4(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1040 <scanf@plt>
movl   $0x1,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    119a <main+0x7a>
lea    0xed4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1172 <main+0x52>
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jg     11fc <main+0xdc>
mov    -0x14(%rbp),%esi
lea    0xea6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
mov    $0x7,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11e0 <main+0xc0>
lea    0xe88(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11e5 <main+0xc5>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11a1 <main+0x81>
lea    0xe5e(%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   %r13
push   %r12
push   %rbx
push   %rax
lea    0xebe(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xed6(%rip),%rbx
lea    0x4(%rsp),%rsi
mov    %rbx,%rdi
call   1050 <scanf@plt>
lea    0xec5(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1050 <scanf@plt>
mov    $0x1,%ebx
cmpl   $0x2,(%rsp)
jl     11a2 <main+0x72>
mov    $0x1,%ebx
lea    0xecc(%rip),%rbp
nopl   (%rax)
mov    %rbp,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%ebx
cmp    (%rsp),%ebx
jl     1190 <main+0x60>
cmpl   $0x0,0x4(%rsp)
jle    1214 <main+0xe4>
mov    %ebx,%r15d
neg    %r15d
lea    0xea7(%rip),%r14
xor    %r13d,%r13d
jmp    11ca <main+0x9a>
nopl   0x0(%rax,%rax,1)
add    $0x1,%ebx
cmp    0x4(%rsp),%r13d
jge    1214 <main+0xe4>
mov    %r13d,%r12d
lea    0x1(%r12),%r13d
mov    %ebx,%eax
imul   $0x24924925,%rax,%rax
shr    $0x20,%rax
mov    %ebx,%ecx
sub    %eax,%ecx
shr    %ecx
add    %eax,%ecx
shr    $0x2,%ecx
lea    0x0(,%rcx,8),%ebp
sub    %ecx,%ebp
add    %r15d,%ebp
mov    %r14,%rdi
mov    %r13d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
cmp    %r12d,%ebp
jne    11c0 <main+0x90>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    11c0 <main+0x90>
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 = [38 x i8] c"Enter the number of days this 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 = [4 x i8] c"%3d\00"
@.str.5 = [2 x i8] c"\0A\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 ([38 x i8], [38 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* %3)
%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* %4)
store i32 1, i32* %2
br label %10
10: ; preds = %16, %0
%11 = load i32, i32* %2
%12 = load i32, i32* %4
%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* %2
%18 = add nsw i32 %17, 1
store i32 %18, i32* %2
br label %10
19: ; preds = %10
store i32 1, i32* %5
br label %20
20: ; preds = %33, %19
%21 = load i32, i32* %5
%22 = load i32, i32* %3
%23 = icmp sle i32 %21, %22
br i1 %23, label %24, label %38
24: ; preds = %20
%25 = load i32, i32* %5
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %25)
%27 = load i32, i32* %2
%28 = srem i32 %27, 7
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %24
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
br label %32
32: ; preds = %30, %24
br label %33
33: ; preds = %32
%34 = load i32, i32* %2
%35 = add nsw i32 %34, 1
store i32 %35, i32* %2
%36 = load i32, i32* %5
%37 = add nsw i32 %36, 1
store i32 %37, i32* %5
br label %20
38: ; preds = %20
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [38 x i8] c"Enter the number of days this 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 = [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 ([38 x i8], [38 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 [ 1, %0 ], [ %18, %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 = %31, %11
%22 = call i32 @putchar(i32 10)
ret i32 0
23: ; preds = %11, %31
%24 = phi i32 [ %33, %31 ], [ 1, %11 ]
%25 = phi i32 [ %32, %31 ], [ %12, %11 ]
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %24)
%27 = urem i32 %25, 7
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %23
%30 = call i32 @putchar(i32 10)
br label %31
31: ; preds = %23, %29
%32 = add nuw nsw i32 %25, 1
%33 = add nuw nsw i32 %24, 1
%34 = load i32, i32* %1
%35 = icmp slt i32 %24, %34
br i1 %35, label %23, label %21
}