#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_mon;
  int tm_year;
};

/* Variables and functions */
int /*<<< orphan*/ bu_extra_argument(char *);
scalar_t__ bu_handle_version(int, char **);
scalar_t__ has_arg(int, char **, char *);
struct tm *localtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ print_month(int, int);
int /*<<< orphan*/ print_year(int);
int /*<<< orphan*/ puts(char *);
scalar_t__ strtol(char *, char **, int);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main(int argc, char **argv) {
  if (has_arg(argc, argv, "-h") || has_arg(argc, argv, "--help")) {
    puts("Usage: cal [[MONTH] YEAR]");
    puts("Prints a calendar for the specified timeframe.\n");
    puts("If MONTH and YEAR are provided, prints the calendar for the "
         "specified month.");
    puts("If only YEAR is provided, prints the calendar for all of YEAR.");
    puts("Otherwise, prints the calendar for the current month and year.");
    return 1;
  }
  if (bu_handle_version(argc, argv)) {
    return 0;
  }
  if (argc > 3) {
    bu_extra_argument(argv[0]);
    return 1;
  }
  int year = 0;
  int month = 0;
  if (argc == 3) {
    year = (int)strtol(argv[2], (char **)NULL, 10);
    month = (int)strtol(argv[1], (char **)NULL, 10);
  }
  if (argc == 2) {
    year = (int)strtol(argv[1], (char **)NULL, 10);
  }
  if (year == 0 && month == 0) {
    time_t current_time = time(NULL);
    struct tm *ltime = localtime(&current_time);
    month = ltime->tm_mon + 1;
    year = ltime->tm_year + 1900;
  }
  if (month) {
    print_month(year, month);
  } else {
    print_year(year);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe4c(%rip),%rdx
call   1060 <has_arg@plt>
cmp    $0x0,%rax
jne    11e0 <main+0x50>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe32(%rip),%rdx
call   1060 <has_arg@plt>
cmp    $0x0,%rax
je     1228 <main+0x98>
lea    0xe23(%rip),%rdi
call   1050 <puts@plt>
lea    0xe31(%rip),%rdi
call   1050 <puts@plt>
lea    0xe55(%rip),%rdi
call   1050 <puts@plt>
lea    0xe96(%rip),%rdi
call   1050 <puts@plt>
lea    0xec9(%rip),%rdi
call   1050 <puts@plt>
movl   $0x1,-0x4(%rbp)
jmp    134a <main+0x1ba>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   10b0 <bu_handle_version@plt>
cmp    $0x0,%rax
je     124a <main+0xba>
movl   $0x0,-0x4(%rbp)
jmp    134a <main+0x1ba>
cmpl   $0x3,-0x8(%rbp)
jle    126c <main+0xdc>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10a0 <bu_extra_argument@plt>
movl   $0x1,-0x4(%rbp)
jmp    134a <main+0x1ba>
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x3,-0x8(%rbp)
jne    12b6 <main+0x126>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1080 <strtol@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1080 <strtol@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x2,-0x8(%rbp)
jne    12d9 <main+0x149>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1080 <strtol@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    1321 <main+0x191>
cmpl   $0x0,-0x18(%rbp)
jne    1321 <main+0x191>
xor    %eax,%eax
mov    %eax,%edi
call   1090 <time@plt>
mov    %eax,-0x1c(%rbp)
lea    -0x1c(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    (%rax),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x28(%rbp),%rax
mov    0x4(%rax),%eax
add    $0x76c,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     133b <main+0x1ab>
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
call   1040 <print_month@plt>
jmp    1343 <main+0x1b3>
mov    -0x14(%rbp),%edi
call   1070 <print_year@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xe5d(%rip),%rdx
call   1060 <has_arg@plt>
test   %rax,%rax
jne    11c3 <main+0x33>
lea    0xe4f(%rip),%rdx
mov    %ebp,%edi
mov    %rbx,%rsi
call   1060 <has_arg@plt>
test   %rax,%rax
je     120f <main+0x7f>
lea    0xe40(%rip),%rdi
call   1050 <puts@plt>
lea    0xe4e(%rip),%rdi
call   1050 <puts@plt>
lea    0xe72(%rip),%rdi
call   1050 <puts@plt>
lea    0xeb3(%rip),%rdi
call   1050 <puts@plt>
lea    0xee6(%rip),%rdi
call   1050 <puts@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %ebp,%edi
mov    %rbx,%rsi
call   10b0 <bu_handle_version@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
jne    1204 <main+0x74>
cmp    $0x4,%ebp
jl     1232 <main+0xa2>
mov    (%rbx),%rdi
call   10a0 <bu_extra_argument@plt>
jmp    11ff <main+0x6f>
cmp    $0x2,%ebp
je     126d <main+0xdd>
xor    %r14d,%r14d
mov    $0x0,%r15d
cmp    $0x3,%ebp
jne    1283 <main+0xf3>
mov    0x10(%rbx),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1080 <strtol@plt>
mov    %rax,%r15
mov    0x8(%rbx),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1080 <strtol@plt>
mov    %rax,%r14
jmp    1283 <main+0xf3>
mov    0x8(%rbx),%rdi
xor    %r14d,%r14d
xor    %esi,%esi
mov    $0xa,%edx
call   1080 <strtol@plt>
mov    %rax,%r15
mov    %r15d,%eax
or     %r14d,%eax
jne    12b1 <main+0x121>
xor    %edi,%edi
call   1090 <time@plt>
mov    %eax,0x4(%rsp)
lea    0x4(%rsp),%rdi
call   1030 <localtime@plt>
mov    (%rax),%r14d
add    $0x1,%r14d
mov    $0x76c,%r15d
add    0x4(%rax),%r15d
mov    %r15d,%edi
test   %r14d,%r14d
je     12c3 <main+0x133>
mov    %r14d,%esi
call   1040 <print_month@plt>
jmp    12c8 <main+0x138>
call   1070 <print_year@plt>
xor    %eax,%eax
jmp    1204 <main+0x74>

LLVM IR (-O0):
%struct.tm = type { i32, i32 }
@.str = [3 x i8] c"-h\00"
@.str.1 = [7 x i8] c"--help\00"
@.str.2 = [26 x i8] c"Usage: cal [[MONTH] YEAR]\00"
@.str.3 = [48 x i8] c"Prints a calendar for the specified timeframe.\0A\00"
@.str.4 = [77 x i8] c"If MONTH and YEAR are provided, prints the calendar for the specified month.\00"
@.str.5 = [63 x i8] c"If only YEAR is provided, prints the calendar for all of YEAR.\00"
@.str.6 = [63 x i8] c"Otherwise, prints the calendar for the current month and year.\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca %struct.tm*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = load i8**, i8*** %5
%12 = call i64 @has_arg(i32 %10, i8** %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%13 = icmp ne i64 %12, 0
br i1 %13, label %19, label %14
14: ; preds = %2
%15 = load i32, i32* %4
%16 = load i8**, i8*** %5
%17 = call i64 @has_arg(i32 %15, i8** %16, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %25
19: ; preds = %14, %2
%20 = call i32 @puts(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
%21 = call i32 @puts(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.3, i64 0, i64 0))
%22 = call i32 @puts(i8* getelementptr inbounds ([77 x i8], [77 x i8]* @.str.4, i64 0, i64 0))
%23 = call i32 @puts(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.5, i64 0, i64 0))
%24 = call i32 @puts(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.6, i64 0, i64 0))
store i32 1, i32* %3
br label %90
25: ; preds = %14
%26 = load i32, i32* %4
%27 = load i8**, i8*** %5
%28 = call i64 @bu_handle_version(i32 %26, i8** %27)
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %31
30: ; preds = %25
store i32 0, i32* %3
br label %90
31: ; preds = %25
%32 = load i32, i32* %4
%33 = icmp sgt i32 %32, 3
br i1 %33, label %34, label %39
34: ; preds = %31
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 0
%37 = load i8*, i8** %36
%38 = call i32 @bu_extra_argument(i8* %37)
store i32 1, i32* %3
br label %90
39: ; preds = %31
store i32 0, i32* %6
store i32 0, i32* %7
%40 = load i32, i32* %4
%41 = icmp eq i32 %40, 3
br i1 %41, label %42, label %53
42: ; preds = %39
%43 = load i8**, i8*** %5
%44 = getelementptr inbounds i8*, i8** %43, i64 2
%45 = load i8*, i8** %44
%46 = call i64 @strtol(i8* %45, i8** null, i32 10)
%47 = trunc i64 %46 to i32
store i32 %47, i32* %6
%48 = load i8**, i8*** %5
%49 = getelementptr inbounds i8*, i8** %48, i64 1
%50 = load i8*, i8** %49
%51 = call i64 @strtol(i8* %50, i8** null, i32 10)
%52 = trunc i64 %51 to i32
store i32 %52, i32* %7
br label %53
53: ; preds = %42, %39
%54 = load i32, i32* %4
%55 = icmp eq i32 %54, 2
br i1 %55, label %56, label %62
56: ; preds = %53
%57 = load i8**, i8*** %5
%58 = getelementptr inbounds i8*, i8** %57, i64 1
%59 = load i8*, i8** %58
%60 = call i64 @strtol(i8* %59, i8** null, i32 10)
%61 = trunc i64 %60 to i32
store i32 %61, i32* %6
br label %62
62: ; preds = %56, %53
%63 = load i32, i32* %6
%64 = icmp eq i32 %63, 0
br i1 %64, label %65, label %79
65: ; preds = %62
%66 = load i32, i32* %7
%67 = icmp eq i32 %66, 0
br i1 %67, label %68, label %79
68: ; preds = %65
%69 = call i32 @time(i32* null)
store i32 %69, i32* %8
%70 = call %struct.tm* @localtime(i32* %8)
store %struct.tm* %70, %struct.tm** %9
%71 = load %struct.tm*, %struct.tm** %9
%72 = getelementptr inbounds %struct.tm, %struct.tm* %71, i32 0, i32 0
%73 = load i32, i32* %72
%74 = add nsw i32 %73, 1
store i32 %74, i32* %7
%75 = load %struct.tm*, %struct.tm** %9
%76 = getelementptr inbounds %struct.tm, %struct.tm* %75, i32 0, i32 1
%77 = load i32, i32* %76
%78 = add nsw i32 %77, 1900
store i32 %78, i32* %6
br label %79
79: ; preds = %68, %65, %62
%80 = load i32, i32* %7
%81 = icmp ne i32 %80, 0
br i1 %81, label %82, label %86
82: ; preds = %79
%83 = load i32, i32* %6
%84 = load i32, i32* %7
%85 = call i32 @print_month(i32 %83, i32 %84)
br label %89
86: ; preds = %79
%87 = load i32, i32* %6
%88 = call i32 @print_year(i32 %87)
br label %89
89: ; preds = %86, %82
store i32 0, i32* %3
br label %90
90: ; preds = %89, %34, %30, %19
%91 = load i32, i32* %3
ret i32 %91
}

LLVM IR (-O2):
%struct.tm = type { i32, i32 }
@.str = [3 x i8] c"-h\00"
@.str.1 = [7 x i8] c"--help\00"
@.str.2 = [26 x i8] c"Usage: cal [[MONTH] YEAR]\00"
@.str.3 = [48 x i8] c"Prints a calendar for the specified timeframe.\0A\00"
@.str.4 = [77 x i8] c"If MONTH and YEAR are provided, prints the calendar for the specified month.\00"
@.str.5 = [63 x i8] c"If only YEAR is provided, prints the calendar for all of YEAR.\00"
@.str.6 = [63 x i8] c"Otherwise, prints the calendar for the current month and year.\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = tail call i64 @has_arg(i32 %0, i8** %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = tail call i64 @has_arg(i32 %0, i8** %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp eq i64 %7, 0
br i1 %8, label %15, label %9
9: ; preds = %6, %2
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @.str.3, i64 0, i64 0))
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([77 x i8], [77 x i8]* @.str.4, i64 0, i64 0))
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([63 x i8], [63 x i8]* @.str.5, i64 0, i64 0))
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([63 x i8], [63 x i8]* @.str.6, i64 0, i64 0))
br label %62
15: ; preds = %6
%16 = tail call i64 @bu_handle_version(i32 %0, i8** %1)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %62
18: ; preds = %15
%19 = icmp sgt i32 %0, 3
br i1 %19, label %20, label %23
20: ; preds = %18
%21 = load i8*, i8** %1
%22 = tail call i32 @bu_extra_argument(i8* %21)
br label %62
23: ; preds = %18
switch i32 %0, label %38 [
i32 3, label %24
i32 2, label %33
]
24: ; preds = %23
%25 = getelementptr inbounds i8*, i8** %1, i64 2
%26 = load i8*, i8** %25
%27 = tail call i64 @strtol(i8* nocapture %26, i8** null, i32 10)
%28 = trunc i64 %27 to i32
%29 = getelementptr inbounds i8*, i8** %1, i64 1
%30 = load i8*, i8** %29
%31 = tail call i64 @strtol(i8* nocapture %30, i8** null, i32 10)
%32 = trunc i64 %31 to i32
br label %38
33: ; preds = %23
%34 = getelementptr inbounds i8*, i8** %1, i64 1
%35 = load i8*, i8** %34
%36 = tail call i64 @strtol(i8* nocapture %35, i8** null, i32 10)
%37 = trunc i64 %36 to i32
br label %38
38: ; preds = %23, %24, %33
%39 = phi i32 [ 0, %33 ], [ %32, %24 ], [ 0, %23 ]
%40 = phi i32 [ %37, %33 ], [ %28, %24 ], [ 0, %23 ]
%41 = icmp eq i32 %40, 0
%42 = icmp eq i32 %39, 0
%43 = select i1 %41, i1 %42, i1 false
br i1 %43, label %44, label %54
44: ; preds = %38
%45 = bitcast i32* %3 to i8*
%46 = tail call i32 @time(i32* null)
store i32 %46, i32* %3
%47 = call %struct.tm* @localtime(i32* %3)
%48 = getelementptr inbounds %struct.tm, %struct.tm* %47, i64 0, i32 0
%49 = load i32, i32* %48
%50 = add nsw i32 %49, 1
%51 = getelementptr inbounds %struct.tm, %struct.tm* %47, i64 0, i32 1
%52 = load i32, i32* %51
%53 = add nsw i32 %52, 1900
br label %54
54: ; preds = %44, %38
%55 = phi i32 [ %53, %44 ], [ %40, %38 ]
%56 = phi i32 [ %50, %44 ], [ %39, %38 ]
%57 = icmp eq i32 %56, 0
br i1 %57, label %60, label %58
58: ; preds = %54
%59 = call i32 @print_month(i32 %55, i32 %56)
br label %62
60: ; preds = %54
%61 = call i32 @print_year(i32 %55)
br label %62
62: ; preds = %58, %60, %15, %20, %9
%63 = phi i32 [ 1, %9 ], [ 1, %20 ], [ 0, %15 ], [ 0, %60 ], [ 0, %58 ]
ret i32 %63
}