#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 *gmtime(scalar_t__ *);
struct tm *localtime(scalar_t__ *);
long timer_to_gmdate(time_t time_secs) {
  struct tm *time_struct;
  if (time_secs == 0)
    return (0);
  else {
    time_struct = gmtime(&time_secs);
    if (time_struct == NULL)
      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_gmdate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1144 <timer_to_gmdate+0x24>
movq   $0x0,-0x8(%rbp)
jmp    11e8 <timer_to_gmdate+0xc8>
lea    -0x10(%rbp),%rdi
call   1040 <gmtime@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1169 <timer_to_gmdate+0x49>
lea    -0x10(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11e0 <timer_to_gmdate+0xc0>
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    11e8 <timer_to_gmdate+0xc8>
movq   $0x12c9985,-0x8(%rbp)
01
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<timer_to_gmdate>:
push   %rax
mov    %rdi,(%rsp)
test   %rdi,%rdi
je     119b <timer_to_gmdate+0x7b>
mov    %rsp,%rdi
call   1040 <gmtime@plt>
test   %rax,%rax
jne    1144 <timer_to_gmdate+0x24>
mov    %rsp,%rdi
call   1030 <localtime@plt>
test   %rax,%rax
je     119f <timer_to_gmdate+0x7f>
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_gmdate(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 %46
8: ; preds = %1
%9 = call %struct.tm* @gmtime(i64* %3)
store %struct.tm* %9, %struct.tm** %4
%10 = load %struct.tm*, %struct.tm** %4
%11 = icmp eq %struct.tm* %10, null
br i1 %11, label %12, label %14
12: ; preds = %8
%13 = call %struct.tm* @localtime(i64* %3)
store %struct.tm* %13, %struct.tm** %4
br label %14
14: ; preds = %12, %8
%15 = load %struct.tm*, %struct.tm** %4
%16 = icmp ne %struct.tm* %15, null
br i1 %16, label %17, label %45
17: ; preds = %14
%18 = load %struct.tm*, %struct.tm** %4
%19 = getelementptr inbounds %struct.tm, %struct.tm* %18, i32 0, i32 0
%20 = load i32, i32* %19
%21 = add nsw i32 %20, 1900
store i32 %21, i32* %19
%22 = load %struct.tm*, %struct.tm** %4
%23 = getelementptr inbounds %struct.tm, %struct.tm* %22, i32 0, i32 0
%24 = load i32, i32* %23
%25 = sdiv i32 %24, 100
%26 = sext i32 %25 to i64
%27 = mul nsw i64 %26, 1000000
%28 = load %struct.tm*, %struct.tm** %4
%29 = getelementptr inbounds %struct.tm, %struct.tm* %28, i32 0, i32 0
%30 = load i32, i32* %29
%31 = srem i32 %30, 100
%32 = sext i32 %31 to i64
%33 = mul nsw i64 %32, 10000
%34 = add nsw i64 %27, %33
%35 = load %struct.tm*, %struct.tm** %4
%36 = getelementptr inbounds %struct.tm, %struct.tm* %35, i32 0, i32 2
%37 = load i64, i64* %36
%38 = add nsw i64 %37, 1
%39 = mul nsw i64 %38, 100
%40 = add nsw i64 %34, %39
%41 = load %struct.tm*, %struct.tm** %4
%42 = getelementptr inbounds %struct.tm, %struct.tm* %41, i32 0, i32 1
%43 = load i64, i64* %42
%44 = add nsw i64 %40, %43
store i64 %44, i64* %2
br label %46
45: ; preds = %14
store i64 19700101, i64* %2
br label %46
46: ; preds = %45, %17, %7
%47 = load i64, i64* %2
ret i64 %47
}

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