#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 char const *time_t;
struct tm {
  int tm_mday;
  int tm_mon;
  int tm_year;
  int tm_hour;
  int tm_min;
  int tm_sec;
};

/* Variables and functions */
int /*<<< orphan*/ *localtime_r(char const **, struct tm *);
char *mktime(struct tm *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
char *time(int /*<<< orphan*/ *);
int /*<<< orphan*/ tzset();
int _mktime(char const *progname) {
  time_t t;
  struct tm tm;
  printf("%s: Testing mktime()\n", progname);
  tzset();
  t = time(NULL);
  printf("time: %ld\n", t);
  if (localtime_r(&t, &tm) == NULL) {
    perror("localtime_r");
    return -1;
  }
  printf("localtime: %02d/%02d/%4d %02d:%02d:%02d\n", tm.tm_mday, tm.tm_mon + 1,
         tm.tm_year + 1900, tm.tm_hour, tm.tm_min, tm.tm_sec);
  if ((t = mktime(&tm)) == (time_t)-1 || t == 0) {
    perror("mktime");
    return -1;
  }
  printf("mktime: %ld\n", t);
  return 0;
}


x86 assembly (clang, -O0):
<_mktime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xe89(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1050 <tzset@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1060 <time@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
lea    0xeb7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x18(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1030 <localtime_r@plt>
cmp    $0x0,%rax
jne    11d3 <_mktime+0x73>
lea    0xe54(%rip),%rdi
call   1080 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    125a <_mktime+0xfa>
mov    -0x30(%rbp),%esi
mov    -0x2c(%rbp),%edx
add    $0x1,%edx
mov    -0x28(%rbp),%ecx
add    $0x76c,%ecx
mov    -0x24(%rbp),%r8d
mov    -0x20(%rbp),%r9d
mov    -0x1c(%rbp),%eax
lea    0xe2b(%rip),%rdi
mov    %eax,(%rsp)
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x30(%rbp),%rdi
call   1070 <mktime@plt>
mov    %rax,-0x18(%rbp)
mov    $0xffffffffffffffff,%rcx
cmp    %rcx,%rax
je     1229 <_mktime+0xc9>
cmpq   $0x0,-0x18(%rbp)
jne    1241 <_mktime+0xe1>
lea    0xe1b(%rip),%rdi
call   1080 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    125a <_mktime+0xfa>
mov    -0x18(%rbp),%rsi
lea    0xe06(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_mktime>:
push   %rbx
sub    $0x30,%rsp
mov    %rdi,%rsi
lea    0xe91(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1050 <tzset@plt>
xor    %edi,%edi
call   1060 <time@plt>
mov    %rax,0x10(%rsp)
lea    0xec4(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x10(%rsp),%rdi
lea    0x18(%rsp),%rsi
call   1030 <localtime_r@plt>
test   %rax,%rax
je     121e <_mktime+0xbe>
mov    0x18(%rsp),%esi
mov    0x1c(%rsp),%edx
mov    $0x76c,%ecx
add    0x20(%rsp),%ecx
add    $0x1,%edx
mov    0x24(%rsp),%r8d
mov    0x28(%rsp),%r9d
mov    0x2c(%rsp),%eax
mov    %eax,(%rsp)
lea    0xe48(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x18(%rsp),%rdi
call   1070 <mktime@plt>
mov    %rax,0x10(%rsp)
lea    0x1(%rax),%rcx
cmp    $0x1,%rcx
jbe    1215 <_mktime+0xb5>
lea    0xe4f(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebx,%eax
add    $0x30,%rsp
pop    %rbx
ret
lea    0xe2f(%rip),%rdi
jmp    1225 <_mktime+0xc5>
lea    0xdf1(%rip),%rdi
call   1080 <perror@plt>
mov    $0xffffffff,%ebx
jmp    120d <_mktime+0xad>

LLVM IR (-O0):
%struct.tm = type { i32, i32, i32, i32, i32, i32 }
@.str = [22 x i8] c"%s: Testing mktime()\0A\00"
@.str.1 = [11 x i8] c"time: %ld\0A\00"
@.str.2 = [12 x i8] c"localtime_r\00"
@.str.3 = [41 x i8] c"localtime: %02d/%02d/%4d %02d:%02d:%02d\0A\00"
@.str.4 = [7 x i8] c"mktime\00"
@.str.5 = [13 x i8] c"mktime: %ld\0A\00"
define i32 @_mktime(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca %struct.tm
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = call i32 (...) @tzset()
%9 = call i8* @time(i32* null)
store i8* %9, i8** %4
%10 = load i8*, i8** %4
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %10)
%12 = call i32* @localtime_r(i8** %4, %struct.tm* %5)
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %16
14: ; preds = %1
%15 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %2
br label %42
16: ; preds = %1
%17 = getelementptr inbounds %struct.tm, %struct.tm* %5, i32 0, i32 0
%18 = load i32, i32* %17
%19 = getelementptr inbounds %struct.tm, %struct.tm* %5, i32 0, i32 1
%20 = load i32, i32* %19
%21 = add nsw i32 %20, 1
%22 = getelementptr inbounds %struct.tm, %struct.tm* %5, i32 0, i32 2
%23 = load i32, i32* %22
%24 = add nsw i32 %23, 1900
%25 = getelementptr inbounds %struct.tm, %struct.tm* %5, i32 0, i32 3
%26 = load i32, i32* %25
%27 = getelementptr inbounds %struct.tm, %struct.tm* %5, i32 0, i32 4
%28 = load i32, i32* %27
%29 = getelementptr inbounds %struct.tm, %struct.tm* %5, i32 0, i32 5
%30 = load i32, i32* %29
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0), i32 %18, i32 %21, i32 %24, i32 %26, i32 %28, i32 %30)
%32 = call i8* @mktime(%struct.tm* %5)
store i8* %32, i8** %4
%33 = icmp eq i8* %32, inttoptr (i64 -1 to i8*)
br i1 %33, label %37, label %34
34: ; preds = %16
%35 = load i8*, i8** %4
%36 = icmp eq i8* %35, null
br i1 %36, label %37, label %39
37: ; preds = %34, %16
%38 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
store i32 -1, i32* %2
br label %42
39: ; preds = %34
%40 = load i8*, i8** %4
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i8* %40)
store i32 0, i32* %2
br label %42
42: ; preds = %39, %37, %14
%43 = load i32, i32* %2
ret i32 %43
}

LLVM IR (-O2):
%struct.tm = type { i32, i32, i32, i32, i32, i32 }
@.str = [22 x i8] c"%s: Testing mktime()\0A\00"
@.str.1 = [11 x i8] c"time: %ld\0A\00"
@.str.2 = [12 x i8] c"localtime_r\00"
@.str.3 = [41 x i8] c"localtime: %02d/%02d/%4d %02d:%02d:%02d\0A\00"
@.str.4 = [7 x i8] c"mktime\00"
@.str.5 = [13 x i8] c"mktime: %ld\0A\00"
define i32 @_mktime(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.tm
%4 = bitcast i8** %2 to i8*
%5 = bitcast %struct.tm* %3 to i8*
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %0)
%7 = tail call i32 (...) @tzset()
%8 = tail call i8* @time(i32* null)
store i8* %8, i8** %2
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %8)
%10 = call i32* @localtime_r(i8** %2, %struct.tm* %3)
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %14
12: ; preds = %1
%13 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
br label %36
14: ; preds = %1
%15 = getelementptr inbounds %struct.tm, %struct.tm* %3, i64 0, i32 0
%16 = load i32, i32* %15
%17 = getelementptr inbounds %struct.tm, %struct.tm* %3, i64 0, i32 1
%18 = load i32, i32* %17
%19 = add nsw i32 %18, 1
%20 = getelementptr inbounds %struct.tm, %struct.tm* %3, i64 0, i32 2
%21 = load i32, i32* %20
%22 = add nsw i32 %21, 1900
%23 = getelementptr inbounds %struct.tm, %struct.tm* %3, i64 0, i32 3
%24 = load i32, i32* %23
%25 = getelementptr inbounds %struct.tm, %struct.tm* %3, i64 0, i32 4
%26 = load i32, i32* %25
%27 = getelementptr inbounds %struct.tm, %struct.tm* %3, i64 0, i32 5
%28 = load i32, i32* %27
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0), i32 %16, i32 %19, i32 %22, i32 %24, i32 %26, i32 %28)
%30 = call i8* @mktime(%struct.tm* %3)
store i8* %30, i8** %2
%31 = ptrtoint i8* %30 to i64
switch i64 %31, label %34 [
i64 -1, label %32
i64 0, label %32
]
32: ; preds = %14, %14
%33 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
br label %36
34: ; preds = %14
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i8* %30)
br label %36
36: ; preds = %34, %32, %12
%37 = phi i32 [ -1, %12 ], [ -1, %32 ], [ 0, %34 ]
ret i32 %37
}