#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__ time_t;
struct timeval {
  scalar_t__ tv_sec;
};
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
size_t pretty_time(char *, int, scalar_t__);
int /*<<< orphan*/ strncpy(char *, char *, int);
scalar_t__ time(int /*<<< orphan*/ *);
char *ago(const struct timeval *t) {
  static char buf[1024];
  size_t offset;
  time_t now = time(NULL);
  if (now == t->tv_sec)
    strncpy(buf, "Now", sizeof(buf) - 1);
  else if (now < t->tv_sec)
    strncpy(buf,
            "("
            "\x1b[31m"
            "System clock wound backward; connection problems may ensue."
            "\x1b[0m"
            ")",
            sizeof(buf) - 1);
  else {
    offset = pretty_time(buf, sizeof(buf), now - t->tv_sec);
    strncpy(buf + offset, " ago", sizeof(buf) - offset - 1);
  }
  return buf;
}


x86 assembly (clang, -O0):
<ago>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1040 <time@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x8(%rbp),%rcx
cmp    (%rcx),%rax
jne    1177 <ago+0x47>
lea    0x2eef(%rip),%rdi
lea    0xe98(%rip),%rsi
mov    $0x3ff,%edx
call   1030 <strncpy@plt>
jmp    11f0 <ago+0xc0>
mov    -0x18(%rbp),%rax
mov    -0x8(%rbp),%rcx
cmp    (%rcx),%rax
jge    11a5 <ago+0x75>
lea    0x2ec1(%rip),%rdi
lea    0xe6e(%rip),%rsi
mov    $0x3ff,%edx
call   1030 <strncpy@plt>
jmp    11eb <ago+0xbb>
mov    -0x18(%rbp),%rdx
mov    -0x8(%rbp),%rax
sub    (%rax),%rdx
lea    0x2e99(%rip),%rdi
mov    $0x400,%esi
call   1050 <pretty_time@plt>
mov    %rax,-0x10(%rbp)
lea    0x2e84(%rip),%rdi
add    -0x10(%rbp),%rdi
mov    $0x400,%eax
sub    -0x10(%rbp),%rax
sub    $0x1,%rax
mov    %eax,%edx
lea    0xe65(%rip),%rsi
call   1030 <strncpy@plt>
jmp    11f0 <ago+0xc0>
lea    0x2e59(%rip),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ago>:
push   %rbx
mov    %rdi,%rbx
xor    %edi,%edi
call   1040 <time@plt>
sub    (%rbx),%rax
jne    1155 <ago+0x25>
lea    0x2f09(%rip),%rdi
lea    0xeb2(%rip),%rsi
mov    $0x3ff,%edx
jmp    1197 <ago+0x67>
jge    116c <ago+0x3c>
lea    0x2ef2(%rip),%rdi
lea    0xe9f(%rip),%rsi
mov    $0x3ff,%edx
jmp    1197 <ago+0x67>
lea    0x2edd(%rip),%rbx
mov    %rbx,%rdi
mov    $0x400,%esi
mov    %rax,%rdx
call   1050 <pretty_time@plt>
add    %rax,%rbx
mov    $0x3ff,%edx
sub    %eax,%edx
lea    0xeb7(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strncpy@plt>
lea    0x2ead(%rip),%rax
pop    %rbx
ret

LLVM IR (-O0):
%struct.timeval = type { i64 }
@ago.buf = internal global [1024 x i8] zeroinitializer
@.str = [4 x i8] c"Now\00"
@.str.1 = [71 x i8] c"(\1B[31mSystem clock wound backward; connection problems may ensue.\1B[0m)\00"
@.str.2 = [5 x i8] c" ago\00"
define i8* @ago(%struct.timeval* %0) {
%2 = alloca %struct.timeval*
%3 = alloca i64
%4 = alloca i64
store %struct.timeval* %0, %struct.timeval** %2
%5 = call i64 @time(i32* null)
store i64 %5, i64* %4
%6 = load i64, i64* %4
%7 = load %struct.timeval*, %struct.timeval** %2
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i32 0, i32 0
%9 = load i64, i64* %8
%10 = icmp eq i64 %6, %9
br i1 %10, label %11, label %13
11: ; preds = %1
%12 = call i32 @strncpy(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @ago.buf, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 1023)
br label %36
13: ; preds = %1
%14 = load i64, i64* %4
%15 = load %struct.timeval*, %struct.timeval** %2
%16 = getelementptr inbounds %struct.timeval, %struct.timeval* %15, i32 0, i32 0
%17 = load i64, i64* %16
%18 = icmp slt i64 %14, %17
br i1 %18, label %19, label %21
19: ; preds = %13
%20 = call i32 @strncpy(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @ago.buf, i64 0, i64 0), i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str.1, i64 0, i64 0), i32 1023)
br label %35
21: ; preds = %13
%22 = load i64, i64* %4
%23 = load %struct.timeval*, %struct.timeval** %2
%24 = getelementptr inbounds %struct.timeval, %struct.timeval* %23, i32 0, i32 0
%25 = load i64, i64* %24
%26 = sub nsw i64 %22, %25
%27 = call i64 @pretty_time(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @ago.buf, i64 0, i64 0), i32 1024, i64 %26)
store i64 %27, i64* %3
%28 = load i64, i64* %3
%29 = getelementptr inbounds i8, i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @ago.buf, i64 0, i64 0), i64 %28
%30 = load i64, i64* %3
%31 = sub i64 1024, %30
%32 = sub i64 %31, 1
%33 = trunc i64 %32 to i32
%34 = call i32 @strncpy(i8* %29, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %33)
br label %35
35: ; preds = %21, %19
br label %36
36: ; preds = %35, %11
ret i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @ago.buf, i64 0, i64 0)
}

LLVM IR (-O2):
%struct.timeval = type { i64 }
@ago.buf = internal global [1024 x i8] zeroinitializer
@.str = [4 x i8] c"Now\00"
@.str.1 = [71 x i8] c"(\1B[31mSystem clock wound backward; connection problems may ensue.\1B[0m)\00"
@.str.2 = [5 x i8] c" ago\00"
define i8* @ago(%struct.timeval* nocapture %0) {
%2 = tail call i64 @time(i32* null)
%3 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 0
%4 = load i64, i64* %3
%5 = icmp eq i64 %2, %4
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = tail call i32 @strncpy(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @ago.buf, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 1023)
br label %19
8: ; preds = %1
%9 = icmp slt i64 %2, %4
br i1 %9, label %10, label %12
10: ; preds = %8
%11 = tail call i32 @strncpy(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @ago.buf, i64 0, i64 0), i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str.1, i64 0, i64 0), i32 1023)
br label %19
12: ; preds = %8
%13 = sub nsw i64 %2, %4
%14 = tail call i64 @pretty_time(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @ago.buf, i64 0, i64 0), i32 1024, i64 %13)
%15 = getelementptr inbounds [1024 x i8], [1024 x i8]* @ago.buf, i64 0, i64 %14
%16 = trunc i64 %14 to i32
%17 = sub i32 1023, %16
%18 = tail call i32 @strncpy(i8* %15, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %17)
br label %19
19: ; preds = %10, %12, %6
ret i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @ago.buf, i64 0, i64 0)
}