#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 */
int /*<<< orphan*/ ap_snprintf(char *, int, char *, char *);
char *getenv(char *);
int /*<<< orphan*/ mktime(struct tm *);
int /*<<< orphan*/ putenv(char *);
int /*<<< orphan*/ tzset();
extern time_t timegm(struct tm *tm) {
  time_t ret;
  char *tz;
  tz = getenv("TZ");
  putenv("TZ=UTC");
  tzset();
  ret = mktime(tm);
  if (tz) {
    char buf[256];
    ap_snprintf(buf, sizeof(buf), "TZ=%s", tz);
    putenv(buf);
  } else
    putenv("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   1040 <putenv@plt>
mov    $0x0,%al
call   1050 <tzset@plt>
mov    -0x8(%rbp),%rdi
call   1060 <mktime@plt>
mov    %eax,-0xc(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11c6 <timegm+0x76>
lea    -0x120(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x100,%esi
lea    0xe5a(%rip),%rdx
call   1070 <ap_snprintf@plt>
lea    -0x120(%rbp),%rdi
call   1040 <putenv@plt>
jmp    11d2 <timegm+0x82>
lea    0xe43(%rip),%rdi
call   1040 <putenv@plt>
mov    $0x0,%al
call   1050 <tzset@plt>
mov    -0xc(%rbp),%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<timegm>:
push   %rbp
push   %r14
push   %rbx
sub    $0x100,%rsp
mov    %rdi,%rbp
lea    0xe9b(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rbx
lea    0xe8f(%rip),%rdi
call   1040 <putenv@plt>
xor    %eax,%eax
call   1050 <tzset@plt>
mov    %rbp,%rdi
call   1060 <mktime@plt>
mov    %eax,%ebp
test   %rbx,%rbx
je     11ae <timegm+0x5e>
lea    0xe74(%rip),%rdx
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x100,%esi
mov    %rbx,%rcx
call   1070 <ap_snprintf@plt>
mov    %r14,%rdi
jmp    11b5 <timegm+0x65>
lea    0xe5b(%rip),%rdi
call   1040 <putenv@plt>
xor    %eax,%eax
call   1050 <tzset@plt>
mov    %ebp,%eax
add    $0x100,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.tm = type { i32 }
@.str = [3 x i8] c"TZ\00"
@.str.1 = [7 x i8] c"TZ=UTC\00"
@.str.2 = [6 x i8] c"TZ=%s\00"
@.str.3 = [4 x i8] c"TZ=\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 ([7 x i8], [7 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 @ap_snprintf(i8* %14, i32 256, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %15)
%17 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%18 = call i32 @putenv(i8* %17)
br label %21
19: ; preds = %1
%20 = call i32 @putenv(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, 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 = [7 x i8] c"TZ=UTC\00"
@.str.2 = [6 x i8] c"TZ=%s\00"
@.str.3 = [4 x i8] c"TZ=\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 ([7 x i8], [7 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 @ap_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* %9)
br label %14
12: ; preds = %1
%13 = tail call i32 @putenv(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
br label %14
14: ; preds = %12, %8
%15 = call i32 (...) @tzset()
ret i32 %6
}