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


x86 assembly (clang, -O0):
<my_timegm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xe9d(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
lea    0xe8d(%rip),%rdi
lea    0xe88(%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,-0x18(%rbp)
je     11bc <my_timegm+0x6c>
mov    -0x18(%rbp),%rsi
lea    0xe53(%rip),%rdi
mov    $0x1,%edx
call   1040 <setenv@plt>
jmp    11c8 <my_timegm+0x78>
lea    0xe3d(%rip),%rdi
call   1070 <unsetenv@plt>
mov    $0x0,%al
call   1050 <tzset@plt>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<my_timegm>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%r14
lea    0xea2(%rip),%rbp
mov    %rbp,%rdi
call   1030 <getenv@plt>
mov    %rax,%rbx
lea    0xe92(%rip),%rsi
mov    %rbp,%rdi
mov    $0x1,%edx
call   1040 <setenv@plt>
xor    %eax,%eax
call   1050 <tzset@plt>
mov    %r14,%rdi
call   1060 <mktime@plt>
mov    %eax,%ebp
lea    0xe6b(%rip),%rdi
test   %rbx,%rbx
je     11a9 <my_timegm+0x59>
mov    %rbx,%rsi
mov    $0x1,%edx
call   1040 <setenv@plt>
jmp    11ae <my_timegm+0x5e>
call   1070 <unsetenv@plt>
xor    %eax,%eax
call   1050 <tzset@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.tm = type { i32 }
@.str = [3 x i8] c"TZ\00"
@.str.1 = [1 x i8] zeroinitializer
define i32 @my_timegm(%struct.tm* %0) {
%2 = alloca %struct.tm*
%3 = alloca i32
%4 = alloca i8*
store %struct.tm* %0, %struct.tm** %2
%5 = call i8* @getenv(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i8* %5, i8** %4
%6 = 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)
%7 = call i32 (...) @tzset()
%8 = load %struct.tm*, %struct.tm** %2
%9 = call i32 @mktime(%struct.tm* %8)
store i32 %9, i32* %3
%10 = load i8*, i8** %4
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %15
12: ; preds = %1
%13 = load i8*, i8** %4
%14 = call i32 @setenv(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %13, i32 1)
br label %17
15: ; preds = %1
%16 = call i32 @unsetenv(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
br label %17
17: ; preds = %15, %12
%18 = call i32 (...) @tzset()
%19 = load i32, i32* %3
ret i32 %19
}

LLVM IR (-O2):
%struct.tm = type { i32 }
@.str = [3 x i8] c"TZ\00"
@.str.1 = [1 x i8] zeroinitializer
define i32 @my_timegm(%struct.tm* nocapture %0) {
%2 = tail call i8* @getenv(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%3 = 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)
%4 = tail call i32 (...) @tzset()
%5 = tail call i32 @mktime(%struct.tm* %0)
%6 = icmp eq i8* %2, null
br i1 %6, label %9, label %7
7: ; preds = %1
%8 = tail call i32 @setenv(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %2, i32 1)
br label %11
9: ; preds = %1
%10 = tail call i32 @unsetenv(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %9, %7
%12 = tail call i32 (...) @tzset()
ret i32 %5
}