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


x86 assembly (clang, -O0):
<mktime_utc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe99(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xe85(%rip),%rdi
mov    $0x1,%edx
call   1040 <setenv@plt>
mov    $0x0,%al
call   1050 <tzset@plt>
mov    -0x8(%rbp),%rdi
call   1060 <mktime@plt>
mov    %eax,-0x1c(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11bd <mktime_utc+0x6d>
mov    -0x18(%rbp),%rsi
lea    0xe52(%rip),%rdi
mov    $0x1,%edx
call   1040 <setenv@plt>
jmp    11c9 <mktime_utc+0x79>
lea    0xe3c(%rip),%rdi
call   1070 <unsetenv@plt>
mov    $0x0,%al
call   1050 <tzset@plt>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mktime_utc>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbp
mov    %rdi,%r14
lea    0xe9c(%rip),%r15
mov    %r15,%rdi
call   1030 <getenv@plt>
mov    %rax,%rbx
mov    %r15,%rdi
mov    %rbp,%rsi
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    0xe69(%rip),%rdi
test   %rbx,%rbx
je     11ab <mktime_utc+0x5b>
mov    %rbx,%rsi
mov    $0x1,%edx
call   1040 <setenv@plt>
jmp    11b0 <mktime_utc+0x60>
call   1070 <unsetenv@plt>
xor    %eax,%eax
call   1050 <tzset@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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