#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 time_t;
struct tm {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ die(char *);
int /*<<< orphan*/ die_sans_errno(char *);
int /*<<< orphan*/ *localtime_r(int *, struct tm *);
int /*<<< orphan*/ multithread_write(char *, int *);
int strftime(char *, int, char *, struct tm *);
int time(int /*<<< orphan*/ *);
void *date_mon(void *thread_id) {
  time_t time_in_seconds = time(NULL);
  if (time_in_seconds == -1) {
    die("time in date_mon failed");
  }
  struct tm broken_down_time;
  if (localtime_r(&time_in_seconds, &broken_down_time) == NULL) {
    die_sans_errno("localtime_r in date_mon failed");
  }
  char out_buffer[30];
  int bytes_written =
      strftime(out_buffer, 30, "%a, %b %e %l:%M %p", &broken_down_time);
  if (bytes_written == 0) {
    die_sans_errno("strftime in date_mon failed");
  }
  multithread_write(out_buffer, (int *)thread_id);
  return NULL;
}


x86 assembly (clang, -O0):
<date_mon>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1040 <time@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    118e <date_mon+0x2e>
lea    0xead(%rip),%rdi
call   1070 <die@plt>
lea    -0xc(%rbp),%rdi
lea    -0x10(%rbp),%rsi
call   1030 <localtime_r@plt>
cmp    $0x0,%rax
jne    11b1 <date_mon+0x51>
lea    0xe54(%rip),%rdi
call   1080 <die_sans_errno@plt>
lea    -0x30(%rbp),%rdi
mov    $0x1e,%esi
lea    0xe5e(%rip),%rdx
lea    -0x10(%rbp),%rcx
call   1060 <strftime@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jne    11e3 <date_mon+0x83>
lea    0xe54(%rip),%rdi
call   1080 <die_sans_errno@plt>
lea    -0x30(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1050 <multithread_write@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<date_mon>:
push   %rbx
sub    $0x30,%rsp
mov    %rdi,%rbx
xor    %edi,%edi
call   1040 <time@plt>
mov    %eax,0xc(%rsp)
cmp    $0xffffffff,%eax
jne    1184 <date_mon+0x24>
lea    0xeb7(%rip),%rdi
call   1070 <die@plt>
lea    0xc(%rsp),%rdi
lea    0x8(%rsp),%rsi
call   1030 <localtime_r@plt>
test   %rax,%rax
jne    11a4 <date_mon+0x44>
lea    0xe61(%rip),%rdi
call   1080 <die_sans_errno@plt>
lea    0xe74(%rip),%rdx
lea    0x10(%rsp),%rdi
lea    0x8(%rsp),%rcx
mov    $0x1e,%esi
call   1060 <strftime@plt>
test   %eax,%eax
jne    11cf <date_mon+0x6f>
lea    0xe68(%rip),%rdi
call   1080 <die_sans_errno@plt>
lea    0x10(%rsp),%rdi
mov    %rbx,%rsi
call   1050 <multithread_write@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.tm = type { i32 }
@.str = [24 x i8] c"time in date_mon failed\00"
@.str.1 = [31 x i8] c"localtime_r in date_mon failed\00"
@.str.2 = [19 x i8] c"%a, %b %e %l:%M %p\00"
@.str.3 = [28 x i8] c"strftime in date_mon failed\00"
define i8* @date_mon(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca %struct.tm
%5 = alloca [30 x i8]
%6 = alloca i32
store i8* %0, i8** %2
%7 = call i32 @time(i32* null)
store i32 %7, i32* %3
%8 = load i32, i32* %3
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %12
10: ; preds = %1
%11 = call i32 @die(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %10, %1
%13 = call i32* @localtime_r(i32* %3, %struct.tm* %4)
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = call i32 @die_sans_errno(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
br label %17
17: ; preds = %15, %12
%18 = getelementptr inbounds [30 x i8], [30 x i8]* %5, i64 0, i64 0
%19 = call i32 @strftime(i8* %18, i32 30, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), %struct.tm* %4)
store i32 %19, i32* %6
%20 = load i32, i32* %6
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %17
%23 = call i32 @die_sans_errno(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
br label %24
24: ; preds = %22, %17
%25 = getelementptr inbounds [30 x i8], [30 x i8]* %5, i64 0, i64 0
%26 = load i8*, i8** %2
%27 = bitcast i8* %26 to i32*
%28 = call i32 @multithread_write(i8* %25, i32* %27)
ret i8* null
}

LLVM IR (-O2):
%struct.tm = type { i32 }
@.str = [24 x i8] c"time in date_mon failed\00"
@.str.1 = [31 x i8] c"localtime_r in date_mon failed\00"
@.str.2 = [19 x i8] c"%a, %b %e %l:%M %p\00"
@.str.3 = [28 x i8] c"strftime in date_mon failed\00"
define noalias i8* @date_mon(i8* %0) {
%2 = alloca i32
%3 = alloca %struct.tm
%4 = alloca [30 x i8]
%5 = bitcast i32* %2 to i8*
%6 = tail call i32 @time(i32* null)
store i32 %6, i32* %2
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = tail call i32 @die(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %8, %1
%11 = bitcast %struct.tm* %3 to i8*
%12 = call i32* @localtime_r(i32* %2, %struct.tm* %3)
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %16
14: ; preds = %10
%15 = call i32 @die_sans_errno(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
br label %16
16: ; preds = %14, %10
%17 = getelementptr inbounds [30 x i8], [30 x i8]* %4, i64 0, i64 0
%18 = call i32 @strftime(i8* %17, i32 30, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), %struct.tm* %3)
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %16
%21 = call i32 @die_sans_errno(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
br label %22
22: ; preds = %20, %16
%23 = bitcast i8* %0 to i32*
%24 = call i32 @multithread_write(i8* %17, i32* %23)
ret i8* null
}