#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 long uint64_t;
struct tm {
  unsigned long tm_year;
  unsigned long tm_mon;
  unsigned long tm_mday;
  int /*<<< orphan*/ member_0;
};

/* Variables and functions */
long mktime(struct tm *);
unsigned long strtoul(char const *, char **, int);
uint64_t hazer_parse_dmy(const char *string) {
  uint64_t nanoseconds = 0;
  unsigned long ddmmyy = 0;
  struct tm datetime = {0};
  extern long timezone;
  ddmmyy = strtoul(string, (char **)0, 10);
  datetime.tm_year = ddmmyy % 100;
  if (datetime.tm_year < 93) {
    datetime.tm_year += 100;
  }
  datetime.tm_mon = ((ddmmyy % 10000) / 100) - 1;
  datetime.tm_mday = ddmmyy / 10000;
  nanoseconds = mktime(&datetime);
  nanoseconds -= timezone;
  nanoseconds *= 1000000000ULL;
  return nanoseconds;
}


x86 assembly (clang, -O0):
<hazer_parse_dmy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
lea    -0x38(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1030 <memset@plt>
mov    -0x8(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1050 <strtoul@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    $0x64,%ecx
xor    %edx,%edx
div    %rcx
mov    %rdx,-0x38(%rbp)
cmpq   $0x5d,-0x38(%rbp)
jae    119b <hazer_parse_dmy+0x6b>
mov    -0x38(%rbp),%rax
add    $0x64,%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rax
mov    $0x2710,%ecx
xor    %edx,%edx
div    %rcx
mov    %rdx,%rax
mov    $0x64,%ecx
xor    %edx,%edx
div    %rcx
sub    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
mov    $0x2710,%ecx
xor    %edx,%edx
div    %rcx
mov    %rax,-0x28(%rbp)
lea    -0x38(%rbp),%rdi
call   1040 <mktime@plt>
mov    %rax,-0x10(%rbp)
mov    0x2dfc(%rip),%rax
mov    (%rax),%rcx
mov    -0x10(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x10(%rbp)
imul   $0x3b9aca00,-0x10(%rbp),%rax
3b
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hazer_parse_dmy>:
sub    $0x28,%rsp
movq   $0x0,0x20(%rsp)
xor    %esi,%esi
mov    $0xa,%edx
call   1040 <strtoul@plt>
mov    %rax,%rcx
shr    $0x2,%rax
movabs $0x28f5c28f5c28f5c3,%rdx
c2 f5 28
mul    %rdx
shr    $0x2,%rdx
imul   $0x64,%rdx,%rax
mov    %rcx,%rdx
sub    %rax,%rdx
neg    %rax
cmp    $0x5d,%rdx
lea    0x64(%rcx,%rax,1),%rax
cmovae %rdx,%rax
mov    %rax,0x8(%rsp)
movabs $0x346dc5d63886594b,%rdx
c5 6d 34
mov    %rcx,%rax
mul    %rdx
shr    $0xb,%rdx
imul   $0x2710,%edx,%eax
sub    %eax,%ecx
movzwl %cx,%eax
shr    $0x2,%eax
imul   $0x147b,%eax,%eax
shr    $0x11,%eax
add    $0xffffffffffffffff,%rax
mov    %rax,0x10(%rsp)
mov    %rdx,0x18(%rsp)
lea    0x8(%rsp),%rdi
call   1030 <mktime@plt>
mov    0x2e26(%rip),%rcx
sub    (%rcx),%rax
imul   $0x3b9aca00,%rax,%rax
add    $0x28,%rsp
ret

LLVM IR (-O0):
%struct.tm = type { i64, i64, i64, i32 }
@timezone = external global i64
define i64 @hazer_parse_dmy(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i64
%5 = alloca %struct.tm
store i8* %0, i8** %2
store i64 0, i64* %3
store i64 0, i64* %4
%6 = bitcast %struct.tm* %5 to i8*
%7 = load i8*, i8** %2
%8 = call i64 @strtoul(i8* %7, i8** null, i32 10)
store i64 %8, i64* %4
%9 = load i64, i64* %4
%10 = urem i64 %9, 100
%11 = getelementptr inbounds %struct.tm, %struct.tm* %5, i32 0, i32 0
store i64 %10, i64* %11
%12 = getelementptr inbounds %struct.tm, %struct.tm* %5, i32 0, i32 0
%13 = load i64, i64* %12
%14 = icmp ult i64 %13, 93
br i1 %14, label %15, label %19
15: ; preds = %1
%16 = getelementptr inbounds %struct.tm, %struct.tm* %5, i32 0, i32 0
%17 = load i64, i64* %16
%18 = add i64 %17, 100
store i64 %18, i64* %16
br label %19
19: ; preds = %15, %1
%20 = load i64, i64* %4
%21 = urem i64 %20, 10000
%22 = udiv i64 %21, 100
%23 = sub i64 %22, 1
%24 = getelementptr inbounds %struct.tm, %struct.tm* %5, i32 0, i32 1
store i64 %23, i64* %24
%25 = load i64, i64* %4
%26 = udiv i64 %25, 10000
%27 = getelementptr inbounds %struct.tm, %struct.tm* %5, i32 0, i32 2
store i64 %26, i64* %27
%28 = call i64 @mktime(%struct.tm* %5)
store i64 %28, i64* %3
%29 = load i64, i64* @timezone
%30 = load i64, i64* %3
%31 = sub nsw i64 %30, %29
store i64 %31, i64* %3
%32 = load i64, i64* %3
%33 = mul i64 %32, 1000000000
store i64 %33, i64* %3
%34 = load i64, i64* %3
ret i64 %34
}

LLVM IR (-O2):
%struct.tm = type { i64, i64, i64, i32 }
@timezone = external global i64
define i64 @hazer_parse_dmy(i8* nocapture %0) {
%2 = alloca %struct.tm
%3 = bitcast %struct.tm* %2 to i8*
%4 = getelementptr inbounds %struct.tm, %struct.tm* %2, i64 0, i32 3
%5 = bitcast i32* %4 to i64*
store i64 0, i64* %5
%6 = tail call i64 @strtoul(i8* nocapture %0, i8** null, i32 10)
%7 = urem i64 %6, 100
%8 = icmp ult i64 %7, 93
%9 = add nuw nsw i64 %7, 100
%10 = select i1 %8, i64 %9, i64 %7
%11 = getelementptr inbounds %struct.tm, %struct.tm* %2, i64 0, i32 0
store i64 %10, i64* %11
%12 = urem i64 %6, 10000
%13 = trunc i64 %12 to i16
%14 = udiv i16 %13, 100
%15 = zext i16 %14 to i64
%16 = add nsw i64 %15, -1
%17 = getelementptr inbounds %struct.tm, %struct.tm* %2, i64 0, i32 1
store i64 %16, i64* %17
%18 = udiv i64 %6, 10000
%19 = getelementptr inbounds %struct.tm, %struct.tm* %2, i64 0, i32 2
store i64 %18, i64* %19
%20 = call i64 @mktime(%struct.tm* %2)
%21 = load i64, i64* @timezone
%22 = sub nsw i64 %20, %21
%23 = mul i64 %22, 1000000000
ret i64 %23
}