#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 {
  scalar_t__ tm_sec;
  scalar_t__ tm_min;
  scalar_t__ tm_hour;
};

/* Variables and functions */
struct tm *gmtime(scalar_t__ *);
struct tm *localtime(scalar_t__ *);
long timer_to_gmtime(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)
      return ((long)(time_struct->tm_hour) * 1000000L +
              (long)(time_struct->tm_min) * 10000L +
              (long)(time_struct->tm_sec) * 100 + (0));
    else
      return (0);
  }
}


x86 assembly (clang, -O0):
<timer_to_gmtime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1144 <timer_to_gmtime+0x24>
movq   $0x0,-0x8(%rbp)
jmp    11af <timer_to_gmtime+0x8f>
lea    -0x10(%rbp),%rdi
call   1040 <gmtime@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1169 <timer_to_gmtime+0x49>
lea    -0x10(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11a7 <timer_to_gmtime+0x87>
mov    -0x18(%rbp),%rax
imul   $0xf4240,0x10(%rax),%rax
mov    -0x18(%rbp),%rcx
imul   $0x2710,0x8(%rcx),%rcx
add    %rcx,%rax
mov    -0x18(%rbp),%rcx
imul   $0x64,(%rcx),%rcx
add    %rcx,%rax
add    $0x0,%rax
mov    %rax,-0x8(%rbp)
jmp    11af <timer_to_gmtime+0x8f>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<timer_to_gmtime>:
push   %rax
mov    %rdi,(%rsp)
test   %rdi,%rdi
je     1160 <timer_to_gmtime+0x40>
mov    %rsp,%rdi
call   1040 <gmtime@plt>
test   %rax,%rax
jne    1144 <timer_to_gmtime+0x24>
mov    %rsp,%rdi
call   1030 <localtime@plt>
test   %rax,%rax
je     1160 <timer_to_gmtime+0x40>
imul   $0xf4240,0x10(%rax),%rcx
imul   $0x2710,0x8(%rax),%rdx
add    %rcx,%rdx
imul   $0x64,(%rax),%rax
add    %rdx,%rax
pop    %rcx
ret
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
%struct.tm = type { i64, i64, i64 }
define i64 @timer_to_gmtime(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 %34
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 %33
17: ; preds = %14
%18 = load %struct.tm*, %struct.tm** %4
%19 = getelementptr inbounds %struct.tm, %struct.tm* %18, i32 0, i32 2
%20 = load i64, i64* %19
%21 = mul nsw i64 %20, 1000000
%22 = load %struct.tm*, %struct.tm** %4
%23 = getelementptr inbounds %struct.tm, %struct.tm* %22, i32 0, i32 1
%24 = load i64, i64* %23
%25 = mul nsw i64 %24, 10000
%26 = add nsw i64 %21, %25
%27 = load %struct.tm*, %struct.tm** %4
%28 = getelementptr inbounds %struct.tm, %struct.tm* %27, i32 0, i32 0
%29 = load i64, i64* %28
%30 = mul nsw i64 %29, 100
%31 = add nsw i64 %26, %30
%32 = add nsw i64 %31, 0
store i64 %32, i64* %2
br label %34
33: ; preds = %14
store i64 0, i64* %2
br label %34
34: ; preds = %33, %17, %7
%35 = load i64, i64* %2
ret i64 %35
}

LLVM IR (-O2):
%struct.tm = type { i64, i64, i64 }
define i64 @timer_to_gmtime(i64 %0) {
%2 = alloca i64
store i64 %0, i64* %2
%3 = icmp eq i64 %0, 0
br i1 %3, label %23, 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 %23, 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 2
%13 = load i64, i64* %12
%14 = mul nsw i64 %13, 1000000
%15 = getelementptr inbounds %struct.tm, %struct.tm* %11, i64 0, i32 1
%16 = load i64, i64* %15
%17 = mul nsw i64 %16, 10000
%18 = add nsw i64 %17, %14
%19 = getelementptr inbounds %struct.tm, %struct.tm* %11, i64 0, i32 0
%20 = load i64, i64* %19
%21 = mul nsw i64 %20, 100
%22 = add nsw i64 %18, %21
br label %23
23: ; preds = %7, %1, %10
%24 = phi i64 [ %22, %10 ], [ 0, %1 ], [ 0, %7 ]
ret i64 %24
}