#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_mday;
  int tm_mon;
  int tm_year;
  int tm_min;
  int tm_hour;
};

/* Variables and functions */
struct tm *localtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
unsigned char *prodos_time(void) {
  static unsigned char time_buff[4];
  time_t now = time(NULL);
  struct tm *tm = localtime(&now);
  int ptime = (tm->tm_mday & 0x1F) | (((tm->tm_mon + 1) & 0x0F) << 5) |
              (((tm->tm_year - 100) & 0x7F) << 9) |
              ((tm->tm_min & 0x3F) << 16) | ((tm->tm_hour & 0x1F) << 24);
  time_buff[0] = (unsigned char)ptime;
  time_buff[1] = (unsigned char)(ptime >> 8);
  time_buff[2] = (unsigned char)(ptime >> 16);
  time_buff[3] = (unsigned char)(ptime >> 24);
  return time_buff;
}


x86 assembly (clang, -O0):
<prodos_time>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
xor    %eax,%eax
mov    %eax,%edi
call   1040 <time@plt>
mov    %eax,-0x4(%rbp)
lea    -0x4(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
and    $0x1f,%eax
mov    -0x10(%rbp),%rcx
mov    0x4(%rcx),%ecx
add    $0x1,%ecx
and    $0xf,%ecx
shl    $0x5,%ecx
or     %ecx,%eax
mov    -0x10(%rbp),%rcx
mov    0x8(%rcx),%ecx
sub    $0x64,%ecx
and    $0x7f,%ecx
shl    $0x9,%ecx
or     %ecx,%eax
mov    -0x10(%rbp),%rcx
mov    0xc(%rcx),%ecx
and    $0x3f,%ecx
shl    $0x10,%ecx
or     %ecx,%eax
mov    -0x10(%rbp),%rcx
mov    0x10(%rcx),%ecx
and    $0x1f,%ecx
shl    $0x18,%ecx
or     %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %al,0x2e99(%rip)
mov    -0x14(%rbp),%eax
sar    $0x8,%eax
mov    %al,0x2e8e(%rip)
mov    -0x14(%rbp),%eax
sar    $0x10,%eax
mov    %al,0x2e83(%rip)
mov    -0x14(%rbp),%eax
sar    $0x18,%eax
mov    %al,0x2e78(%rip)
lea    0x2e6e(%rip),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<prodos_time>:
push   %rbx
sub    $0x10,%rsp
xor    %edi,%edi
call   1040 <time@plt>
mov    %eax,0xc(%rsp)
lea    0xc(%rsp),%rdi
call   1030 <localtime@plt>
mov    (%rax),%ecx
mov    0x4(%rax),%edx
and    $0x1f,%ecx
shl    $0x5,%edx
lea    0x20(%rdx),%esi
and    $0x100,%esi
lea    (%rdx,%rcx,1),%edi
add    $0x20,%edi
mov    0x8(%rax),%edx
shl    $0x9,%edx
lea    (%rdx,%rsi,1),%ebx
add    $0x3800,%ebx
mov    0xc(%rax),%cl
mov    0x10(%rax),%dl
mov    %dil,0x2ec1(%rip)
lea    0x2eba(%rip),%rax
mov    %bh,0x2eb5(%rip)
and    $0x3f,%cl
mov    %cl,0x2ead(%rip)
and    $0x1f,%dl
mov    %dl,0x2ea5(%rip)
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.tm = type { i32, i32, i32, i32, i32 }
@prodos_time.time_buff = internal global [4 x i8] zeroinitializer
define i8* @prodos_time() {
%1 = alloca i32
%2 = alloca %struct.tm*
%3 = alloca i32
%4 = call i32 @time(i32* null)
store i32 %4, i32* %1
%5 = call %struct.tm* @localtime(i32* %1)
store %struct.tm* %5, %struct.tm** %2
%6 = load %struct.tm*, %struct.tm** %2
%7 = getelementptr inbounds %struct.tm, %struct.tm* %6, i32 0, i32 0
%8 = load i32, i32* %7
%9 = and i32 %8, 31
%10 = load %struct.tm*, %struct.tm** %2
%11 = getelementptr inbounds %struct.tm, %struct.tm* %10, i32 0, i32 1
%12 = load i32, i32* %11
%13 = add nsw i32 %12, 1
%14 = and i32 %13, 15
%15 = shl i32 %14, 5
%16 = or i32 %9, %15
%17 = load %struct.tm*, %struct.tm** %2
%18 = getelementptr inbounds %struct.tm, %struct.tm* %17, i32 0, i32 2
%19 = load i32, i32* %18
%20 = sub nsw i32 %19, 100
%21 = and i32 %20, 127
%22 = shl i32 %21, 9
%23 = or i32 %16, %22
%24 = load %struct.tm*, %struct.tm** %2
%25 = getelementptr inbounds %struct.tm, %struct.tm* %24, i32 0, i32 3
%26 = load i32, i32* %25
%27 = and i32 %26, 63
%28 = shl i32 %27, 16
%29 = or i32 %23, %28
%30 = load %struct.tm*, %struct.tm** %2
%31 = getelementptr inbounds %struct.tm, %struct.tm* %30, i32 0, i32 4
%32 = load i32, i32* %31
%33 = and i32 %32, 31
%34 = shl i32 %33, 24
%35 = or i32 %29, %34
store i32 %35, i32* %3
%36 = load i32, i32* %3
%37 = trunc i32 %36 to i8
store i8 %37, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @prodos_time.time_buff, i64 0, i64 0)
%38 = load i32, i32* %3
%39 = ashr i32 %38, 8
%40 = trunc i32 %39 to i8
store i8 %40, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @prodos_time.time_buff, i64 0, i64 1)
%41 = load i32, i32* %3
%42 = ashr i32 %41, 16
%43 = trunc i32 %42 to i8
store i8 %43, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @prodos_time.time_buff, i64 0, i64 2)
%44 = load i32, i32* %3
%45 = ashr i32 %44, 24
%46 = trunc i32 %45 to i8
store i8 %46, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @prodos_time.time_buff, i64 0, i64 3)
ret i8* getelementptr inbounds ([4 x i8], [4 x i8]* @prodos_time.time_buff, i64 0, i64 0)
}

