#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 */
char *getenv(char *);
int /*<<< orphan*/ mktime(struct tm *);
int /*<<< orphan*/ setenv(char *, char const *, int);
char *strdup(char const *);
int /*<<< orphan*/ tzset();
int /*<<< orphan*/ unsetenv(char *);
time_t portable_timegm(struct tm *tm) {
  static const char *tz;
  if (!tz) {
    tz = getenv("TZ");
    if (tz)
      tz = strdup(tz);
  }
  setenv("TZ", "", 1);
  tzset();
  time_t ret = mktime(tm);
  if (tz)
    setenv("TZ", tz, 1);
  else
    unsetenv("TZ");
  tzset();
  return ret;
}


x86 assembly (clang, -O0):
<portable_timegm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,0x2ee4(%rip)
jne    11b3 <portable_timegm+0x53>
lea    0xe7f(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,0x2ecb(%rip)
cmpq   $0x0,0x2ec3(%rip)
je     11ae <portable_timegm+0x4e>
mov    0x2eb6(%rip),%rdi
call   1080 <strdup@plt>
mov    %rax,0x2eaa(%rip)
jmp    11b3 <portable_timegm+0x53>
lea    0xe46(%rip),%rdi
lea    0xe41(%rip),%rsi
mov    $0x1,%edx
call   1040 <setenv@plt>
mov    $0x0,%al
call   1050 <tzset@plt>
mov    -0x8(%rbp),%rdi
call   1060 <mktime@plt>
mov    %eax,-0xc(%rbp)
cmpq   $0x0,0x2e72(%rip)
je     1209 <portable_timegm+0xa9>
mov    0x2e65(%rip),%rsi
lea    0xe06(%rip),%rdi
mov    $0x1,%edx
call   1040 <setenv@plt>
jmp    1215 <portable_timegm+0xb5>
lea    0xdf0(%rip),%rdi
call   1070 <unsetenv@plt>
mov    $0x0,%al
call   1050 <tzset@plt>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<portable_timegm>:
push   %rbx
mov    %rdi,%rbx
cmpq   $0x0,0x2eec(%rip)
jne    1195 <portable_timegm+0x35>
lea    0xe8b(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,0x2ed7(%rip)
test   %rax,%rax
je     1195 <portable_timegm+0x35>
mov    %rax,%rdi
call   1080 <strdup@plt>
mov    %rax,0x2ec3(%rip)
lea    0xe64(%rip),%rdi
lea    0xe5f(%rip),%rsi
mov    $0x1,%edx
call   1040 <setenv@plt>
xor    %eax,%eax
call   1050 <tzset@plt>
mov    %rbx,%rdi
call   1060 <mktime@plt>
mov    %eax,%ebx
mov    0x2e93(%rip),%rsi
lea    0xe34(%rip),%rdi
test   %rsi,%rsi
je     11dd <portable_timegm+0x7d>
mov    $0x1,%edx
call   1040 <setenv@plt>
jmp    11e2 <portable_timegm+0x82>
call   1070 <unsetenv@plt>
xor    %eax,%eax
call   1050 <tzset@plt>
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
%struct.tm = type { i32 }
@portable_timegm.tz = internal global i8* null
@.str = [3 x i8] c"TZ\00"
@.str.1 = [1 x i8] zeroinitializer
define i32 @portable_timegm(%struct.tm* %0) {
%2 = alloca %struct.tm*
%3 = alloca i32
store %struct.tm* %0, %struct.tm** %2
%4 = load i8*, i8** @portable_timegm.tz
%5 = icmp ne i8* %4, null
br i1 %5, label %14, label %6
6: ; preds = %1
%7 = call i8* @getenv(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i8* %7, i8** @portable_timegm.tz
%8 = load i8*, i8** @portable_timegm.tz
%9 = icmp ne i8* %8, null
br i1 %9, label %10, label %13
10: ; preds = %6
%11 = load i8*, i8** @portable_timegm.tz
%12 = call i8* @strdup(i8* %11)
store i8* %12, i8** @portable_timegm.tz
br label %13
13: ; preds = %10, %6
br label %14
14: ; preds = %13, %1
%15 = call i32 @setenv(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), i32 1)
%16 = call i32 (...) @tzset()
%17 = load %struct.tm*, %struct.tm** %2
%18 = call i32 @mktime(%struct.tm* %17)
store i32 %18, i32* %3
%19 = load i8*, i8** @portable_timegm.tz
%20 = icmp ne i8* %19, null
br i1 %20, label %21, label %24
21: ; preds = %14
%22 = load i8*, i8** @portable_timegm.tz
%23 = call i32 @setenv(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %22, i32 1)
br label %26
24: ; preds = %14
%25 = call i32 @unsetenv(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
br label %26
26: ; preds = %24, %21
%27 = call i32 (...) @tzset()
%28 = load i32, i32* %3
ret i32 %28
}

LLVM IR (-O2):
%struct.tm = type { i32 }
@portable_timegm.tz = internal unnamed_addr global i8* null
@.str = [3 x i8] c"TZ\00"
@.str.1 = [1 x i8] zeroinitializer
define i32 @portable_timegm(%struct.tm* nocapture %0) {
%2 = load i8*, i8** @portable_timegm.tz
%3 = icmp eq i8* %2, null
br i1 %3, label %4, label %9
4: ; preds = %1
%5 = tail call i8* @getenv(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i8* %5, i8** @portable_timegm.tz
%6 = icmp eq i8* %5, null
br i1 %6, label %9, label %7
7: ; preds = %4
%8 = tail call i8* @strdup(i8* %5)
store i8* %8, i8** @portable_timegm.tz
br label %9
9: ; preds = %4, %7, %1
%10 = tail call i32 @setenv(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), i32 1)
%11 = tail call i32 (...) @tzset()
%12 = tail call i32 @mktime(%struct.tm* %0)
%13 = load i8*, i8** @portable_timegm.tz
%14 = icmp eq i8* %13, null
br i1 %14, label %17, label %15
15: ; preds = %9
%16 = tail call i32 @setenv(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %13, i32 1)
br label %19
17: ; preds = %9
%18 = tail call i32 @unsetenv(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
br label %19
19: ; preds = %17, %15
%20 = tail call i32 (...) @tzset()
ret i32 %12
}