#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 dummy;
};
typedef int pid_t;

/* Variables and functions */
int /*<<< orphan*/ EX_OSERR;
int /*<<< orphan*/ err(int /*<<< orphan*/, char *);
int /*<<< orphan*/ errx(int /*<<< orphan*/, char *);
int execlp(char *, char *, char **, char **, char *);
int fork();
struct tm *localtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ mktime(struct tm *);
int strftime(char *, size_t, char *, struct tm *);
int wait(int /*<<< orphan*/ *);
void whatmonth(struct tm *date) {
  char monthnum[3];
  char yearnum[5];
  pid_t pid;
  time_t t;
  t = mktime(date);
  date = localtime(&t);
  pid = fork();
  if (pid == -1) {
    err(EX_OSERR, "could not fork()");
  } else if (pid == 0) {
    if (strftime((char *)&monthnum, (size_t)3, "%m", date) < 1)
      errx(EX_OSERR, "could not strftime() month");
    if (strftime((char *)&yearnum, (size_t)5, "%Y", date) < 1)
      errx(EX_OSERR, "could not strftime() year");
    if (execlp("cal", "cal", &monthnum, &yearnum, (char *)0) == -1)
      err(EX_OSERR, "could not execlp() cal");
  } else {
    if (wait(NULL) == -1)
      err(EX_OSERR, "wait() error");
  }
}


x86 assembly (clang, -O0):
<whatmonth>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <mktime@plt>
mov    %eax,-0x18(%rbp)
lea    -0x18(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x8(%rbp)
mov    $0x0,%al
call   10a0 <fork@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11d3 <whatmonth+0x53>
mov    0x2e20(%rip),%rax
mov    (%rax),%edi
lea    0xe37(%rip),%rsi
call   1050 <err@plt>
jmp    12bb <whatmonth+0x13b>
cmpl   $0x0,-0x14(%rbp)
jne    128a <whatmonth+0x10a>
lea    -0xb(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x3,%esi
lea    0xe20(%rip),%rdx
call   1070 <strftime@plt>
cmp    $0x1,%eax
jge    1214 <whatmonth+0x94>
mov    0x2dda(%rip),%rax
mov    (%rax),%edi
lea    0xe05(%rip),%rsi
call   1040 <errx@plt>
lea    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x5,%esi
lea    0xe07(%rip),%rdx
call   1070 <strftime@plt>
cmp    $0x1,%eax
jge    124b <whatmonth+0xcb>
mov    0x2da3(%rip),%rax
mov    (%rax),%edi
lea    0xdec(%rip),%rsi
call   1040 <errx@plt>
lea    -0xb(%rbp),%rdx
lea    -0x10(%rbp),%rcx
lea    0xe05(%rip),%rsi
xor    %eax,%eax
mov    %eax,%r8d
mov    %rsi,%rdi
call   1080 <execlp@plt>
cmp    $0xffffffff,%eax
jne    1285 <whatmonth+0x105>
mov    0x2d69(%rip),%rax
mov    (%rax),%edi
lea    0xdcc(%rip),%rsi
call   1050 <err@plt>
jmp    12b6 <whatmonth+0x136>
xor    %eax,%eax
mov    %eax,%edi
call   1090 <wait@plt>
cmp    $0xffffffff,%eax
jne    12b1 <whatmonth+0x131>
mov    0x2d3d(%rip),%rax
mov    (%rax),%edi
lea    0xdb7(%rip),%rsi
call   1050 <err@plt>
jmp    12b6 <whatmonth+0x136>
jmp    12bb <whatmonth+0x13b>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<whatmonth>:
push   %rbx
sub    $0x10,%rsp
call   1060 <mktime@plt>
mov    %eax,0x4(%rsp)
lea    0x4(%rsp),%rdi
call   1030 <localtime@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   10a0 <fork@plt>
cmp    $0xffffffff,%eax
je     1241 <whatmonth+0xc1>
test   %eax,%eax
jne    124a <whatmonth+0xca>
lea    0xe57(%rip),%rdx
lea    0x1(%rsp),%rdi
mov    $0x3,%esi
mov    %rbx,%rcx
call   1070 <strftime@plt>
test   %eax,%eax
jg     11e5 <whatmonth+0x65>
mov    0x2e09(%rip),%rax
mov    (%rax),%edi
lea    0xe34(%rip),%rsi
call   1040 <errx@plt>
lea    0xe43(%rip),%rdx
lea    0xb(%rsp),%rdi
mov    $0x5,%esi
mov    %rbx,%rcx
call   1070 <strftime@plt>
test   %eax,%eax
jg     1217 <whatmonth+0x97>
mov    0x2dd7(%rip),%rax
mov    (%rax),%edi
lea    0xe20(%rip),%rsi
call   1040 <errx@plt>
lea    0xe41(%rip),%rdi
lea    0x1(%rsp),%rdx
lea    0xb(%rsp),%rcx
mov    %rdi,%rsi
xor    %r8d,%r8d
call   1080 <execlp@plt>
cmp    $0xffffffff,%eax
jne    126b <whatmonth+0xeb>
lea    0xe0d(%rip),%rsi
jmp    125d <whatmonth+0xdd>
lea    0xdb8(%rip),%rsi
jmp    125d <whatmonth+0xdd>
xor    %edi,%edi
call   1090 <wait@plt>
cmp    $0xffffffff,%eax
jne    126b <whatmonth+0xeb>
lea    0xe06(%rip),%rsi
mov    0x2d7c(%rip),%rax
mov    (%rax),%edi
call   1050 <err@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.tm = type { i32 }
@EX_OSERR = global i32 0
@.str = [17 x i8] c"could not fork()\00"
@.str.1 = [3 x i8] c"%m\00"
@.str.2 = [27 x i8] c"could not strftime() month\00"
@.str.3 = [3 x i8] c"%Y\00"
@.str.4 = [26 x i8] c"could not strftime() year\00"
@.str.5 = [4 x i8] c"cal\00"
@.str.6 = [23 x i8] c"could not execlp() cal\00"
@.str.7 = [13 x i8] c"wait() error\00"
define void @whatmonth(%struct.tm* %0) {
%2 = alloca %struct.tm*
%3 = alloca [3 x i8]
%4 = alloca [5 x i8]
%5 = alloca i32
%6 = alloca i32
store %struct.tm* %0, %struct.tm** %2
%7 = load %struct.tm*, %struct.tm** %2
%8 = call i32 @mktime(%struct.tm* %7)
store i32 %8, i32* %6
%9 = call %struct.tm* @localtime(i32* %6)
store %struct.tm* %9, %struct.tm** %2
%10 = call i32 (...) @fork()
store i32 %10, i32* %5
%11 = load i32, i32* %5
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %16
13: ; preds = %1
%14 = load i32, i32* @EX_OSERR
%15 = call i32 @err(i32 %14, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
br label %52
16: ; preds = %1
%17 = load i32, i32* %5
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %44
19: ; preds = %16
%20 = bitcast [3 x i8]* %3 to i8*
%21 = load %struct.tm*, %struct.tm** %2
%22 = call i32 @strftime(i8* %20, i64 3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), %struct.tm* %21)
%23 = icmp slt i32 %22, 1
br i1 %23, label %24, label %27
24: ; preds = %19
%25 = load i32, i32* @EX_OSERR
%26 = call i32 @errx(i32 %25, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
br label %27
27: ; preds = %24, %19
%28 = bitcast [5 x i8]* %4 to i8*
%29 = load %struct.tm*, %struct.tm** %2
%30 = call i32 @strftime(i8* %28, i64 5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), %struct.tm* %29)
%31 = icmp slt i32 %30, 1
br i1 %31, label %32, label %35
32: ; preds = %27
%33 = load i32, i32* @EX_OSERR
%34 = call i32 @errx(i32 %33, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0))
br label %35
35: ; preds = %32, %27
%36 = bitcast [3 x i8]* %3 to i8**
%37 = bitcast [5 x i8]* %4 to i8**
%38 = call i32 @execlp(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8** %36, i8** %37, i8* null)
%39 = icmp eq i32 %38, -1
br i1 %39, label %40, label %43
40: ; preds = %35
%41 = load i32, i32* @EX_OSERR
%42 = call i32 @err(i32 %41, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0))
br label %43
43: ; preds = %40, %35
br label %51
44: ; preds = %16
%45 = call i32 @wait(i32* null)
%46 = icmp eq i32 %45, -1
br i1 %46, label %47, label %50
47: ; preds = %44
%48 = load i32, i32* @EX_OSERR
%49 = call i32 @err(i32 %48, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0))
br label %50
50: ; preds = %47, %44
br label %51
51: ; preds = %50, %43
br label %52
52: ; preds = %51, %13
ret void
}

