#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 /*<<< orphan*/ tm_hour;
  scalar_t__ tm_isdst;
};

/* Variables and functions */
struct tm *gmtime(int *);
int mktime(struct tm *);
time_t _timegm(struct tm *t) {
  time_t tl, tb;
  struct tm *tg;
  t->tm_isdst = 0;
  tl = mktime(t);
  if (tl == -1) {
    t->tm_hour--;
    tl = mktime(t);
    if (tl == -1) {
      return -1;
    }
    tl += 3600;
  }
  tg = gmtime(&tl);
  tg->tm_isdst = 0;
  tb = mktime(tg);
  if (tb == -1) {
    tg->tm_hour--;
    tb = mktime(tg);
    if (tb == -1) {
      return -1;
    }
    tb += 3600;
  }
  return (tl - (tb - tl));
}


x86 assembly (clang, -O0):
<_timegm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movq   $0x0,0x8(%rax)
mov    -0x10(%rbp),%rdi
call   1030 <mktime@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1186 <_timegm+0x66>
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
add    $0xffffffff,%ecx
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rdi
call   1030 <mktime@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    117b <_timegm+0x5b>
movl   $0xffffffff,-0x4(%rbp)
jmp    11fb <_timegm+0xdb>
mov    -0x14(%rbp),%eax
add    $0xe10,%eax
mov    %eax,-0x14(%rbp)
lea    -0x14(%rbp),%rdi
call   1040 <gmtime@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movq   $0x0,0x8(%rax)
mov    -0x20(%rbp),%rdi
call   1030 <mktime@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    11ed <_timegm+0xcd>
mov    -0x20(%rbp),%rax
mov    (%rax),%ecx
add    $0xffffffff,%ecx
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rdi
call   1030 <mktime@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    11e2 <_timegm+0xc2>
movl   $0xffffffff,-0x4(%rbp)
jmp    11fb <_timegm+0xdb>
mov    -0x18(%rbp),%eax
add    $0xe10,%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
mov    -0x18(%rbp),%ecx
sub    -0x14(%rbp),%ecx
sub    %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_timegm>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
movq   $0x0,0x8(%rdi)
call   1030 <mktime@plt>
mov    %eax,0xc(%rsp)
cmp    $0xffffffff,%eax
jne    1157 <_timegm+0x37>
addl   $0xffffffff,(%rbx)
mov    %rbx,%rdi
call   1030 <mktime@plt>
cmp    $0xffffffff,%eax
je     1198 <_timegm+0x78>
add    $0xe10,%eax
mov    %eax,0xc(%rsp)
lea    0xc(%rsp),%rdi
call   1040 <gmtime@plt>
mov    %rax,%rbx
movq   $0x0,0x8(%rax)
mov    %rax,%rdi
call   1030 <mktime@plt>
cmp    $0xffffffff,%eax
jne    118e <_timegm+0x6e>
addl   $0xffffffff,(%rbx)
mov    %rbx,%rdi
call   1030 <mktime@plt>
cmp    $0xffffffff,%eax
je     1198 <_timegm+0x78>
add    $0xe10,%eax
mov    0xc(%rsp),%ecx
add    %ecx,%ecx
sub    %eax,%ecx
jmp    119d <_timegm+0x7d>
mov    $0xffffffff,%ecx
mov    %ecx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.tm = type { i32, i64 }
define i32 @_timegm(%struct.tm* %0) {
%2 = alloca i32
%3 = alloca %struct.tm*
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.tm*
store %struct.tm* %0, %struct.tm** %3
%7 = load %struct.tm*, %struct.tm** %3
%8 = getelementptr inbounds %struct.tm, %struct.tm* %7, i32 0, i32 1
store i64 0, i64* %8
%9 = load %struct.tm*, %struct.tm** %3
%10 = call i32 @mktime(%struct.tm* %9)
store i32 %10, i32* %4
%11 = load i32, i32* %4
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %26
13: ; preds = %1
%14 = load %struct.tm*, %struct.tm** %3
%15 = getelementptr inbounds %struct.tm, %struct.tm* %14, i32 0, i32 0
%16 = load i32, i32* %15
%17 = add nsw i32 %16, -1
store i32 %17, i32* %15
%18 = load %struct.tm*, %struct.tm** %3
%19 = call i32 @mktime(%struct.tm* %18)
store i32 %19, i32* %4
%20 = load i32, i32* %4
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %23
22: ; preds = %13
store i32 -1, i32* %2
br label %53
23: ; preds = %13
%24 = load i32, i32* %4
%25 = add nsw i32 %24, 3600
store i32 %25, i32* %4
br label %26
26: ; preds = %23, %1
%27 = call %struct.tm* @gmtime(i32* %4)
store %struct.tm* %27, %struct.tm** %6
%28 = load %struct.tm*, %struct.tm** %6
%29 = getelementptr inbounds %struct.tm, %struct.tm* %28, i32 0, i32 1
store i64 0, i64* %29
%30 = load %struct.tm*, %struct.tm** %6
%31 = call i32 @mktime(%struct.tm* %30)
store i32 %31, i32* %5
%32 = load i32, i32* %5
%33 = icmp eq i32 %32, -1
br i1 %33, label %34, label %47
34: ; preds = %26
%35 = load %struct.tm*, %struct.tm** %6
%36 = getelementptr inbounds %struct.tm, %struct.tm* %35, i32 0, i32 0
%37 = load i32, i32* %36
%38 = add nsw i32 %37, -1
store i32 %38, i32* %36
%39 = load %struct.tm*, %struct.tm** %6
%40 = call i32 @mktime(%struct.tm* %39)
store i32 %40, i32* %5
%41 = load i32, i32* %5
%42 = icmp eq i32 %41, -1
br i1 %42, label %43, label %44
43: ; preds = %34
store i32 -1, i32* %2
br label %53
44: ; preds = %34
%45 = load i32, i32* %5
%46 = add nsw i32 %45, 3600
store i32 %46, i32* %5
br label %47
47: ; preds = %44, %26
%48 = load i32, i32* %4
%49 = load i32, i32* %5
%50 = load i32, i32* %4
%51 = sub nsw i32 %49, %50
%52 = sub nsw i32 %48, %51
store i32 %52, i32* %2
br label %53
53: ; preds = %47, %43, %22
%54 = load i32, i32* %2
ret i32 %54
}

