#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 long long time_t;

/* Variables and functions */
char *getenv(char *);
int /*<<< orphan*/ is_usec_has_dst(long long);
int /*<<< orphan*/ reset_tz(char *);
int /*<<< orphan*/ setenv(char *, char const *, int);
long long get_rawoffset_usec(const char *zone, long long t) {
  char *tz = getenv("TZ");
  setenv("TZ", zone, 1);
  time_t newt = t - 1;
  if (!is_usec_has_dst(newt)) {
    reset_tz(tz);
    return newt;
  }
  newt = t + 1;
  if (!is_usec_has_dst(newt)) {
    reset_tz(tz);
    return newt;
  }
  reset_tz(tz);
  return 0;
}


x86 assembly (clang, -O0):
<get_rawoffset_usec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    0xea9(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xe95(%rip),%rdi
mov    $0x1,%edx
call   1040 <setenv@plt>
mov    -0x18(%rbp),%rax
sub    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1050 <is_usec_has_dst@plt>
cmp    $0x0,%eax
jne    11a9 <get_rawoffset_usec+0x69>
mov    -0x20(%rbp),%rdi
call   1060 <reset_tz@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11ee <get_rawoffset_usec+0xae>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1050 <is_usec_has_dst@plt>
cmp    $0x0,%eax
jne    11dd <get_rawoffset_usec+0x9d>
mov    -0x20(%rbp),%rdi
call   1060 <reset_tz@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11ee <get_rawoffset_usec+0xae>
mov    -0x20(%rbp),%rdi
call   1060 <reset_tz@plt>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_rawoffset_usec>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r15
mov    %rdi,%rbx
lea    0xeab(%rip),%r12
mov    %r12,%rdi
call   1030 <getenv@plt>
mov    %rax,%r14
mov    %r12,%rdi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1040 <setenv@plt>
lea    -0x1(%r15),%rbx
mov    %rbx,%rdi
call   1050 <is_usec_has_dst@plt>
test   %eax,%eax
je     11a0 <get_rawoffset_usec+0x60>
add    $0x1,%r15
mov    %r15,%rdi
call   1050 <is_usec_has_dst@plt>
mov    %eax,%ebp
mov    %r14,%rdi
call   1060 <reset_tz@plt>
xor    %ebx,%ebx
test   %ebp,%ebp
cmove  %r15,%rbx
jmp    11a8 <get_rawoffset_usec+0x68>
mov    %r14,%rdi
call   1060 <reset_tz@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"TZ\00"
define i64 @get_rawoffset_usec(i8* %0, i64 %1) {
%3 = alloca i64
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i64
store i8* %0, i8** %4
store i64 %1, i64* %5
%8 = call i8* @getenv(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i8* %8, i8** %6
%9 = load i8*, i8** %4
%10 = call i32 @setenv(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %9, i32 1)
%11 = load i64, i64* %5
%12 = sub nsw i64 %11, 1
store i64 %12, i64* %7
%13 = load i64, i64* %7
%14 = call i32 @is_usec_has_dst(i64 %13)
%15 = icmp ne i32 %14, 0
br i1 %15, label %20, label %16
16: ; preds = %2
%17 = load i8*, i8** %6
%18 = call i32 @reset_tz(i8* %17)
%19 = load i64, i64* %7
store i64 %19, i64* %3
br label %33
20: ; preds = %2
%21 = load i64, i64* %5
%22 = add nsw i64 %21, 1
store i64 %22, i64* %7
%23 = load i64, i64* %7
%24 = call i32 @is_usec_has_dst(i64 %23)
%25 = icmp ne i32 %24, 0
br i1 %25, label %30, label %26
26: ; preds = %20
%27 = load i8*, i8** %6
%28 = call i32 @reset_tz(i8* %27)
%29 = load i64, i64* %7
store i64 %29, i64* %3
br label %33
30: ; preds = %20
%31 = load i8*, i8** %6
%32 = call i32 @reset_tz(i8* %31)
store i64 0, i64* %3
br label %33
33: ; preds = %30, %26, %16
%34 = load i64, i64* %3
ret i64 %34
}

LLVM IR (-O2):
@.str = [3 x i8] c"TZ\00"
define i64 @get_rawoffset_usec(i8* %0, i64 %1) {
%3 = tail call i8* @getenv(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%4 = tail call i32 @setenv(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %0, i32 1)
%5 = add nsw i64 %1, -1
%6 = tail call i32 @is_usec_has_dst(i64 %5)
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = tail call i32 @reset_tz(i8* %3)
br label %16
10: ; preds = %2
%11 = add nsw i64 %1, 1
%12 = tail call i32 @is_usec_has_dst(i64 %11)
%13 = icmp eq i32 %12, 0
%14 = tail call i32 @reset_tz(i8* %3)
%15 = select i1 %13, i64 %11, i64 0
br label %16
16: ; preds = %10, %8
%17 = phi i64 [ %5, %8 ], [ %15, %10 ]
ret i64 %17
}