#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*/ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ putchar(char);
int /*<<< orphan*/ stderr;
void show_cal(int year, int mon, int week_start) {
  static char *head = "Su Mo Tu We Th Fr Sa\n";
  int i, wrap, day;
  switch (mon) {
  case 1:
  case 3:
  case 5:
  case 7:
  case 8:
  case 10:
  case 12:
    day = 31;
    break;
  case 4:
  case 6:
  case 9:
  case 11:
    day = 30;
    break;
  case 2:
    day = (((year % 4 == 0 && year % 100) || (year % 400 == 0)) ? 29 : 28);
    break;
  default:
    fputs("month illegal\n", stderr);
    return;
  }
  printf("%s", head);
  wrap = 0;
  for (i = 0; i < week_start; i++) {
    printf("   ");
    wrap++;
  }
  for (i = 1; i <= day; i++) {
    printf("%-3d", i);
    if (++wrap % 7 == 0)
      putchar('\n');
  }
  putchar('\n');
}


x86 assembly (clang, -O0):
<show_cal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x1c(%rbp)
sub    $0x1,%eax
je     1202 <show_cal+0xd2>
jmp    1155 <show_cal+0x25>
mov    -0x1c(%rbp),%eax
sub    $0x2,%eax
je     121a <show_cal+0xea>
jmp    1166 <show_cal+0x36>
mov    -0x1c(%rbp),%eax
sub    $0x3,%eax
je     1202 <show_cal+0xd2>
jmp    1177 <show_cal+0x47>
mov    -0x1c(%rbp),%eax
sub    $0x4,%eax
je     120e <show_cal+0xde>
jmp    1188 <show_cal+0x58>
mov    -0x1c(%rbp),%eax
sub    $0x5,%eax
je     1202 <show_cal+0xd2>
jmp    1199 <show_cal+0x69>
mov    -0x1c(%rbp),%eax
sub    $0x6,%eax
je     120e <show_cal+0xde>
jmp    11aa <show_cal+0x7a>
mov    -0x1c(%rbp),%eax
add    $0xfffffff9,%eax
sub    $0x2,%eax
jb     1202 <show_cal+0xd2>
jmp    11be <show_cal+0x8e>
mov    -0x1c(%rbp),%eax
sub    $0x9,%eax
je     120e <show_cal+0xde>
jmp    11cf <show_cal+0x9f>
mov    -0x1c(%rbp),%eax
sub    $0xa,%eax
je     1202 <show_cal+0xd2>
jmp    11e0 <show_cal+0xb0>
mov    -0x1c(%rbp),%eax
sub    $0xb,%eax
je     120e <show_cal+0xde>
jmp    11f1 <show_cal+0xc1>
mov    -0x1c(%rbp),%eax
sub    $0xc,%eax
jne    1276 <show_cal+0x146>
jmp    1202 <show_cal+0xd2>
movl   $0x1f,-0x18(%rbp)
jmp    1290 <show_cal+0x160>
movl   $0x1e,-0x18(%rbp)
jmp    1290 <show_cal+0x160>
mov    -0x4(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1247 <show_cal+0x117>
mov    -0x4(%rbp),%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
mov    $0x1,%al
cmp    $0x0,%edx
mov    %al,-0x1d(%rbp)
jne    125b <show_cal+0x12b>
mov    -0x4(%rbp),%eax
mov    $0x190,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
sete   %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%dl
mov    $0x1c,%eax
mov    $0x1d,%ecx
test   $0x1,%dl
cmovne %ecx,%eax
mov    %eax,-0x18(%rbp)
jmp    1290 <show_cal+0x160>
mov    0x2d63(%rip),%rax
mov    (%rax),%esi
lea    0xd90(%rip),%rdi
call   1050 <fputs@plt>
jmp    1349 <show_cal+0x219>
mov    0x2da1(%rip),%rsi
lea    0xd87(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    12e4 <show_cal+0x1b4>
lea    0xd62(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    12b3 <show_cal+0x183>
movl   $0x1,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x18(%rbp),%eax
jg     133f <show_cal+0x20f>
mov    -0x10(%rbp),%esi
lea    0xd2b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    $0x7,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    132c <show_cal+0x1fc>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    1331 <show_cal+0x201>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    12eb <show_cal+0x1bb>
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<show_cal>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
cmp    $0xc,%esi
ja     1285 <show_cal+0x145>
mov    %edx,%r12d
mov    $0x20,%r15d
mov    $0x15aa,%eax
bt     %esi,%eax
jb     1178 <show_cal+0x38>
mov    $0xa50,%eax
bt     %esi,%eax
jae    122e <show_cal+0xee>
mov    $0x1f,%r15d
lea    0xe99(%rip),%rdi
call   1040 <puts@plt>
test   %r12d,%r12d
jle    11b1 <show_cal+0x71>
lea    0xe7f(%rip),%rbp
mov    %r12d,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbp,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0xffffffff,%ebx
jne    11a0 <show_cal+0x60>
jmp    11b4 <show_cal+0x74>
xor    %r12d,%r12d
add    $0x1,%r12d
mov    $0x1,%ebp
lea    0xe4f(%rip),%r14
jmp    11dc <show_cal+0x9c>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%ebp
add    $0x1,%r12d
cmp    %ebp,%r15d
je     121c <show_cal+0xdc>
mov    %r12d,%eax
imul   $0x24924925,%rax,%rax
shr    $0x20,%rax
mov    %r12d,%ebx
sub    %eax,%ebx
shr    %ebx
add    %eax,%ebx
shr    $0x2,%ebx
lea    0x0(,%rbx,8),%eax
sub    %eax,%ebx
mov    %r14,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
add    %r12d,%ebx
jne    11d0 <show_cal+0x90>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    11d0 <show_cal+0x90>
mov    $0xa,%edi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <putchar@plt>
cmp    $0x2,%esi
jne    1285 <show_cal+0x145>
test   $0x3,%dil
jne    1263 <show_cal+0x123>
movslq %edi,%rax
imul   $0x51eb851f,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x25,%rax
add    %ecx,%eax
imul   $0x64,%eax,%eax
mov    %edi,%ecx
mov    $0x1e,%r15d
sub    %eax,%ecx
jne    1178 <show_cal+0x38>
imul   $0xc28f5c29,%edi,%eax
add    $0x51eb850,%eax
ror    $0x4,%eax
cmp    $0xa3d70b,%eax
mov    $0x1d,%r15d
adc    $0x0,%r15d
jmp    1178 <show_cal+0x38>
mov    0x2d54(%rip),%rax
mov    (%rax),%esi
lea    0xd6b(%rip),%rdi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <fputs@plt>

LLVM IR (-O0):
@show_cal.head = internal global i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i32 0, i32 0)
@.str = [22 x i8] c"Su Mo Tu We Th Fr Sa\0A\00"
@.str.1 = [15 x i8] c"month illegal\0A\00"
@stderr = global i32 0
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [4 x i8] c" \00"
@.str.4 = [5 x i8] c"%-3d\00"
define void @show_cal(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%10 = load i32, i32* %5
switch i32 %10, label %29 [
i32 1, label %11
i32 3, label %11
i32 5, label %11
i32 7, label %11
i32 8, label %11
i32 10, label %11
i32 12, label %11
i32 4, label %12
i32 6, label %12
i32 9, label %12
i32 11, label %12
i32 2, label %13
]
11: ; preds = %3, %3, %3, %3, %3, %3, %3
store i32 31, i32* %9
br label %32
12: ; preds = %3, %3, %3, %3
store i32 30, i32* %9
br label %32
13: ; preds = %3
%14 = load i32, i32* %4
%15 = srem i32 %14, 4
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %13
%18 = load i32, i32* %4
%19 = srem i32 %18, 100
%20 = icmp ne i32 %19, 0
br i1 %20, label %25, label %21
21: ; preds = %17, %13
%22 = load i32, i32* %4
%23 = srem i32 %22, 400
%24 = icmp eq i32 %23, 0
br label %25
25: ; preds = %21, %17
%26 = phi i1 [ true, %17 ], [ %24, %21 ]
%27 = zext i1 %26 to i64
%28 = select i1 %26, i32 29, i32 28
store i32 %28, i32* %9
br label %32
29: ; preds = %3
%30 = load i32, i32* @stderr
%31 = call i32 @fputs(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %30)
br label %66
32: ; preds = %25, %12, %11
%33 = load i8*, i8** @show_cal.head
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %33)
store i32 0, i32* %8
store i32 0, i32* %7
br label %35
35: ; preds = %43, %32
%36 = load i32, i32* %7
%37 = load i32, i32* %6
%38 = icmp slt i32 %36, %37
br i1 %38, label %39, label %46
39: ; preds = %35
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%41 = load i32, i32* %8
%42 = add nsw i32 %41, 1
store i32 %42, i32* %8
br label %43
43: ; preds = %39
%44 = load i32, i32* %7
%45 = add nsw i32 %44, 1
store i32 %45, i32* %7
br label %35
46: ; preds = %35
store i32 1, i32* %7
br label %47
47: ; preds = %61, %46
%48 = load i32, i32* %7
%49 = load i32, i32* %9
%50 = icmp sle i32 %48, %49
br i1 %50, label %51, label %64
51: ; preds = %47
%52 = load i32, i32* %7
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %52)
%54 = load i32, i32* %8
%55 = add nsw i32 %54, 1
store i32 %55, i32* %8
%56 = srem i32 %55, 7
%57 = icmp eq i32 %56, 0
br i1 %57, label %58, label %60
58: ; preds = %51
%59 = call i32 @putchar(i8 signext 10)
br label %60
60: ; preds = %58, %51
br label %61
61: ; preds = %60
%62 = load i32, i32* %7
%63 = add nsw i32 %62, 1
store i32 %63, i32* %7
br label %47
64: ; preds = %47
%65 = call i32 @putchar(i8 signext 10)
br label %66
66: ; preds = %64, %29
ret void
}

