#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;
};
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
char *getenv(char *);
int /*<<< orphan*/ mktime(struct tm *);
int /*<<< orphan*/ putenv(char *);
int /*<<< orphan*/ snprintf(char *, int, char *, char *);
int /*<<< orphan*/ tzset();
time_t timegm(struct tm *tm) {
  time_t ret;
  char *tz;
  tz = getenv("TZ");
  putenv((char *)"TZ=");
  tzset();
  ret = mktime(tm);
  if (tz) {
    char buf[256];
    snprintf(buf, sizeof(buf), "TZ=%s", tz);
    putenv(tz);
  } else
    putenv((char *)"TZ");
  tzset();
  return ret;
}


x86 assembly (clang, -O0):
<timegm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xe9a(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
lea    0xe8d(%rip),%rdi
call   1050 <putenv@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     11c3 <timegm+0x73>
lea    -0x120(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x100,%esi
lea    0xe57(%rip),%rdx
call   1040 <snprintf@plt>
mov    -0x18(%rbp),%rdi
call   1050 <putenv@plt>
jmp    11cf <timegm+0x7f>
lea    0xe36(%rip),%rdi
call   1050 <putenv@plt>
mov    $0x0,%al
call   1060 <tzset@plt>
mov    -0xc(%rbp),%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<timegm>:
push   %rbp
push   %rbx
sub    $0x108,%rsp
mov    %rdi,%rbp
lea    0xe9d(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rbx
lea    0xe91(%rip),%rdi
call   1050 <putenv@plt>
xor    %eax,%eax
call   1060 <tzset@plt>
mov    %rbp,%rdi
call   1070 <mktime@plt>
mov    %eax,%ebp
test   %rbx,%rbx
je     11a9 <timegm+0x59>
lea    0xe73(%rip),%rdx
mov    %rsp,%rdi
mov    $0x100,%esi
mov    %rbx,%rcx
call   1040 <snprintf@plt>
mov    %rbx,%rdi
jmp    11b0 <timegm+0x60>
lea    0xe50(%rip),%rdi
call   1050 <putenv@plt>
xor    %eax,%eax
call   1060 <tzset@plt>
mov    %ebp,%eax
add    $0x108,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.tm = type { i32 }
@.str = [3 x i8] c"TZ\00"
@.str.1 = [4 x i8] c"TZ=\00"
@.str.2 = [6 x i8] c"TZ=%s\00"
define i32 @timegm(%struct.tm* %0) {
%2 = alloca %struct.tm*
%3 = alloca i32
%4 = alloca i8*
%5 = alloca [256 x i8]
store %struct.tm* %0, %struct.tm** %2
%6 = call i8* @getenv(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i8* %6, i8** %4
%7 = call i32 @putenv(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%8 = call i32 (...) @tzset()
%9 = load %struct.tm*, %struct.tm** %2
%10 = call i32 @mktime(%struct.tm* %9)
store i32 %10, i32* %3
%11 = load i8*, i8** %4
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %19
13: ; preds = %1
%14 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%15 = load i8*, i8** %4
%16 = call i32 @snprintf(i8* %14, i32 256, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %15)
%17 = load i8*, i8** %4
%18 = call i32 @putenv(i8* %17)
br label %21
19: ; preds = %1
%20 = call i32 @putenv(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
br label %21
21: ; preds = %19, %13
%22 = call i32 (...) @tzset()
%23 = load i32, i32* %3
ret i32 %23
}

LLVM IR (-O2):
%struct.tm = type { i32 }
@.str = [3 x i8] c"TZ\00"
@.str.1 = [4 x i8] c"TZ=\00"
@.str.2 = [6 x i8] c"TZ=%s\00"
define i32 @timegm(%struct.tm* nocapture %0) {
%2 = alloca [256 x i8]
%3 = tail call i8* @getenv(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%4 = tail call i32 @putenv(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%5 = tail call i32 (...) @tzset()
%6 = tail call i32 @mktime(%struct.tm* %0)
%7 = icmp eq i8* %3, null
br i1 %7, label %12, label %8
8: ; preds = %1
%9 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%10 = call i32 @snprintf(i8* %9, i32 256, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %3)
%11 = call i32 @putenv(i8* %3)
br label %14
12: ; preds = %1
%13 = tail call i32 @putenv(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
br label %14
14: ; preds = %12, %8
%15 = call i32 (...) @tzset()
ret i32 %6
}