#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 /*<<< orphan*/ uint32_t;
typedef int /*<<< orphan*/ time_t;
struct tm {
  int dummy;
};
typedef int int32_t;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ OS_conv_datenum(int, int, int, int);
int conv_date(int *, char *);
struct tm *gmtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, int /*<<< orphan*/, int, int,
                          int /*<<< orphan*/);
int /*<<< orphan*/ strftime(char *, int, char *, struct tm *);
int32_t OS_conv_unixtime(int32_t *secondsp, time_t timestamp) {
  struct tm t;
  int32_t datenum;
  uint32_t checktime;
  char buf[64];
  t = *gmtime(&timestamp);
  strftime(buf, sizeof(buf), "%Y-%m-%dT%H:%M:%SZ", &t);
  datenum = conv_date(secondsp, buf);
  if ((checktime = OS_conv_datenum(datenum, *secondsp / 3600,
                                   (*secondsp % 3600) / 60, *secondsp % 60)) !=
      timestamp) {
    printf("error: timestamp.%lu -> (%d + %d) -> %u\n", timestamp, datenum,
           *secondsp, checktime);
    return (-1);
  }
  return (datenum);
}


x86 assembly (clang, -O0):
<OS_conv_unixtime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
lea    -0x14(%rbp),%rdi
call   1070 <gmtime@plt>
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
lea    -0x60(%rbp),%rdi
mov    $0x40,%esi
lea    0xe83(%rip),%rdx
lea    -0x18(%rbp),%rcx
call   1060 <strftime@plt>
mov    -0x10(%rbp),%rdi
lea    -0x60(%rbp),%rsi
call   1030 <conv_date@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    $0xe10,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    $0xe10,%ecx
cltd
idiv   %ecx
mov    %edx,%eax
mov    $0x3c,%ecx
cltd
idiv   %ecx
mov    %eax,-0x64(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    $0x3c,%ecx
cltd
idiv   %ecx
mov    %edx,%ecx
mov    -0x64(%rbp),%edx
call   1050 <OS_conv_datenum@plt>
mov    %eax,-0x20(%rbp)
cmp    -0x14(%rbp),%eax
je     1210 <OS_conv_unixtime+0xc0>
mov    -0x14(%rbp),%esi
mov    -0x1c(%rbp),%edx
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
mov    -0x20(%rbp),%r8d
lea    0xe14(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1216 <OS_conv_unixtime+0xc6>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<OS_conv_unixtime>:
push   %rbp
push   %rbx
sub    $0x58,%rsp
mov    %rdi,%rbx
mov    %esi,0x4(%rsp)
lea    0x4(%rsp),%rdi
call   1070 <gmtime@plt>
mov    (%rax),%eax
mov    %eax,0x8(%rsp)
lea    0xe8c(%rip),%rdx
lea    0x10(%rsp),%rbp
lea    0x8(%rsp),%rcx
mov    %rbp,%rdi
mov    $0x40,%esi
call   1060 <strftime@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1030 <conv_date@plt>
mov    %eax,%ebp
movslq (%rbx),%rcx
imul   $0xffffffff91a2b3c5,%rcx,%rsi
shr    $0x20,%rsi
add    %ecx,%esi
mov    %esi,%eax
shr    $0x1f,%eax
sar    $0xb,%esi
add    %eax,%esi
imul   $0xe10,%esi,%eax
mov    %ecx,%edx
sub    %eax,%edx
movswl %dx,%eax
imul   $0xffff8889,%eax,%eax
shr    $0x10,%eax
add    %edx,%eax
movzwl %ax,%eax
movswl %ax,%edx
shr    $0xf,%eax
sar    $0x5,%edx
add    %eax,%edx
movswl %dx,%edx
imul   $0xffffffff88888889,%rcx,%rax
shr    $0x20,%rax
add    %ecx,%eax
mov    %eax,%edi
shr    $0x1f,%edi
sar    $0x5,%eax
add    %edi,%eax
imul   $0x3c,%eax,%eax
sub    %eax,%ecx
mov    %ebp,%edi
call   1050 <OS_conv_datenum@plt>
mov    0x4(%rsp),%esi
cmp    %esi,%eax
je     121e <OS_conv_unixtime+0xce>
mov    (%rbx),%ecx
lea    0xe04(%rip),%rdi
mov    %ebp,%edx
mov    %eax,%r8d
call   1040 <printf@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x58,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.tm = type { i32 }
@.str = [19 x i8] c"%Y-%m-%dT%H:%M:%SZ\00"
@.str.1 = [41 x i8] c"error: timestamp.%lu -> (%d + %d) -> %u\0A\00"
define i32 @OS_conv_unixtime(i32* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
%6 = alloca %struct.tm
%7 = alloca i32
%8 = alloca i32
%9 = alloca [64 x i8]
store i32* %0, i32** %4
store i32 %1, i32* %5
%10 = call %struct.tm* @gmtime(i32* %5)
%11 = bitcast %struct.tm* %6 to i8*
%12 = bitcast %struct.tm* %10 to i8*
%13 = getelementptr inbounds [64 x i8], [64 x i8]* %9, i64 0, i64 0
%14 = call i32 @strftime(i8* %13, i32 64, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), %struct.tm* %6)
%15 = load i32*, i32** %4
%16 = getelementptr inbounds [64 x i8], [64 x i8]* %9, i64 0, i64 0
%17 = call i32 @conv_date(i32* %15, i8* %16)
store i32 %17, i32* %7
%18 = load i32, i32* %7
%19 = load i32*, i32** %4
%20 = load i32, i32* %19
%21 = sdiv i32 %20, 3600
%22 = load i32*, i32** %4
%23 = load i32, i32* %22
%24 = srem i32 %23, 3600
%25 = sdiv i32 %24, 60
%26 = load i32*, i32** %4
%27 = load i32, i32* %26
%28 = srem i32 %27, 60
%29 = call i32 @OS_conv_datenum(i32 %18, i32 %21, i32 %25, i32 %28)
store i32 %29, i32* %8
%30 = load i32, i32* %5
%31 = icmp ne i32 %29, %30
br i1 %31, label %32, label %39
32: ; preds = %2
%33 = load i32, i32* %5
%34 = load i32, i32* %7
%35 = load i32*, i32** %4
%36 = load i32, i32* %35
%37 = load i32, i32* %8
%38 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i32 %33, i32 %34, i32 %36, i32 %37)
store i32 -1, i32* %3
br label %41
39: ; preds = %2
%40 = load i32, i32* %7
store i32 %40, i32* %3
br label %41
41: ; preds = %39, %32
%42 = load i32, i32* %3
ret i32 %42
}

