#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*/ fgets(char *, int, int /*<<< orphan*/);
int inputYOrN(int /*<<< orphan*/);
int /*<<< orphan*/ lineBreak();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ sscanf(char *, char *, unsigned char *);
int /*<<< orphan*/ stdin;
void calendar(void) {
  int cont;
  char buffer_a[4], buffer_b[4];
  puts("Calendar Generator");
  lineBreak();
  cont = inputYOrN(0);
  while (cont) {
    unsigned char start, number, i, a;
    lineBreak();
    printf("Enter the start day of the month (1(Mon) to 7(Sun)) : ");
    fgets(buffer_a, 4, stdin);
    sscanf(buffer_a, "%hhu", &start);
    printf("\nEnter the number of days in the month: ");
    fgets(buffer_b, 4, stdin);
    sscanf(buffer_b, "%hhu", &number);
    printf("\nMon  Tue  Wed  Thu  Fri  Sat  Sun");
    printf("\n---  ---  ---  ---  ---  ---  ---\n");
    for (i = 1; i < start; i++) {
      printf("     ");
    }
    for (a = 1; a <= number; a++) {
      printf("%d", a);
      if (a < 10) {
        printf("    ");
      } else if (a < 100) {
        printf("   ");
      } else {
        printf("  ");
      }
      if (((i - 1 + a) % 7) == 0) {
        printf("\n");
      } else {
      }
    }
    printf("\n---------------------------------\n");
    printf("\nCalendar complete.\n");
    cont = inputYOrN(0);
  }
}


