#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 /*<<< orphan*/ tm_min;
  int /*<<< orphan*/ tm_hour;
  scalar_t__ tm_yday;
};

/* Variables and functions */
unsigned char dec2bcd(int /*<<< orphan*/);
struct tm *localtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(unsigned char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
void stamp_now(unsigned char *stamp) {
  time_t t;
  struct tm *ptm;
  int days, leap;
  memset(stamp, 0, 4);
  time(&t);
  ptm = localtime(&t);
  if (!ptm)
    return;
  if (ptm->tm_year >= 78) {
    leap = (ptm->tm_year - 76) / 4;
    leap *= 1461;
    days = (ptm->tm_year % 4) * 365;
    if (days)
      ++days;
    days += ptm->tm_yday;
    days += leap;
    days -= 730;
    stamp[0] = days & 0xFF;
    stamp[1] = days >> 8;
  }
  stamp[2] = dec2bcd(ptm->tm_hour);
  stamp[3] = dec2bcd(ptm->tm_min);
}


x86 assembly (clang, -O0):
<stamp_now>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1050 <memset@plt>
lea    -0xc(%rbp),%rdi
call   1060 <time@plt>
lea    -0xc(%rbp),%rdi
call   1040 <localtime@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1182 <stamp_now+0x42>
jmp    1246 <stamp_now+0x106>
mov    -0x18(%rbp),%rax
cmpl   $0x4e,(%rax)
jl     121c <stamp_now+0xdc>
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
sub    $0x4c,%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %eax,-0x20(%rbp)
imul   $0x5b5,-0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
imul   $0x16d,%edx,%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     11d7 <stamp_now+0x97>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
mov    0x10(%rax),%rcx
movslq -0x1c(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%eax
add    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
sub    $0x2da,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,(%rax)
mov    -0x1c(%rbp),%eax
sar    $0x8,%eax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,0x1(%rax)
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%edi
call   1030 <dec2bcd@plt>
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,0x2(%rax)
mov    -0x18(%rbp),%rax
mov    0x4(%rax),%edi
call   1030 <dec2bcd@plt>
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,0x3(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stamp_now>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
xor    %esi,%esi
mov    $0x4,%edx
call   1050 <memset@plt>
lea    0x4(%rsp),%rbx
mov    %rbx,%rdi
call   1060 <time@plt>
mov    %rbx,%rdi
call   1040 <localtime@plt>
test   %rax,%rax
je     11bc <stamp_now+0x7c>
mov    %rax,%rbx
mov    (%rax),%eax
cmp    $0x4e,%eax
jl     11a4 <stamp_now+0x64>
lea    -0x4c(%rax),%ecx
shr    $0x2,%ecx
imul   $0x5b5,%ecx,%ecx
and    $0x3,%eax
imul   $0x16d,%eax,%edx
add    $0x1,%edx
test   %eax,%eax
cmove  %eax,%edx
mov    0x10(%rbx),%eax
add    %ecx,%edx
add    %edx,%eax
add    $0xfffffd26,%eax
mov    %ax,(%r14)
mov    0x8(%rbx),%edi
call   1030 <dec2bcd@plt>
mov    %al,0x2(%r14)
mov    0x4(%rbx),%edi
call   1030 <dec2bcd@plt>
mov    %al,0x3(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.tm = type { i32, i32, i32, i64 }
define void @stamp_now(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca %struct.tm*
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %2
%7 = load i8*, i8** %2
%8 = call i32 @memset(i8* %7, i32 0, i32 4)
%9 = call i32 @time(i32* %3)
%10 = call %struct.tm* @localtime(i32* %3)
store %struct.tm* %10, %struct.tm** %4
%11 = load %struct.tm*, %struct.tm** %4
%12 = icmp ne %struct.tm* %11, null
br i1 %12, label %14, label %13
13: ; preds = %1
br label %73
14: ; preds = %1
%15 = load %struct.tm*, %struct.tm** %4
%16 = getelementptr inbounds %struct.tm, %struct.tm* %15, i32 0, i32 0
%17 = load i32, i32* %16
%18 = icmp sge i32 %17, 78
br i1 %18, label %19, label %60
19: ; preds = %14
%20 = load %struct.tm*, %struct.tm** %4
%21 = getelementptr inbounds %struct.tm, %struct.tm* %20, i32 0, i32 0
%22 = load i32, i32* %21
%23 = sub nsw i32 %22, 76
%24 = sdiv i32 %23, 4
store i32 %24, i32* %6
%25 = load i32, i32* %6
%26 = mul nsw i32 %25, 1461
store i32 %26, i32* %6
%27 = load %struct.tm*, %struct.tm** %4
%28 = getelementptr inbounds %struct.tm, %struct.tm* %27, i32 0, i32 0
%29 = load i32, i32* %28
%30 = srem i32 %29, 4
%31 = mul nsw i32 %30, 365
store i32 %31, i32* %5
%32 = load i32, i32* %5
%33 = icmp ne i32 %32, 0
br i1 %33, label %34, label %37
34: ; preds = %19
%35 = load i32, i32* %5
%36 = add nsw i32 %35, 1
store i32 %36, i32* %5
br label %37
37: ; preds = %34, %19
%38 = load %struct.tm*, %struct.tm** %4
%39 = getelementptr inbounds %struct.tm, %struct.tm* %38, i32 0, i32 3
%40 = load i64, i64* %39
%41 = load i32, i32* %5
%42 = sext i32 %41 to i64
%43 = add nsw i64 %42, %40
%44 = trunc i64 %43 to i32
store i32 %44, i32* %5
%45 = load i32, i32* %6
%46 = load i32, i32* %5
%47 = add nsw i32 %46, %45
store i32 %47, i32* %5
%48 = load i32, i32* %5
%49 = sub nsw i32 %48, 730
store i32 %49, i32* %5
%50 = load i32, i32* %5
%51 = and i32 %50, 255
%52 = trunc i32 %51 to i8
%53 = load i8*, i8** %2
%54 = getelementptr inbounds i8, i8* %53, i64 0
store i8 %52, i8* %54
%55 = load i32, i32* %5
%56 = ashr i32 %55, 8
%57 = trunc i32 %56 to i8
%58 = load i8*, i8** %2
%59 = getelementptr inbounds i8, i8* %58, i64 1
store i8 %57, i8* %59
br label %60
60: ; preds = %37, %14
%61 = load %struct.tm*, %struct.tm** %4
%62 = getelementptr inbounds %struct.tm, %struct.tm* %61, i32 0, i32 2
%63 = load i32, i32* %62
%64 = call zeroext i8 @dec2bcd(i32 %63)
%65 = load i8*, i8** %2
%66 = getelementptr inbounds i8, i8* %65, i64 2
store i8 %64, i8* %66
%67 = load %struct.tm*, %struct.tm** %4
%68 = getelementptr inbounds %struct.tm, %struct.tm* %67, i32 0, i32 1
%69 = load i32, i32* %68
%70 = call zeroext i8 @dec2bcd(i32 %69)
%71 = load i8*, i8** %2
%72 = getelementptr inbounds i8, i8* %71, i64 3
store i8 %70, i8* %72
br label %73
73: ; preds = %60, %13
ret void
}

LLVM IR (-O2):
%struct.tm = type { i32, i32, i32, i64 }
define void @stamp_now(i8* %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = tail call i32 @memset(i8* %0, i32 0, i32 4)
%5 = call i32 @time(i32* %2)
%6 = call %struct.tm* @localtime(i32* %2)
%7 = icmp eq %struct.tm* %6, null
br i1 %7, label %40, label %8
8: ; preds = %1
%9 = getelementptr inbounds %struct.tm, %struct.tm* %6, i64 0, i32 0
%10 = load i32, i32* %9
%11 = icmp sgt i32 %10, 77
br i1 %11, label %12, label %31
12: ; preds = %8
%13 = add nsw i32 %10, -76
%14 = lshr i32 %13, 2
%15 = mul nsw i32 %14, 1461
%16 = and i32 %10, 3
%17 = icmp eq i32 %16, 0
%18 = mul nuw nsw i32 %16, 365
%19 = add nuw nsw i32 %18, 1
%20 = select i1 %17, i32 0, i32 %19
%21 = getelementptr inbounds %struct.tm, %struct.tm* %6, i64 0, i32 3
%22 = load i64, i64* %21
%23 = trunc i64 %22 to i32
%24 = add nsw i32 %15, -730
%25 = add i32 %24, %20
%26 = add i32 %25, %23
%27 = trunc i32 %26 to i8
store i8 %27, i8* %0
%28 = lshr i32 %26, 8
%29 = trunc i32 %28 to i8
%30 = getelementptr inbounds i8, i8* %0, i64 1
store i8 %29, i8* %30
br label %31
31: ; preds = %12, %8
%32 = getelementptr inbounds %struct.tm, %struct.tm* %6, i64 0, i32 2
%33 = load i32, i32* %32
%34 = call zeroext i8 @dec2bcd(i32 %33)
%35 = getelementptr inbounds i8, i8* %0, i64 2
store i8 %34, i8* %35
%36 = getelementptr inbounds %struct.tm, %struct.tm* %6, i64 0, i32 1
%37 = load i32, i32* %36
%38 = call zeroext i8 @dec2bcd(i32 %37)
%39 = getelementptr inbounds i8, i8* %0, i64 3
store i8 %38, i8* %39
br label %40
40: ; preds = %1, %31
ret void
}