LLVM IR (-O2):
%struct.tm = type { i32 }
@EX_OSERR = global i32 0
@.str = [17 x i8] c"could not fork()\00"
@.str.1 = [3 x i8] c"%m\00"
@.str.2 = [27 x i8] c"could not strftime() month\00"
@.str.3 = [3 x i8] c"%Y\00"
@.str.4 = [26 x i8] c"could not strftime() year\00"
@.str.5 = [4 x i8] c"cal\00"
@.str.6 = [23 x i8] c"could not execlp() cal\00"
@.str.7 = [13 x i8] c"wait() error\00"
define void @whatmonth(%struct.tm* nocapture %0) {
%2 = alloca [3 x i8]
%3 = alloca [5 x i8]
%4 = alloca i32
%5 = getelementptr inbounds [3 x i8], [3 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 0
%7 = bitcast i32* %4 to i8*
%8 = tail call i32 @mktime(%struct.tm* %0)
store i32 %8, i32* %4
%9 = call %struct.tm* @localtime(i32* %4)
%10 = call i32 (...) @fork()
switch i32 %10, label %28 [
i32 -1, label %31
i32 0, label %11
]
11: ; preds = %1
%12 = call i32 @strftime(i8* %5, i64 3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), %struct.tm* %9)
%13 = icmp slt i32 %12, 1
br i1 %13, label %14, label %17
14: ; preds = %11
%15 = load i32, i32* @EX_OSERR
%16 = call i32 @errx(i32 %15, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
br label %17
17: ; preds = %14, %11
%18 = call i32 @strftime(i8* %6, i64 5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), %struct.tm* %9)
%19 = icmp slt i32 %18, 1
br i1 %19, label %20, label %23
20: ; preds = %17
%21 = load i32, i32* @EX_OSERR
%22 = call i32 @errx(i32 %21, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0))
br label %23
23: ; preds = %20, %17
%24 = bitcast [3 x i8]* %2 to i8**
%25 = bitcast [5 x i8]* %3 to i8**
%26 = call i32 @execlp(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8** %24, i8** %25, i8* null)
%27 = icmp eq i32 %26, -1
br i1 %27, label %31, label %35
28: ; preds = %1
%29 = call i32 @wait(i32* null)
%30 = icmp eq i32 %29, -1
br i1 %30, label %31, label %35
31: ; preds = %28, %23, %1
%32 = phi i8* [ getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), %1 ], [ getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0), %23 ], [ getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0), %28 ]
%33 = load i32, i32* @EX_OSERR
%34 = call i32 @err(i32 %33, i8* %32)
br label %35
35: ; preds = %31, %23, %28
ret void
}