#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*/ putenv(char *);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ tzset();
time_t timegm(struct tm *tm) {
  time_t ret;
  char *tz;
  char buffer[255];
  tz = getenv("TZ");
  putenv("TZ=UTC0");
  tzset();
  ret = mktime(tm);
  if (tz)
    sprintf(buffer, "TZ=%s", tz);
  else
    strcpy(buffer, "TZ=");
  putenv(buffer);
  tzset();
  return ret;
}


x86 assembly (clang, -O0):
<timegm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xe8a(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
lea    0xe7d(%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     11c5 <timegm+0x65>
lea    -0x120(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe50(%rip),%rsi
call   1080 <sprintf@plt>
jmp    11d8 <timegm+0x78>
lea    -0x120(%rbp),%rdi
lea    0xe3e(%rip),%rsi
call   1040 <strcpy@plt>
lea    -0x120(%rbp),%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    0xe8d(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rbx
lea    0xe81(%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     11b1 <timegm+0x51>
lea    0xe67(%rip),%rsi
mov    %rsp,%rdi
mov    %rbx,%rdx
call   1080 <sprintf@plt>
jmp    11c0 <timegm+0x60>
lea    0xe59(%rip),%rsi
mov    %rsp,%rdi
call   1040 <strcpy@plt>
mov    %rsp,%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 = [8 x i8] c"TZ=UTC0\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 [255 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 ([8 x i8], [8 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 %17
13: ; preds = %1
%14 = getelementptr inbounds [255 x i8], [255 x i8]* %5, i64 0, i64 0
%15 = load i8*, i8** %4
%16 = call i32 @sprintf(i8* %14, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %15)
br label %20
17: ; preds = %1
%18 = getelementptr inbounds [255 x i8], [255 x i8]* %5, i64 0, i64 0
%19 = call i32 @strcpy(i8* %18, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
br label %20
20: ; preds = %17, %13
%21 = getelementptr inbounds [255 x i8], [255 x i8]* %5, i64 0, i64 0
%22 = call i32 @putenv(i8* %21)
%23 = call i32 (...) @tzset()
%24 = load i32, i32* %3
ret i32 %24
}

LLVM IR (-O2):
%struct.tm = type { i32 }
@.str = [3 x i8] c"TZ\00"
@.str.1 = [8 x i8] c"TZ=UTC0\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 [255 x i8]
%3 = getelementptr inbounds [255 x i8], [255 x i8]* %2, i64 0, i64 0
%4 = tail call i8* @getenv(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%5 = tail call i32 @putenv(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%6 = tail call i32 (...) @tzset()
%7 = tail call i32 @mktime(%struct.tm* %0)
%8 = icmp eq i8* %4, null
br i1 %8, label %11, label %9
9: ; preds = %1
%10 = call i32 @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %4)
br label %13
11: ; preds = %1
%12 = call i32 @strcpy(i8* %3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
br label %13
13: ; preds = %11, %9
%14 = call i32 @putenv(i8* %3)
%15 = call i32 (...) @tzset()
ret i32 %7
}