LLVM IR (-O2):
%struct.tm = type { i32 }
@.str = [19 x i8] c"%Y-%m-%dT%H:%M:%SZ\00"
@.str.1 = [41 x i8] c"error: timestamp.%lu -> (%d + %d) -> %u\0A\00"
define i32 @OS_conv_unixtime(i32* %0, i32 %1) {
%3 = alloca i32
%4 = alloca %struct.tm
%5 = alloca [64 x i8]
store i32 %1, i32* %3
%6 = bitcast %struct.tm* %4 to i8*
%7 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%8 = call %struct.tm* @gmtime(i32* %3)
%9 = getelementptr %struct.tm, %struct.tm* %8, i64 0, i32 0
%10 = getelementptr inbounds %struct.tm, %struct.tm* %4, i64 0, i32 0
%11 = load i32, i32* %9
store i32 %11, i32* %10
%12 = call i32 @strftime(i8* %7, i32 64, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), %struct.tm* %4)
%13 = call i32 @conv_date(i32* %0, i8* %7)
%14 = load i32, i32* %0
%15 = sdiv i32 %14, 3600
%16 = srem i32 %14, 3600
%17 = trunc i32 %16 to i16
%18 = sdiv i16 %17, 60
%19 = sext i16 %18 to i32
%20 = srem i32 %14, 60
%21 = call i32 @OS_conv_datenum(i32 %13, i32 %15, i32 %19, i32 %20)
%22 = load i32, i32* %3
%23 = icmp eq i32 %21, %22
br i1 %23, label %27, label %24
24: ; preds = %2
%25 = load i32, i32* %0
%26 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i32 %22, i32 %13, i32 %25, i32 %21)
br label %27
27: ; preds = %2, %24
%28 = phi i32 [ -1, %24 ], [ %13, %2 ]
ret i32 %28
}