LLVM IR (-O2):
@.str.1 = [15 x i8] c"month illegal\0A\00"
@stderr = global i32 0
@.str.3 = [4 x i8] c" \00"
@.str.4 = [5 x i8] c"%-3d\00"
@str = [21 x i8] c"Su Mo Tu We Th Fr Sa\00"
define void @show_cal(i32 %0, i32 %1, i32 %2) {
switch i32 %1, label %15 [
i32 1, label %18
i32 3, label %18
i32 5, label %18
i32 7, label %18
i32 8, label %18
i32 10, label %18
i32 12, label %18
i32 4, label %4
i32 6, label %4
i32 9, label %4
i32 11, label %4
i32 2, label %5
]
4: ; preds = %3, %3, %3, %3
br label %18
5: ; preds = %3
%6 = and i32 %0, 3
%7 = icmp ne i32 %6, 0
%8 = srem i32 %0, 100
%9 = icmp eq i32 %8, 0
%10 = or i1 %7, %9
br i1 %10, label %11, label %18
11: ; preds = %5
%12 = srem i32 %0, 400
%13 = icmp eq i32 %12, 0
%14 = select i1 %13, i32 30, i32 29
br label %18
15: ; preds = %3
%16 = load i32, i32* @stderr
%17 = tail call i32 @fputs(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %16)
br label %43
18: ; preds = %11, %5, %3, %3, %3, %3, %3, %3, %3, %4
%19 = phi i32 [ 31, %4 ], [ 32, %3 ], [ 32, %3 ], [ 32, %3 ], [ 32, %3 ], [ 32, %3 ], [ 32, %3 ], [ 32, %3 ], [ %14, %11 ], [ 30, %5 ]
%20 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
%21 = icmp sgt i32 %2, 0
br i1 %21, label %22, label %27
22: ; preds = %18, %22
%23 = phi i32 [ %25, %22 ], [ 0, %18 ]
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%25 = add nuw nsw i32 %23, 1
%26 = icmp eq i32 %25, %2
br i1 %26, label %27, label %22
27: ; preds = %22, %18
%28 = phi i32 [ 0, %18 ], [ %2, %22 ]
br label %29
29: ; preds = %27, %38
%30 = phi i32 [ %33, %38 ], [ %28, %27 ]
%31 = phi i32 [ %39, %38 ], [ 1, %27 ]
%32 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %31)
%33 = add nuw nsw i32 %30, 1
%34 = urem i32 %33, 7
%35 = icmp eq i32 %34, 0
br i1 %35, label %36, label %38
36: ; preds = %29
%37 = tail call i32 @putchar(i8 signext 10)
br label %38
38: ; preds = %29, %36
%39 = add nuw nsw i32 %31, 1
%40 = icmp eq i32 %39, %19
br i1 %40, label %41, label %29
41: ; preds = %38
%42 = tail call i32 @putchar(i8 signext 10)
br label %43
43: ; preds = %41, %15
ret void
}