#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_hour;
  int tm_min;
  int tm_year;
  int tm_sec;
  int tm_mon;
  int tm_mday;
};
struct timezone {
  int dummy;
};
struct timeval {
  int tv_usec;
};

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, struct timezone *);
struct tm *localtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
unsigned long CalculateNewSerialNumber(void) {
  time_t now;
  struct tm *nowtm;
  unsigned short first, second;
  unsigned long result;
  struct timeval tval;
  struct timezone tzone;
  gettimeofday(&tval, &tzone);
  now = time(NULL);
  nowtm = localtime(&now);
  first = ((nowtm->tm_hour << 8) + nowtm->tm_min) + (nowtm->tm_year + 1900);
  second = ((nowtm->tm_sec << 8) + (tval.tv_usec / 10)) +
           ((nowtm->tm_mon << 8) + nowtm->tm_mday);
  result = first + (second << 16);
  return result;
}


x86 assembly (clang, -O0):
<CalculateNewSerialNumber>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
lea    -0x28(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1040 <gettimeofday@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1050 <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
shl    $0x8,%eax
mov    -0x10(%rbp),%rcx
add    0x4(%rcx),%eax
mov    -0x10(%rbp),%rcx
mov    0x8(%rcx),%ecx
add    $0x76c,%ecx
add    %ecx,%eax
mov    %ax,-0x12(%rbp)
mov    -0x10(%rbp),%rax
mov    0xc(%rax),%eax
shl    $0x8,%eax
mov    %eax,-0x34(%rbp)
mov    -0x28(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x34(%rbp),%eax
add    %ecx,%eax
mov    -0x10(%rbp),%rcx
mov    0x10(%rcx),%ecx
shl    $0x8,%ecx
mov    -0x10(%rbp),%rdx
add    0x14(%rdx),%ecx
add    %ecx,%eax
mov    %ax,-0x14(%rbp)
movzwl -0x12(%rbp),%eax
movzwl -0x14(%rbp),%ecx
shl    $0x10,%ecx
add    %ecx,%eax
cltq
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CalculateNewSerialNumber>:
sub    $0x18,%rsp
lea    0x8(%rsp),%rdi
lea    0x10(%rsp),%rsi
call   1040 <gettimeofday@plt>
xor    %edi,%edi
call   1050 <time@plt>
mov    %eax,0xc(%rsp)
lea    0xc(%rsp),%rdi
call   1030 <localtime@plt>
mov    (%rax),%ecx
mov    0x8(%rax),%edx
shl    $0x8,%ecx
add    0x4(%rax),%ecx
add    %edx,%ecx
add    $0x76c,%ecx
movslq 0x8(%rsp),%rdx
imul   $0x66666667,%rdx,%rdx
mov    %rdx,%rsi
shr    $0x3f,%rsi
shr    $0x22,%rdx
add    %esi,%edx
mov    0x10(%rax),%esi
add    0xc(%rax),%esi
shl    $0x8,%esi
add    0x14(%rax),%edx
add    %esi,%edx
movzwl %cx,%eax
shl    $0x10,%edx
or     %eax,%edx
movslq %edx,%rax
add    $0x18,%rsp
ret

LLVM IR (-O0):
%struct.tm = type { i32, i32, i32, i32, i32, i32 }
%struct.timeval = type { i32 }
%struct.timezone = type { i32 }
define i64 @CalculateNewSerialNumber() {
%1 = alloca i32
%2 = alloca %struct.tm*
%3 = alloca i16
%4 = alloca i16
%5 = alloca i64
%6 = alloca %struct.timeval
%7 = alloca %struct.timezone
%8 = call i32 @gettimeofday(%struct.timeval* %6, %struct.timezone* %7)
%9 = call i32 @time(i32* null)
store i32 %9, i32* %1
%10 = call %struct.tm* @localtime(i32* %1)
store %struct.tm* %10, %struct.tm** %2
%11 = load %struct.tm*, %struct.tm** %2
%12 = getelementptr inbounds %struct.tm, %struct.tm* %11, i32 0, i32 0
%13 = load i32, i32* %12
%14 = shl i32 %13, 8
%15 = load %struct.tm*, %struct.tm** %2
%16 = getelementptr inbounds %struct.tm, %struct.tm* %15, i32 0, i32 1
%17 = load i32, i32* %16
%18 = add nsw i32 %14, %17
%19 = load %struct.tm*, %struct.tm** %2
%20 = getelementptr inbounds %struct.tm, %struct.tm* %19, i32 0, i32 2
%21 = load i32, i32* %20
%22 = add nsw i32 %21, 1900
%23 = add nsw i32 %18, %22
%24 = trunc i32 %23 to i16
store i16 %24, i16* %3
%25 = load %struct.tm*, %struct.tm** %2
%26 = getelementptr inbounds %struct.tm, %struct.tm* %25, i32 0, i32 3
%27 = load i32, i32* %26
%28 = shl i32 %27, 8
%29 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 0
%30 = load i32, i32* %29
%31 = sdiv i32 %30, 10
%32 = add nsw i32 %28, %31
%33 = load %struct.tm*, %struct.tm** %2
%34 = getelementptr inbounds %struct.tm, %struct.tm* %33, i32 0, i32 4
%35 = load i32, i32* %34
%36 = shl i32 %35, 8
%37 = load %struct.tm*, %struct.tm** %2
%38 = getelementptr inbounds %struct.tm, %struct.tm* %37, i32 0, i32 5
%39 = load i32, i32* %38
%40 = add nsw i32 %36, %39
%41 = add nsw i32 %32, %40
%42 = trunc i32 %41 to i16
store i16 %42, i16* %4
%43 = load i16, i16* %3
%44 = zext i16 %43 to i32
%45 = load i16, i16* %4
%46 = zext i16 %45 to i32
%47 = shl i32 %46, 16
%48 = add nsw i32 %44, %47
%49 = sext i32 %48 to i64
store i64 %49, i64* %5
%50 = load i64, i64* %5
ret i64 %50
}

LLVM IR (-O2):
%struct.timeval = type { i32 }
%struct.timezone = type { i32 }
%struct.tm = type { i32, i32, i32, i32, i32, i32 }
define i64 @CalculateNewSerialNumber() {
%1 = alloca i32
%2 = alloca %struct.timeval
%3 = alloca %struct.timezone
%4 = bitcast i32* %1 to i8*
%5 = bitcast %struct.timeval* %2 to i8*
%6 = bitcast %struct.timezone* %3 to i8*
%7 = call i32 @gettimeofday(%struct.timeval* %2, %struct.timezone* %3)
%8 = tail call i32 @time(i32* null)
store i32 %8, i32* %1
%9 = call %struct.tm* @localtime(i32* %1)
%10 = getelementptr inbounds %struct.tm, %struct.tm* %9, i64 0, i32 0
%11 = load i32, i32* %10
%12 = shl i32 %11, 8
%13 = getelementptr inbounds %struct.tm, %struct.tm* %9, i64 0, i32 1
%14 = load i32, i32* %13
%15 = getelementptr inbounds %struct.tm, %struct.tm* %9, i64 0, i32 2
%16 = load i32, i32* %15
%17 = add i32 %14, 1900
%18 = add i32 %17, %12
%19 = add i32 %18, %16
%20 = getelementptr inbounds %struct.tm, %struct.tm* %9, i64 0, i32 3
%21 = load i32, i32* %20
%22 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 0
%23 = load i32, i32* %22
%24 = sdiv i32 %23, 10
%25 = getelementptr inbounds %struct.tm, %struct.tm* %9, i64 0, i32 4
%26 = load i32, i32* %25
%27 = getelementptr inbounds %struct.tm, %struct.tm* %9, i64 0, i32 5
%28 = load i32, i32* %27
%29 = add i32 %26, %21
%30 = shl i32 %29, 8
%31 = add i32 %28, %24
%32 = add i32 %31, %30
%33 = and i32 %19, 65535
%34 = shl i32 %32, 16
%35 = or i32 %34, %33
%36 = sext i32 %35 to i64
ret i64 %36
}