#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 time_t;
struct tm {
  int tm_year;
  int tm_mon;
  int tm_mday;
  int tm_sec;
  int tm_isdst;
  scalar_t__ tm_min;
  scalar_t__ tm_hour;
};
typedef int /*<<< orphan*/ daybuf;

/* Variables and functions */
struct tm *localtime(int *);
int mktime(struct tm *);
int /*<<< orphan*/ printf(char *, long, ...);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ setenv(char *, char *, int);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strftime(char *, int, char *, struct tm *);
int main(void) {
  struct tm time_str, *tm;
  time_t t;
  char daybuf[20];
  int result;
  time_str.tm_year = 2001 - 1900;
  time_str.tm_mon = 7 - 1;
  time_str.tm_mday = 4;
  time_str.tm_hour = 0;
  time_str.tm_min = 0;
  time_str.tm_sec = 1;
  time_str.tm_isdst = -1;
  if (mktime(&time_str) == -1) {
    (void)puts("-unknown-");
    result = 1;
  } else {
    (void)strftime(daybuf, sizeof(daybuf), "%A", &time_str);
    (void)puts(daybuf);
    result = strcmp(daybuf, "Wednesday") != 0;
  }
  setenv("TZ", "EST+5", 1);
  t = 1 * 60 * 60 + 2 * 60 + 29;
  tm = localtime(&t);
  if (tm == NULL) {
    (void)puts("localtime returned NULL");
    result = 1;
  } else {
    time_str = *tm;
    t = mktime(&time_str);
    if (t != 1 * 60 * 60 + 2 * 60 + 29) {
      printf("mktime returned %ld, expected %d\n", (long)t,
             1 * 60 * 60 + 2 * 60 + 29);
      result = 1;
    } else
      (void)puts("Dec 31 1969 EST test passed");
    setenv("TZ", "CET-1", 1);
    t = mktime(&time_str);
    if (t != (time_t)-1) {
      printf("mktime returned %ld, expected -1\n", (long)t);
      result = 1;
    } else
      (void)puts("Dec 31 1969 CET test passed");
  }
  return result;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x65,-0x30(%rbp)
movl   $0x6,-0x2c(%rbp)
movl   $0x4,-0x28(%rbp)
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movl   $0x1,-0x24(%rbp)
movl   $0xffffffff,-0x20(%rbp)
lea    -0x30(%rbp),%rdi
call   1090 <mktime@plt>
cmp    $0xffffffff,%eax
jne    11ec <main+0x6c>
lea    0xe25(%rip),%rdi
call   1040 <puts@plt>
movl   $0x1,-0x54(%rbp)
jmp    122d <main+0xad>
lea    -0x50(%rbp),%rdi
mov    $0x14,%esi
lea    0xe0e(%rip),%rdx
lea    -0x30(%rbp),%rcx
call   10a0 <strftime@plt>
lea    -0x50(%rbp),%rdi
call   1040 <puts@plt>
lea    -0x50(%rbp),%rdi
lea    0xdf4(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
setne  %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x54(%rbp)
lea    0xde3(%rip),%rdi
lea    0xddf(%rip),%rsi
mov    $0x1,%edx
call   1050 <setenv@plt>
movl   $0xea5,-0x3c(%rbp)
lea    -0x3c(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    127c <main+0xfc>
lea    0xdb5(%rip),%rdi
call   1040 <puts@plt>
movl   $0x1,-0x54(%rbp)
jmp    1333 <main+0x1b3>
mov    -0x38(%rbp),%rsi
lea    -0x30(%rbp),%rdi
mov    $0x28,%edx
call   1080 <memcpy@plt>
lea    -0x30(%rbp),%rdi
call   1090 <mktime@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0xea5,-0x3c(%rbp)
je     12ca <main+0x14a>
movslq -0x3c(%rbp),%rsi
lea    0xd86(%rip),%rdi
mov    $0xea5,%edx
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x1,-0x54(%rbp)
jmp    12d6 <main+0x156>
lea    0xd89(%rip),%rdi
call   1040 <puts@plt>
lea    0xd3a(%rip),%rdi
lea    0xd92(%rip),%rsi
mov    $0x1,%edx
call   1050 <setenv@plt>
lea    -0x30(%rbp),%rdi
call   1090 <mktime@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0xffffffff,-0x3c(%rbp)
je     1322 <main+0x1a2>
movslq -0x3c(%rbp),%rsi
lea    0xd6d(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x1,-0x54(%rbp)
jmp    132e <main+0x1ae>
lea    0xd75(%rip),%rdi
call   1040 <puts@plt>
jmp    1333 <main+0x1b3>
mov    -0x54(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x58,%rsp
xorps  %xmm0,%xmm0
movups %xmm0,0x28(%rsp)
movaps 0xe7b(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movl   $0xffffffff,0x20(%rsp)
ff
lea    0x10(%rsp),%rdi
call   1080 <mktime@plt>
cmp    $0xffffffff,%eax
je     11e1 <main+0x71>
lea    0xe72(%rip),%rdx
lea    0x40(%rsp),%rbx
lea    0x10(%rsp),%rcx
mov    %rbx,%rdi
mov    $0x14,%esi
call   1090 <strftime@plt>
mov    %rbx,%rdi
call   1040 <puts@plt>
lea    0xe4f(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strcmp@plt>
xor    %ebp,%ebp
test   %rax,%rax
setne  %bpl
jmp    11f2 <main+0x82>
lea    0xe28(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%ebp
lea    0xe2e(%rip),%rdi
lea    0xe2a(%rip),%rsi
mov    $0x1,%ebx
mov    $0x1,%edx
call   1050 <setenv@plt>
movl   $0xea5,0xc(%rsp)
lea    0xc(%rsp),%rdi
call   1030 <localtime@plt>
test   %rax,%rax
je     1263 <main+0xf3>
mov    0x20(%rax),%rcx
mov    %rcx,0x30(%rsp)
movups (%rax),%xmm0
movups 0x10(%rax),%xmm1
movaps %xmm1,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
lea    0x10(%rsp),%rdi
call   1080 <mktime@plt>
mov    %eax,0xc(%rsp)
cmp    $0xea5,%eax
jne    1271 <main+0x101>
lea    0xe0e(%rip),%rdi
call   1040 <puts@plt>
jmp    128c <main+0x11c>
lea    0xdc6(%rip),%rdi
call   1040 <puts@plt>
jmp    12dd <main+0x16d>
movslq %eax,%rsi
lea    0xdcd(%rip),%rdi
mov    $0xea5,%edx
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x1,%ebp
lea    0xd94(%rip),%rdi
lea    0xdec(%rip),%rsi
mov    $0x1,%ebx
mov    $0x1,%edx
call   1050 <setenv@plt>
lea    0x10(%rsp),%rdi
call   1080 <mktime@plt>
mov    %eax,0xc(%rsp)
cmp    $0xffffffff,%eax
je     12cf <main+0x15f>
movslq %eax,%rsi
lea    0xdc6(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    12dd <main+0x16d>
lea    0xdd8(%rip),%rdi
call   1040 <puts@plt>
mov    %ebp,%ebx
mov    %ebx,%eax
add    $0x58,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.tm = type { i32, i32, i32, i32, i32, i64, i64 }
@.str = [10 x i8] c"-unknown-\00"
@.str.1 = [3 x i8] c"%A\00"
@.str.2 = [10 x i8] c"Wednesday\00"
@.str.3 = [3 x i8] c"TZ\00"
@.str.4 = [6 x i8] c"EST+5\00"
@.str.5 = [24 x i8] c"localtime returned NULL\00"
@.str.6 = [34 x i8] c"mktime returned %ld, expected %d\0A\00"
@.str.7 = [28 x i8] c"Dec 31 1969 EST test passed\00"
@.str.8 = [6 x i8] c"CET-1\00"
@.str.9 = [34 x i8] c"mktime returned %ld, expected -1\0A\00"
@.str.10 = [28 x i8] c"Dec 31 1969 CET test passed\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.tm
%3 = alloca %struct.tm*
%4 = alloca i32
%5 = alloca [20 x i8]
%6 = alloca i32
store i32 0, i32* %1
%7 = getelementptr inbounds %struct.tm, %struct.tm* %2, i32 0, i32 0
store i32 101, i32* %7
%8 = getelementptr inbounds %struct.tm, %struct.tm* %2, i32 0, i32 1
store i32 6, i32* %8
%9 = getelementptr inbounds %struct.tm, %struct.tm* %2, i32 0, i32 2
store i32 4, i32* %9
%10 = getelementptr inbounds %struct.tm, %struct.tm* %2, i32 0, i32 6
store i64 0, i64* %10
%11 = getelementptr inbounds %struct.tm, %struct.tm* %2, i32 0, i32 5
store i64 0, i64* %11
%12 = getelementptr inbounds %struct.tm, %struct.tm* %2, i32 0, i32 3
store i32 1, i32* %12
%13 = getelementptr inbounds %struct.tm, %struct.tm* %2, i32 0, i32 4
store i32 -1, i32* %13
%14 = call i32 @mktime(%struct.tm* %2)
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %18
16: ; preds = %0
%17 = call i32 @puts(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %6
br label %27
18: ; preds = %0
%19 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 0
%20 = call i32 @strftime(i8* %19, i32 20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), %struct.tm* %2)
%21 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 0
%22 = call i32 @puts(i8* %21)
%23 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 0
%24 = call i64 @strcmp(i8* %23, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%25 = icmp ne i64 %24, 0
%26 = zext i1 %25 to i32
store i32 %26, i32* %6
br label %27
27: ; preds = %18, %16
%28 = call i32 @setenv(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 1)
store i32 3749, i32* %4
%29 = call %struct.tm* @localtime(i32* %4)
store %struct.tm* %29, %struct.tm** %3
%30 = load %struct.tm*, %struct.tm** %3
%31 = icmp eq %struct.tm* %30, null
br i1 %31, label %32, label %34
32: ; preds = %27
%33 = call i32 @puts(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0))
store i32 1, i32* %6
br label %59
34: ; preds = %27
%35 = load %struct.tm*, %struct.tm** %3
%36 = bitcast %struct.tm* %2 to i8*
%37 = bitcast %struct.tm* %35 to i8*
%38 = call i32 @mktime(%struct.tm* %2)
store i32 %38, i32* %4
%39 = load i32, i32* %4
%40 = icmp ne i32 %39, 3749
br i1 %40, label %41, label %45
41: ; preds = %34
%42 = load i32, i32* %4
%43 = sext i32 %42 to i64
%44 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.6, i64 0, i64 0), i64 %43, i32 3749)
store i32 1, i32* %6
br label %47
45: ; preds = %34
%46 = call i32 @puts(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.7, i64 0, i64 0))
br label %47
47: ; preds = %45, %41
%48 = call i32 @setenv(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0), i32 1)
%49 = call i32 @mktime(%struct.tm* %2)
store i32 %49, i32* %4
%50 = load i32, i32* %4
%51 = icmp ne i32 %50, -1
br i1 %51, label %52, label %56
52: ; preds = %47
%53 = load i32, i32* %4
%54 = sext i32 %53 to i64
%55 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.9, i64 0, i64 0), i64 %54)
store i32 1, i32* %6
br label %58
56: ; preds = %47
%57 = call i32 @puts(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.10, i64 0, i64 0))
br label %58
58: ; preds = %56, %52
br label %59
59: ; preds = %58, %32
%60 = load i32, i32* %6
ret i32 %60
}

LLVM IR (-O2):
%struct.tm = type { i32, i32, i32, i32, i32, i64, i64 }
@.str = [10 x i8] c"-unknown-\00"
@.str.1 = [3 x i8] c"%A\00"
@.str.2 = [10 x i8] c"Wednesday\00"
@.str.3 = [3 x i8] c"TZ\00"
@.str.4 = [6 x i8] c"EST+5\00"
@.str.5 = [24 x i8] c"localtime returned NULL\00"
@.str.6 = [34 x i8] c"mktime returned %ld, expected %d\0A\00"
@.str.7 = [28 x i8] c"Dec 31 1969 EST test passed\00"
@.str.8 = [6 x i8] c"CET-1\00"
@.str.9 = [34 x i8] c"mktime returned %ld, expected -1\0A\00"
@.str.10 = [28 x i8] c"Dec 31 1969 CET test passed\00"
define i32 @main() {
%1 = alloca %struct.tm
%2 = alloca i32
%3 = alloca [20 x i8]
%4 = bitcast %struct.tm* %1 to i8*
%5 = bitcast i32* %2 to i8*
%6 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds %struct.tm, %struct.tm* %1, i64 0, i32 5
%8 = bitcast i64* %7 to i8*
%9 = bitcast %struct.tm* %1 to <4 x i32>*
store <4 x i32> <i32 101, i32 6, i32 4, i32 1>, <4 x i32>* %9
%10 = getelementptr inbounds %struct.tm, %struct.tm* %1, i64 0, i32 4
store i32 -1, i32* %10
%11 = call i32 @mktime(%struct.tm* %1)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %15
13: ; preds = %0
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %21
15: ; preds = %0
%16 = call i32 @strftime(i8* %6, i32 20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), %struct.tm* %1)
%17 = call i32 @puts(i8* %6)
%18 = call i64 @strcmp(i8* %6, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%19 = icmp ne i64 %18, 0
%20 = zext i1 %19 to i32
br label %21
21: ; preds = %15, %13
%22 = phi i32 [ 1, %13 ], [ %20, %15 ]
%23 = call i32 @setenv(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 1)
store i32 3749, i32* %2
%24 = call %struct.tm* @localtime(i32* %2)
%25 = icmp eq %struct.tm* %24, null
br i1 %25, label %26, label %28
26: ; preds = %21
%27 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0))
br label %47
28: ; preds = %21
%29 = bitcast %struct.tm* %24 to i8*
%30 = call i32 @mktime(%struct.tm* %1)
store i32 %30, i32* %2
%31 = icmp eq i32 %30, 3749
br i1 %31, label %35, label %32
32: ; preds = %28
%33 = sext i32 %30 to i64
%34 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.6, i64 0, i64 0), i64 %33, i32 3749)
br label %37
35: ; preds = %28
%36 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.7, i64 0, i64 0))
br label %37
37: ; preds = %35, %32
%38 = phi i32 [ 1, %32 ], [ %22, %35 ]
%39 = call i32 @setenv(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0), i32 1)
%40 = call i32 @mktime(%struct.tm* %1)
store i32 %40, i32* %2
%41 = icmp eq i32 %40, -1
br i1 %41, label %45, label %42
42: ; preds = %37
%43 = sext i32 %40 to i64
%44 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.9, i64 0, i64 0), i64 %43)
br label %47
45: ; preds = %37
%46 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.10, i64 0, i64 0))
br label %47
47: ; preds = %42, %45, %26
%48 = phi i32 [ 1, %26 ], [ 1, %42 ], [ %38, %45 ]
ret i32 %48
}