#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 */
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ sprintf(char *, char *, char *, int, int, int, int, int);
int sstrtotime(char *);
char *sage(char *timestamp1, char *timestamp2) {
  int e1 = sstrtotime(timestamp1);
  int e2 = sstrtotime(timestamp2);
  timestamp1 = (char *)malloc(1024);
  memset(timestamp1, 0, 1024);
  int diff = e1 - e2;
  int negative = diff < 0 ? 1 : 0;
  int sec = 0, min = 0, hour = 0, dd = 0, yy = 0;
  if (negative) {
    diff = -1 * diff;
  }
  sec = diff % 60;
  diff /= 60;
  min = diff % 60;
  diff /= 60;
  hour = diff % 24;
  diff /= 24;
  dd = diff % 365;
  diff /= 365;
  yy = diff;
  sprintf(timestamp1, "%s%d years %d days %d hours %d minutes %d seconds",
          negative ? "-" : "", yy, dd, hour, min, sec);
  return timestamp1;
}


x86 assembly (clang, -O0):
<sage>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <sstrtotime@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <sstrtotime@plt>
mov    %eax,-0x18(%rbp)
mov    $0x400,%edi
call   1050 <malloc@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1040 <memset@plt>
mov    -0x14(%rbp),%eax
sub    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edx
xor    %eax,%eax
mov    $0x1,%ecx
cmp    $0x0,%edx
cmovl  %ecx,%eax
mov    %eax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
cmpl   $0x0,-0x20(%rbp)
je     11d9 <sage+0x99>
imul   $0xffffffff,-0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    $0x3c,%ecx
cltd
idiv   %ecx
mov    %edx,-0x24(%rbp)
mov    -0x1c(%rbp),%eax
mov    $0x3c,%ecx
cltd
idiv   %ecx
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    $0x3c,%ecx
cltd
idiv   %ecx
mov    %edx,-0x28(%rbp)
mov    -0x1c(%rbp),%eax
mov    $0x3c,%ecx
cltd
idiv   %ecx
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    $0x18,%ecx
cltd
idiv   %ecx
mov    %edx,-0x2c(%rbp)
mov    -0x1c(%rbp),%eax
mov    $0x18,%ecx
cltd
idiv   %ecx
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    $0x16d,%ecx
cltd
idiv   %ecx
mov    %edx,-0x30(%rbp)
mov    -0x1c(%rbp),%eax
mov    $0x16d,%ecx
cltd
idiv   %ecx
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%ecx
lea    0xdd6(%rip),%rdx
lea    0xdce(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rdx
mov    -0x34(%rbp),%ecx
mov    -0x30(%rbp),%r8d
mov    -0x2c(%rbp),%r9d
mov    -0x28(%rbp),%r10d
mov    -0x24(%rbp),%eax
lea    0xd7c(%rip),%rsi
mov    %r10d,(%rsp)
mov    %eax,0x8(%rsp)
call   1060 <sprintf@plt>
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sage>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
call   1030 <sstrtotime@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <sstrtotime@plt>
mov    %eax,%ebx
mov    $0x400,%edi
call   1050 <malloc@plt>
mov    %rax,%r14
mov    %rax,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1040 <memset@plt>
sub    %ebx,%ebp
lea    0xeb5(%rip),%rax
lea    0xeaf(%rip),%rdx
cmovs  %rax,%rdx
mov    %ebp,%esi
neg    %esi
cmovs  %ebp,%esi
mov    $0x88888889,%edi
mov    %esi,%eax
mov    $0x91a2b3c5,%r9d
imul   %rsi,%r9
mov    $0xc22e4507,%ebp
imul   %rsi,%rbp
imul   $0x4418a47b,%rsi,%rcx
mov    %rsi,%rbx
imul   %rdi,%rbx
shr    $0x25,%rbx
imul   $0x3c,%ebx,%esi
sub    %esi,%eax
mov    %rbx,%rsi
imul   %rdi,%rsi
shr    $0x25,%rsi
imul   $0x3c,%esi,%esi
sub    %esi,%ebx
shr    $0x2b,%r9
mov    $0xaaaaaaab,%esi
imul   %r9,%rsi
shr    $0x24,%rsi
shl    $0x3,%esi
lea    (%rsi,%rsi,2),%esi
sub    %esi,%r9d
shr    $0x30,%rbp
imul   $0xb38d,%ebp,%esi
shr    $0x18,%esi
imul   $0x16d,%esi,%esi
sub    %esi,%ebp
movzwl %bp,%r8d
shr    $0x37,%rcx
lea    0xdf2(%rip),%rsi
mov    %r14,%rdi
push   %rax
push   %rbx
call   1060 <sprintf@plt>
add    $0x10,%rsp
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [50 x i8] c"%s%d years %d days %d hours %d minutes %d seconds\00"
@.str.1 = [2 x i8] c"-\00"
@.str.2 = [1 x i8] zeroinitializer
define i8* @sage(i8* %0, i8* %1) {
%3 = alloca i8*
%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
%13 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%14 = load i8*, i8** %3
%15 = call i32 @sstrtotime(i8* %14)
store i32 %15, i32* %5
%16 = load i8*, i8** %4
%17 = call i32 @sstrtotime(i8* %16)
store i32 %17, i32* %6
%18 = call i64 @malloc(i32 1024)
%19 = inttoptr i64 %18 to i8*
store i8* %19, i8** %3
%20 = load i8*, i8** %3
%21 = call i32 @memset(i8* %20, i32 0, i32 1024)
%22 = load i32, i32* %5
%23 = load i32, i32* %6
%24 = sub nsw i32 %22, %23
store i32 %24, i32* %7
%25 = load i32, i32* %7
%26 = icmp slt i32 %25, 0
%27 = zext i1 %26 to i64
%28 = select i1 %26, i32 1, i32 0
store i32 %28, i32* %8
store i32 0, i32* %9
store i32 0, i32* %10
store i32 0, i32* %11
store i32 0, i32* %12
store i32 0, i32* %13
%29 = load i32, i32* %8
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %34
31: ; preds = %2
%32 = load i32, i32* %7
%33 = mul nsw i32 -1, %32
store i32 %33, i32* %7
br label %34
34: ; preds = %31, %2
%35 = load i32, i32* %7
%36 = srem i32 %35, 60
store i32 %36, i32* %9
%37 = load i32, i32* %7
%38 = sdiv i32 %37, 60
store i32 %38, i32* %7
%39 = load i32, i32* %7
%40 = srem i32 %39, 60
store i32 %40, i32* %10
%41 = load i32, i32* %7
%42 = sdiv i32 %41, 60
store i32 %42, i32* %7
%43 = load i32, i32* %7
%44 = srem i32 %43, 24
store i32 %44, i32* %11
%45 = load i32, i32* %7
%46 = sdiv i32 %45, 24
store i32 %46, i32* %7
%47 = load i32, i32* %7
%48 = srem i32 %47, 365
store i32 %48, i32* %12
%49 = load i32, i32* %7
%50 = sdiv i32 %49, 365
store i32 %50, i32* %7
%51 = load i32, i32* %7
store i32 %51, i32* %13
%52 = load i8*, i8** %3
%53 = load i32, i32* %8
%54 = icmp ne i32 %53, 0
%55 = zext i1 %54 to i64
%56 = select i1 %54, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0)
%57 = load i32, i32* %13
%58 = load i32, i32* %12
%59 = load i32, i32* %11
%60 = load i32, i32* %10
%61 = load i32, i32* %9
%62 = call i32 @sprintf(i8* %52, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0), i8* %56, i32 %57, i32 %58, i32 %59, i32 %60, i32 %61)
%63 = load i8*, i8** %3
ret i8* %63
}

