#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 n = 0, day = 0;
  printf("Enter number of days in month: ");
  scanf("%d", &n);
  printf("Enter starting day (1=Sun, ..., 7=Sat): ");
  scanf("%d", &day);
  printf("\n");
  int i;
  for (i = 1; i < day; i++)
    printf("   ");
  int j;
  for (j = 1; j <= n; j++) {
    j < 10 ? printf(" %d ", j) : printf("%d ", j);
    day++;
    if (day > 7) {
      day = 1;
      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)
lea    0xebc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xece(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
lea    0xec1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeb0(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1040 <scanf@plt>
lea    0xecc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11b6 <main+0x96>
lea    0xead(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    118e <main+0x6e>
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     1235 <main+0x115>
cmpl   $0xa,-0x14(%rbp)
jge    11e9 <main+0xc9>
mov    -0x14(%rbp),%esi
lea    0xe75(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11fa <main+0xda>
mov    -0x14(%rbp),%esi
lea    0xe60(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x7,-0xc(%rbp)
jle    1222 <main+0x102>
movl   $0x1,-0xc(%rbp)
lea    0xe31(%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    11bd <main+0x9d>
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   $0x2,(%rsp)
jl     11b2 <main+0x82>
mov    $0x1,%ebp
lea    0xeaf(%rip),%rbx
nopl   (%rax)
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%ebp
cmp    (%rsp),%ebp
jl     11a0 <main+0x70>
cmpl   $0x0,0x4(%rsp)
jle    120f <main+0xdf>
mov    $0x1,%ebx
lea    0xe8b(%rip),%r14
lea    0xe85(%rip),%r15
jmp    11db <main+0xab>
xchg   %ax,%ax
lea    0x1(%rbx),%eax
cmp    0x4(%rsp),%ebx
mov    %eax,%ebx
jge    120f <main+0xdf>
cmp    $0xa,%ebx
mov    %r15,%rdi
cmovb  %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%rsp),%eax
lea    0x1(%rax),%ecx
mov    %ecx,(%rsp)
cmp    $0x7,%eax
jl     11d0 <main+0xa0>
movl   $0x1,(%rsp)
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    11d0 <main+0xa0>
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 = [41 x i8] c"Enter starting day (1=Sun, ..., 7=Sat): \00"
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [4 x i8] c" \00"
@.str.5 = [5 x i8] c" %d \00"
@.str.6 = [4 x i8] c"%d \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
%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 ([41 x i8], [41 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* %4
br label %11
11: ; preds = %17, %0
%12 = load i32, i32* %4
%13 = load i32, i32* %3
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %20
15: ; preds = %11
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
br label %17
17: ; preds = %15
%18 = load i32, i32* %4
%19 = add nsw i32 %18, 1
store i32 %19, i32* %4
br label %11
20: ; preds = %11
store i32 1, i32* %5
br label %21
21: ; preds = %43, %20
%22 = load i32, i32* %5
%23 = load i32, i32* %2
%24 = icmp sle i32 %22, %23
br i1 %24, label %25, label %46
25: ; preds = %21
%26 = load i32, i32* %5
%27 = icmp slt i32 %26, 10
br i1 %27, label %28, label %31
28: ; preds = %25
%29 = load i32, i32* %5
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 %29)
br label %34
31: ; preds = %25
%32 = load i32, i32* %5
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i32 %32)
br label %34
34: ; preds = %31, %28
%35 = phi i32 [ %30, %28 ], [ %33, %31 ]
%36 = load i32, i32* %3
%37 = add nsw i32 %36, 1
store i32 %37, i32* %3
%38 = load i32, i32* %3
%39 = icmp sgt i32 %38, 7
br i1 %39, label %40, label %42
40: ; preds = %34
store i32 1, i32* %3
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %42
42: ; preds = %40, %34
br label %43
43: ; preds = %42
%44 = load i32, i32* %5
%45 = add nsw i32 %44, 1
store i32 %45, i32* %5
br label %21
46: ; preds = %21
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 = [41 x i8] c"Enter starting day (1=Sun, ..., 7=Sat): \00"
@.str.4 = [4 x i8] c" \00"
@.str.5 = [5 x i8] c" %d \00"
@.str.6 = [4 x i8] c"%d \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 ([41 x i8], [41 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* %2
%11 = icmp sgt i32 %10, 1
br i1 %11, label %15, label %12
12: ; preds = %15, %0
%13 = load i32, i32* %1
%14 = icmp slt i32 %13, 1
br i1 %14, label %35, label %21
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.4, 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 %12
21: ; preds = %12, %31
%22 = phi i32 [ %32, %31 ], [ 1, %12 ]
%23 = icmp ult i32 %22, 10
%24 = select i1 %23, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0)
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) %24, i32 %22)
%26 = load i32, i32* %2
%27 = add nsw i32 %26, 1
store i32 %27, i32* %2
%28 = icmp sgt i32 %26, 6
br i1 %28, label %29, label %31
29: ; preds = %21
store i32 1, i32* %2
%30 = call i32 @putchar(i32 10)
br label %31
31: ; preds = %21, %29
%32 = add nuw nsw i32 %22, 1
%33 = load i32, i32* %1
%34 = icmp slt i32 %22, %33
br i1 %34, label %21, label %35
35: ; preds = %31, %12
ret i32 0
}