x86 assembly (clang, -O0):
<calendar>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xe91(%rip),%rdi
call   1040 <puts@plt>
mov    $0x0,%al
call   1060 <lineBreak@plt>
xor    %edi,%edi
call   1030 <inputYOrN@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
je     133f <calendar+0x1df>
mov    $0x0,%al
call   1060 <lineBreak@plt>
lea    0xe76(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x8(%rbp),%rdi
mov    0x2e39(%rip),%rax
mov    (%rax),%edx
mov    $0x4,%esi
call   1070 <fgets@plt>
lea    -0x8(%rbp),%rdi
lea    0xe84(%rip),%rsi
lea    -0xd(%rbp),%rdx
call   1080 <sscanf@plt>
lea    0xe79(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0xc(%rbp),%rdi
mov    0x2e00(%rip),%rax
mov    (%rax),%edx
mov    $0x4,%esi
call   1070 <fgets@plt>
lea    -0xc(%rbp),%rdi
lea    0xe4b(%rip),%rsi
lea    -0xe(%rbp),%rdx
call   1080 <sscanf@plt>
lea    0xe69(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe7e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movb   $0x1,-0xf(%rbp)
movzbl -0xf(%rbp),%eax
movzbl -0xd(%rbp),%ecx
cmp    %ecx,%eax
jge    1253 <calendar+0xf3>
lea    0xe80(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0xf(%rbp),%al
add    $0x1,%al
mov    %al,-0xf(%rbp)
jmp    1228 <calendar+0xc8>
movb   $0x1,-0x10(%rbp)
movzbl -0x10(%rbp),%eax
movzbl -0xe(%rbp),%ecx
cmp    %ecx,%eax
jg     1314 <calendar+0x1b4>
movzbl -0x10(%rbp),%esi
lea    0xe53(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movzbl -0x10(%rbp),%eax
cmp    $0xa,%eax
jge    1299 <calendar+0x139>
lea    0xe33(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    12cc <calendar+0x16c>
movzbl -0x10(%rbp),%eax
cmp    $0x64,%eax
jge    12b9 <calendar+0x159>
lea    0xe14(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    12c7 <calendar+0x167>
lea    0xe02(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    12cc <calendar+0x16c>
movzbl -0xf(%rbp),%eax
sub    $0x1,%eax
movzbl -0x10(%rbp),%ecx
add    %ecx,%eax
mov    $0x7,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    12fd <calendar+0x19d>
lea    0xdcc(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1302 <calendar+0x1a2>
jmp    1302 <calendar+0x1a2>
jmp    1307 <calendar+0x1a7>
mov    -0x10(%rbp),%al
add    $0x1,%al
mov    %al,-0x10(%rbp)
jmp    1257 <calendar+0xf7>
lea    0xdad(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xdc3(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %edi,%edi
call   1030 <inputYOrN@plt>
mov    %eax,-0x4(%rbp)
jmp    1185 <calendar+0x25>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calendar>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xe7b(%rip),%rdi
call   1050 <puts@plt>
xor    %eax,%eax
call   1070 <lineBreak@plt>
xor    %edi,%edi
call   1040 <inputYOrN@plt>
test   %eax,%eax
je     1325 <calendar+0x1b5>
lea    0xef7(%rip),%r15
lea    0xeee(%rip),%r12
jmp    11d7 <calendar+0x67>
lea    0xf10(%rip),%rdi
call   1050 <puts@plt>
lea    0xf27(%rip),%rdi
call   1050 <puts@plt>
xor    %edi,%edi
call   1040 <inputYOrN@plt>
test   %eax,%eax
je     1325 <calendar+0x1b5>
xor    %eax,%eax
call   1070 <lineBreak@plt>
lea    0xe2e(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x2df5(%rip),%r14
mov    (%r14),%edx
lea    0x14(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x4,%esi
call   1080 <fgets@plt>
mov    %rbx,%rdi
lea    0xe38(%rip),%r13
mov    %r13,%rsi
lea    0xf(%rsp),%rdx
call   1090 <sscanf@plt>
lea    0xe29(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    (%r14),%edx
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x4,%esi
call   1080 <fgets@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
lea    0xe(%rsp),%rdx
call   1090 <sscanf@plt>
lea    0xe1f(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe3d(%rip),%rdi
call   1050 <puts@plt>
mov    $0x1,%bl
cmpb   $0x2,0xf(%rsp)
lea    0xe21(%rip),%rbp
jb     1293 <calendar+0x123>
mov    $0x1,%bl
xchg   %ax,%ax
mov    %rbp,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x1,%bl
cmp    0xf(%rsp),%bl
jb     1280 <calendar+0x110>
cmpb   $0x0,0xe(%rsp)
lea    0xe02(%rip),%rbp
je     11b0 <calendar+0x40>
movzbl %bl,%r14d
add    $0xffffffff,%r14d
mov    $0x1,%r13d
jmp    12d3 <calendar+0x163>
cs nopw 0x0(%rax,%rax,1)
nop
lea    0x1(%r13),%eax
movzbl %al,%r13d
cmp    0xe(%rsp),%r13b
ja     11b0 <calendar+0x40>
mov    %rbp,%rdi
mov    %r13d,%esi
xor    %eax,%eax
call   1060 <printf@plt>
cmp    $0x64,%r13b
mov    %r15,%rdi
lea    0xdaf(%rip),%rax
cmovb  %rax,%rdi
cmp    $0xa,%r13b
cmovb  %r12,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r13d,%eax
add    %r14d,%eax
imul   $0xb6db6db7,%eax,%eax
add    $0x12492492,%eax
cmp    $0x24924924,%eax
ja     12c0 <calendar+0x150>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    12c0 <calendar+0x150>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [19 x i8] c"Calendar Generator\00"
@.str.1 = [55 x i8] c"Enter the start day of the month (1(Mon) to 7(Sun)) : \00"
@stdin = global i32 0
@.str.2 = [5 x i8] c"%hhu\00"
@.str.3 = [41 x i8] c"\0AEnter the number of days in the month: \00"
@.str.4 = [35 x i8] c"\0AMon Tue Wed Thu Fri Sat Sun\00"
@.str.5 = [36 x i8] c"\0A--- --- --- --- --- --- ---\0A\00"
@.str.6 = [6 x i8] c" \00"
@.str.7 = [3 x i8] c"%d\00"
@.str.8 = [5 x i8] c" \00"
@.str.9 = [4 x i8] c" \00"
@.str.10 = [3 x i8] c" \00"
@.str.11 = [2 x i8] c"\0A\00"
@.str.12 = [36 x i8] c"\0A---------------------------------\0A\00"
@.str.13 = [21 x i8] c"\0ACalendar complete.\0A\00"
define void @calendar() {
%1 = alloca i32
%2 = alloca [4 x i8]
%3 = alloca [4 x i8]
%4 = alloca i8
%5 = alloca i8
%6 = alloca i8
%7 = alloca i8
%8 = call i32 @puts(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%9 = call i32 (...) @lineBreak()
%10 = call i32 @inputYOrN(i32 0)
store i32 %10, i32* %1
br label %11
11: ; preds = %82, %0
%12 = load i32, i32* %1
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %86
14: ; preds = %11
%15 = call i32 (...) @lineBreak()
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.1, i64 0, i64 0))
%17 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 0
%18 = load i32, i32* @stdin
%19 = call i32 @fgets(i8* %17, i32 4, i32 %18)
%20 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 0
%21 = call i32 @sscanf(i8* %20, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %4)
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0))
%23 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 0
%24 = load i32, i32* @stdin
%25 = call i32 @fgets(i8* %23, i32 4, i32 %24)
%26 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 0
%27 = call i32 @sscanf(i8* %26, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %5)
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0))
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.5, i64 0, i64 0))
store i8 1, i8* %6
br label %30
30: ; preds = %38, %14
%31 = load i8, i8* %6
%32 = zext i8 %31 to i32
%33 = load i8, i8* %4
%34 = zext i8 %33 to i32
%35 = icmp slt i32 %32, %34
br i1 %35, label %36, label %41
36: ; preds = %30
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
br label %38
38: ; preds = %36
%39 = load i8, i8* %6
%40 = add i8 %39, 1
store i8 %40, i8* %6
br label %30
41: ; preds = %30
store i8 1, i8* %7
br label %42
42: ; preds = %79, %41
%43 = load i8, i8* %7
%44 = zext i8 %43 to i32
%45 = load i8, i8* %5
%46 = zext i8 %45 to i32
%47 = icmp sle i32 %44, %46
br i1 %47, label %48, label %82
48: ; preds = %42
%49 = load i8, i8* %7
%50 = zext i8 %49 to i32
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i32 %50)
%52 = load i8, i8* %7
%53 = zext i8 %52 to i32
%54 = icmp slt i32 %53, 10
br i1 %54, label %55, label %57
55: ; preds = %48
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0))
br label %66
57: ; preds = %48
%58 = load i8, i8* %7
%59 = zext i8 %58 to i32
%60 = icmp slt i32 %59, 100
br i1 %60, label %61, label %63
61: ; preds = %57
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0))
br label %65
63: ; preds = %57
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.10, i64 0, i64 0))
br label %65
65: ; preds = %63, %61
br label %66
66: ; preds = %65, %55
%67 = load i8, i8* %6
%68 = zext i8 %67 to i32
%69 = sub nsw i32 %68, 1
%70 = load i8, i8* %7
%71 = zext i8 %70 to i32
%72 = add nsw i32 %69, %71
%73 = srem i32 %72, 7
%74 = icmp eq i32 %73, 0
br i1 %74, label %75, label %77
75: ; preds = %66
%76 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.11, i64 0, i64 0))
br label %78
77: ; preds = %66
br label %78
78: ; preds = %77, %75
br label %79
79: ; preds = %78
%80 = load i8, i8* %7
%81 = add i8 %80, 1
store i8 %81, i8* %7
br label %42
82: ; preds = %42
%83 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.12, i64 0, i64 0))
%84 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.13, i64 0, i64 0))
%85 = call i32 @inputYOrN(i32 0)
store i32 %85, i32* %1
br label %11
86: ; preds = %11
ret void
}