LLVM IR (-O2):
@.str = [50 x i8] c"%s%d years %d days %d hours %d minutes %d seconds\00"
@.str.1 = [2 x i8] c"-\00"
@.str.2 = [1 x i8] zeroinitializer
define i8* @sage(i8* %0, i8* %1) {
%3 = tail call i32 @sstrtotime(i8* %0)
%4 = tail call i32 @sstrtotime(i8* %1)
%5 = tail call i64 @malloc(i32 1024)
%6 = inttoptr i64 %5 to i8*
%7 = tail call i32 @memset(i8* %6, i32 0, i32 1024)
%8 = sub nsw i32 %3, %4
%9 = icmp slt i32 %8, 0
%10 = sub nsw i32 0, %8
%11 = select i1 %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0)
%12 = select i1 %9, i32 %10, i32 %8
%13 = urem i32 %12, 60
%14 = udiv i32 %12, 60
%15 = urem i32 %14, 60
%16 = udiv i32 %12, 3600
%17 = urem i32 %16, 24
%18 = udiv i32 %12, 86400
%19 = trunc i32 %18 to i16
%20 = urem i16 %19, 365
%21 = zext i16 %20 to i32
%22 = udiv i32 %12, 31536000
%23 = tail call i32 @sprintf(i8* dereferenceable(1) %6, i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0), i8* %11, i32 %22, i32 %21, i32 %17, i32 %15, i32 %13)
ret i8* %6
}