#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 scalar_t__ time_t;
struct tm {
  int tm_year;
  long tm_mday;
  scalar_t__ tm_mon;
};

/* Variables and functions */
struct tm *localtime(scalar_t__ *);
long timer_to_date(time_t time_secs) {
  struct tm *time_struct;
  if (time_secs == 0) {
    return 0;
  } else {
    time_struct = localtime(&time_secs);
    if (time_struct) {
      time_struct->tm_year += 1900;
      return ((long)(time_struct->tm_year / 100) * 1000000L +
              (long)(time_struct->tm_year % 100) * 10000L +
              (long)(time_struct->tm_mon + 1) * 100 + (time_struct->tm_mday));
    } else {
      return (19700101);
    }
  }
}


x86 assembly (clang, -O0):
<timer_to_date>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1134 <timer_to_date+0x24>
movq   $0x0,-0x8(%rbp)
jmp    11c0 <timer_to_date+0xb0>
lea    -0x10(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11b8 <timer_to_date+0xa8>
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
add    $0x76c,%ecx
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
cltq
imul   $0xf4240,%rax,%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
mov    -0x20(%rbp),%rax
movslq %edx,%rcx
imul   $0x2710,%rcx,%rcx
add    %rcx,%rax
mov    -0x18(%rbp),%rcx
mov    0x10(%rcx),%rcx
add    $0x1,%rcx
imul   $0x64,%rcx,%rcx
add    %rcx,%rax
mov    -0x18(%rbp),%rcx
add    0x8(%rcx),%rax
mov    %rax,-0x8(%rbp)
jmp    11c0 <timer_to_date+0xb0>
movq   $0x12c9985,-0x8(%rbp)
01
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<timer_to_date>:
push   %rax
mov    %rdi,(%rsp)
test   %rdi,%rdi
je     117e <timer_to_date+0x6e>
mov    %rsp,%rdi
call   1030 <localtime@plt>
test   %rax,%rax
je     1182 <timer_to_date+0x72>
mov    (%rax),%ecx
lea    0x76c(%rcx),%edx
mov    %edx,(%rax)
movslq %edx,%rdx
imul   $0x51eb851f,%rdx,%rdx
mov    %rdx,%rsi
shr    $0x3f,%rsi
sar    $0x25,%rdx
add    %esi,%edx
movslq %edx,%rdx
imul   $0xf4240,%rdx,%rsi
imul   $0x64,%edx,%edx
neg    %edx
add    %edx,%ecx
add    $0x76c,%ecx
imul   $0x2710,%ecx,%ecx
movslq %ecx,%rcx
imul   $0x64,0x10(%rax),%rdx
add    0x8(%rax),%rdx
add    %rcx,%rdx
lea    (%rsi,%rdx,1),%rax
add    $0x64,%rax
pop    %rcx
ret
xor    %eax,%eax
pop    %rcx
ret
mov    $0x12c9985,%eax
pop    %rcx
ret

LLVM IR (-O0):
%struct.tm = type { i32, i64, i64 }
define i64 @timer_to_date(i64 %0) {
%2 = alloca i64
%3 = alloca i64
%4 = alloca %struct.tm*
store i64 %0, i64* %3
%5 = load i64, i64* %3
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %8
7: ; preds = %1
store i64 0, i64* %2
br label %41
8: ; preds = %1
%9 = call %struct.tm* @localtime(i64* %3)
store %struct.tm* %9, %struct.tm** %4
%10 = load %struct.tm*, %struct.tm** %4
%11 = icmp ne %struct.tm* %10, null
br i1 %11, label %12, label %40
12: ; preds = %8
%13 = load %struct.tm*, %struct.tm** %4
%14 = getelementptr inbounds %struct.tm, %struct.tm* %13, i32 0, i32 0
%15 = load i32, i32* %14
%16 = add nsw i32 %15, 1900
store i32 %16, i32* %14
%17 = load %struct.tm*, %struct.tm** %4
%18 = getelementptr inbounds %struct.tm, %struct.tm* %17, i32 0, i32 0
%19 = load i32, i32* %18
%20 = sdiv i32 %19, 100
%21 = sext i32 %20 to i64
%22 = mul nsw i64 %21, 1000000
%23 = load %struct.tm*, %struct.tm** %4
%24 = getelementptr inbounds %struct.tm, %struct.tm* %23, i32 0, i32 0
%25 = load i32, i32* %24
%26 = srem i32 %25, 100
%27 = sext i32 %26 to i64
%28 = mul nsw i64 %27, 10000
%29 = add nsw i64 %22, %28
%30 = load %struct.tm*, %struct.tm** %4
%31 = getelementptr inbounds %struct.tm, %struct.tm* %30, i32 0, i32 2
%32 = load i64, i64* %31
%33 = add nsw i64 %32, 1
%34 = mul nsw i64 %33, 100
%35 = add nsw i64 %29, %34
%36 = load %struct.tm*, %struct.tm** %4
%37 = getelementptr inbounds %struct.tm, %struct.tm* %36, i32 0, i32 1
%38 = load i64, i64* %37
%39 = add nsw i64 %35, %38
store i64 %39, i64* %2
br label %41
40: ; preds = %8
store i64 19700101, i64* %2
br label %41
41: ; preds = %40, %12, %7
%42 = load i64, i64* %2
ret i64 %42
}

LLVM IR (-O2):
%struct.tm = type { i32, i64, i64 }
define i64 @timer_to_date(i64 %0) {
%2 = alloca i64
store i64 %0, i64* %2
%3 = icmp eq i64 %0, 0
br i1 %3, label %26, label %4
4: ; preds = %1
%5 = call %struct.tm* @localtime(i64* %2)
%6 = icmp eq %struct.tm* %5, null
br i1 %6, label %26, label %7
7: ; preds = %4
%8 = getelementptr inbounds %struct.tm, %struct.tm* %5, i64 0, i32 0
%9 = load i32, i32* %8
%10 = add nsw i32 %9, 1900
store i32 %10, i32* %8
%11 = sdiv i32 %10, 100
%12 = sext i32 %11 to i64
%13 = mul nsw i64 %12, 1000000
%14 = srem i32 %10, 100
%15 = mul nsw i32 %14, 10000
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds %struct.tm, %struct.tm* %5, i64 0, i32 2
%18 = load i64, i64* %17
%19 = mul i64 %18, 100
%20 = getelementptr inbounds %struct.tm, %struct.tm* %5, i64 0, i32 1
%21 = load i64, i64* %20
%22 = add i64 %19, 100
%23 = add i64 %22, %21
%24 = add i64 %23, %16
%25 = add i64 %24, %13
br label %26
26: ; preds = %4, %1, %7
%27 = phi i64 [ %25, %7 ], [ 0, %1 ], [ 19700101, %4 ]
ret i64 %27
}