LLVM IR (-O2):
%struct.tm = type { i32, i64 }
define i32 @_timegm(%struct.tm* nocapture %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 1
store i64 0, i64* %4
%5 = tail call i32 @mktime(%struct.tm* %0)
store i32 %5, i32* %2
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %15
7: ; preds = %1
%8 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 0
%9 = load i32, i32* %8
%10 = add nsw i32 %9, -1
store i32 %10, i32* %8
%11 = tail call i32 @mktime(%struct.tm* %0)
%12 = icmp eq i32 %11, -1
br i1 %12, label %33, label %13
13: ; preds = %7
%14 = add nsw i32 %11, 3600
store i32 %14, i32* %2
br label %15
15: ; preds = %13, %1
%16 = call %struct.tm* @gmtime(i32* %2)
%17 = getelementptr inbounds %struct.tm, %struct.tm* %16, i64 0, i32 1
store i64 0, i64* %17
%18 = call i32 @mktime(%struct.tm* %16)
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %28
20: ; preds = %15
%21 = getelementptr inbounds %struct.tm, %struct.tm* %16, i64 0, i32 0
%22 = load i32, i32* %21
%23 = add nsw i32 %22, -1
store i32 %23, i32* %21
%24 = call i32 @mktime(%struct.tm* %16)
%25 = icmp eq i32 %24, -1
br i1 %25, label %33, label %26
26: ; preds = %20
%27 = add nsw i32 %24, 3600
br label %28
28: ; preds = %26, %15
%29 = phi i32 [ %27, %26 ], [ %18, %15 ]
%30 = load i32, i32* %2
%31 = shl i32 %30, 1
%32 = sub i32 %31, %29
br label %33
33: ; preds = %20, %7, %28
%34 = phi i32 [ %32, %28 ], [ -1, %7 ], [ -1, %20 ]
ret i32 %34
}