#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*/ localtime_r(int /*<<< orphan*/ const *, struct tm *);
scalar_t__ strcmp(char const *, char const *);
int /*<<< orphan*/ time_set_tz(char const *);
void neo_time_expand(const time_t tt, const char *mytimezone, struct tm *ttm) {
  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;
  }
  localtime_r(&tt, ttm);
  if (cur_tz && change_back) {
    time_set_tz(cur_tz);
  }
}


x86 assembly (clang, -O0):
<neo_time_expand>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
lea    0xea6(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     118c <neo_time_expand+0x4c>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
je     119c <neo_time_expand+0x5c>
mov    -0x10(%rbp),%rdi
call   1060 <time_set_tz@plt>
movl   $0x1,-0x24(%rbp)
mov    -0x18(%rbp),%rsi
lea    -0x4(%rbp),%rdi
call   1040 <localtime_r@plt>
cmpq   $0x0,-0x20(%rbp)
je     11c7 <neo_time_expand+0x87>
cmpl   $0x0,-0x24(%rbp)
je     11c7 <neo_time_expand+0x87>
mov    -0x20(%rbp),%rdi
call   1060 <time_set_tz@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<neo_time_expand>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %edi,0xc(%rsp)
lea    0xea6(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     119b <neo_time_expand+0x5b>
mov    %rax,%rbx
mov    %r15,%rdi
mov    %rax,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     11a3 <neo_time_expand+0x63>
mov    %r15,%rdi
call   1060 <time_set_tz@plt>
lea    0xc(%rsp),%rdi
mov    %r14,%rsi
call   1040 <localtime_r@plt>
test   %rbx,%rbx
je     11b0 <neo_time_expand+0x70>
mov    %rbx,%rdi
call   1060 <time_set_tz@plt>
jmp    11b0 <neo_time_expand+0x70>
mov    %r15,%rdi
call   1060 <time_set_tz@plt>
lea    0xc(%rsp),%rdi
mov    %r14,%rsi
call   1040 <localtime_r@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
%struct.tm = type { i32 }
@.str = [3 x i8] c"TZ\00"
define void @neo_time_expand(i32 %0, i8* %1, %struct.tm* %2) {
%4 = alloca i32
store i32 %0, i32* %4
%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 %17, label %7
7: ; preds = %3
%8 = tail call i64 @strcmp(i8* %1, i8* %5)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = call i32 @localtime_r(i32* %4, %struct.tm* %2)
br label %20
12: ; preds = %7
%13 = tail call i32 @time_set_tz(i8* %1)
%14 = call i32 @localtime_r(i32* %4, %struct.tm* %2)
br i1 %6, label %20, label %15
15: ; preds = %12
%16 = call i32 @time_set_tz(i8* %5)
br label %20
17: ; preds = %3
%18 = tail call i32 @time_set_tz(i8* %1)
%19 = call i32 @localtime_r(i32* %4, %struct.tm* %2)
br label %20
20: ; preds = %17, %10, %15, %12
ret void
}