#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 */

/* Variables and functions */
int /*<<< orphan*/ calendar_date(int, int *, int *, int *);
int /*<<< orphan*/ sprintf(char *, char *, int, int, int, int, int, int);
void write_time_string(char *timestr, int jul, int secs) {
  int ss, min, hh, dd, mm, yy;
  hh = secs / 3600;
  min = (secs - hh * 3600) / 60;
  ss = secs - 3600 * hh - 60 * min;
  calendar_date(jul, &yy, &mm, &dd);
  sprintf(timestr, "%04d-%02d-%02d %02d:%02d:%02d", yy, mm, dd, hh, min, ss);
}


x86 assembly (clang, -O0):
<write_time_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    $0xe10,%ecx
cltd
idiv   %ecx
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%eax
imul   $0xe10,-0x1c(%rbp),%ecx
sub    %ecx,%eax
mov    $0x3c,%ecx
cltd
idiv   %ecx
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%eax
imul   $0xe10,-0x1c(%rbp),%ecx
sub    %ecx,%eax
imul   $0x3c,-0x18(%rbp),%ecx
sub    %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x28(%rbp),%rsi
lea    -0x24(%rbp),%rdx
lea    -0x20(%rbp),%rcx
call   1030 <calendar_date@plt>
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%edx
mov    -0x24(%rbp),%ecx
mov    -0x20(%rbp),%r8d
mov    -0x1c(%rbp),%r9d
mov    -0x18(%rbp),%r10d
mov    -0x14(%rbp),%eax
lea    0xe60(%rip),%rsi
mov    %r10d,(%rsp)
mov    %eax,0x8(%rsp)
call   1040 <sprintf@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_time_string>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %esi,%eax
mov    %rdi,%r14
movslq %edx,%rcx
imul   $0xffffffff91a2b3c5,%rcx,%r15
shr    $0x20,%r15
add    %ecx,%r15d
mov    %r15d,%edx
shr    $0x1f,%edx
sar    $0xb,%r15d
add    %edx,%r15d
imul   $0xfffff1f0,%r15d,%edx
add    %ecx,%edx
movslq %edx,%rcx
imul   $0xffffffff88888889,%rcx,%rbx
shr    $0x20,%rbx
add    %ecx,%ebx
mov    %ebx,%edx
shr    $0x1f,%edx
sar    $0x5,%ebx
add    %edx,%ebx
imul   $0xffffffc4,%ebx,%r12d
add    %ecx,%r12d
lea    0xc(%rsp),%rsi
lea    0x10(%rsp),%rdx
lea    0x14(%rsp),%rcx
mov    %eax,%edi
call   1030 <calendar_date@plt>
mov    0xc(%rsp),%edx
mov    0x10(%rsp),%ecx
mov    0x14(%rsp),%r8d
lea    0xe5e(%rip),%rsi
mov    %r14,%rdi
mov    %r15d,%r9d
push   %r12
push   %rbx
call   1040 <sprintf@plt>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [30 x i8] c"%04d-%02d-%02d %02d:%02d:%02d\00"
define void @write_time_string(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%13 = load i32, i32* %6
%14 = sdiv i32 %13, 3600
store i32 %14, i32* %9
%15 = load i32, i32* %6
%16 = load i32, i32* %9
%17 = mul nsw i32 %16, 3600
%18 = sub nsw i32 %15, %17
%19 = sdiv i32 %18, 60
store i32 %19, i32* %8
%20 = load i32, i32* %6
%21 = load i32, i32* %9
%22 = mul nsw i32 3600, %21
%23 = sub nsw i32 %20, %22
%24 = load i32, i32* %8
%25 = mul nsw i32 60, %24
%26 = sub nsw i32 %23, %25
store i32 %26, i32* %7
%27 = load i32, i32* %5
%28 = call i32 @calendar_date(i32 %27, i32* %12, i32* %11, i32* %10)
%29 = load i8*, i8** %4
%30 = load i32, i32* %12
%31 = load i32, i32* %11
%32 = load i32, i32* %10
%33 = load i32, i32* %9
%34 = load i32, i32* %8
%35 = load i32, i32* %7
%36 = call i32 @sprintf(i8* %29, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 %30, i32 %31, i32 %32, i32 %33, i32 %34, i32 %35)
ret void
}

LLVM IR (-O2):
@.str = [30 x i8] c"%04d-%02d-%02d %02d:%02d:%02d\00"
define void @write_time_string(i8* nocapture writeonly %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = bitcast i32* %4 to i8*
%8 = bitcast i32* %5 to i8*
%9 = bitcast i32* %6 to i8*
%10 = sdiv i32 %2, 3600
%11 = mul nsw i32 %10, -3600
%12 = add i32 %11, %2
%13 = sdiv i32 %12, 60
%14 = mul nsw i32 %13, -60
%15 = add i32 %14, %12
%16 = call i32 @calendar_date(i32 %1, i32* %6, i32* %5, i32* %4)
%17 = load i32, i32* %6
%18 = load i32, i32* %5
%19 = load i32, i32* %4
%20 = call i32 @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 %17, i32 %18, i32 %19, i32 %10, i32 %13, i32 %15)
ret void
}