#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 tm_isdst;
};

/* Variables and functions */
char *getenv(char *);
int /*<<< orphan*/ mktime(struct tm *);
scalar_t__ strcmp(char const *, char const *);
int /*<<< orphan*/ time_set_tz(char const *);
time_t neo_time_compact(struct tm *ttm, const char *mytimezone) {
  time_t r;
  int save_isdst = ttm->tm_isdst;
  const char *cur_tz = getenv("TZ");
  int change_back = 0;
  if (cur_tz == NULL || strcmp(mytimezone, cur_tz)) {
    time_set_tz(mytimezone);
    change_back = 1;
  }
  ttm->tm_isdst = -1;
  r = mktime(ttm);
  ttm->tm_isdst = save_isdst;
  if (cur_tz && change_back) {
    time_set_tz(cur_tz);
  }
  return r;
}


x86 assembly (clang, -O0):
<neo_time_compact>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
lea    0xea0(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1192 <neo_time_compact+0x52>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
je     11a2 <neo_time_compact+0x62>
mov    -0x10(%rbp),%rdi
call   1050 <time_set_tz@plt>
movl   $0x1,-0x24(%rbp)
mov    -0x8(%rbp),%rax
movl   $0xffffffff,(%rax)
mov    -0x8(%rbp),%rdi
call   1060 <mktime@plt>
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
cmpq   $0x0,-0x20(%rbp)
je     11df <neo_time_compact+0x9f>
cmpl   $0x0,-0x24(%rbp)
je     11df <neo_time_compact+0x9f>
mov    -0x20(%rbp),%rdi
call   1050 <time_set_tz@plt>
mov    -0x14(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<neo_time_compact>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r15
mov    %rdi,%rbx
mov    (%rdi),%r12d
lea    0xea8(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%r14
test   %rax,%rax
je     1175 <neo_time_compact+0x35>
mov    %r15,%rdi
mov    %r14,%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
je     1182 <neo_time_compact+0x42>
mov    %r15,%rdi
call   1050 <time_set_tz@plt>
mov    $0x1,%r15b
jmp    1185 <neo_time_compact+0x45>
xor    %r15d,%r15d
movl   $0xffffffff,(%rbx)
mov    %rbx,%rdi
call   1060 <mktime@plt>
mov    %eax,%ebp
mov    %r12d,(%rbx)
test   %r14,%r14
je     11aa <neo_time_compact+0x6a>
test   %r15b,%r15b
je     11aa <neo_time_compact+0x6a>
mov    %r14,%rdi
call   1050 <time_set_tz@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.tm = type { i32 }
@.str = [3 x i8] c"TZ\00"
define i32 @neo_time_compact(%struct.tm* %0, i8* %1) {
%3 = alloca %struct.tm*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
store %struct.tm* %0, %struct.tm** %3
store i8* %1, i8** %4
%9 = load %struct.tm*, %struct.tm** %3
%10 = getelementptr inbounds %struct.tm, %struct.tm* %9, i32 0, i32 0
%11 = load i32, i32* %10
store i32 %11, i32* %6
%12 = call i8* @getenv(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i8* %12, i8** %7
store i32 0, i32* %8
%13 = load i8*, i8** %7
%14 = icmp eq i8* %13, null
br i1 %14, label %20, label %15
15: ; preds = %2
%16 = load i8*, i8** %4
%17 = load i8*, i8** %7
%18 = call i64 @strcmp(i8* %16, i8* %17)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %15, %2
%21 = load i8*, i8** %4
%22 = call i32 @time_set_tz(i8* %21)
store i32 1, i32* %8
br label %23
23: ; preds = %20, %15
%24 = load %struct.tm*, %struct.tm** %3
%25 = getelementptr inbounds %struct.tm, %struct.tm* %24, i32 0, i32 0
store i32 -1, i32* %25
%26 = load %struct.tm*, %struct.tm** %3
%27 = call i32 @mktime(%struct.tm* %26)
store i32 %27, i32* %5
%28 = load i32, i32* %6
%29 = load %struct.tm*, %struct.tm** %3
%30 = getelementptr inbounds %struct.tm, %struct.tm* %29, i32 0, i32 0
store i32 %28, i32* %30
%31 = load i8*, i8** %7
%32 = icmp ne i8* %31, null
br i1 %32, label %33, label %39
33: ; preds = %23
%34 = load i32, i32* %8
%35 = icmp ne i32 %34, 0
br i1 %35, label %36, label %39
36: ; preds = %33
%37 = load i8*, i8** %7
%38 = call i32 @time_set_tz(i8* %37)
br label %39
39: ; preds = %36, %33, %23
%40 = load i32, i32* %5
ret i32 %40
}

LLVM IR (-O2):
%struct.tm = type { i32 }
@.str = [3 x i8] c"TZ\00"
define i32 @neo_time_compact(%struct.tm* nocapture %0, i8* %1) {
%3 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 0
%4 = load i32, i32* %3
%5 = tail call i8* @getenv(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i8* %5, null
br i1 %6, label %10, label %7
7: ; preds = %2
%8 = tail call i64 @strcmp(i8* %1, i8* %5)
%9 = icmp eq i64 %8, 0
br i1 %9, label %12, label %10
10: ; preds = %7, %2
%11 = tail call i32 @time_set_tz(i8* %1)
br label %12
12: ; preds = %10, %7
%13 = phi i1 [ true, %10 ], [ false, %7 ]
store i32 -1, i32* %3
%14 = tail call i32 @mktime(%struct.tm* %0)
store i32 %4, i32* %3
%15 = icmp ne i8* %5, null
%16 = and i1 %15, %13
br i1 %16, label %17, label %19
17: ; preds = %12
%18 = tail call i32 @time_set_tz(i8* %5)
br label %19
19: ; preds = %17, %12
ret i32 %14
}