#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 */
typedef int /*<<< orphan*/ time_t;
struct tm {
  int tm_year;
  int tm_mon;
};

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ atoi(char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
struct tm *localtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ printheader(struct tm *, int);
int /*<<< orphan*/ printmonth(struct tm *);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main(int argc, char *argv[]) {
  struct tm *local_time;
  bool printall = false;
  time_t unix_time;
  time(&unix_time);
  local_time = localtime(&unix_time);
  switch (argc) {
  case 1:
    local_time->tm_year += 1900;
    local_time->tm_mon++;
    break;
  case 2:
    local_time->tm_year = (unsigned)atoi(argv[1]);
    local_time->tm_mon = 1;
    printall = true;
    break;
  case 3:
    local_time->tm_mon = (unsigned)atoi(argv[1]);
    local_time->tm_year = (unsigned)atoi(argv[2]);
    break;
  default:
    fprintf(stderr, "Usage: %s [[month] year]\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  if (local_time->tm_mon > 12 || local_time->tm_year < 0 ||
      local_time->tm_year > 9999) {
    fprintf(stderr, "Usage: %s [[month] year]\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  char days[] = "Su Mo Tu We Th Fr Sa";
  if (printall) {
    do {
      printheader(local_time, false);
      puts(days);
      printmonth(local_time);
    } while (++local_time->tm_mon < 12);
  } else {
    printheader(local_time, true);
    puts(days);
    printmonth(local_time);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
lea    -0x20(%rbp),%rdi
mov    %rdi,-0x50(%rbp)
call   1080 <time@plt>
mov    -0x50(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x44(%rbp)
sub    $0x1,%eax
je     11ed <main+0x6d>
jmp    11cb <main+0x4b>
mov    -0x44(%rbp),%eax
sub    $0x2,%eax
je     120d <main+0x8d>
jmp    11dc <main+0x5c>
mov    -0x44(%rbp),%eax
sub    $0x3,%eax
je     1239 <main+0xb9>
jmp    1269 <main+0xe9>
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
add    $0x76c,%ecx
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
mov    0x4(%rax),%ecx
add    $0x1,%ecx
mov    %ecx,0x4(%rax)
jmp    1293 <main+0x113>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
movl   $0x1,0x4(%rax)
movl   $0x1,-0x1c(%rbp)
jmp    1293 <main+0x113>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
jmp    1293 <main+0x113>
mov    0x2d70(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xd80(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2d4c(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x18(%rbp),%rax
cmpl   $0xc,0x4(%rax)
jg     12be <main+0x13e>
mov    -0x18(%rbp),%rax
cmpl   $0x0,(%rax)
jl     12be <main+0x13e>
mov    -0x18(%rbp),%rax
cmpl   $0x270f,(%rax)
jle    12e8 <main+0x168>
mov    0x2d1b(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xd2b(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2cf7(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    0xd31(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0xd2e(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    0xd2c(%rip),%eax
mov    %eax,-0x30(%rbp)
mov    0xd27(%rip),%al
mov    %al,-0x2c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     1357 <main+0x1d7>
jmp    131f <main+0x19f>
mov    -0x18(%rbp),%rdi
xor    %esi,%esi
call   1060 <printheader@plt>
lea    -0x40(%rbp),%rdi
call   1040 <puts@plt>
mov    -0x18(%rbp),%rdi
call   1050 <printmonth@plt>
mov    -0x18(%rbp),%rcx
mov    0x4(%rcx),%eax
add    $0x1,%eax
mov    %eax,0x4(%rcx)
cmp    $0xc,%eax
jl     131f <main+0x19f>
jmp    1377 <main+0x1f7>
mov    -0x18(%rbp),%rdi
mov    $0x1,%esi
call   1060 <printheader@plt>
lea    -0x40(%rbp),%rdi
call   1040 <puts@plt>
mov    -0x18(%rbp),%rdi
call   1050 <printmonth@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %rsi,%r14
mov    %edi,%ebp
lea    0x1c(%rsp),%rbx
mov    %rbx,%rdi
call   1080 <time@plt>
mov    %rbx,%rdi
call   1030 <localtime@plt>
mov    %rax,%rbx
cmp    $0x3,%ebp
je     11d0 <main+0x50>
cmp    $0x2,%ebp
je     1236 <main+0xb6>
cmp    $0x1,%ebp
jne    12a3 <main+0x123>
mov    $0x76c,%eax
add    (%rbx),%eax
mov    %eax,(%rbx)
mov    0x4(%rbx),%ebp
add    $0x1,%ebp
mov    %ebp,0x4(%rbx)
jmp    11e9 <main+0x69>
mov    0x8(%r14),%rdi
call   1090 <atoi@plt>
mov    %eax,%ebp
mov    %eax,0x4(%rbx)
mov    0x10(%r14),%rdi
call   1090 <atoi@plt>
mov    %eax,(%rbx)
cmp    $0xc,%ebp
jg     12a3 <main+0x123>
cmp    $0x270f,%eax
ja     12a3 <main+0x123>
movaps 0xe1c(%rip),%xmm0
movaps %xmm0,(%rsp)
movabs $0x61532072462068,%rax
mov    %rax,0xd(%rsp)
mov    %rbx,%rdi
mov    $0x1,%esi
call   1060 <printheader@plt>
mov    %rsp,%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
call   1050 <printmonth@plt>
jmp    1298 <main+0x118>
mov    0x8(%r14),%rdi
call   1090 <atoi@plt>
mov    %eax,(%rbx)
movl   $0x1,0x4(%rbx)
cmp    $0x2710,%eax
jae    12a3 <main+0x123>
movaps 0xdca(%rip),%xmm0
movaps %xmm0,(%rsp)
movabs $0x61532072462068,%rax
mov    %rax,0xd(%rsp)
mov    %rsp,%rbp
nopl   0x0(%rax)
mov    %rbx,%rdi
xor    %esi,%esi
call   1060 <printheader@plt>
mov    %rbp,%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
call   1050 <printmonth@plt>
mov    0x4(%rbx),%eax
lea    0x1(%rax),%ecx
mov    %ecx,0x4(%rbx)
cmp    $0xb,%eax
jl     1270 <main+0xf0>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2d36(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
lea    0xd4a(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2d16(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
%struct.tm = type { i32, i32 }
@stderr = global i32 0
@.str = [26 x i8] c"Usage: %s [[month] year]\0A\00"
@EXIT_FAILURE = global i32 0
@__const.main.days = [21 x i8] c"Su Mo Tu We Th Fr Sa\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.tm*
%7 = alloca i32
%8 = alloca i32
%9 = alloca [21 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
%10 = call i32 @time(i32* %8)
%11 = call %struct.tm* @localtime(i32* %8)
store %struct.tm* %11, %struct.tm** %6
%12 = load i32, i32* %4
switch i32 %12, label %44 [
i32 1, label %13
i32 2, label %22
i32 3, label %31
]
13: ; preds = %2
%14 = load %struct.tm*, %struct.tm** %6
%15 = getelementptr inbounds %struct.tm, %struct.tm* %14, i32 0, i32 0
%16 = load i32, i32* %15
%17 = add nsw i32 %16, 1900
store i32 %17, i32* %15
%18 = load %struct.tm*, %struct.tm** %6
%19 = getelementptr inbounds %struct.tm, %struct.tm* %18, i32 0, i32 1
%20 = load i32, i32* %19
%21 = add nsw i32 %20, 1
store i32 %21, i32* %19
br label %52
22: ; preds = %2
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = call i32 @atoi(i8* %25)
%27 = load %struct.tm*, %struct.tm** %6
%28 = getelementptr inbounds %struct.tm, %struct.tm* %27, i32 0, i32 0
store i32 %26, i32* %28
%29 = load %struct.tm*, %struct.tm** %6
%30 = getelementptr inbounds %struct.tm, %struct.tm* %29, i32 0, i32 1
store i32 1, i32* %30
store i32 1, i32* %7
br label %52
31: ; preds = %2
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 1
%34 = load i8*, i8** %33
%35 = call i32 @atoi(i8* %34)
%36 = load %struct.tm*, %struct.tm** %6
%37 = getelementptr inbounds %struct.tm, %struct.tm* %36, i32 0, i32 1
store i32 %35, i32* %37
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 2
%40 = load i8*, i8** %39
%41 = call i32 @atoi(i8* %40)
%42 = load %struct.tm*, %struct.tm** %6
%43 = getelementptr inbounds %struct.tm, %struct.tm* %42, i32 0, i32 0
store i32 %41, i32* %43
br label %52
44: ; preds = %2
%45 = load i32, i32* @stderr
%46 = load i8**, i8*** %5
%47 = getelementptr inbounds i8*, i8** %46, i64 0
%48 = load i8*, i8** %47
%49 = call i32 @fprintf(i32 %45, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %48)
%50 = load i32, i32* @EXIT_FAILURE
%51 = call i32 @exit(i32 %50)
unreachable
52: ; preds = %31, %22, %13
%53 = load %struct.tm*, %struct.tm** %6
%54 = getelementptr inbounds %struct.tm, %struct.tm* %53, i32 0, i32 1
%55 = load i32, i32* %54
%56 = icmp sgt i32 %55, 12
br i1 %56, label %67, label %57
57: ; preds = %52
%58 = load %struct.tm*, %struct.tm** %6
%59 = getelementptr inbounds %struct.tm, %struct.tm* %58, i32 0, i32 0
%60 = load i32, i32* %59
%61 = icmp slt i32 %60, 0
br i1 %61, label %67, label %62
62: ; preds = %57
%63 = load %struct.tm*, %struct.tm** %6
%64 = getelementptr inbounds %struct.tm, %struct.tm* %63, i32 0, i32 0
%65 = load i32, i32* %64
%66 = icmp sgt i32 %65, 9999
br i1 %66, label %67, label %75
67: ; preds = %62, %57, %52
%68 = load i32, i32* @stderr
%69 = load i8**, i8*** %5
%70 = getelementptr inbounds i8*, i8** %69, i64 0
%71 = load i8*, i8** %70
%72 = call i32 @fprintf(i32 %68, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %71)
%73 = load i32, i32* @EXIT_FAILURE
%74 = call i32 @exit(i32 %73)
unreachable
75: ; preds = %62
%76 = bitcast [21 x i8]* %9 to i8*
%77 = load i32, i32* %7
%78 = icmp ne i32 %77, 0
br i1 %78, label %79, label %94
79: ; preds = %75
br label %80
80: ; preds = %87, %79
%81 = load %struct.tm*, %struct.tm** %6
%82 = call i32 @printheader(%struct.tm* %81, i32 0)
%83 = getelementptr inbounds [21 x i8], [21 x i8]* %9, i64 0, i64 0
%84 = call i32 @puts(i8* %83)
%85 = load %struct.tm*, %struct.tm** %6
%86 = call i32 @printmonth(%struct.tm* %85)
br label %87
87: ; preds = %80
%88 = load %struct.tm*, %struct.tm** %6
%89 = getelementptr inbounds %struct.tm, %struct.tm* %88, i32 0, i32 1
%90 = load i32, i32* %89
%91 = add nsw i32 %90, 1
store i32 %91, i32* %89
%92 = icmp slt i32 %91, 12
br i1 %92, label %80, label %93
93: ; preds = %87
br label %101
94: ; preds = %75
%95 = load %struct.tm*, %struct.tm** %6
%96 = call i32 @printheader(%struct.tm* %95, i32 1)
%97 = getelementptr inbounds [21 x i8], [21 x i8]* %9, i64 0, i64 0
%98 = call i32 @puts(i8* %97)
%99 = load %struct.tm*, %struct.tm** %6
%100 = call i32 @printmonth(%struct.tm* %99)
br label %101
101: ; preds = %94, %93
ret i32 0
}

LLVM IR (-O2):
%struct.tm = type { i32, i32 }
@stderr = global i32 0
@.str = [26 x i8] c"Usage: %s [[month] year]\0A\00"
@EXIT_FAILURE = global i32 0
@__const.main.days = [21 x i8] c"Su Mo Tu We Th Fr Sa\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca [21 x i8]
%5 = bitcast i32* %3 to i8*
%6 = call i32 @time(i32* %3)
%7 = call %struct.tm* @localtime(i32* %3)
switch i32 %0, label %24 [
i32 1, label %8
i32 2, label %36
i32 3, label %15
]
8: ; preds = %2
%9 = getelementptr inbounds %struct.tm, %struct.tm* %7, i64 0, i32 0
%10 = load i32, i32* %9
%11 = add nsw i32 %10, 1900
store i32 %11, i32* %9
%12 = getelementptr inbounds %struct.tm, %struct.tm* %7, i64 0, i32 1
%13 = load i32, i32* %12
%14 = add nsw i32 %13, 1
store i32 %14, i32* %12
br label %30
15: ; preds = %2
%16 = getelementptr inbounds i8*, i8** %1, i64 1
%17 = load i8*, i8** %16
%18 = call i32 @atoi(i8* %17)
%19 = getelementptr inbounds %struct.tm, %struct.tm* %7, i64 0, i32 1
store i32 %18, i32* %19
%20 = getelementptr inbounds i8*, i8** %1, i64 2
%21 = load i8*, i8** %20
%22 = call i32 @atoi(i8* %21)
%23 = getelementptr inbounds %struct.tm, %struct.tm* %7, i64 0, i32 0
store i32 %22, i32* %23
br label %30
24: ; preds = %2
%25 = load i32, i32* @stderr
%26 = load i8*, i8** %1
%27 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %26)
%28 = load i32, i32* @EXIT_FAILURE
%29 = call i32 @exit(i32 %28)
unreachable
30: ; preds = %15, %8
%31 = phi i32 [ %22, %15 ], [ %11, %8 ]
%32 = phi i32 [ %18, %15 ], [ %14, %8 ]
%33 = icmp sgt i32 %32, 12
%34 = icmp ugt i32 %31, 9999
%35 = select i1 %33, i1 true, i1 %34
br i1 %35, label %44, label %59
36: ; preds = %2
%37 = getelementptr inbounds i8*, i8** %1, i64 1
%38 = load i8*, i8** %37
%39 = call i32 @atoi(i8* %38)
%40 = getelementptr inbounds %struct.tm, %struct.tm* %7, i64 0, i32 0
store i32 %39, i32* %40
%41 = getelementptr inbounds %struct.tm, %struct.tm* %7, i64 0, i32 1
store i32 1, i32* %41
%42 = getelementptr inbounds %struct.tm, %struct.tm* %7, i64 0, i32 1
%43 = icmp ugt i32 %39, 9999
br i1 %43, label %44, label %50
44: ; preds = %36, %30
%45 = load i32, i32* @stderr
%46 = load i8*, i8** %1
%47 = call i32 @fprintf(i32 %45, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %46)
%48 = load i32, i32* @EXIT_FAILURE
%49 = call i32 @exit(i32 %48)
unreachable
50: ; preds = %36
%51 = getelementptr inbounds [21 x i8], [21 x i8]* %4, i64 0, i64 0
br label %52
52: ; preds = %50, %52
%53 = call i32 @printheader(%struct.tm* %7, i32 0)
%54 = call i32 @puts(i8* %51)
%55 = call i32 @printmonth(%struct.tm* %7)
%56 = load i32, i32* %42
%57 = add nsw i32 %56, 1
store i32 %57, i32* %42
%58 = icmp slt i32 %56, 11
br i1 %58, label %52, label %64
59: ; preds = %30
%60 = getelementptr inbounds [21 x i8], [21 x i8]* %4, i64 0, i64 0
%61 = call i32 @printheader(%struct.tm* %7, i32 1)
%62 = call i32 @puts(i8* %60)
%63 = call i32 @printmonth(%struct.tm* %7)
br label %64
64: ; preds = %52, %59
%65 = getelementptr inbounds [21 x i8], [21 x i8]* %4, i64 0, i64 0
ret i32 0
}