#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 */

/* Variables and functions */
int /*<<< orphan*/ free(char *);
char *getenv(char *);
char *malloc(scalar_t__);
char *realloc(char *, scalar_t__);
scalar_t__ strcmp(char *, char const *);
int /*<<< orphan*/ strcpy(char *, char const *);
scalar_t__ strlen(char const *);
scalar_t__ tzparse(char const *);
int /*<<< orphan*/ tzreset();
void tzset(void) {
  const char *tz = getenv("TZ");
  static char *tz_envval;
  if (tz && *tz) {
    if (tz_envval) {
      if (strcmp(tz_envval, tz) == 0)
        return;
      tz_envval = realloc(tz_envval, strlen(tz) + 1);
      strcpy(tz_envval, tz);
    } else {
      tz_envval = malloc(strlen(tz) + 1);
      strcpy(tz_envval, tz);
    }
    if (tzparse(tz) == 0)
      return;
  }
  if (tz_envval) {
    free(tz_envval);
    tz_envval = 0;
    tzreset();
  }
}


x86 assembly (clang, -O0):
<tzset>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xe61(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1279 <tzset+0xe9>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1279 <tzset+0xe9>
cmpq   $0x0,0x2ea5(%rip)
je     1230 <tzset+0xa0>
mov    0x2e98(%rip),%rdi
mov    -0x8(%rbp),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    11f0 <tzset+0x60>
jmp    12a5 <tzset+0x115>
mov    0x2e79(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x10(%rbp),%rdi
mov    %rax,%rsi
add    $0x1,%rsi
call   10a0 <realloc@plt>
mov    %rax,0x2e55(%rip)
mov    0x2e4e(%rip),%rdi
mov    -0x8(%rbp),%rsi
call   1050 <strcpy@plt>
jmp    125c <tzset+0xcc>
mov    -0x8(%rbp),%rdi
call   1060 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   1090 <malloc@plt>
mov    %rax,0x2e24(%rip)
mov    0x2e1d(%rip),%rdi
mov    -0x8(%rbp),%rsi
call   1050 <strcpy@plt>
mov    -0x8(%rbp),%rdi
call   10b0 <tzparse@plt>
cmp    $0x0,%rax
jne    1274 <tzset+0xe4>
jmp    12a5 <tzset+0x115>
jmp    1279 <tzset+0xe9>
cmpq   $0x0,0x2def(%rip)
je     12a5 <tzset+0x115>
mov    0x2de2(%rip),%rdi
call   1040 <free@plt>
movq   $0x0,0x2dd2(%rip)
mov    $0x0,%al
call   1070 <tzreset@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tzset>:
push   %r14
push   %rbx
push   %rax
lea    0xe65(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1213 <tzset+0x83>
mov    %rax,%rbx
cmpb   $0x0,(%rax)
je     1213 <tzset+0x83>
mov    0x2ebc(%rip),%rdi
test   %rdi,%rdi
je     11e3 <tzset+0x53>
mov    %rbx,%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
je     123d <tzset+0xad>
mov    0x2ea3(%rip),%r14
mov    %rbx,%rdi
call   1060 <strlen@plt>
lea    0x1(%rax),%rsi
mov    %r14,%rdi
call   10a0 <realloc@plt>
jmp    11f4 <tzset+0x64>
mov    %rbx,%rdi
call   1060 <strlen@plt>
lea    0x1(%rax),%rdi
call   1090 <malloc@plt>
mov    %rax,0x2e75(%rip)
mov    %rax,%rdi
mov    %rbx,%rsi
call   1050 <strcpy@plt>
mov    %rbx,%rdi
call   10b0 <tzparse@plt>
test   %rax,%rax
je     123d <tzset+0xad>
mov    0x2e56(%rip),%rdi
test   %rdi,%rdi
je     123d <tzset+0xad>
call   1040 <free@plt>
movq   $0x0,0x2e41(%rip)
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1070 <tzreset@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [3 x i8] c"TZ\00"
@tzset.tz_envval = internal global i8* null
define void @tzset() {
%1 = alloca i8*
%2 = call i8* @getenv(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i8* %2, i8** %1
%3 = load i8*, i8** %1
%4 = icmp ne i8* %3, null
br i1 %4, label %5, label %42
5: ; preds = %0
%6 = load i8*, i8** %1
%7 = load i8, i8* %6
%8 = sext i8 %7 to i32
%9 = icmp ne i32 %8, 0
br i1 %9, label %10, label %42
10: ; preds = %5
%11 = load i8*, i8** @tzset.tz_envval
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %28
13: ; preds = %10
%14 = load i8*, i8** @tzset.tz_envval
%15 = load i8*, i8** %1
%16 = call i64 @strcmp(i8* %14, i8* %15)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %13
br label %49
19: ; preds = %13
%20 = load i8*, i8** @tzset.tz_envval
%21 = load i8*, i8** %1
%22 = call i64 @strlen(i8* %21)
%23 = add nsw i64 %22, 1
%24 = call i8* @realloc(i8* %20, i64 %23)
store i8* %24, i8** @tzset.tz_envval
%25 = load i8*, i8** @tzset.tz_envval
%26 = load i8*, i8** %1
%27 = call i32 @strcpy(i8* %25, i8* %26)
br label %36
28: ; preds = %10
%29 = load i8*, i8** %1
%30 = call i64 @strlen(i8* %29)
%31 = add nsw i64 %30, 1
%32 = call i8* @malloc(i64 %31)
store i8* %32, i8** @tzset.tz_envval
%33 = load i8*, i8** @tzset.tz_envval
%34 = load i8*, i8** %1
%35 = call i32 @strcpy(i8* %33, i8* %34)
br label %36
36: ; preds = %28, %19
%37 = load i8*, i8** %1
%38 = call i64 @tzparse(i8* %37)
%39 = icmp eq i64 %38, 0
br i1 %39, label %40, label %41
40: ; preds = %36
br label %49
41: ; preds = %36
br label %42
42: ; preds = %41, %5, %0
%43 = load i8*, i8** @tzset.tz_envval
%44 = icmp ne i8* %43, null
br i1 %44, label %45, label %49
45: ; preds = %42
%46 = load i8*, i8** @tzset.tz_envval
%47 = call i32 @free(i8* %46)
store i8* null, i8** @tzset.tz_envval
%48 = call i32 (...) @tzreset()
br label %49
49: ; preds = %18, %40, %45, %42
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"TZ\00"
@tzset.tz_envval = internal unnamed_addr global i8* null
define void @tzset() {
%1 = tail call i8* @getenv(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%2 = icmp eq i8* %1, null
br i1 %2, label %26, label %3
3: ; preds = %0
%4 = load i8, i8* %1
%5 = icmp eq i8 %4, 0
br i1 %5, label %26, label %6
6: ; preds = %3
%7 = load i8*, i8** @tzset.tz_envval
%8 = icmp eq i8* %7, null
br i1 %8, label %17, label %9
9: ; preds = %6
%10 = tail call i64 @strcmp(i8* %7, i8* %1)
%11 = icmp eq i64 %10, 0
br i1 %11, label %32, label %12
12: ; preds = %9
%13 = load i8*, i8** @tzset.tz_envval
%14 = tail call i64 @strlen(i8* %1)
%15 = add nsw i64 %14, 1
%16 = tail call i8* @realloc(i8* %13, i64 %15)
br label %21
17: ; preds = %6
%18 = tail call i64 @strlen(i8* %1)
%19 = add nsw i64 %18, 1
%20 = tail call i8* @malloc(i64 %19)
br label %21
21: ; preds = %17, %12
%22 = phi i8* [ %20, %17 ], [ %16, %12 ]
store i8* %22, i8** @tzset.tz_envval
%23 = tail call i32 @strcpy(i8* %22, i8* %1)
%24 = tail call i64 @tzparse(i8* %1)
%25 = icmp eq i64 %24, 0
br i1 %25, label %32, label %26
26: ; preds = %21, %3, %0
%27 = load i8*, i8** @tzset.tz_envval
%28 = icmp eq i8* %27, null
br i1 %28, label %32, label %29
29: ; preds = %26
%30 = tail call i32 @free(i8* %27)
store i8* null, i8** @tzset.tz_envval
%31 = tail call i32 (...) @tzreset()
br label %32
32: ; preds = %26, %29, %21, %9
ret void
}