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


x86 assembly (clang, -O0):
<mktime_pain_in_the_ass>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xe7d(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11a4 <mktime_pain_in_the_ass+0x34>
mov    -0x18(%rbp),%rdi
call   1090 <strdup@plt>
mov    %rax,-0x18(%rbp)
lea    0xe55(%rip),%rdi
lea    0xe50(%rip),%rsi
mov    $0x1,%edx
call   1050 <setenv@plt>
mov    $0x0,%al
call   1060 <tzset@plt>
mov    -0x8(%rbp),%rdi
call   1070 <mktime@plt>
mov    %eax,-0xc(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11fd <mktime_pain_in_the_ass+0x8d>
mov    -0x18(%rbp),%rsi
lea    0xe1b(%rip),%rdi
mov    $0x1,%edx
call   1050 <setenv@plt>
mov    -0x18(%rbp),%rdi
call   1040 <free@plt>
jmp    1209 <mktime_pain_in_the_ass+0x99>
lea    0xdfc(%rip),%rdi
call   1080 <unsetenv@plt>
mov    $0x0,%al
call   1060 <tzset@plt>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mktime_pain_in_the_ass>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%r14
lea    0xe82(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1195 <mktime_pain_in_the_ass+0x25>
mov    %rax,%rdi
call   1090 <strdup@plt>
mov    %rax,%rbx
jmp    1197 <mktime_pain_in_the_ass+0x27>
xor    %ebx,%ebx
lea    0xe62(%rip),%rdi
lea    0xe5d(%rip),%rsi
mov    $0x1,%edx
call   1050 <setenv@plt>
xor    %eax,%eax
call   1060 <tzset@plt>
mov    %r14,%rdi
call   1070 <mktime@plt>
mov    %eax,%ebp
lea    0xe39(%rip),%rdi
test   %rbx,%rbx
je     11e3 <mktime_pain_in_the_ass+0x73>
mov    %rbx,%rsi
mov    $0x1,%edx
call   1050 <setenv@plt>
mov    %rbx,%rdi
call   1040 <free@plt>
jmp    11e8 <mktime_pain_in_the_ass+0x78>
call   1080 <unsetenv@plt>
xor    %eax,%eax
call   1060 <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 @mktime_pain_in_the_ass(%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 = load i8*, i8** %4
%7 = icmp ne i8* %6, null
br i1 %7, label %8, label %11
8: ; preds = %1
%9 = load i8*, i8** %4
%10 = call i8* @strdup(i8* %9)
store i8* %10, i8** %4
br label %11
11: ; preds = %8, %1
%12 = 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)
%13 = call i32 (...) @tzset()
%14 = load %struct.tm*, %struct.tm** %2
%15 = call i32 @mktime(%struct.tm* %14)
store i32 %15, i32* %3
%16 = load i8*, i8** %4
%17 = icmp ne i8* %16, null
br i1 %17, label %18, label %23
18: ; preds = %11
%19 = load i8*, i8** %4
%20 = call i32 @setenv(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %19, i32 1)
%21 = load i8*, i8** %4
%22 = call i32 @free(i8* %21)
br label %25
23: ; preds = %11
%24 = call i32 @unsetenv(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
br label %25
25: ; preds = %23, %18
%26 = call i32 (...) @tzset()
%27 = load i32, i32* %3
ret i32 %27
}

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