LLVM IR (-O2):
@.str = [19 x i8] c"Calendar Generator\00"
@.str.1 = [55 x i8] c"Enter the start day of the month (1(Mon) to 7(Sun)) : \00"
@stdin = global i32 0
@.str.2 = [5 x i8] c"%hhu\00"
@.str.3 = [41 x i8] c"\0AEnter the number of days in the month: \00"
@.str.4 = [35 x i8] c"\0AMon Tue Wed Thu Fri Sat Sun\00"
@.str.6 = [6 x i8] c" \00"
@.str.7 = [3 x i8] c"%d\00"
@.str.8 = [5 x i8] c" \00"
@.str.9 = [4 x i8] c" \00"
@.str.10 = [3 x i8] c" \00"
@str = [35 x i8] c"\0A--- --- --- --- --- --- ---\00"
@str.14 = [35 x i8] c"\0A---------------------------------\00"
@str.15 = [20 x i8] c"\0ACalendar complete.\00"
define void @calendar() {
%1 = alloca [4 x i8]
%2 = alloca [4 x i8]
%3 = alloca i8
%4 = alloca i8
%5 = getelementptr inbounds [4 x i8], [4 x i8]* %1, i64 0, i64 0
%6 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 0
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%8 = tail call i32 (...) @lineBreak()
%9 = tail call i32 @inputYOrN(i32 0)
%10 = icmp eq i32 %9, 0
br i1 %10, label %62, label %11
11: ; preds = %0, %57
%12 = call i32 (...) @lineBreak()
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([55 x i8], [55 x i8]* @.str.1, i64 0, i64 0))
%14 = load i32, i32* @stdin
%15 = call i32 @fgets(i8* %5, i32 4, i32 %14)
%16 = call i32 @sscanf(i8* %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %3)
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0))
%18 = load i32, i32* @stdin
%19 = call i32 @fgets(i8* %6, i32 4, i32 %18)
%20 = call i32 @sscanf(i8* %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %4)
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0))
%22 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str, i64 0, i64 0))
%23 = load i8, i8* %3
%24 = icmp ugt i8 %23, 1
br i1 %24, label %32, label %25
25: ; preds = %32, %11
%26 = phi i8 [ 1, %11 ], [ %35, %32 ]
%27 = load i8, i8* %4
%28 = icmp eq i8 %27, 0
br i1 %28, label %57, label %29
29: ; preds = %25
%30 = zext i8 %26 to i32
%31 = add nsw i32 %30, -1
br label %38
32: ; preds = %11, %32
%33 = phi i8 [ %35, %32 ], [ 1, %11 ]
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
%35 = add nuw i8 %33, 1
%36 = load i8, i8* %3
%37 = icmp ult i8 %35, %36
br i1 %37, label %32, label %25
38: ; preds = %29, %52
%39 = phi i32 [ 1, %29 ], [ %54, %52 ]
%40 = trunc i32 %39 to i8
%41 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i32 %39)
%42 = icmp ult i8 %40, 10
%43 = icmp ult i8 %40, 100
%44 = select i1 %43, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.10, i64 0, i64 0)
%45 = select i1 %42, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0), i8* %44
%46 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) %45)
%47 = add nsw i32 %31, %39
%48 = srem i32 %47, 7
%49 = icmp eq i32 %48, 0
br i1 %49, label %50, label %52
50: ; preds = %38
%51 = call i32 @putchar(i32 10)
br label %52
52: ; preds = %50, %38
%53 = add i8 %40, 1
%54 = zext i8 %53 to i32
%55 = load i8, i8* %4
%56 = icmp ugt i8 %53, %55
br i1 %56, label %57, label %38
57: ; preds = %52, %25
%58 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str.14, i64 0, i64 0))
%59 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.15, i64 0, i64 0))
%60 = call i32 @inputYOrN(i32 0)
%61 = icmp eq i32 %60, 0
br i1 %61, label %62, label %11
62: ; preds = %57, %0
ret void
}