#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 int /*<<< orphan*/ time_t;
struct tm {
  int dummy;
};

/* Variables and functions */
int difftime(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ gmtime_r(int /*<<< orphan*/ *, struct tm *);
int /*<<< orphan*/ mktime(struct tm *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int time_localoffset(int force) {
  static int localoffset = 1;
  if (force || localoffset == 1) {
    time_t now;
    struct tm gm;
    now = time(NULL);
    gmtime_r(&now, &gm);
    localoffset = difftime(now, mktime(&gm));
  }
  return localoffset;
}


x86 assembly (clang, -O0):
<time_localoffset>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jne    1162 <time_localoffset+0x22>
cmpl   $0x1,0x2ee4(%rip)
jne    119a <time_localoffset+0x5a>
xor    %eax,%eax
mov    %eax,%edi
call   1050 <time@plt>
mov    %eax,-0x8(%rbp)
lea    -0x8(%rbp),%rdi
lea    -0x10(%rbp),%rsi
call   1040 <gmtime_r@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
lea    -0x10(%rbp),%rdi
call   1060 <mktime@plt>
mov    -0x14(%rbp),%edi
mov    %eax,%esi
call   1030 <difftime@plt>
mov    %eax,0x2ea6(%rip)
mov    0x2ea0(%rip),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<time_localoffset>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
test   %edi,%edi
jne    1155 <time_localoffset+0x15>
mov    0x2ef0(%rip),%eax
cmp    $0x1,%eax
jne    118d <time_localoffset+0x4d>
xor    %edi,%edi
call   1050 <time@plt>
mov    %eax,0xc(%rsp)
lea    0xc(%rsp),%rdi
lea    0x10(%rsp),%rbx
mov    %rbx,%rsi
call   1040 <gmtime_r@plt>
mov    0xc(%rsp),%ebp
mov    %rbx,%rdi
call   1060 <mktime@plt>
mov    %ebp,%edi
mov    %eax,%esi
call   1030 <difftime@plt>
mov    %eax,0x2eb3(%rip)
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.tm = type { i32 }
@time_localoffset.localoffset = internal global i32 1
define i32 @time_localoffset(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.tm
store i32 %0, i32* %2
%5 = load i32, i32* %2
%6 = icmp ne i32 %5, 0
br i1 %6, label %10, label %7
7: ; preds = %1
%8 = load i32, i32* @time_localoffset.localoffset
%9 = icmp eq i32 %8, 1
br i1 %9, label %10, label %16
10: ; preds = %7, %1
%11 = call i32 @time(i32* null)
store i32 %11, i32* %3
%12 = call i32 @gmtime_r(i32* %3, %struct.tm* %4)
%13 = load i32, i32* %3
%14 = call i32 @mktime(%struct.tm* %4)
%15 = call i32 @difftime(i32 %13, i32 %14)
store i32 %15, i32* @time_localoffset.localoffset
br label %16
16: ; preds = %10, %7
%17 = load i32, i32* @time_localoffset.localoffset
ret i32 %17
}

LLVM IR (-O2):
%struct.tm = type { i32 }
@time_localoffset.localoffset = internal unnamed_addr global i32 1
define i32 @time_localoffset(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.tm
%4 = icmp ne i32 %0, 0
%5 = load i32, i32* @time_localoffset.localoffset
%6 = icmp eq i32 %5, 1
%7 = select i1 %4, i1 true, i1 %6
br i1 %7, label %8, label %16
8: ; preds = %1
%9 = bitcast i32* %2 to i8*
%10 = bitcast %struct.tm* %3 to i8*
%11 = tail call i32 @time(i32* null)
store i32 %11, i32* %2
%12 = call i32 @gmtime_r(i32* %2, %struct.tm* %3)
%13 = load i32, i32* %2
%14 = call i32 @mktime(%struct.tm* %3)
%15 = call i32 @difftime(i32 %13, i32 %14)
store i32 %15, i32* @time_localoffset.localoffset
br label %16
16: ; preds = %1, %8
%17 = phi i32 [ %5, %1 ], [ %15, %8 ]
ret i32 %17
}