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

/* Variables and functions */
int /*<<< orphan*/ julian_adj(struct tm *, int, long, long *, int *);
int /*<<< orphan*/ julian_to_date(long, int *, int *, int *);
int OPENSSL_gmtime_adj(struct tm *tm, int off_day, long offset_sec) {
  int time_sec, time_year, time_month, time_day;
  long time_jd;
  if (!julian_adj(tm, off_day, offset_sec, &time_jd, &time_sec)) {
    return 0;
  }
  julian_to_date(time_jd, &time_year, &time_month, &time_day);
  if (time_year < 1900 || time_year > 9999) {
    return 0;
  }
  tm->tm_year = time_year - 1900;
  tm->tm_mon = time_month - 1;
  tm->tm_mday = time_day;
  tm->tm_hour = time_sec / 3600;
  tm->tm_min = (time_sec / 60) % 60;
  tm->tm_sec = time_sec % 60;
  return 1;
}


x86 assembly (clang, -O0):
<OPENSSL_gmtime_adj>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%rdx
lea    -0x38(%rbp),%rcx
lea    -0x24(%rbp),%r8
call   1040 <julian_adj@plt>
cmp    $0x0,%eax
jne    1160 <OPENSSL_gmtime_adj+0x40>
movl   $0x0,-0x4(%rbp)
jmp    1208 <OPENSSL_gmtime_adj+0xe8>
mov    -0x38(%rbp),%rdi
lea    -0x28(%rbp),%rsi
lea    -0x2c(%rbp),%rdx
lea    -0x30(%rbp),%rcx
call   1030 <julian_to_date@plt>
cmpl   $0x76c,-0x28(%rbp)
jl     118f <OPENSSL_gmtime_adj+0x6f>
cmpl   $0x270f,-0x28(%rbp)
jle    119b <OPENSSL_gmtime_adj+0x7b>
movl   $0x0,-0x4(%rbp)
jmp    1208 <OPENSSL_gmtime_adj+0xe8>
mov    -0x28(%rbp),%ecx
sub    $0x76c,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x2c(%rbp),%ecx
sub    $0x1,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x30(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0x8(%rax)
mov    -0x24(%rbp),%eax
mov    $0xe10,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0xc(%rax)
mov    -0x24(%rbp),%eax
mov    $0x3c,%ecx
cltd
idiv   %ecx
mov    $0x3c,%ecx
cltd
idiv   %ecx
mov    -0x10(%rbp),%rax
mov    %edx,0x10(%rax)
mov    -0x24(%rbp),%eax
mov    $0x3c,%ecx
cltd
idiv   %ecx
mov    -0x10(%rbp),%rax
mov    %edx,0x14(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<OPENSSL_gmtime_adj>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%rbx
lea    0x10(%rsp),%rcx
lea    0xc(%rsp),%r8
call   1040 <julian_adj@plt>
xor    %ebp,%ebp
test   %eax,%eax
je     11e7 <OPENSSL_gmtime_adj+0xc7>
mov    0x10(%rsp),%rdi
lea    0x8(%rsp),%rsi
lea    0x4(%rsp),%rdx
mov    %rsp,%rcx
call   1030 <julian_to_date@plt>
mov    0x8(%rsp),%eax
lea    -0x2710(%rax),%ecx
cmp    $0xffffe05c,%ecx
jb     11e7 <OPENSSL_gmtime_adj+0xc7>
add    $0xfffff894,%eax
mov    %eax,(%rbx)
mov    0x4(%rsp),%eax
add    $0xffffffff,%eax
mov    %eax,0x4(%rbx)
mov    (%rsp),%eax
mov    %eax,0x8(%rbx)
movslq 0xc(%rsp),%rax
imul   $0xffffffff91a2b3c5,%rax,%rcx
shr    $0x20,%rcx
add    %eax,%ecx
mov    %ecx,%edx
shr    $0x1f,%edx
sar    $0xb,%ecx
add    %edx,%ecx
mov    %ecx,0xc(%rbx)
imul   $0xffffffff88888889,%rax,%rcx
shr    $0x20,%rcx
add    %eax,%ecx
mov    %ecx,%edx
shr    $0x1f,%edx
sar    $0x5,%ecx
add    %edx,%ecx
movslq %ecx,%rcx
imul   $0xffffffff88888889,%rcx,%rdx
shr    $0x20,%rdx
add    %ecx,%edx
mov    %edx,%esi
shr    $0x1f,%esi
sar    $0x5,%edx
add    %esi,%edx
imul   $0x3c,%edx,%edx
imul   $0x3c,%ecx,%esi
sub    %edx,%ecx
mov    %ecx,0x10(%rbx)
sub    %esi,%eax
mov    %eax,0x14(%rbx)
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
%struct.tm = type { i32, i32, i32, i32, i32, i32 }
define i32 @OPENSSL_gmtime_adj(%struct.tm* %0, i32 %1, i64 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i64
%9 = bitcast i32* %4 to i8*
%10 = bitcast i32* %5 to i8*
%11 = bitcast i32* %6 to i8*
%12 = bitcast i32* %7 to i8*
%13 = bitcast i64* %8 to i8*
%14 = call i32 @julian_adj(%struct.tm* %0, i32 %1, i64 %2, i64* %8, i32* %4)
%15 = icmp eq i32 %14, 0
br i1 %15, label %38, label %16
16: ; preds = %3
%17 = load i64, i64* %8
%18 = call i32 @julian_to_date(i64 %17, i32* %5, i32* %6, i32* %7)
%19 = load i32, i32* %5
%20 = add i32 %19, -10000
%21 = icmp ult i32 %20, -8100
br i1 %21, label %38, label %22
22: ; preds = %16
%23 = add nsw i32 %19, -1900
%24 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 0
store i32 %23, i32* %24
%25 = load i32, i32* %6
%26 = add nsw i32 %25, -1
%27 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 1
store i32 %26, i32* %27
%28 = load i32, i32* %7
%29 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 2
store i32 %28, i32* %29
%30 = load i32, i32* %4
%31 = sdiv i32 %30, 3600
%32 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 3
store i32 %31, i32* %32
%33 = sdiv i32 %30, 60
%34 = srem i32 %33, 60
%35 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 4
store i32 %34, i32* %35
%36 = srem i32 %30, 60
%37 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 5
store i32 %36, i32* %37
br label %38
38: ; preds = %16, %3, %22
%39 = phi i32 [ 1, %22 ], [ 0, %3 ], [ 0, %16 ]
ret i32 %39
}