#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 {
  scalar_t__ tm_isdst;
};

/* Variables and functions */
int /*<<< orphan*/ EOVERFLOW;
scalar_t__ INT_MAX;
scalar_t__ INT_MIN;
scalar_t__ __secs_to_tm(long long, struct tm *);
long long __tm_to_secs(struct tm *);
int /*<<< orphan*/ errno;
time_t timegm(struct tm *tm) {
  struct tm new;
  long long t = __tm_to_secs(tm);
  if (__secs_to_tm(t, &new) < 0) {
    errno = EOVERFLOW;
    return -1;
  }
  if (t > (long long)INT_MAX || t < (long long)INT_MIN) {
    errno = EOVERFLOW;
    return -1;
  }
  *tm = new;
  tm->tm_isdst = 0;
  return t;
}


x86 assembly (clang, -O0):
<timegm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <__tm_to_secs@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1040 <__secs_to_tm@plt>
cmp    $0x0,%rax
jge    116e <timegm+0x4e>
mov    0x2e99(%rip),%rax
mov    (%rax),%ecx
mov    0x2e68(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    11d1 <timegm+0xb1>
mov    -0x20(%rbp),%rax
mov    0x2e67(%rip),%rcx
cmp    (%rcx),%rax
jg     1196 <timegm+0x76>
mov    -0x20(%rbp),%rax
mov    0x2e4b(%rip),%rcx
cmp    (%rcx),%rax
jge    11b4 <timegm+0x94>
mov    0x2e53(%rip),%rax
mov    (%rax),%ecx
mov    0x2e22(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    11d1 <timegm+0xb1>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x20(%rbp),%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<timegm>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1030 <__tm_to_secs@plt>
mov    %rax,%rbx
mov    %rsp,%rsi
mov    %rax,%rdi
call   1040 <__secs_to_tm@plt>
test   %rax,%rax
js     1160 <timegm+0x40>
mov    0x2e9a(%rip),%rax
cmp    (%rax),%rbx
jg     1160 <timegm+0x40>
mov    0x2e86(%rip),%rax
cmp    (%rax),%rbx
jl     1160 <timegm+0x40>
movq   $0x0,(%r14)
jmp    1177 <timegm+0x57>
mov    0x2e89(%rip),%rax
mov    (%rax),%eax
mov    0x2e58(%rip),%rcx
mov    %eax,(%rcx)
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.tm = type { i64 }
@EOVERFLOW = global i32 0
@errno = global i32 0
@INT_MAX = global i64 0
@INT_MIN = global i64 0
define i32 @timegm(%struct.tm* %0) {
%2 = alloca i32
%3 = alloca %struct.tm*
%4 = alloca %struct.tm
%5 = alloca i64
store %struct.tm* %0, %struct.tm** %3
%6 = load %struct.tm*, %struct.tm** %3
%7 = call i64 @__tm_to_secs(%struct.tm* %6)
store i64 %7, i64* %5
%8 = load i64, i64* %5
%9 = call i64 @__secs_to_tm(i64 %8, %struct.tm* %4)
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %1
%12 = load i32, i32* @EOVERFLOW
store i32 %12, i32* @errno
store i32 -1, i32* %2
br label %31
13: ; preds = %1
%14 = load i64, i64* %5
%15 = load i64, i64* @INT_MAX
%16 = icmp sgt i64 %14, %15
br i1 %16, label %21, label %17
17: ; preds = %13
%18 = load i64, i64* %5
%19 = load i64, i64* @INT_MIN
%20 = icmp slt i64 %18, %19
br i1 %20, label %21, label %23
21: ; preds = %17, %13
%22 = load i32, i32* @EOVERFLOW
store i32 %22, i32* @errno
store i32 -1, i32* %2
br label %31
23: ; preds = %17
%24 = load %struct.tm*, %struct.tm** %3
%25 = bitcast %struct.tm* %24 to i8*
%26 = bitcast %struct.tm* %4 to i8*
%27 = load %struct.tm*, %struct.tm** %3
%28 = getelementptr inbounds %struct.tm, %struct.tm* %27, i32 0, i32 0
store i64 0, i64* %28
%29 = load i64, i64* %5
%30 = trunc i64 %29 to i32
store i32 %30, i32* %2
br label %31
31: ; preds = %23, %21, %11
%32 = load i32, i32* %2
ret i32 %32
}

LLVM IR (-O2):
%struct.tm = type { i64 }
@EOVERFLOW = global i32 0
@errno = global i32 0
@INT_MAX = global i64 0
@INT_MIN = global i64 0
define i32 @timegm(%struct.tm* %0) {
%2 = alloca %struct.tm
%3 = bitcast %struct.tm* %2 to i8*
%4 = tail call i64 @__tm_to_secs(%struct.tm* %0)
%5 = call i64 @__secs_to_tm(i64 %4, %struct.tm* %2)
%6 = icmp slt i64 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = load i32, i32* @EOVERFLOW
store i32 %8, i32* @errno
br label %20
9: ; preds = %1
%10 = load i64, i64* @INT_MAX
%11 = icmp sgt i64 %4, %10
%12 = load i64, i64* @INT_MIN
%13 = icmp slt i64 %4, %12
%14 = select i1 %11, i1 true, i1 %13
br i1 %14, label %15, label %17
15: ; preds = %9
%16 = load i32, i32* @EOVERFLOW
store i32 %16, i32* @errno
br label %20
17: ; preds = %9
%18 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 0
store i64 0, i64* %18
%19 = trunc i64 %4 to i32
br label %20
20: ; preds = %17, %15, %7
%21 = phi i32 [ -1, %7 ], [ -1, %15 ], [ %19, %17 ]
ret i32 %21
}