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


x86 assembly (clang, -O0):
<tm_normalizetoutc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
lea    0xe7d(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11a4 <tm_normalizetoutc+0x34>
mov    -0x18(%rbp),%rdi
call   1090 <strdup@plt>
mov    %rax,-0x18(%rbp)
mov    $0x0,%al
call   1080 <tm_utctimezone@plt>
mov    %rax,%rsi
lea    0xe4b(%rip),%rdi
mov    $0x1,%edx
call   1040 <setenv@plt>
cmp    $0x0,%eax
je     11d4 <tm_normalizetoutc+0x64>
movl   $0xffffffff,-0x4(%rbp)
jmp    1225 <tm_normalizetoutc+0xb5>
mov    $0x0,%al
call   1050 <tzset@plt>
mov    -0x10(%rbp),%rdi
call   1060 <mktime@plt>
mov    %eax,-0x1c(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     120c <tm_normalizetoutc+0x9c>
mov    -0x18(%rbp),%rsi
lea    0xe03(%rip),%rdi
mov    $0x1,%edx
call   1040 <setenv@plt>
jmp    1218 <tm_normalizetoutc+0xa8>
lea    0xded(%rip),%rdi
call   1070 <unsetenv@plt>
mov    $0x0,%al
call   1050 <tzset@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tm_normalizetoutc>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%r14
lea    0xe82(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1195 <tm_normalizetoutc+0x25>
mov    %rax,%rdi
call   1090 <strdup@plt>
mov    %rax,%rbx
jmp    1197 <tm_normalizetoutc+0x27>
xor    %ebx,%ebx
xor    %eax,%eax
call   1080 <tm_utctimezone@plt>
lea    0xe5b(%rip),%rdi
mov    %rax,%rsi
mov    $0x1,%edx
call   1040 <setenv@plt>
mov    $0xffffffff,%ebp
test   %eax,%eax
jne    11f3 <tm_normalizetoutc+0x83>
xor    %eax,%eax
call   1050 <tzset@plt>
mov    %r14,%rdi
call   1060 <mktime@plt>
mov    %eax,%ebp
lea    0xe2d(%rip),%rdi
test   %rbx,%rbx
je     11e7 <tm_normalizetoutc+0x77>
mov    %rbx,%rsi
mov    $0x1,%edx
call   1040 <setenv@plt>
jmp    11ec <tm_normalizetoutc+0x7c>
call   1070 <unsetenv@plt>
xor    %eax,%eax
call   1050 <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"
define i32 @tm_normalizetoutc(%struct.tm* %0) {
%2 = alloca i32
%3 = alloca %struct.tm*
%4 = alloca i8*
%5 = alloca i32
store %struct.tm* %0, %struct.tm** %3
%6 = call i8* @getenv(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i8* %6, i8** %4
%7 = load i8*, i8** %4
%8 = icmp ne i8* %7, null
br i1 %8, label %9, label %12
9: ; preds = %1
%10 = load i8*, i8** %4
%11 = call i8* @strdup(i8* %10)
store i8* %11, i8** %4
br label %12
12: ; preds = %9, %1
%13 = call i8* (...) @tm_utctimezone()
%14 = call i32 @setenv(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %13, i32 1)
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %12
store i32 -1, i32* %2
br label %31
17: ; preds = %12
%18 = call i32 (...) @tzset()
%19 = load %struct.tm*, %struct.tm** %3
%20 = call i32 @mktime(%struct.tm* %19)
store i32 %20, i32* %5
%21 = load i8*, i8** %4
%22 = icmp ne i8* %21, null
br i1 %22, label %23, label %26
23: ; preds = %17
%24 = load i8*, i8** %4
%25 = call i32 @setenv(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %24, i32 1)
br label %28
26: ; preds = %17
%27 = call i32 @unsetenv(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
br label %28
28: ; preds = %26, %23
%29 = call i32 (...) @tzset()
%30 = load i32, i32* %5
store i32 %30, i32* %2
br label %31
31: ; preds = %28, %16
%32 = load i32, i32* %2
ret i32 %32
}

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