LLVM IR (-O2):
%struct.tm = type { i32, i32, i32, i32, i32 }
@prodos_time.time_buff = internal global [4 x i8] zeroinitializer
define i8* @prodos_time() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 @time(i32* null)
store i32 %3, i32* %1
%4 = call %struct.tm* @localtime(i32* %1)
%5 = getelementptr inbounds %struct.tm, %struct.tm* %4, i64 0, i32 0
%6 = load i32, i32* %5
%7 = and i32 %6, 31
%8 = getelementptr inbounds %struct.tm, %struct.tm* %4, i64 0, i32 1
%9 = load i32, i32* %8
%10 = shl i32 %9, 5
%11 = add i32 %10, 32
%12 = and i32 %11, 256
%13 = or i32 %11, %7
%14 = getelementptr inbounds %struct.tm, %struct.tm* %4, i64 0, i32 2
%15 = load i32, i32* %14
%16 = shl i32 %15, 9
%17 = add i32 %16, 14336
%18 = or i32 %12, %17
%19 = getelementptr inbounds %struct.tm, %struct.tm* %4, i64 0, i32 3
%20 = load i32, i32* %19
%21 = getelementptr inbounds %struct.tm, %struct.tm* %4, i64 0, i32 4
%22 = load i32, i32* %21
%23 = trunc i32 %13 to i8
store i8 %23, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @prodos_time.time_buff, i64 0, i64 0)
%24 = lshr exact i32 %18, 8
%25 = trunc i32 %24 to i8
store i8 %25, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @prodos_time.time_buff, i64 0, i64 1)
%26 = trunc i32 %20 to i8
%27 = and i8 %26, 63
store i8 %27, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @prodos_time.time_buff, i64 0, i64 2)
%28 = trunc i32 %22 to i8
%29 = and i8 %28, 31
store i8 %29, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @prodos_time.time_buff, i64 0, i64 3)
ret i8* getelementptr inbounds ([4 x i8], [4 x i8]* @prodos_time.time_buff, i64 0, i64 0)
}