#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 scalar_t__ const time_t;
struct tm {
  int tm_yday;
  int /*<<< orphan*/ tm_year;
};

/* Variables and functions */
int EINVAL;
struct tm *gmtime_r(scalar_t__ const *, struct tm *);
scalar_t__ const mktime(struct tm *);
int sb_get_time(time_t time, struct tm *tm) {
  struct tm time_2000 = {
      .tm_yday = 1,
      .tm_year = 0,
  };
  const time_t seconds_to_2000 = mktime(&time_2000);
  const time_t seconds_to_now = seconds_to_2000 + time;
  struct tm *ret;
  ret = gmtime_r(&seconds_to_now, tm);
  return ret ? 0 : -EINVAL;
}


x86 assembly (clang, -O0):
<sb_get_time>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xec9(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    -0x18(%rbp),%rdi
call   1040 <mktime@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
add    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rsi
lea    -0x28(%rbp),%rdi
call   1030 <gmtime_r@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     117a <sb_get_time+0x5a>
xor    %eax,%eax
mov    %eax,-0x34(%rbp)
jmp    1188 <sb_get_time+0x68>
xor    %eax,%eax
mov    0x2e5d(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sb_get_time>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
movq   $0x1,0x10(%rsp)
lea    0x10(%rsp),%rdi
call   1040 <mktime@plt>
add    %rbx,%rax
mov    %rax,0x8(%rsp)
lea    0x8(%rsp),%rdi
mov    %r14,%rsi
call   1030 <gmtime_r@plt>
mov    0x2e84(%rip),%rdx
xor    %ecx,%ecx
sub    (%rdx),%ecx
xor    %edx,%edx
test   %rax,%rax
cmovne %edx,%ecx
mov    %ecx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.tm = type { i32, i32 }
@__const.sb_get_time.time_2000 = %struct.tm { i32 1, i32 0 }
@EINVAL = global i32 0
define i32 @sb_get_time(i64 %0, %struct.tm* %1) {
%3 = alloca i64
%4 = alloca %struct.tm*
%5 = alloca %struct.tm
%6 = alloca i64
%7 = alloca i64
%8 = alloca %struct.tm*
store i64 %0, i64* %3
store %struct.tm* %1, %struct.tm** %4
%9 = bitcast %struct.tm* %5 to i8*
%10 = call i64 @mktime(%struct.tm* %5)
store i64 %10, i64* %6
%11 = load i64, i64* %6
%12 = load i64, i64* %3
%13 = add nsw i64 %11, %12
store i64 %13, i64* %7
%14 = load %struct.tm*, %struct.tm** %4
%15 = call %struct.tm* @gmtime_r(i64* %7, %struct.tm* %14)
store %struct.tm* %15, %struct.tm** %8
%16 = load %struct.tm*, %struct.tm** %8
%17 = icmp ne %struct.tm* %16, null
br i1 %17, label %18, label %19
18: ; preds = %2
br label %22
19: ; preds = %2
%20 = load i32, i32* @EINVAL
%21 = sub nsw i32 0, %20
br label %22
22: ; preds = %19, %18
%23 = phi i32 [ 0, %18 ], [ %21, %19 ]
ret i32 %23
}

LLVM IR (-O2):
%struct.tm = type { i32, i32 }
@EINVAL = global i32 0
define i32 @sb_get_time(i64 %0, %struct.tm* %1) {
%3 = alloca i64
%4 = bitcast i64* %3 to %struct.tm*
%5 = alloca i64
%6 = bitcast i64* %3 to i8*
store i64 1, i64* %3
%7 = call i64 @mktime(%struct.tm* %4)
%8 = bitcast i64* %5 to i8*
%9 = add nsw i64 %7, %0
store i64 %9, i64* %5
%10 = call %struct.tm* @gmtime_r(i64* %5, %struct.tm* %1)
%11 = icmp eq %struct.tm* %10, null
%12 = load i32, i32* @EINVAL
%13 = sub nsw i32 0, %12
%14 = select i1 %11, i32 %13, i32 0
ret i32 %14
}