#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_hour;
  int tm_min;
  int tm_year;
  int tm_yday;
};
typedef int int32_t;

/* Variables and functions */
struct tm *gmtime(scalar_t__ *);
struct tm *localtime(scalar_t__ *);
scalar_t__ time(int /*<<< orphan*/ *);
int32_t gmt2local(time_t t) {
  register int dt, dir;
  register struct tm *gmt, *loc;
  struct tm sgmt;
  if (t == 0)
    t = time(NULL);
  gmt = &sgmt;
  *gmt = *gmtime(&t);
  loc = localtime(&t);
  dt = (loc->tm_hour - gmt->tm_hour) * 60 * 60 +
       (loc->tm_min - gmt->tm_min) * 60;
  dir = loc->tm_year - gmt->tm_year;
  if (dir == 0)
    dir = loc->tm_yday - gmt->tm_yday;
  dt += dir * 24 * 60 * 60;
  return (dt);
}


x86 assembly (clang, -O0):
<gmt2local>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1154 <gmt2local+0x24>
xor    %eax,%eax
mov    %eax,%edi
call   1040 <time@plt>
mov    %rax,-0x8(%rbp)
lea    -0x30(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
lea    -0x8(%rbp),%rdi
call   1050 <gmtime@plt>
mov    %rax,%rcx
mov    -0x38(%rbp),%rax
mov    (%rcx),%rdx
mov    %rdx,(%rax)
mov    0x8(%rcx),%rcx
mov    %rcx,0x8(%rax)
lea    -0x8(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
mov    -0x18(%rbp),%rcx
sub    (%rcx),%eax
imul   $0x3c,%eax,%eax
imul   $0x3c,%eax,%eax
mov    -0x20(%rbp),%rcx
mov    0x4(%rcx),%ecx
mov    -0x18(%rbp),%rdx
sub    0x4(%rdx),%ecx
imul   $0x3c,%ecx,%ecx
add    %ecx,%eax
mov    %eax,-0xc(%rbp)
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%eax
mov    -0x18(%rbp),%rcx
sub    0x8(%rcx),%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jne    11e3 <gmt2local+0xb3>
mov    -0x20(%rbp),%rax
mov    0xc(%rax),%eax
mov    -0x18(%rbp),%rcx
sub    0xc(%rcx),%eax
mov    %eax,-0x10(%rbp)
imul   $0x18,-0x10(%rbp),%eax
imul   $0x3c,%eax,%eax
imul   $0x3c,%eax,%eax
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gmt2local>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdi,0x8(%rsp)
test   %rdi,%rdi
jne    1152 <gmt2local+0x22>
xor    %edi,%edi
call   1040 <time@plt>
mov    %rax,0x8(%rsp)
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
call   1050 <gmtime@plt>
mov    (%rax),%r12d
mov    0x4(%rax),%r14d
mov    0x8(%rax),%ebp
mov    0xc(%rax),%r15d
mov    %rbx,%rdi
call   1030 <localtime@plt>
mov    (%rax),%esi
mov    0x4(%rax),%ecx
mov    0x8(%rax),%edx
sub    %ebp,%edx
jne    1187 <gmt2local+0x57>
mov    0xc(%rax),%edx
sub    %r15d,%edx
sub    %r12d,%esi
imul   $0xe10,%esi,%eax
sub    %r14d,%ecx
imul   $0x3c,%ecx,%ecx
add    %eax,%ecx
imul   $0x15180,%edx,%eax
add    %ecx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.tm = type { i32, i32, i32, i32 }
define i32 @gmt2local(i64 %0) {
%2 = alloca i64
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.tm*
%6 = alloca %struct.tm*
%7 = alloca %struct.tm
store i64 %0, i64* %2
%8 = load i64, i64* %2
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %1
%11 = call i64 @time(i32* null)
store i64 %11, i64* %2
br label %12
12: ; preds = %10, %1
store %struct.tm* %7, %struct.tm** %5
%13 = load %struct.tm*, %struct.tm** %5
%14 = call %struct.tm* @gmtime(i64* %2)
%15 = bitcast %struct.tm* %13 to i8*
%16 = bitcast %struct.tm* %14 to i8*
%17 = call %struct.tm* @localtime(i64* %2)
store %struct.tm* %17, %struct.tm** %6
%18 = load %struct.tm*, %struct.tm** %6
%19 = getelementptr inbounds %struct.tm, %struct.tm* %18, i32 0, i32 0
%20 = load i32, i32* %19
%21 = load %struct.tm*, %struct.tm** %5
%22 = getelementptr inbounds %struct.tm, %struct.tm* %21, i32 0, i32 0
%23 = load i32, i32* %22
%24 = sub nsw i32 %20, %23
%25 = mul nsw i32 %24, 60
%26 = mul nsw i32 %25, 60
%27 = load %struct.tm*, %struct.tm** %6
%28 = getelementptr inbounds %struct.tm, %struct.tm* %27, i32 0, i32 1
%29 = load i32, i32* %28
%30 = load %struct.tm*, %struct.tm** %5
%31 = getelementptr inbounds %struct.tm, %struct.tm* %30, i32 0, i32 1
%32 = load i32, i32* %31
%33 = sub nsw i32 %29, %32
%34 = mul nsw i32 %33, 60
%35 = add nsw i32 %26, %34
store i32 %35, i32* %3
%36 = load %struct.tm*, %struct.tm** %6
%37 = getelementptr inbounds %struct.tm, %struct.tm* %36, i32 0, i32 2
%38 = load i32, i32* %37
%39 = load %struct.tm*, %struct.tm** %5
%40 = getelementptr inbounds %struct.tm, %struct.tm* %39, i32 0, i32 2
%41 = load i32, i32* %40
%42 = sub nsw i32 %38, %41
store i32 %42, i32* %4
%43 = load i32, i32* %4
%44 = icmp eq i32 %43, 0
br i1 %44, label %45, label %53
45: ; preds = %12
%46 = load %struct.tm*, %struct.tm** %6
%47 = getelementptr inbounds %struct.tm, %struct.tm* %46, i32 0, i32 3
%48 = load i32, i32* %47
%49 = load %struct.tm*, %struct.tm** %5
%50 = getelementptr inbounds %struct.tm, %struct.tm* %49, i32 0, i32 3
%51 = load i32, i32* %50
%52 = sub nsw i32 %48, %51
store i32 %52, i32* %4
br label %53
53: ; preds = %45, %12
%54 = load i32, i32* %4
%55 = mul nsw i32 %54, 24
%56 = mul nsw i32 %55, 60
%57 = mul nsw i32 %56, 60
%58 = load i32, i32* %3
%59 = add nsw i32 %58, %57
store i32 %59, i32* %3
%60 = load i32, i32* %3
ret i32 %60
}

LLVM IR (-O2):
%struct.tm = type { i32, i32, i32, i32 }
define i32 @gmt2local(i64 %0) {
%2 = alloca i64
store i64 %0, i64* %2
%3 = icmp eq i64 %0, 0
br i1 %3, label %4, label %6
4: ; preds = %1
%5 = tail call i64 @time(i32* null)
store i64 %5, i64* %2
br label %6
6: ; preds = %4, %1
%7 = call %struct.tm* @gmtime(i64* %2)
%8 = getelementptr inbounds %struct.tm, %struct.tm* %7, i64 0, i32 0
%9 = load i32, i32* %8
%10 = getelementptr inbounds %struct.tm, %struct.tm* %7, i64 0, i32 1
%11 = load i32, i32* %10
%12 = getelementptr inbounds %struct.tm, %struct.tm* %7, i64 0, i32 2
%13 = load i32, i32* %12
%14 = getelementptr inbounds %struct.tm, %struct.tm* %7, i64 0, i32 3
%15 = load i32, i32* %14
%16 = call %struct.tm* @localtime(i64* %2)
%17 = getelementptr inbounds %struct.tm, %struct.tm* %16, i64 0, i32 0
%18 = load i32, i32* %17
%19 = getelementptr inbounds %struct.tm, %struct.tm* %16, i64 0, i32 1
%20 = load i32, i32* %19
%21 = getelementptr inbounds %struct.tm, %struct.tm* %16, i64 0, i32 2
%22 = load i32, i32* %21
%23 = sub nsw i32 %22, %13
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %29
25: ; preds = %6
%26 = getelementptr inbounds %struct.tm, %struct.tm* %16, i64 0, i32 3
%27 = load i32, i32* %26
%28 = sub nsw i32 %27, %15
br label %29
29: ; preds = %25, %6
%30 = phi i32 [ %28, %25 ], [ %23, %6 ]
%31 = sub nsw i32 %18, %9
%32 = mul i32 %31, 3600
%33 = sub nsw i32 %20, %11
%34 = mul nsw i32 %33, 60
%35 = add nsw i32 %34, %32
%36 = mul i32 %30, 86400
%37 = add nsw i32 %35, %36
ret i32 %37
}